00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00024
00025 #ifndef MessageType_H_
00026 #define MessageType_H_
00027
00028 #include <sys/time.h>
00029 #include "Configuration.h"
00030 #include "UniSetTypes.h"
00031 #include "IOController_i.hh"
00032
00033 namespace UniSetTypes
00034 {
00035 class Message
00036 {
00037 public:
00038 enum TypeOfMessage
00039 {
00040 Unused,
00041 SensorInfo,
00042 SysCommand,
00043 Confirm,
00044 Info,
00045 Timer,
00046 Alarm,
00047 DataBase,
00048 TheLastFieldOfTypeOfMessage
00049 };
00050
00051 int type;
00052
00053 enum Priority
00054 {
00055 Low,
00056 Medium,
00057 High,
00058 Super
00059 };
00060
00061 Priority priority;
00062 ObjectId node;
00063 ObjectId supplier;
00064 ObjectId consumer;
00065 struct timeval tm;
00066
00067 Message();
00068
00069 template<class In>
00070 static TransportMessage transport(const In& msg)
00071 {
00072 TransportMessage tmsg;
00073 assert(sizeof(UniSetTypes::RawDataOfTransportMessage)>=sizeof(msg));
00074 memcpy(&tmsg.data,&msg,sizeof(msg));
00075 return tmsg;
00076 }
00077 };
00078
00079
00080 class VoidMessage : public Message
00081 {
00082 public:
00083 VoidMessage( const TransportMessage& tm );
00084 VoidMessage();
00085 inline bool operator < ( const VoidMessage& msg ) const
00086 {
00087 if( priority != msg.priority )
00088 return priority < msg.priority;
00089
00090 if( tm.tv_sec != msg.tm.tv_sec )
00091 return tm.tv_sec >= msg.tm.tv_sec;
00092
00093 return tm.tv_usec >= msg.tm.tv_usec;
00094 }
00095
00096 inline TransportMessage transport_msg() const
00097 {
00098 return transport(*this);
00099 }
00100
00101 UniSetTypes::ByteOfMessage data[sizeof(UniSetTypes::RawDataOfTransportMessage)-sizeof(Message)];
00102 };
00103
00105 class SensorMessage : public Message
00106 {
00107 public:
00108
00109 ObjectId id;
00110 bool state;
00111 long value;
00112 bool undefined;
00113
00114
00115 long sm_tv_sec;
00116 long sm_tv_usec;
00117
00118 UniversalIO::IOTypes sensor_type;
00119 IOController_i::CalibrateInfo ci;
00120
00121
00122 bool threshold;
00123 UniSetTypes::ThresholdId tid;
00124
00125 SensorMessage();
00126 SensorMessage(ObjectId id, bool state, Priority priority = Message::Medium,
00127 UniversalIO::IOTypes st = UniversalIO::DigitalInput,
00128 ObjectId consumer=UniSetTypes::DefaultObjectId);
00129
00130 SensorMessage(ObjectId id, long value, const IOController_i::CalibrateInfo& ci,
00131 Priority priority = Message::Medium,
00132 UniversalIO::IOTypes st = UniversalIO::AnalogInput,
00133 ObjectId consumer=UniSetTypes::DefaultObjectId);
00134
00135 SensorMessage(const VoidMessage *msg);
00136 inline TransportMessage transport_msg() const
00137 {
00138 return transport(*this);
00139 }
00140 };
00141
00143 class SystemMessage : public Message
00144 {
00145 public:
00146 enum Command
00147 {
00148 StartUp,
00149 FoldUp,
00150 Finish,
00151 WatchDog,
00152 ReConfiguration,
00153 NetworkInfo,
00158 LogRotate
00159 };
00160
00161 SystemMessage();
00162 SystemMessage(Command command, Priority priority = Message::High,
00163 ObjectId consumer=UniSetTypes::DefaultObjectId);
00164 SystemMessage(const VoidMessage *msg);
00165
00166 inline TransportMessage transport_msg() const
00167 {
00168 return transport(*this);
00169 }
00170
00171 int command;
00172 long data[2];
00173 };
00174
00176 class InfoMessage : public Message
00177 {
00178 public:
00179 enum Character{
00180 Normal,
00181 Warning
00182 };
00183 InfoMessage();
00184 InfoMessage(ObjectId id, const std::string str, ObjectId node = conf->getLocalNode(),
00185 Character ch = InfoMessage::Normal,
00186 Priority priority = Message::Medium, ObjectId consumer=UniSetTypes::DefaultObjectId);
00187
00188 InfoMessage(ObjectId id, MessageCode icode, ObjectId node = conf->getLocalNode(),
00189 Character ch = InfoMessage::Normal,
00190 Priority priority = Message::Medium, ObjectId consumer=UniSetTypes::DefaultObjectId);
00191
00192 InfoMessage(const VoidMessage *msg);
00193
00194 inline TransportMessage transport_msg() const
00195 {
00196 return transport(*this);
00197 }
00198
00199 ObjectId id;
00200 MessageCode infocode;
00201 Character character;
00202 bool broadcast;
00209 bool route;
00210
00211
00212
00213
00214
00215
00216
00217
00218 static const unsigned int size_of_info_message = 55;
00219 char message[size_of_info_message];
00220 };
00221
00223 class AlarmMessage : public Message
00224 {
00225 public:
00226 enum Character{
00227 Normal,
00228 Attention,
00229 Warning,
00230 Alarm
00231 };
00232
00233 AlarmMessage();
00234 AlarmMessage(ObjectId id, const std::string str, ObjectId node = conf->getLocalNode(),
00235 Character ch = AlarmMessage::Alarm,
00236 Priority prior = Message::Medium, ObjectId cons=UniSetTypes::DefaultObjectId);
00237
00238 AlarmMessage(ObjectId id, const std::string str, MessageCode ccode,
00239 ObjectId node = conf->getLocalNode(),
00240 Character ch = AlarmMessage::Alarm,
00241 Priority prior = Message::Medium, ObjectId cons=UniSetTypes::DefaultObjectId);
00242
00243 AlarmMessage(ObjectId id, MessageCode acode, MessageCode ccode,
00244 ObjectId node=conf->getLocalNode(),
00245 Character ch=AlarmMessage::Alarm,
00246 Priority prior=Message::Medium,
00247 ObjectId cons=UniSetTypes::DefaultObjectId);
00248
00249 AlarmMessage(const VoidMessage *msg);
00250
00251 inline TransportMessage transport_msg() const
00252 {
00253 return transport(*this);
00254 }
00255
00256 ObjectId id;
00257 MessageCode alarmcode;
00258 MessageCode causecode;
00259 Character character;
00260 bool broadcast;
00267 bool route;
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278 static const unsigned int size_of_alarm_message = 55;
00279 char message[size_of_alarm_message];
00280 };
00281
00283 class DBMessage : public Message
00284 {
00285 public:
00286 enum TypeOfQuery
00287 {
00288 Query,
00289 Update,
00290 Insert
00291 };
00292
00293 DBMessage();
00294
00295 DBMessage(TypeOfQuery qtype, const std::string query, TypeOfMessage tblid,
00296 Priority prior=Message::Low,
00297 ObjectId cons=UniSetTypes::DefaultObjectId);
00298 DBMessage(const VoidMessage *msg);
00299
00300 inline TransportMessage transport_msg() const
00301 {
00302 return transport(*this);
00303 }
00304 DBMessage::TypeOfQuery qtype;
00305 TypeOfMessage tblid;
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315 static const unsigned int size_of_query = 55;
00316 char data[size_of_query];
00317 };
00318
00320 class TimerMessage : public Message
00321 {
00322 public:
00323 TimerMessage();
00324 TimerMessage(UniSetTypes::TimerId id, Priority prior = Message::High,
00325 ObjectId cons=UniSetTypes::DefaultObjectId);
00326 TimerMessage(const VoidMessage *msg);
00327 inline TransportMessage transport_msg() const
00328 {
00329 return transport(*this);
00330 }
00331
00332 UniSetTypes::TimerId id;
00333 };
00334
00336 class ConfirmMessage: public Message
00337 {
00338 public:
00339
00340 inline TransportMessage transport_msg() const
00341 {
00342 return transport(*this);
00343 }
00344
00345 ConfirmMessage( const VoidMessage *msg );
00346
00347 ConfirmMessage(long in_sensor_id,
00348 double in_value,
00349 time_t in_time,
00350 time_t in_time_usec,
00351 time_t in_confirm,
00352 Priority in_priority = Message::Medium);
00353
00354
00355 long sensor_id;
00356 double value;
00357 time_t time;
00358 time_t time_usec;
00359 time_t confirm;
00360
00361 bool broadcast;
00362
00368 bool route;
00369
00370 protected:
00371 ConfirmMessage();
00372 };
00373
00374 }
00375
00376 #endif // MessageType_H_