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

nasa / trick / 41067945034

30 Oct 2026 01:59PM UTC coverage: 57.411% (+0.03%) from 57.386%
41067945034

push

github

web-flow
feat: Add input processor and thread sync to frame logging data (#2249)

Co-authored-by: Hong Chen <hchen99@users.noreply.github.com>

18 of 19 new or added lines in 3 files covered. (94.74%)

9 existing lines in 5 files now uncovered.

15095 of 26293 relevant lines covered (57.41%)

477503.99 hits per line

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

78.0
/trick_source/sim_services/VariableServer/VariableServerSession.cpp
1
#include "trick/VariableServerSession.hh"
2
#include "trick/TrickConstant.hh"
3
#include "trick/exec_proto.h"
4
#include "trick/Message_proto.hh"
5
#include "trick/message_proto.h"
6
#include "trick/input_processor_proto.h"
7
#include "trick/realtimesync_proto.h"
8

9
int Trick::VariableServerSession::instance_counter = 0;
10
std::string Trick::VariableServerSession::log_subdir = "session_logs";
11

12
Trick::VariableServerSession::VariableServerSession() {
66 ✔
13
    _debug = 0;
66 ✔
14
    _enabled = true ;
66 ✔
15
    _log = false ;
66 ✔
16
    _session_log = false;
66 ✔
17
    _session_log_msg_stream = -1;
66 ✔
18
    _info_msg = false;
66 ✔
19
    _copy_mode = VS_COPY_ASYNC ;
66 ✔
20
    _write_mode = VS_WRITE_ASYNC ;
66 ✔
21
    _frame_multiple = 1 ;
66 ✔
22
    _frame_offset = 0 ;
66 ✔
23
    _freeze_frame_multiple = 1 ;
66 ✔
24
    _freeze_frame_offset = 0 ;
66 ✔
25
    _update_rate = 0.1 ;
66 ✔
26
    _cycle_tics = (long long)(_update_rate * exec_get_time_tic_value()) ;
66 ✔
27
    if (_cycle_tics == 0) {
66 ✔
28
        _cycle_tics = 1;
11 ✔
29
    }
30

31
    _next_tics = TRICK_MAX_LONG_LONG ;
66 ✔
32
    _freeze_next_tics = TRICK_MAX_LONG_LONG ;
66 ✔
33
    _byteswap = false ;
66 ✔
34
    _validate_address = false ;
66 ✔
35
    _send_stdio = false ;
66 ✔
36

37
    _binary_data = false;
66 ✔
38
    _byteswap = false;
66 ✔
39
    _binary_data_nonames = false;
66 ✔
40

41
    _exit_cmd = false;
66 ✔
42
    _pause_cmd = false;
66 ✔
43

44
    _instance_num = instance_counter++;
66 ✔
45

46
    pthread_mutex_init(&_copy_mutex, NULL);
66 ✔
47
}
66 ✔
48

49
Trick::VariableServerSession::~VariableServerSession() {
77 ✔
50
    for (unsigned int ii = 0 ; ii < _session_variables.size() ; ii++ ) {
69 ✔
51
        delete _session_variables[ii];
3 ✔
52
    }
53
 }
77 ✔
54

55

56
void Trick::VariableServerSession::set_connection(ClientConnection * conn) {
22 ✔
57
    _connection = conn;
22 ✔
58
    log_connection_opened();
22 ✔
59
}
22 ✔
60

61
bool Trick::VariableServerSession::is_session_log_open() {
1 ✔
62
    return _session_log_msg_stream != -1;
1 ✔
63
}
64

65
void Trick::VariableServerSession::open_session_log() {
1 ✔
66
    std::string name = "VSSession" + std::to_string(_instance_num);
1 ✔
67
    _session_log_msg_stream = open_custom_message_file(log_subdir + "/" + name + ".log", name);
1 ✔
68
}
1 ✔
69

70

71
// Command to turn on log to varserver_log file
72
int Trick::VariableServerSession::set_log(bool on_off) {
1 ✔
73
    _log = on_off;
1 ✔
74
    return(0) ;
1 ✔
75
}
76

77
// Command to turn on individual session log file
78
int Trick::VariableServerSession::set_session_log(bool on_off) {
1 ✔
79
    _session_log = on_off;
1 ✔
80
    return(0) ;
1 ✔
81
}
82

83
bool Trick::VariableServerSession::get_pause() {
734 ✔
84
    return _pause_cmd ;
734 ✔
85
}
86

87
void Trick::VariableServerSession::set_pause( bool on_off) {
1 ✔
88
    _pause_cmd = on_off ;
1 ✔
89
}
1 ✔
90

91

92
bool Trick::VariableServerSession::get_exit_cmd() {
739 ✔
93
    return _exit_cmd ;
739 ✔
94
}
95

96
void Trick::VariableServerSession::pause_copy() {
×
97
    pthread_mutex_lock(&_copy_mutex);
×
98
}
×
99

100
void Trick::VariableServerSession::unpause_copy() {
×
101
    pthread_mutex_unlock(&_copy_mutex);
×
102
}
×
103

104
void Trick::VariableServerSession::disconnect_references() {
×
105
    for (VariableReference * variable : _session_variables) {
×
106
        variable->tagAsInvalid();
×
107
    }
108
}
×
109

110
long long Trick::VariableServerSession::get_next_tics() const {
×
111
    if ( ! _enabled ) {
×
112
        return TRICK_MAX_LONG_LONG ;
×
113
    }
114
    return _next_tics ;
×
115
}
116

117
long long Trick::VariableServerSession::get_freeze_next_tics() const {
×
118
    if ( ! _enabled ) {
×
119
        return TRICK_MAX_LONG_LONG ;
×
120
    }
121
    return _freeze_next_tics ;
×
122
}
123

124
void Trick::VariableServerSession::log_connection_opened() {
22 ✔
125
    if (_session_log) {
22 ✔
UNCOV
126
        if (!is_session_log_open()) {
×
UNCOV
127
            open_session_log();
×
128
        }
129
    
UNCOV
130
        message_publish(_session_log_msg_stream, "Variable Server Session started with %s:%d\n", _connection->getClientHostname().c_str(), _connection->getClientPort());
×
131
    }
132
}
22 ✔
133

134
void Trick::VariableServerSession::log_received_message(const std::string& msg) {
380 ✔
135
    if (_log) {
380 ✔
136
        message_publish(MSG_PLAYBACK, "tag=<%s> time=%f %s", _connection->getClientTag().c_str(), exec_get_sim_time(), msg.c_str());
1 ✔
137
    }
138

139
    if (_session_log) {
380 ✔
140
        if (!is_session_log_open()) 
1 ✔
141
            open_session_log();
1 ✔
142

143
        message_publish(_session_log_msg_stream, "tag=<%s> time=%f %s", _connection->getClientTag().c_str(), exec_get_sim_time(), msg.c_str());
1 ✔
144
    }
145

146
    if (_debug >= 3) {
380 ✔
147
        message_publish(MSG_DEBUG, "%p tag=<%s> var_server received bytes = msg_len = %d\n", _connection, _connection->getClientTag().c_str(), msg.size());
1 ✔
148
    }
149

150
    if (_debug >= 1 || _info_msg) {
380 ✔
151
        message_publish(MSG_DEBUG, "tag=<%s> time=%f %s", _connection->getClientTag().c_str(), exec_get_sim_time(), msg.c_str());
2 ✔
152
    }
153
    
154
}
380 ✔
155

156
int Trick::VariableServerSession::handle_message() {
745 ✔
157

158
    std::string received_message;
745 ✔
159
    int nbytes = _connection->read(received_message);
745 ✔
160
    if (nbytes > 0) {
745 ✔
161
        log_received_message(received_message);
380 ✔
162
        ip_parse(received_message.c_str()); /* returns 0 if no parsing error */
380 ✔
163
    }
164

165
    return nbytes;
745 ✔
166
}
745 ✔
167

168
Trick::VariableReference * Trick::VariableServerSession::find_session_variable(std::string name) const {
7 ✔
169
    for (VariableReference * ref : _session_variables) {
23 ✔
170
        // Look for matching name
171
        if (name.compare(ref->getName()) == 0) {
16 ✔
172
            return ref;
7 ✔
173
        }
174
    }
175

176
    return NULL;
×
177
}
178

179
int Trick::VariableServerSession::set_info_message(bool on) {
1 ✔
180
    _info_msg = on;
1 ✔
181
    return 0;
1 ✔
182
}
183

184
double Trick::VariableServerSession::get_update_rate() const {
736 ✔
185
    return _update_rate;
736 ✔
186
}
187

188
VS_WRITE_MODE Trick::VariableServerSession::get_write_mode () const {
737 ✔
189
    return _write_mode;
737 ✔
190
}
191

192
VS_COPY_MODE Trick::VariableServerSession::get_copy_mode () const {
739 ✔
193
    return _copy_mode;
739 ✔
194
}
195

196
long long Trick::VariableServerSession::get_cycle_tics() const {
10 ✔
197
    return _cycle_tics;
10 ✔
198
}
199

200
int Trick::VariableServerSession::get_frame_multiple () const {
×
201
    return _frame_multiple;
×
202
}
203

204
int Trick::VariableServerSession::get_frame_offset () const {
×
205
    return _frame_offset;
×
206
}
207

208
int Trick::VariableServerSession::get_freeze_frame_multiple () const {
×
209
    return _freeze_frame_multiple;
×
210
}
211

212
int Trick::VariableServerSession::get_freeze_frame_offset () const {
×
213
    return _freeze_frame_offset;
×
214
}
215

216
bool Trick::VariableServerSession::get_enabled () const {
736 ✔
217
    return _enabled;
736 ✔
218
}
219

220
void Trick::VariableServerSession::set_freeze_next_tics(long long tics) {
5 ✔
221
    _freeze_next_tics = tics;
5 ✔
222
}
5 ✔
223

224
void Trick::VariableServerSession::set_next_tics(long long tics) {
5 ✔
225
    _next_tics = tics;
5 ✔
226
}
5 ✔
227

228
void Trick::VariableServerSession::set_exit_cmd() {
×
229
    _exit_cmd = true;
×
230
}
×
231

232

233

234
std::ostream& Trick::operator<< (std::ostream& s, const Trick::VariableServerSession& session) {
2 ✔
235
    if (session._binary_data) {
2 ✔
236
        s << "    \"format\":\"BINARY\",\n";
1 ✔
237
    } else {
238
        s << "    \"format\":\"ASCII\",\n";
1 ✔
239
    }
240
    s << "    \"update_rate\":" << session.get_update_rate() << ",\n";
2 ✔
241

242
    s << "    \"variables\":[\n";
2 ✔
243

244
    int n_vars = (int)session._session_variables.size();
2 ✔
245
    for (int i=0 ; i<n_vars ; i++) {
8 ✔
246
        s << *(session._session_variables[i]);
6 ✔
247
        if ((n_vars-i)>1) {
6 ✔
248
            s << "," ;
4 ✔
249
        }
250
        s << "\n";
6 ✔
251
    }
252
    s << "    ]\n";
2 ✔
253

254
    return s;
2 ✔
255
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc