My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
SignalTaskMsg.h
Go to the documentation of this file.
1 #ifndef GCP_UTIL_SIGNALTASKMSG_H
2 #define GCP_UTIL_SIGNALTASKMSG_H
3 
11 #include "gcp/util/common/Exception.h"
12 #include "gcp/util/common/GenericTaskMsg.h"
13 
14 #include <string.h>
15 
16 namespace gcp {
17  namespace util {
18 
19  class SignalTaskMsg :
21 
22  public:
23 
24  enum MsgType {
25  ADD_SIGNAL_HANDLER,
26  ADD_TIMER_HANDLER,
27  SIG_ENABLE_TIMER,
28  SIG_INSTALL_TIMER,
29  SIG_INSTALL_SIGNAL,
30  };
31 
32  MsgType type;
33 
37  union {
38 
39  struct {
40  char name[SIGNAL_NAME_LEN+1];
41  int sigNo;
42  unsigned long initSec;
43  unsigned long initNsec;
44  unsigned long intervalSec;
45  unsigned long intervalNsec;
46  SIGNALTASK_HANDLER_FN(*handler);
47  } installTimer;
48 
49  struct {
50  char name[SIGNAL_NAME_LEN+1];
51  bool enable;
52  } enableTimer;
53 
54  struct {
55  int sigNo;
56  SIGNALTASK_HANDLER_FN(*handler);
57  void* arg;
58  } installSignal;
59 
60  struct {
61  int sigNo;
62  SIGNALTASK_HANDLER_FN(*handler);
63  bool add;
64  } addSignalHandler;
65 
66  struct {
67  char name[SIGNAL_NAME_LEN+1];
68  SIGNALTASK_HANDLER_FN(*handler);
69  bool add;
70  } addTimerHandler;
71 
72  } body;
73 
74  //------------------------------------------------------------
75  // Methods for packing signal messages
76  //------------------------------------------------------------
77 
81  inline void packInstallTimerMsg(std::string name,
82  int sigNo,
83  unsigned long initSec,
84  unsigned long initNsec,
85  unsigned long intervalSec,
86  unsigned long intervalNsec,
87  SIGNALTASK_HANDLER_FN(*handler))
88  {
89 
90  if(name.size() > SIGNAL_NAME_LEN) {
91  ThrowError("Name string is too long");
92  }
93 
95  gcp::util::GenericTaskMsg::TASK_SPECIFIC;
96 
97  type = SIG_INSTALL_TIMER;
98 
99  strncpy(body.installTimer.name, name.c_str(), SIGNAL_NAME_LEN);
100  body.installTimer.sigNo = sigNo;
101  body.installTimer.initSec = initSec;
102  body.installTimer.initNsec = initNsec;
103  body.installTimer.intervalSec = intervalSec;
104  body.installTimer.intervalNsec = intervalNsec;
105  body.installTimer.handler = handler;
106  }
107 
111  inline void packInstallSignalMsg(int sigNo,
112  SIGNALTASK_HANDLER_FN(*handler),
113  void* arg)
114  {
115  genericMsgType_ =
116  gcp::util::GenericTaskMsg::TASK_SPECIFIC;
117 
118  type = SIG_INSTALL_SIGNAL;
119 
120  body.installSignal.sigNo = sigNo;
121  body.installSignal.handler = handler;
122  body.installSignal.arg = arg;
123  }
124 
128  inline void packEnableTimerMsg(std::string name,
129  bool enable)
130  {
131  genericMsgType_ =
132  gcp::util::GenericTaskMsg::TASK_SPECIFIC;
133 
134  type = SIG_ENABLE_TIMER;
135 
136  if(name.size() > SIGNAL_NAME_LEN)
137  ThrowError("Name string is too long");
138 
139  strncpy(body.enableTimer.name, name.c_str(),
140  SIGNAL_NAME_LEN);
141 
142  body.enableTimer.enable = enable;
143  }
144 
148  inline void packAddHandlerMsg(std::string name,
149  SIGNALTASK_HANDLER_FN(*handler),
150  bool add)
151  {
152  genericMsgType_ =
153  gcp::util::GenericTaskMsg::TASK_SPECIFIC;
154 
155  type = ADD_TIMER_HANDLER;
156 
157  if(name.size() > SIGNAL_NAME_LEN)
158  ThrowError("Name string is too long");
159 
160  strncpy(body.addTimerHandler.name, name.c_str(),
161  SIGNAL_NAME_LEN);
162 
163  body.addTimerHandler.handler = handler;
164  body.addTimerHandler.add = add;
165  }
166 
170  inline void packAddHandlerMsg(int sigNo,
171  SIGNALTASK_HANDLER_FN(*handler),
172  bool add)
173  {
174  genericMsgType_ =
175  gcp::util::GenericTaskMsg::TASK_SPECIFIC;
176 
177  type = ADD_SIGNAL_HANDLER;
178 
179  body.addSignalHandler.sigNo = sigNo;
180  body.addSignalHandler.handler = handler;
181  body.addSignalHandler.add = add;
182  }
183 
184 
185  }; // End class SignalTaskMsg
186 
187  } // End namespace util
188 } // End namespace gcp
189 
190 
191 #endif // End #ifndef
void packInstallTimerMsg(std::string name, int sigNo, unsigned long initSec, unsigned long initNsec, unsigned long intervalSec, unsigned long intervalNsec, SIGNALTASK_HANDLER_FN(*handler))
Definition: SignalTaskMsg.h:81
Definition: GenericTaskMsg.h:31
Definition: SignalTaskMsg.h:19
void packAddHandlerMsg(int sigNo, SIGNALTASK_HANDLER_FN(*handler), bool add)
Definition: SignalTaskMsg.h:170
void packEnableTimerMsg(std::string name, bool enable)
Definition: SignalTaskMsg.h:128
GenericMsgType genericMsgType_
Definition: GenericTaskMsg.h:50
void packAddHandlerMsg(std::string name, SIGNALTASK_HANDLER_FN(*handler), bool add)
Definition: SignalTaskMsg.h:148
union gcp::util::SignalTaskMsg::@253 body
void packInstallSignalMsg(int sigNo, SIGNALTASK_HANDLER_FN(*handler), void *arg)
Definition: SignalTaskMsg.h:111