summaryrefslogtreecommitdiffstats
path: root/src/uscxml/concurrency/eventqueue/DelayedEventQueue.h
blob: 8825c27de8a5c83b2538dd9c2df515f9825392fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef DELAYEDEVENTQUEUE_H_JA6WRBVP
#define DELAYEDEVENTQUEUE_H_JA6WRBVP

#include "uscxml/concurrency/tinythread.h"

#include <event2/thread.h>
#include <event2/http.h>
#include <event2/event.h>

#include <inttypes.h>

#include <map>
#include <string>
#include <iostream>

namespace uscxml {

class DelayedEventQueue {
public:

	struct callbackData {
		void *userData;
		void (*callback)(void*, const std::string eventId);
		std::string eventId;
		struct event *event;
		DelayedEventQueue* eventQueue;
	};

	DelayedEventQueue();
	virtual ~DelayedEventQueue();

	void addEvent(std::string eventId, void (*callback)(void*, const std::string eventId), uint32_t delayMs, void* userData);
	void cancelEvent(std::string eventId);

	void start();
	void stop();
	static void run(void*);

	static void timerCallback(evutil_socket_t fd, short what, void *arg);
	static void dummyCallback(evutil_socket_t fd, short what, void *arg);

	bool _isStarted;
	tthread::thread* _thread;
	tthread::recursive_mutex _mutex;

	std::map<std::string, callbackData> _callbackData;
	struct event_base* _eventLoop;
};

}


#endif /* end of include guard: DELAYEDEVENTQUEUE_H_JA6WRBVP */