• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nasa / trick / 20283694683

16 Dec 2025 09:44PM UTC coverage: 55.586% (-0.3%) from 55.934%
20283694683

push

github

web-flow
Add vs support for stl vector, deque, and array containers of supported data types (#1996)

* Added TV GUI side support for vectors

* Initial check-in for variable server to support vector.

* Added accessor functions to ATTRIBUTES to get stl container size and element at index so mm ref_dim can get element at index for a vector as getting element of an array plus bounds check for vector.

* Added support to deque and array as they be treated similar to vector.

* Updated the test due to vs vector support change.

* Added vector/deque/array of TRICK_STRUCTURED data type support.

* Updated to support vector<bool>.

* Updated to support vector/deque/array of *.

* Updated to support vector/deque/array of TRICK_ENUMERATED and display enum name for the stl enum elements for TV; also updated to show bool element as normal bool var for TV.

* Made elements of vector/array/deque to be editable from TV.

* Not to change the stl type to element when not indexing.

* Added special handling for updating vector of bool since std::vector<bool> is optimized to store bits compactly (8 bools per byte) in c++.

* Need to print NULL for the newly added ATTRIBUTES assessor function for filed attributes in io src file.

* Added var_get_stl_size command to vs sesssion and updated tv to show index range as constraint arrays for vector/deque/array when adding a var.

* Added test cases for vector/deque/array and also changed to use its own vs msg type for var_get_stl_size.

* Removed the unused function as it was changed to use clang api instead.

* Updated not to use static temp attr for working on storing vector<boo> to its ref_attr.

---------

Co-authored-by: plherrin <pherring04@gmail.com>

46 of 212 new or added lines in 8 files covered. (21.7%)

2 existing lines in 2 files now uncovered.

12508 of 22502 relevant lines covered (55.59%)

304713.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

16.67
/trick_source/sim_services/VariableServer/var_server_ext.cpp
1

2
#include <iostream>
3
#include <string.h>
4

5
#include "trick/VariableServer.hh"
6
#include "trick/exec_proto.h"
7
#include "trick/message_proto.h"
8
#include "trick/message_type.h"
9
#include "trick/memorymanager_c_intf.h"
10
#include "trick/map_trick_units_to_udunits.hh"
11

12
extern Trick::VariableServer * the_vs ;
13

14
Trick::VariableServerSessionThread * get_vst() {
×
15
    return the_vs->get_vst(pthread_self()) ;
×
16
}
17

18
Trick::VariableServerSession * get_session() {
1,030✔
19
    return the_vs->get_session(pthread_self()) ;
1,030✔
20
}
21

22
int var_add(std::string in_name) {
×
23
    Trick::VariableServerSession * session = get_session();
×
24
    
25
    if (session != NULL ) {
×
26
        session->var_add(in_name) ;
×
27
    }
28
    return(0) ;
×
29
}
30

31
int var_add(std::string in_name, std::string in_units) {
×
32
    Trick::VariableServerSession * session = get_session();
×
33
    
34
    if (session != NULL ) {
×
35
        session->var_add(in_name, in_units) ;
×
36
    }
37
    return(0) ;
×
38
}
39

40
int var_remove(std::string in_name) {
×
41
    Trick::VariableServerSession * session = get_session();
×
42
    
43
    if (session != NULL ) {
×
44
        session->var_remove(in_name) ;
×
45
    }
46
    return(0) ;
×
47
}
48

49
int var_units(std::string var_name , std::string units_name) {
×
50
    Trick::VariableServerSession * session = get_session();
×
51
    
52
    if (session != NULL ) {
×
53
        session->var_units(var_name , units_name) ;
×
54
    }
55
    return(0) ;
×
56
}
57

58
int var_exists(std::string in_name) {
×
59
    Trick::VariableServerSession * session = get_session();
×
60
    
61
    if (session != NULL ) {
×
62
        session->var_exists(in_name) ;
×
63
    }
64
    return(0) ;
×
65
}
66

NEW
67
int var_get_stl_size(std::string in_name)
×
68
{
NEW
69
    Trick::VariableServerSession *session = get_session();
×
70

NEW
71
    if (session != NULL)
×
72
    {
NEW
73
        session->var_get_stl_size(in_name);
×
74
    }
NEW
75
    return (0);
×
76
}
77

78
int var_send_once(std::string in_name) {
×
79
    Trick::VariableServerSession * session = get_session();
×
80
    
81
    if (session != NULL ) {
×
82
        session->var_send_once(in_name, 1) ;
×
83
    }
84
    return(0) ;
×
85
}
86

87
int var_send_once(std::string in_name, int num) {
×
88
    Trick::VariableServerSession * session = get_session();
×
89
    
90
    if (session != NULL ) {
×
91
        session->var_send_once(in_name, num) ;
×
92
    }
93
    return(0) ;
×
94
}
95

96
int var_send() {
×
97
    Trick::VariableServerSession * session = get_session();
×
98
    
99
    if (session != NULL ) {
×
100
        session->var_send() ;
×
101
    }
102
    return(0) ;
×
103
}
104

105
int var_clear() {
×
106
    Trick::VariableServerSession * session = get_session();
×
107
    
108
    if (session != NULL ) {
×
109
        session->var_clear() ;
×
110
    }
111

112
    // std::cout << "Done with var_clear" << std::endl;
113
    return(0) ;
×
114
}
115

116
int var_cycle(double in_rate) {
×
117
    Trick::VariableServerSession * session = get_session();
×
118
    
119
    if (session != NULL ) {
×
120
        session->var_cycle(in_rate) ;
×
121
    }
122
    return(0) ;
×
123
}
124

125
int var_pause() {
×
126
    Trick::VariableServerSession * session = get_session();
×
127
    
128
    if (session != NULL ) {
×
129
        session->set_pause(true) ;
×
130
    }
131
    return(0) ;
×
132

133
}
134

135
int var_unpause() {
×
136
    Trick::VariableServerSession * session = get_session();
×
137
    
138
    if (session != NULL ) {
×
139
        session->set_pause(false) ;
×
140
    }
141
    return(0) ;
×
142

143
}
144

145
int var_exit() {
×
146
    Trick::VariableServerSession * session = get_session();
×
147
    
148
    if (session != NULL ) {
×
149
        session->var_exit() ;
×
150
    }
151
    return(0) ;
×
152
}
153

154
int var_validate_address(int on_off) {
×
155
    Trick::VariableServerSession * session = get_session();
×
156
    
157
    if (session != NULL ) {
×
158
        session->var_validate_address((bool)on_off) ;
×
159
    }
160
    return(0) ;
×
161
}
162

163
int var_debug(int level) {
×
164
    Trick::VariableServerSession * session = get_session();
×
165
    
166
    if (session != NULL ) {
×
167
        session->var_debug(level) ;
×
168
    }
169
    return(0) ;
×
170
}
171

172
int var_ascii() {
×
173
    Trick::VariableServerSession * session = get_session();
×
174
    
175
    if (session != NULL ) {
×
176
        session->var_ascii() ;
×
177
    }
178
    return(0) ;
×
179
}
180

181
int var_binary() {
×
182
    Trick::VariableServerSession * session = get_session();
×
183
    
184
    if (session != NULL ) {
×
185
        session->var_binary() ;
×
186
    }
187
    return(0) ;
×
188
}
189

190
int var_retry_bad_ref() {
×
191
    message_publish(MSG_WARNING,"var_retry_bad_ref has been deprecated\n") ;
×
192
    return(0) ;
×
193
}
194

195
int var_binary_nonames() {
×
196
    Trick::VariableServerSession * session  = get_session();
×
197
    
198
    if (session != NULL ) {
×
199
        session->var_binary_nonames() ;
×
200
    }
201
    return(0) ;
×
202
}
203

204
int var_set_copy_mode(int mode) {
×
205
    Trick::VariableServerSession * session = get_session();
×
206
    
207
    if (session != NULL ) {
×
208
        session->var_set_copy_mode(mode) ;
×
209
        if ( mode == VS_COPY_SCHEDULED ) {
×
210
            the_vs->get_next_sync_call_time() ;
×
211
            the_vs->get_next_freeze_call_time() ;
×
212
        }
213
    }
214
    return 0 ;
×
215
}
216

217
int var_set_write_mode(int mode) {
×
218
Trick::VariableServerSession * session = get_session();
×
219
    if (session != NULL ) {
×
220
        session->var_set_write_mode(mode) ;
×
221
    }
222
    return 0 ;
×
223
}
224

225
int var_set_send_stdio(int mode) {
×
226
Trick::VariableServerSession * session = get_session();
×
227
    if (session != NULL ) {
×
228
        session->set_send_stdio((bool)mode) ;
×
229
    }
230
    return 0 ;
×
231
}
232

233
int var_sync(int mode) {
×
234
Trick::VariableServerSession * session = get_session();
×
235
    if (session != NULL ) {
×
236
        session->var_sync(mode) ;
×
237
        if ( mode ) {
×
238
            the_vs->get_next_sync_call_time() ;
×
239
            the_vs->get_next_freeze_call_time() ;
×
240
        }
241
    }
242
    return(0) ;
×
243
}
244

245
int var_set_frame_multiple(unsigned int mult) {
×
246
Trick::VariableServerSession * session = get_session();
×
247
    if (session != NULL ) {
×
248
        session->var_set_frame_multiple(mult) ;
×
249
    }
250
    return 0 ;
×
251
}
252

253
int var_set_frame_offset(unsigned int offset) {
×
254
Trick::VariableServerSession * session = get_session();
×
255
    if (session != NULL ) {
×
256
        session->var_set_frame_offset(offset) ;
×
257
    }
258
    return 0 ;
×
259
}
260

261
int var_set_freeze_frame_multiple(unsigned int mult) {
×
262
Trick::VariableServerSession * session = get_session();
×
263
    if (session != NULL ) {
×
264
        session->var_set_freeze_frame_multiple(mult) ;
×
265
    }
266
    return 0 ;
×
267
}
268

269
int var_set_freeze_frame_offset(unsigned int offset) {
×
270
Trick::VariableServerSession * session = get_session();
×
271
    if (session != NULL ) {
×
272
        session->var_set_freeze_frame_offset(offset) ;
×
273
    }
274
    return 0 ;
×
275
}
276

277
int var_byteswap(bool on_off) {
×
278
Trick::VariableServerSession * session = get_session();
×
279
    if (session != NULL ) {
×
280
        session->var_byteswap(on_off) ;
×
281
    }
282
    return(0) ;
×
283
}
284

285
int var_write_stdio(int stream , std::string text ) {
1,030✔
286
    // std::cout << "Executing var_write_stdio" << std::endl;
287
    Trick::VariableServerSession * session = get_session();
1,030✔
288
    if (session != NULL and session->get_send_stdio() == true) {
1,030✔
289
        session->write_stdio(stream, text) ;
×
290
    } else {
291
        if ( stream == 1 ) {
1,030✔
292
            fprintf( stdout , "%s" , text.c_str() ) ;
1,008✔
293
        } else {
294
            fprintf( stderr , "%s" , text.c_str() ) ;
22✔
295
        }
296
    }
297
    return(0) ;
1,030✔
298
}
299

300
int var_set_client_tag( std::string text ) {
×
301
    Trick::VariableServerSessionThread * vst = get_vst();
×
302
    if (vst != NULL) {
×
303

304
        vst->set_client_tag(text);
×
305
        
306
#if __linux__
307
#ifdef __GNUC__
308
#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 2
309
        std::string short_str = std::string("VS_") + text.substr(0,12) ;
×
310
        pthread_setname_np(pthread_self(), short_str.c_str()) ;
×
311
#endif
312
#endif
313
#endif
314
    }
315
    return(0) ;
×
316
}
317

318
int var_send_list_size() {
×
319

320
    Trick::VariableServerSession * session = get_session();
×
321
    if (session != NULL ) {
×
322
        session->send_list_size() ;
×
323
    }
324
    return(0) ;
×
325
}
326

327
int send_sie_resource() {
×
328
Trick::VariableServerSession * session = get_session();
×
329
    if (session != NULL ) {
×
330
        session->send_sie_resource() ;
×
331
    }
332
    return 0 ;
×
333
}
334

335
int send_sie_class() {
×
336
Trick::VariableServerSession * session = get_session();
×
337
    if (session != NULL ) {
×
338
        session->send_sie_class() ;
×
339
    }
340
    return 0 ;
×
341
}
342

343
int send_sie_enum() {
×
344
Trick::VariableServerSession * session = get_session();
×
345
    if (session != NULL ) {
×
346
        session->send_sie_enum() ;
×
347
    }
348
    return 0 ;
×
349
}
350

351
int send_sie_top_level_objects() {
×
352
Trick::VariableServerSession * session = get_session();
×
353
    if (session != NULL ) {
×
354
        return session->send_sie_top_level_objects() ;
×
355
    }
356
    return 0 ;
×
357
}
358

359
int send_file(std::string file_name) {
×
360
Trick::VariableServerSession * session = get_session();
×
361
    if (session != NULL ) {
×
362
        return session->send_file(file_name) ;
×
363
    }
364
    return 0 ;
×
365
}
366

367

368
// Command to turn on log to playback file
369
int var_server_log_on() {
×
370
Trick::VariableServerSession * session = get_session();
×
371
    if (session != NULL ) {
×
372
        return session->set_log(true) ;
×
373
    }
374
    return 0 ;
×
375
}
376

377
// Command to turn off log to playback file
378
int var_server_log_off() {
×
379
Trick::VariableServerSession * session = get_session();
×
380
    if (session != NULL ) {
×
381
        return session->set_log(false) ;
×
382
    }
383
    return 0 ;
×
384
}
385

386
// Command to turn on log to playback file
387
int var_server_session_log_on() {
×
388
Trick::VariableServerSession * session = get_session();
×
389
    if (session != NULL ) {
×
390
        return session->set_session_log(true) ;
×
391
    }
392
    return 0 ;
×
393
}
394

395
// Command to turn off log to playback file
396
int var_server_session_log_off() {
×
397
Trick::VariableServerSession * session = get_session();
×
398
    if (session != NULL ) {
×
399
        return session->set_session_log(false) ;
×
400
    }
401
    return 0 ;
×
402
}
403

404
Trick::VariableServer * var_server_get_var_server() {
×
405
    return the_vs ;
×
406
}
407

408
extern "C" void var_server_list_connections(void) {
×
409
    std::cout << *the_vs << std::endl;
×
410
}
×
411

412
/**
413
 * @relates Trick::VariableServer
414
 * @copydoc Trick::VariableServer::get_hostname
415
 * C wrapper Trick::VariableServer::get_hostname
416
 */
417
extern "C" const char * var_server_get_hostname(void) {
×
418
    const char * ret = (the_vs->get_hostname()) ;
×
419
    return ret;
×
420
}
421

422
/**
423
 * @relates Trick::VariableServer
424
 * @copydoc Trick::VariableServer::get_port
425
 * C wrapper Trick::VariableServer::get_port
426
 */
427
extern "C" unsigned short var_server_get_port(void) {
1✔
428
    return(the_vs->get_listen_thread().get_port()) ;
1✔
429
}
430

431
/**
432
 * @relates Trick::VariableServer
433
 * @copydoc Trick::VariableServer::set_port
434
 * C wrapper Trick::VariableServer::set_port
435
 */
436
extern "C" void var_server_set_port(unsigned short port) {
×
437
    the_vs->get_listen_thread().set_port(port);
×
438
}
×
439

440
/**
441
 * @relates Trick::VariableServer
442
 * @copydoc Trick::VariableServer::set_listen_socket
443
 * C wrapper Trick::VariableServer::set_listen_socket
444
 */
445
extern "C" void var_server_set_source_address(const char * source_address) {
×
446
    the_vs->get_listen_thread().set_source_address(source_address) ;
×
447
}
×
448

449
/**
450
 * @relates Trick::VariableServer
451
 * @copydoc Trick::VariableServer::get_user_tag
452
 * C wrapper Trick::VariableServer::get_user_tag
453
 */
454
extern "C" const char * var_server_get_user_tag(void) {
×
455
    return(the_vs->get_listen_thread().get_user_tag_ref().c_str()) ;
×
456
}
457

458
/**
459
 * @relates Trick::VariableServer
460
 * @copydoc Trick::VariableServer::set_user_tag
461
 * C wrapper Trick::VariableServer::set_user_tag
462
 */
463
extern "C" void var_server_set_user_tag(const char * in_tag) {
×
464
    the_vs->get_listen_thread().set_user_tag(std::string(in_tag));
×
465
}
×
466

467
/**
468
 * @relates Trick::VariableServer
469
 * @copydoc Trick::VariableServer::get_enabled
470
 * C wrapper Trick::VariableServer::get_enabled
471
 */
472
extern "C" int var_server_get_enabled(void) {
×
473
    return(the_vs->get_enabled()) ;
×
474
}
475

476
/**
477
 * @relates Trick::VariableServer
478
 * @copydoc Trick::VariableServer::set_enabled
479
 * C wrapper Trick::VariableServer::set_enabled
480
 */
481
extern "C" void var_server_set_enabled(int on_off) {
×
482
    the_vs->set_enabled((bool)on_off) ;
×
483
}
×
484

485
/**
486
 * @relates Trick::VariableServer
487
 * @copydoc Trick::VariableServer::create_udp_socket
488
 * C wrapper Trick::VariableServer::create_udp_socket
489
 */
490
extern "C" int var_server_create_tcp_socket(const char * source_address, unsigned short port) {
×
491
    the_vs->create_tcp_socket(source_address, port) ;
×
492
    return 0 ;
×
493
}
494

495
/**
496
 * @relates Trick::VariableServer
497
 * @copydoc Trick::VariableServer::create_udp_socket
498
 * C wrapper Trick::VariableServer::create_udp_socket
499
 */
500
extern "C" int var_server_create_udp_socket(const char * source_address, unsigned short port) {
×
501
    the_vs->create_udp_socket(source_address, port) ;
×
502
    return 0 ;
×
503
}
504

505
/**
506
 * @relates Trick::VariableServer
507
 * @copydoc Trick::VariableServer::create_multicast_socket
508
 * C wrapper Trick::VariableServer::create_multicast_socket
509
 */
510
extern "C" int var_server_create_multicast_socket(const char * mcast_address,
×
511
 const char * source_address, unsigned short port) {
512
    return the_vs->create_multicast_socket(mcast_address, source_address, port) ;
×
513
}
514

515
template<class T>
516
void var_set_value( V_DATA & v_data , T value ) ;
517

518
template<>
519
void var_set_value< double > ( V_DATA & v_data , double value ) {
2✔
520
    v_data.value.d = value ;
2✔
521
    v_data.type = TRICK_DOUBLE ;
2✔
522
}
2✔
523

524
template<>
525
void var_set_value< long long > ( V_DATA & v_data , long long value ) {
1✔
526
    v_data.value.ll = value ;
1✔
527
    v_data.type = TRICK_LONG_LONG ;
1✔
528
}
1✔
529

530
template<>
531
void var_set_value< const char * > ( V_DATA & v_data , const char * value ) {
1✔
532
    v_data.value.cp = (char *)value ;
1✔
533
    v_data.type = TRICK_STRING ;
1✔
534
}
1✔
535

536
template<>
537
void var_set_value< void * > ( V_DATA & v_data , void * value ) {
1✔
538
    v_data.value.vp = value ;
1✔
539
    v_data.type = TRICK_VOID_PTR ;
1✔
540
}
1✔
541

542
template<class T>
543
int var_set_base( const char  * var , T value , const char * units ) {
5✔
544
    REF2 *ref = ref_attributes(var) ;
5✔
545
    if ( ref != NULL ) {
5✔
546
        if (ref->attr->io & TRICK_VAR_INPUT) {
5✔
547
            V_TREE v_tree ;
548
            V_DATA v_data ;
549
            v_tree.v_data = &v_data ;
5✔
550
            var_set_value( v_data , value) ;
5✔
551
            if ( units != NULL ) {
5✔
552
                ref->units = strdup(map_trick_units_to_udunits(units).c_str()) ;
1✔
553
            } else {
554
                ref->units = NULL ;
4✔
555
            }
556
            ref_assignment(ref , &v_tree) ;
5✔
557

558
            // Free allocated memory within a REF2 structure. Does not free the REF2 itself
559
            ref_free(ref) ;
5✔
560

561
            // Free the REF2 structure itself
562
            free(ref) ;
5✔
563
            ref = NULL;
5✔
564
        } else {
565
            message_publish(MSG_WARNING,"Cannot assign to %s because io_spec does not allow input\n", var) ;
×
566
            return 1;
×
567
        }
568
    } else {
569
        message_publish(MSG_WARNING,"reference attributes not found for variable %s in call to var_set\n", var) ;
×
570
        return 2;
×
571
    }
572
    return 0 ;
5✔
573
}
574

575
int var_set( const char  * var , double value , const char * units ) {
2✔
576
    return var_set_base(var, value, units) ;
2✔
577
}
578

579
int var_set( const char  * var , long long value , const char * units ) {
1✔
580
    return var_set_base(var, value, units) ;
1✔
581
}
582

583
int var_set( const char  * var , const char * value , const char * units ) {
1✔
584
    return var_set_base(var, value, units) ;
1✔
585
}
586

587
int var_set( const char  * var , void * value , const char * units ) {
1✔
588
    return var_set_base(var, value, units) ;
1✔
589
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc