-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathactions.h
130 lines (109 loc) · 2.4 KB
/
actions.h
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#ifndef actions_h_
#define actions_h_
#include <json/json.h>
typedef websocketpp::server<websocketpp::config::asio> server;
using websocketpp::connection_hdl;
using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;
using websocketpp::lib::thread;
using websocketpp::lib::mutex;
using websocketpp::lib::unique_lock;
using websocketpp::lib::condition_variable;
enum action_type
{
SUBSCRIBE,
UNSUBSCRIBE,
MESSAGE
};
enum subscribe_topic
{
SOURCES,
GLOBAL,
REFERENCE,
MASTERLEVEL,
SOURCELEVEL,
LOUDSPEAKERLEVEL
};
/**
* The value of a Json Key is one of map_value's elements
*/
struct map_value_data
{
int integer;
bool b;
std::string string;
std::vector<int> integer_v;
double decimal;
std::vector<double> decimal_v;
Json::Value json;
};
enum map_value_type
{
BOOL,
STRING,
INTEGER,
DOUBLE,
INTARRAY
};
template <typename T>
struct getValueImp;
typedef struct map_value
{
map_value_type type;
map_value_data data;
template <typename T>
T getValue() {return getValueImp<T>::getValue(this);}
} map_value;
/* This needs to be specialised for every possible type of map_value*/
template <typename T>
struct getValueImp
{
static T getValue(map_value* const value);
};
/*Specialisation for bool type*/
template<>
struct getValueImp<bool>
{
static bool getValue(map_value* const value) {return value->data.b;}
};
/*Specialisation for string type*/
template<>
struct getValueImp<std::string>
{
static std::string getValue(map_value* const value)
{return value->data.string;}
};
/*Specialisation for integer type*/
template<>
struct getValueImp<int>
{
static int getValue(map_value* const value) {return value->data.integer;}
};
/*Specialisation for double type*/
template<>
struct getValueImp<double>
{
static double getValue(map_value* const value) {return value->data.decimal;}
};
//for the different kinds of messages
struct action
{
//constructor for subscribe/unsubscribe messages
action(action_type t, connection_hdl h, std::vector<subscribe_topic> top)
: type(t)
, hdl(h)
, topics(top)
{}
//constructor for other messages
action(action_type t, std::map<std::string, map_value> l)
: type(t)
, load(l)
{}
action_type type;
websocketpp::connection_hdl hdl;
std::vector<subscribe_topic> topics;
std::map<std::string, map_value> load;
//Json::Value msg_root;
};
#endif /* actions_h */