truck-code
pub_sub.h
Go to the documentation of this file.
1 
10 #ifndef SRC_UTILS_PUB_SUB_H_
11 #define SRC_UTILS_PUB_SUB_H_
12 
13 #include <string>
14 #include <vector>
15 #include <tuple>
16 #include <fcntl.h>
18 
19 
20 #define PS_EMTPY -1001
21 
22 
23 class PubSub
24 {
25 public:
33  virtual void publish(int type, void *message);
34 
42  virtual void subscribe(int type);
43 
49  virtual void unsubscribe(int type);
50 
57  virtual std::map <int, void*> get_subscription_results();
58 
60  virtual vector<int> get_subscribed_ids();
61 
62  virtual ~PubSub();
63 
64 private:
65  int _fd_pub = open("/pps/truck", O_WRONLY);
66  map <int, int> _fd_sub;
67  vector <int> _subscribed_ids;
68 #if DEBUG_FLAG
69  map <int, J1939Interpreter*> _interpreters = get_interpreters();
70 #endif
71 
80  virtual void _subscribe_j1939_element(int pgn_num, string pgn_string);
81 
90  virtual void _unsubscribe_j1939_element(int pgn_num, string pgn_string);
91 
104  virtual void _print_published_j1939(void* pdv, int pgn_num, string pgn_string);
105 
106  virtual void _publish_pdu(void *data);
107  virtual void _publish_tsc1(void *data);
108  virtual void _publish_ebc1(void *data);
109  virtual void _publish_ebc2(void *data);
110  virtual void _publish_eec1(void *data);
111  virtual void _publish_eec2(void *data);
112  virtual void _publish_eec3(void *data);
113  virtual void _publish_erc1(void *data);
114  virtual void _publish_etc1(void *data);
115  virtual void _publish_etc2(void *data);
116  virtual void _publish_turbo(void *data);
117  virtual void _publish_vd(void *data);
118  virtual void _publish_rcfg(void *data);
119  virtual void _publish_ecfg(void *data);
120  virtual void _publish_etemp(void *data);
121  virtual void _publish_pto(void *data);
122  virtual void _publish_ccvs(void *data);
123  virtual void _publish_lfe(void *data);
124  virtual void _publish_ambc(void *data);
125  virtual void _publish_iec(void *data);
126  virtual void _publish_vep(void *data);
127  virtual void _publish_tf(void *data);
128  virtual void _publish_rf(void *data);
129  virtual void _publish_hrvd(void *data);
130  virtual void _publish_fd(void *data);
131  virtual void _publish_gfi2(void *data);
132  virtual void _publish_ei(void *data);
133 
134  virtual void _subscribe_pdu();
135  virtual void _subscribe_tsc1();
136  virtual void _subscribe_ebc1();
137  virtual void _subscribe_ebc2();
138  virtual void _subscribe_eec1();
139  virtual void _subscribe_eec2();
140  virtual void _subscribe_eec3();
141  virtual void _subscribe_erc1();
142  virtual void _subscribe_etc1();
143  virtual void _subscribe_etc2();
144  virtual void _subscribe_turbo();
145  virtual void _subscribe_vd();
146  virtual void _subscribe_rcfg();
147  virtual void _subscribe_ecfg();
148  virtual void _subscribe_etemp();
149  virtual void _subscribe_pto();
150  virtual void _subscribe_ccvs();
151  virtual void _subscribe_lfe();
152  virtual void _subscribe_ambc();
153  virtual void _subscribe_iec();
154  virtual void _subscribe_vep();
155  virtual void _subscribe_tf();
156  virtual void _subscribe_rf();
157  virtual void _subscribe_hrvd();
158  virtual void _subscribe_fd();
159  virtual void _subscribe_gfi2();
160  virtual void _subscribe_ei();
161 
162  virtual void _unsubscribe_pdu();
163  virtual void _unsubscribe_tsc1();
164  virtual void _unsubscribe_ebc1();
165  virtual void _unsubscribe_ebc2();
166  virtual void _unsubscribe_eec1();
167  virtual void _unsubscribe_eec2();
168  virtual void _unsubscribe_eec3();
169  virtual void _unsubscribe_erc1();
170  virtual void _unsubscribe_etc1();
171  virtual void _unsubscribe_etc2();
172  virtual void _unsubscribe_turbo();
173  virtual void _unsubscribe_vd();
174  virtual void _unsubscribe_rcfg();
175  virtual void _unsubscribe_ecfg();
176  virtual void _unsubscribe_etemp();
177  virtual void _unsubscribe_pto();
178  virtual void _unsubscribe_ccvs();
179  virtual void _unsubscribe_lfe();
180  virtual void _unsubscribe_ambc();
181  virtual void _unsubscribe_iec();
182  virtual void _unsubscribe_vep();
183  virtual void _unsubscribe_tf();
184  virtual void _unsubscribe_rf();
185  virtual void _unsubscribe_hrvd();
186  virtual void _unsubscribe_fd();
187  virtual void _unsubscribe_gfi2();
188  virtual void _unsubscribe_ei();
189 
190  virtual void* _get_subscribed_pdu();
191  virtual void* _get_subscribed_tsc1();
192  virtual void* _get_subscribed_ebc1();
193  virtual void* _get_subscribed_ebc2();
194  virtual void* _get_subscribed_eec1();
195  virtual void* _get_subscribed_eec2();
196  virtual void* _get_subscribed_eec3();
197  virtual void* _get_subscribed_erc1();
198  virtual void* _get_subscribed_etc1();
199  virtual void* _get_subscribed_etc2();
200  virtual void* _get_subscribed_turbo();
201  virtual void* _get_subscribed_vd();
202  virtual void* _get_subscribed_rcfg();
203  virtual void* _get_subscribed_ecfg();
204  virtual void* _get_subscribed_etemp();
205  virtual void* _get_subscribed_pto();
206  virtual void* _get_subscribed_ccvs();
207  virtual void* _get_subscribed_lfe();
208  virtual void* _get_subscribed_ambc();
209  virtual void* _get_subscribed_iec();
210  virtual void* _get_subscribed_vep();
211  virtual void* _get_subscribed_tf();
212  virtual void* _get_subscribed_rf();
213  virtual void* _get_subscribed_hrvd();
214  virtual void* _get_subscribed_fd();
215  virtual void* _get_subscribed_gfi2();
216  virtual void* _get_subscribed_ei();
217 };
218 
219 
220 #endif /* SRC_UTILS_PUB_SUB_H_ */
virtual void publish(int type, void *message)
Definition: publish.cpp:20
Definition: pub_sub.h:23
virtual void subscribe(int type)
Definition: subscribe.cpp:26
virtual void unsubscribe(int type)
Definition: subscribe.cpp:234
virtual vector< int > get_subscribed_ids()
Definition: subscribe.cpp:21
virtual std::map< int, void * > get_subscription_results()
Definition: subscribe.cpp:444