My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
Master.h
1 #ifndef SZA_TRANSLTOR_MASTER_H
2 #define SZA_TRANSLTOR_MASTER_H
3 
11 #include <vector>
12 
13 #include "gcp/mediator/specific/MasterMsg.h"
14 
15 #include "gcp/util/specific/Directives.h"
16 
17 #include "gcp/util/common/ArrayRegMapDataFrameManager.h"
18 #include "gcp/util/common/GenericMasterTask.h"
19 #include "gcp/util/common/SignalTask.h"
20 
21 #define HEARTBEAT_SIGNAL SIGRTMIN
22 #define DATAFRAME_SIGNAL SIGRTMIN+1
23 #define CONNECT_SIGNAL SIGRTMIN+2
24 
25 #define HEARTBEAT_SEC 60
26 #define DATAFRAME_NSEC 1000000000 // Every second
27 #define CONNECT_SEC 2
28 #define WX_FRAME_COUNT 60 // Read the weather station every 30 seconds
29  // (60 half-second frames)
30 
31 #define MASTER_TASK_FWD_FN(fn) void (fn)(MasterMsg* msg)
32 
33 namespace gcp {
34 namespace mediator {
35 
39  class Control;
40  class Scanner;
41 
64  class Master :
65  public gcp::util::GenericMasterTask<MasterMsg> {
66 
67  public:
68 
69  //============================================================
70  // Master public members & methods
71  //============================================================
72 
78  Master(std::string ctlHost,
79  std::string wxHost,
80  bool sim,
81  bool simRx);
82 
86  ~Master();
87 
88  //------------------------------------------------------------
89  // All task messages will be sent to the Master via
90  // the following message forwarding function. On receipt of a
91  // message, the master will determine which task is the
92  // intended recipient, and forward it appropriately via the
93  // private task forwarding methods below.
94  //
95  // The idea is that when a task is spawned by
96  // Master, it is guaranteed that the
97  // Master msgQ already exists, while there is no
98  // guarantee that the msgQs of the other tasks have yet been
99  // created.
100  //
101  // By forwarding all messages through the master, we are
102  // therefore guaranteed that a task will never attempt to
103  // access the message queue or methods of another task before
104  // the resources of that task have been allocated. We are
105  // also guaranteed that a message will never be lost because
106  // all messages will be queued until the master runs its
107  // serviceMsgQ() method, which happens only after all spawned
108  // tasks are running theirs.
109 
113  MASTER_TASK_FWD_FN(forwardMasterMsg);
114 
119  std::string ctlHost() {
120  return ctlHost_;
121  }
122 
123  std::string wxHost() {
124  return wxHost_;
125  }
126 
128 
129  bool sim() {return sim_;}
130  bool simRx() {return simRx_;}
131 
132  private:
133 
134  //============================================================
135  // Master private members & methods
136  //============================================================
137 
138  bool sim_;
139  bool simRx_;
140 
145  static Master* master_;
146 
151 
155  std::string ctlHost_;
156  std::string wxHost_;
157 
158  //------------------------------------------------------------
159  // Thread management methods
160  //------------------------------------------------------------
161 
165  static THREAD_START(startControl);
166  static THREAD_START(startScanner);
167  static THREAD_START(startSignal);
168 
172  static THREAD_CLEAN(cleanControl);
173  static THREAD_CLEAN(cleanScanner);
174  static THREAD_CLEAN(cleanSignal);
175 
179  static THREAD_PING(pingControl);
180  static THREAD_PING(pingScanner);
181 
182  //------------------------------------------------------------
183  // The thread startup functions will instantiate these objects
184  //------------------------------------------------------------
185 
190  Control* control_;
191 
196  Scanner* scanner_;
197 
198  //------------------------------------------------------------
199  // Static functions which will be passed to the
200  // Signal class as callbacks on receipt of signals.
201  //------------------------------------------------------------
202 
207  static SIGNALTASK_HANDLER_FN(sendSendHeartBeatMsg);
208 
212  static SIGNALTASK_HANDLER_FN(sendSendRestartMsg);
213 
217  static SIGNALTASK_HANDLER_FN(sendShutDownMsg);
218 
222  static SIGNALTASK_HANDLER_FN(trapSegv);
223 
227  static SIGNALTASK_HANDLER_FN(sendStartDataFrameMsg);
228 
232  static SIGNALTASK_HANDLER_FN(sendScannerConnectMsg);
233 
238  static SIGNALTASK_HANDLER_FN(sendControlConnectMsg);
239 
240  //------------------------------------------------------------
241  // Message forwarding methods for spawned tasks.
242  //------------------------------------------------------------
243 
248  MASTER_TASK_FWD_FN(forwardControlMsg);
249 
254  MASTER_TASK_FWD_FN(forwardScannerMsg);
255 
256  //------------------------------------------------------------
257  // Methods called in response to messages received on the
258  // Master msgQ.
259  //------------------------------------------------------------
260 
264  void sendHeartBeat();
265 
269  void restart();
270 
274  void installSignals();
275 
279  void installTimers();
280 
287  void processMsg(MasterMsg* taskMsg);
288 
289  }; // End class Master
290 
291 } // End namespace mediator
292 } // End namespace gcp
293 
294 #endif // End #ifndef
~Master()
Definition: Master.cc:105
Definition: ArrayRegMapDataFrameManager.h:21
std::string ctlHost()
Definition: Master.h:119
Definition: GenericMasterTask.h:22
MASTER_TASK_FWD_FN(forwardMasterMsg)
Definition: Master.h:64
Master(std::string ctlHost, std::string wxHost, bool sim, bool simRx)
Definition: Master.cc:46