CARMA C++
SignalTaskMsg.h
Go to the documentation of this file.
1 #ifndef SIGNALTASKMSG_H
2 #define SIGNALTASKMSG_H
3 
13 #include <cstring>
14 
15 namespace sza {
16  namespace util {
17 
18  class SignalTaskMsg :
20 
21  public:
22 
23  enum MsgType {
24  ADD_SIGNAL_HANDLER,
25  ADD_TIMER_HANDLER,
26  SIG_ENABLE_TIMER,
27  SIG_INSTALL_TIMER,
28  SIG_INSTALL_SIGNAL,
29  };
30 
31  MsgType type;
32 
36  union {
37 
38  struct {
39  char name[SIGNAL_NAME_LEN+1];
40  int sigNo;
41  unsigned long initSec;
42  unsigned long initNsec;
43  unsigned long intervalSec;
44  unsigned long intervalNsec;
45  SIGNALTASK_HANDLER_FN(*handler);
46  } installTimer;
47 
48  struct {
49  char name[SIGNAL_NAME_LEN+1];
50  bool enable;
51  } enableTimer;
52 
53  struct {
54  int sigNo;
55  SIGNALTASK_HANDLER_FN(*handler);
56  void* arg;
57  } installSignal;
58 
59  struct {
60  int sigNo;
61  SIGNALTASK_HANDLER_FN(*handler);
62  bool add;
63  } addSignalHandler;
64 
65  struct {
66  char name[SIGNAL_NAME_LEN+1];
67  SIGNALTASK_HANDLER_FN(*handler);
68  bool add;
69  } addTimerHandler;
70 
71  } body;
72 
73  //------------------------------------------------------------
74  // Methods for packing signal messages
75  //------------------------------------------------------------
76 
80  inline void packInstallTimerMsg(std::string name,
81  int sigNo,
82  unsigned long initSec,
83  unsigned long initNsec,
84  unsigned long intervalSec,
85  unsigned long intervalNsec,
86  SIGNALTASK_HANDLER_FN(*handler))
87  {
88 
89  if(name.size() > SIGNAL_NAME_LEN)
90  ThrowError("Name string is too long");
91 
93  sza::util::GenericTaskMsg::TASK_SPECIFIC;
94 
95  type = SIG_INSTALL_TIMER;
96 
97  strncpy(body.installTimer.name, name.c_str(), SIGNAL_NAME_LEN);
98  body.installTimer.sigNo = sigNo;
99  body.installTimer.initSec = initSec;
100  body.installTimer.initNsec = initNsec;
101  body.installTimer.intervalSec = intervalSec;
102  body.installTimer.intervalNsec = intervalNsec;
103  body.installTimer.handler = handler;
104  }
105 
109  inline void packInstallSignalMsg(int sigNo,
110  SIGNALTASK_HANDLER_FN(*handler),
111  void* arg)
112  {
113  genericMsgType_ =
114  sza::util::GenericTaskMsg::TASK_SPECIFIC;
115 
116  type = SIG_INSTALL_SIGNAL;
117 
118  body.installSignal.sigNo = sigNo;
119  body.installSignal.handler = handler;
120  body.installSignal.arg = arg;
121  }
122 
126  inline void packEnableTimerMsg(std::string name,
127  bool enable)
128  {
129  genericMsgType_ =
130  sza::util::GenericTaskMsg::TASK_SPECIFIC;
131 
132  type = SIG_ENABLE_TIMER;
133 
134  if(name.size() > SIGNAL_NAME_LEN)
135  ThrowError("Name string is too long");
136 
137  strncpy(body.enableTimer.name, name.c_str(),
138  SIGNAL_NAME_LEN);
139 
140  body.enableTimer.enable = enable;
141  }
142 
146  inline void packAddHandlerMsg(std::string name,
147  SIGNALTASK_HANDLER_FN(*handler),
148  bool add)
149  {
150  genericMsgType_ =
151  sza::util::GenericTaskMsg::TASK_SPECIFIC;
152 
153  type = ADD_TIMER_HANDLER;
154 
155  if(name.size() > SIGNAL_NAME_LEN)
156  ThrowError("Name string is too long");
157 
158  strncpy(body.addTimerHandler.name, name.c_str(),
159  SIGNAL_NAME_LEN);
160 
161  body.addTimerHandler.handler = handler;
162  body.addTimerHandler.add = add;
163  }
164 
168  inline void packAddHandlerMsg(int sigNo,
169  SIGNALTASK_HANDLER_FN(*handler),
170  bool add)
171  {
172  genericMsgType_ =
173  sza::util::GenericTaskMsg::TASK_SPECIFIC;
174 
175  type = ADD_SIGNAL_HANDLER;
176 
177  body.addSignalHandler.sigNo = sigNo;
178  body.addSignalHandler.handler = handler;
179  body.addSignalHandler.add = add;
180  }
181 
182 
183  }; // End class SignalTaskMsg
184 
185  }; // End namespace util
186 }; // End namespace sza
187 
188 #endif // End #ifndef
Tagged: Fri Nov 14 12:39:34 UTC 2003.
GenericMsgType genericMsgType_
A type for this message.
A class to encapsulate message types for a generic task.
Tagged: Fri Nov 14 12:39:33 UTC 2003.