IT++ Logo
events.cpp
Go to the documentation of this file.
1 
29 #include <itpp/protocol/events.h>
30 
31 
32 namespace itpp
33 {
34 
35 Ttype Event_Queue::t = 0;
36 
37 unsigned long long int Base_Event::global_id = 0;
38 
39 std::priority_queue < Base_Event*,
40 std::deque<Base_Event*, std::allocator<Base_Event*> >,
41 Compare_Base_Event_Times > Event_Queue::event_queue;
42 
43 bool Event_Queue::keep_running = false;
44 
46 {
47  e->expire_t = t + e->delta_t;
48  event_queue.push(e);
49 }
50 
51 void Event_Queue::_run()
52 {
53  while (!event_queue.empty() && keep_running) {
54  Base_Event* e = event_queue.top(); // Next event to process.
55  event_queue.pop(); // Remove event.
56 
57  if (e->active) { // Only process active events.
58  t = e->expire_t; // Update current time.
59  e->exec(); // Execute the event.
60  }
61 
62  delete e; // This event is history!
63  }
64 
65 }
66 
68 {
69  keep_running = true;
70  _run();
71 }
72 
74 {
75  keep_running = false;
76 }
77 
79 {
80  stop();
81  Base_Event* e;
82 
83  while (!event_queue.empty()) {
84  e = event_queue.top();
85  delete e;
86  event_queue.pop();
87  }
88 
89  t = 0;
90 }
91 
92 // void Event_Queue::cancel_all(BaseSignal *s){
93 
94 // }
95 
96 
97 } // namespace itpp
SourceForge Logo

Generated on Sat May 25 2013 16:32:23 for IT++ by Doxygen 1.8.2