-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPSME_MsgEnv.h
More file actions
46 lines (32 loc) · 1.07 KB
/
IPSME_MsgEnv.h
File metadata and controls
46 lines (32 loc) · 1.07 KB
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
//
// IPSME_MsgEnv.h
//
#ifndef IPSME_MSGENV_H
#define IPSME_MSGENV_H
#pragma comment(lib, "mosquitto.lib")
#include <mosquitto.h>
#include <mutex>
#include <vector>
// rather than include an init() in the interface
// we assume the dev knows we are using mosquitto and calls mosquitto_lib_init() and mosquitto_lib_cleanup()
class IPSME_MsgEnv {
public:
typedef char const * const t_MSG;
typedef void (*tp_callback)(t_MSG, void* p_void);
public:
IPSME_MsgEnv();
~IPSME_MsgEnv();
bool subscribe(tp_callback p_callback, void* p_void);
bool unsubscribe(tp_callback p_callback);
bool publish(t_MSG);
void process_msgs(int i_timeout= 0);
private:
std::vector< std::pair<void*, void*> > _vec;
std::mutex _mutex_vec;
std::unique_ptr<struct mosquitto, decltype(&mosquitto_destroy)> _uptr_mosq_pub;
std::unique_ptr<struct mosquitto, decltype(&mosquitto_destroy)> _uptr_mosq_sub;
std::mutex _mutex_mosq_pub;
std::mutex _mutex_mosq_sub;
friend void message_callback_(struct mosquitto* mosq, void* p_void, const struct mosquitto_message* p_message);
};
#endif // IPSME_MSGENV_H