BasicDelayedEventQueue.h
Go to the documentation of this file.
1 
20 #ifndef BASICDELAYEDEVENTQUEUE_H_49D837C4
21 #define BASICDELAYEDEVENTQUEUE_H_49D837C4
22 
23 #include "BasicEventQueue.h"
24 #include <string>
25 #include <map>
26 #include <list>
27 #include <thread>
28 #include <mutex>
29 #include <condition_variable>
30 
31 #include <event2/event.h>
32 
33 namespace uscxml {
34 
40 public:
42  virtual ~BasicDelayedEventQueue();
43  virtual std::shared_ptr<DelayedEventQueueImpl> create(DelayedEventQueueCallbacks* callbacks);
44  virtual void enqueueDelayed(const Event& event, size_t delayMs, const std::string& eventUUID);
45  virtual void cancelDelayed(const std::string& eventId);
46  virtual void cancelAllDelayed();
47  virtual Event dequeue(size_t blockMs) {
48  return BasicEventQueue::dequeue(blockMs);
49  }
50  virtual void enqueue(const Event& event) {
51  return BasicEventQueue::enqueue(event);
52  }
53  virtual void reset();
54 
55  virtual Data serialize();
56  virtual void deserialize(const Data& data);
57 
58 protected:
59  virtual std::shared_ptr<EventQueueImpl> create() {
60  ErrorEvent e("Cannot create a DelayedEventQueue without callbacks");
61  throw e;
62  }
63 
64  struct callbackData {
65  Event userData;
66  std::string eventUUID;
67  bool persist;
68  struct event *event;
69  BasicDelayedEventQueue* eventQueue;
70  timeval added;
71  timeval due;
72  };
73 
74  bool _isStarted;
75  std::thread* _thread;
76 
77  std::map<std::string, callbackData> _callbackData;
78  struct event_base* _eventLoop;
79  struct event* _dummyEvent;
80 
81  static void run(void* instance);
82  void start();
83  void stop();
84 
85  static void timerCallback(evutil_socket_t fd, short what, void *arg);
86  DelayedEventQueueCallbacks* _callbacks;
87 };
88 
89 }
90 
91 #endif /* end of include guard: BASICDELAYEDEVENTQUEUE_H_49D837C4 */
Definition: Breakpoint.cpp:26
Definition: Event.h:211
Definition: BasicEventQueue.h:37
Definition: BasicDelayedEventQueue.h:39
Definition: EventQueueImpl.h:53
Definition: Event.h:94
Definition: BasicDelayedEventQueue.h:64
Definition: EventQueueImpl.h:62
Definition: Data.h:44