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

nasa / trick / 26653412669

29 May 2026 05:56PM UTC coverage: 57.335% (+0.4%) from 56.928%
26653412669

Pull #2107

github

web-flow
Merge 0641f9fd7 into fdaa62f2e
Pull Request #2107: Checkpoint in freeze only

47 of 60 new or added lines in 5 files covered. (78.33%)

26 existing lines in 8 files now uncovered.

13097 of 22843 relevant lines covered (57.33%)

295601.54 hits per line

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

54.33
/trick_source/sim_services/EventManager/EventManager.cpp
1
/*
2
   PURPOSE: ( Python input processor )
3
   REFERENCE: ( Trick Simulation Environment )
4
   ASSUMPTIONS AND LIMITATIONS: ( None )
5
   CLASS: ( N/A )
6
   LIBRARY DEPENDENCY: ( None )
7
   PROGRAMMERS: ( Alex Lin NASA 2009 )
8
*/
9

10
#include <iostream>
11
#include <sstream>
12
#include <vector>
13
#include <string>
14
#include <cmath>
15

16
#include "trick/EventManager.hh"
17
#include "trick/EventInstrument.hh"
18
#include "trick/memorymanager_c_intf.h"
19
#include "trick/exec_proto.h"
20
#include "trick/exec_proto.hh"
21
#include "trick/message_proto.h"
22
#include "trick/message_type.h"
23

24
Trick::EventManager * the_em ;
25

26
Trick::EventManager::EventManager() :
187✔
27
 active_events(NULL),
28
 num_active_events(0),
29
 num_allocated(0)
187✔
30
{ the_em = this ; }
187✔
31

32
//Command to get the event object given the event's name
33
Trick::Event * Trick::EventManager::get_event(std::string event_name) {
2✔
34
    unsigned int ii ;
35
    Trick::Event* ret = NULL;
2✔
36

37
    /* Find the event name in the active event list and return the pointer to that event */
38
    for ( ii = 0 ; ii < num_active_events ; ii++ ) {
48✔
39
        if ( ! active_events[ii]->get_name().compare(event_name) ) {
47✔
40
            ret = active_events[ii];
1✔
41
            break ;
1✔
42
        }
43
    }
44

45
    return(ret) ;
2✔
46

47
}
48

49
//Add user's event to the active event list.
50
int Trick::EventManager::add_to_active_events(Trick::Event * in_event) {
60✔
51

52
    for ( unsigned int ii = 0 ; ii < num_active_events ; ii++ ) {
399✔
53
        if (in_event == active_events[ii]) {
339✔
UNCOV
54
            return (0) ;
×
55
        }
56
    }
57
    num_active_events++;
60✔
58
    if (num_active_events == 1) {
60✔
59
        active_events = (Trick::Event **)TMM_declare_var_s("Trick::Event* [100]");
22✔
60
        num_allocated = 100 ;
22✔
61
    } else if ( num_active_events >= num_allocated ) {
38✔
62
        num_allocated += 100 ;
×
63
        active_events = (Trick::Event **)TMM_resize_array_1d_a(active_events, num_allocated);
×
64
        for ( unsigned int ii = num_active_events ; ii < num_allocated ; ii++ ) {
×
65
            active_events[ii] = NULL ;
×
66
        }
67
    }
68
    active_events[num_active_events-1] = in_event ;
60✔
69
    return (0) ;
60✔
70
}
71

72
//Command to insert a user's input file event into the input processor's list of events to process.
73
int Trick::EventManager::add_event(Trick::Event * in_event) {
58✔
74

75
    int ret = 0 ;
58✔
76

77
    add_to_active_events(in_event) ;
58✔
78

79
    if (in_event->get_thread() < event_processors.size() ) {
58✔
80
        event_processors[in_event->get_thread()]->add_event(in_event) ;
58✔
81
        in_event->add() ;
58✔
82
    } else {
83
        message_publish(MSG_WARNING, "Event thread number is not in range: thread %d requested, only %d child threads in simulation.\n", in_event->get_thread() , event_processors.size() - 1) ;
×
84
        ret = -1 ;
×
85
    }
86

87
    return ret ;
58✔
88

89
}
90

91
/**
92
@details
93
Command to insert an instrument job (containing in_event) into job queue before target job.
94

95
-# Find the target job.
96
-# If the target job exists
97
 -# Save the target job information to the event.
98
 -# Create an EventInstrument with the event and target job information
99
 -# Add the event instrument to the target job
100
 -# call the event's add routine if it needs to do anything once it is activated.
101
-# else print a warning that the target job does not exist.
102
-# Add the event to the list of active events.
103
*/
104
int Trick::EventManager::add_event_before(Trick::Event * in_event, std::string target_name, unsigned int target_inst) {
×
105

106
    Trick::JobData * target_job ;
107

108
    target_job = exec_get_job( target_name.c_str() , target_inst ) ;
×
109
    if (target_job != NULL ) {
×
110
        in_event->set_before_after(Trick::EVENT_BEFORETARGET) ;
×
111
        in_event->set_target_name(target_name) ;
×
112
        in_event->set_target_inst(target_inst) ;
×
113
        Trick::EventInstrument * instru_job = new Trick::EventInstrument(in_event , target_job) ;
×
114
        target_job->add_inst_before(instru_job) ;
×
115
        events_instrumented.push_back(instru_job) ;
×
116
        in_event->add() ;
×
117
    } else {
118
        message_publish(MSG_WARNING, "Event not added before job: %s does not exist.\n", target_name.c_str()) ;
×
119
        return (0);
×
120
    }
121
    /* Add in_event to list of active events. */
122
    add_to_active_events(in_event) ;
×
123
    return(0);
×
124

125
}
126

127
/**
128
@details
129
Command to insert an instrument job (containing in_event) into job queue after target job.
130

131
-# Find the target job.
132
-# If the target job exists
133
 -# Save the target job information to the event.
134
 -# Create an EventInstrument with the event and target job information
135
 -# Add the event instrument to the target job
136
 -# call the event's add routine if it needs to do anything once it is activated.
137
-# else print a warning that the target job does not exist.
138
-# Add the event to the list of active events.
139
*/
140
int Trick::EventManager::add_event_after(Trick::Event * in_event, std::string target_name, unsigned int target_inst) {
2✔
141

142
    Trick::JobData * target_job ;
143

144
    target_job = exec_get_job( target_name.c_str() , target_inst ) ;
2✔
145
    if (target_job != NULL ) {
2✔
146
        in_event->set_before_after(Trick::EVENT_AFTERTARGET) ;
2✔
147
        in_event->set_target_name(target_name) ;
2✔
148
        in_event->set_target_inst(target_inst) ;
2✔
149
        Trick::EventInstrument * instru_job = new Trick::EventInstrument(in_event , target_job) ;
2✔
150
        target_job->add_inst_after(instru_job) ;
2✔
151
        events_instrumented.push_back(instru_job) ;
2✔
152
        in_event->add() ;
2✔
153
    } else {
154
        message_publish(MSG_WARNING, "Event not added before job: %s does not exist.\n", target_name.c_str()) ;
×
155
        return (0);
×
156
    }
157
    /* Add in_event to list of active events. */
158
    add_to_active_events(in_event) ;
2✔
159
    return(0);
2✔
160

161
}
162

163
// Find the event by name and activate it.
164
int Trick::EventManager::activate_event(const char * event_name) {
×
165
    Trick::Event* ret = NULL;
×
166

167
    ret = get_event(event_name) ;
×
168
    if (ret != NULL) {
×
169
        ret->activate() ;
×
170
    }
171
    return 0 ;
×
172
}
173

174
// Find the event by name and deactivate it.
175
int Trick::EventManager::deactivate_event(const char * event_name) {
×
176
    Trick::Event* ret = NULL;
×
177

178
    ret = get_event(event_name) ;
×
179
    if (ret != NULL) {
×
180
        ret->deactivate() ;
×
181
    }
182
    return 0 ;
×
183
}
184

185
//Command to remove an event from everywhere it was added (it can still be added back again).
186
int Trick::EventManager::remove_event(Trick::Event * in_event) {
2✔
187

188
    unsigned int ii , jj ;
189

190
    if ( ! in_event ) {
2✔
191
        return 0 ;
×
192
    }
193

194
    if ( in_event->get_before_after() == Trick::EVENT_NOTARGET ) {
2✔
195
        /* If the event is cyclic, remove the event from the event processor on the event's thread */
196
        event_processors[in_event->get_thread()]->remove_event(in_event) ;
2✔
197
    } else {
198
        std::vector< Trick::EventInstrument * >::iterator ei_it ;
×
199
        for ( ei_it = events_instrumented.begin() ; ei_it != events_instrumented.end() ; ) {
×
200
            if ( (*ei_it)->get_event() == in_event ) {
×
201
                /* If the event is tied to a job, call the target jobs remove instrument routine */
202
                Trick::EventInstrument * found_event_instru = *ei_it ;
×
203
                ei_it = events_instrumented.erase(ei_it) ;
×
204
                found_event_instru->get_target_job()->remove_inst(found_event_instru->name) ;
×
205
                delete found_event_instru ;
×
206
            } else {
207
                ei_it++ ;
×
208
            }
209
        }
210
    }
211

212
    in_event->remove() ;
2✔
213

214
    /* Remove it from active event list. */
215
    for ( ii = 0 ; ii < num_active_events ; ii++ ) {
10✔
216
        if (in_event == active_events[ii]) {
10✔
217
            for ( jj = ii + 1 ; jj < num_active_events ; jj++ ) {
19✔
218
                active_events[jj - 1] = active_events[jj] ;
17✔
219
            }
220
            num_active_events-- ;
2✔
221
            if (num_active_events == 0) {
2✔
222
                TMM_delete_var_a(active_events);
×
223
                active_events = NULL;
×
224
            }
225
            else {
226
                active_events[num_active_events] = NULL ;
2✔
227
            }
228

229
            break ;
2✔
230
        }
231
    }
232

233
    if ( in_event->get_free_on_removal() ) {
2✔
234
        TMM_delete_var_a(in_event) ;
×
235
    }
236

237
    return 0 ;
2✔
238
}
239

240
/**
241
@details
242
This is called from the S_define file.  There will be one event processor assigned to each thread.
243
-# Add the incoming input processor to the list of known processors.
244
*/
245
void Trick::EventManager::add_event_processor(Trick::EventProcessor * in_ep) {
192✔
246
    event_processors.push_back(in_ep) ;
192✔
247
}
192✔
248

249
//Executive time_tic changed.  Update all event times
250
int Trick::EventManager::time_tic_changed() {
1✔
251

252
    int old_tt ;
253
    int tt ;
254
    unsigned int ii ;
255

256
    old_tt = exec_get_old_time_tic_value() ;
1✔
257
    tt = exec_get_time_tic_value() ;
1✔
258

259
    for ( ii = 0 ; ii < num_active_events ; ii++ ) {
1✔
260
        active_events[ii]->set_next_tics((long long)round((active_events[ii]->get_next_tics() / old_tt) * tt)) ;
×
261
    }
262

263
    return 0 ;
1✔
264
}
265

266
// Remove all events attached to jobs before a checkpoint is reloaded.
267
int Trick::EventManager::preload_checkpoint() {
11✔
268
    std::vector< Trick::EventInstrument * >::iterator ei_it ;
11✔
269
    for ( ei_it = events_instrumented.begin() ; ei_it != events_instrumented.end() ; ) {
11✔
270
        Trick::EventInstrument * found_event_instru = *ei_it ;
×
271
        ei_it = events_instrumented.erase(ei_it) ;
×
272
        found_event_instru->get_target_job()->remove_inst(found_event_instru->name) ;
×
273
        delete found_event_instru ;
×
274
    }
275
    return 0 ;
11✔
276
}
277

278
//Restart job that reloads event_list from checkpointable structures
279
int Trick::EventManager::restart() {
11✔
280
    unsigned int ii ;
281

282
    for ( ii = 0 ; ii < num_active_events ; ii++ ) {
11✔
283
        // rebuild the event_list of all events that were "added"
284

285
        /* call the event restart routine to reset anything the event needs to do. */
UNCOV
286
        active_events[ii]->restart() ;
×
287

UNCOV
288
        if ( active_events[ii]->get_before_after() == Trick::EVENT_BEFORETARGET ) {
×
289
            /* Update event list and insert an instrument job (containing in_event) target job's "before" queue. */
290
            add_event_before( active_events[ii] , active_events[ii]->get_target_name() , active_events[ii]->get_target_inst() ) ;
×
UNCOV
291
        } else if ( active_events[ii]->get_before_after() == Trick::EVENT_AFTERTARGET ) {
×
292
            /* Update event list and insert an instrument job (containing in_event) target job's "after" queue. */
293
            add_event_after( active_events[ii] , active_events[ii]->get_target_name() , active_events[ii]->get_target_inst() ) ;
×
294
        } else {
295
            /* Update event list for normal user events and read events. */
UNCOV
296
            add_event(active_events[ii]);
×
297
        }
298
    }
299
    return (0);
11✔
300
}
301

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

© 2026 Coveralls, Inc