SharedMemory/SharedMemory.h
00001
00002 #ifndef SharedMemory_H_
00003 #define SharedMemory_H_
00004
00005 #include <string>
00006 #include <list>
00007 #include "IONotifyController_LT.h"
00008 #include "Mutex.h"
00009 #include "PassiveTimer.h"
00010 #include "NCRestorer.h"
00011 #include "WDTInterface.h"
00012
00013
00256 class SharedMemory:
00257 public IONotifyController_LT
00258 {
00259 public:
00260 SharedMemory( UniSetTypes::ObjectId id, std::string datafile, std::string confname="" );
00261 virtual ~SharedMemory();
00262
00264 static SharedMemory* init_smemory( int argc, const char* const* argv );
00266 static void help_print( int argc, const char* const* argv );
00267
00268
00269
00270
00271 virtual CORBA::Boolean exist();
00272
00273 void addReadItem( Restorer_XML::ReaderSlot sl );
00274
00275
00276
00277 typedef std::list<long> HBuffer;
00278
00279 struct HistoryItem
00280 {
00281 HistoryItem():id(UniSetTypes::DefaultObjectId){}
00282
00283 UniSetTypes::ObjectId id;
00284 HBuffer buf;
00285
00286 AIOStateList::iterator ait;
00287 DIOStateList::iterator dit;
00288
00289 void add( long val, size_t size )
00290 {
00291 buf.push_back(val);
00292 if( buf.size() >= size )
00293 buf.erase(buf.begin());
00294 }
00295 };
00296
00297 typedef std::list<HistoryItem> HistoryList;
00298
00299 struct HistoryInfo
00300 {
00301 HistoryInfo():
00302 id(0),
00303 size(0),filter(""),
00304 fuse_id(UniSetTypes::DefaultObjectId),
00305 fuse_invert(false),fuse_use_val(false),fuse_val(0),
00306 fuse_sec(0),fuse_usec(0)
00307 {
00308 struct timeval tv;
00309 struct timezone tz;
00310 gettimeofday(&tv,&tz);
00311 fuse_sec = tv.tv_sec;
00312 fuse_usec = tv.tv_usec;
00313 }
00314
00315 long id;
00316 HistoryList hlst;
00317 int size;
00318 std::string filter;
00319 UniSetTypes::ObjectId fuse_id;
00320 bool fuse_invert;
00321 bool fuse_use_val;
00322 long fuse_val;
00323
00324 long fuse_sec;
00325 long fuse_usec;
00326 };
00327
00328 friend std::ostream& operator<<( std::ostream& os, const HistoryInfo& h );
00329
00330 typedef std::list<HistoryInfo> History;
00331
00332
00333
00334
00335 typedef std::list<History::iterator> HistoryItList;
00336 typedef std::map<UniSetTypes::ObjectId,HistoryItList> HistoryFuseMap;
00337
00338 typedef sigc::signal<void,HistoryInfo*> HistorySlot;
00339 HistorySlot signal_history();
00341 inline int getHistoryStep(){ return histSaveTime; }
00343 protected:
00344 typedef std::list<Restorer_XML::ReaderSlot> ReadSlotList;
00345 ReadSlotList lstRSlot;
00346
00347 virtual void processingMessage( UniSetTypes::VoidMessage *msg );
00348 virtual void sysCommand( UniSetTypes::SystemMessage *sm );
00349 virtual void sensorInfo( UniSetTypes::SensorMessage *sm );
00350 virtual void timerInfo( UniSetTypes::TimerMessage *tm );
00351 virtual void askSensors( UniversalIO::UIOCommand cmd );
00352 virtual void sendEvent( UniSetTypes::SystemMessage& sm );
00353
00354
00355 virtual void sigterm( int signo );
00356 bool activateObject();
00357
00358
00359 bool readItem( UniXML& xml, UniXML_iterator& it, xmlNode* sec );
00360
00361 void buildEventList( xmlNode* cnode );
00362 void readEventList( std::string oname );
00363
00364 UniSetTypes::uniset_mutex mutex_start;
00365
00366 struct HeartBeatInfo
00367 {
00368 HeartBeatInfo():
00369 a_sid(UniSetTypes::DefaultObjectId),
00370 d_sid(UniSetTypes::DefaultObjectId),
00371 reboot_msec(UniSetTimer::WaitUpTime),
00372 timer_running(false),
00373 ptReboot(UniSetTimer::WaitUpTime)
00374 {}
00375
00376 UniSetTypes::ObjectId a_sid;
00377 UniSetTypes::ObjectId d_sid;
00378 AIOStateList::iterator ait;
00379 DIOStateList::iterator dit;
00380
00381 int reboot_msec;
00386 bool timer_running;
00387 PassiveTimer ptReboot;
00388 };
00389
00390 enum Timers
00391 {
00392 tmHeartBeatCheck,
00393 tmEvent,
00394 tmHistory,
00395 tmPulsar
00396 };
00397
00398 int heartbeatCheckTime;
00399 std::string heartbeat_node;
00400 int histSaveTime;
00401
00402 void checkHeartBeat();
00403
00404 typedef std::list<HeartBeatInfo> HeartBeatList;
00405 HeartBeatList hlist;
00406 WDTInterface* wdt;
00407 bool activated;
00408 bool workready;
00409
00410 typedef std::list<UniSetTypes::ObjectId> EventList;
00411 EventList elst;
00412 std::string e_filter;
00413 int evntPause;
00414 int activateTimeout;
00415
00416 virtual void loggingInfo(UniSetTypes::SensorMessage& sm);
00417 virtual void dumpOrdersList(const IOController_i::SensorInfo& si, const IONotifyController::ConsumerList& lst){}
00418 virtual void dumpThresholdList(const IOController_i::SensorInfo& si, const IONotifyController::ThresholdExtList& lst){}
00419
00420 bool dblogging;
00421
00422 History hist;
00423 HistoryFuseMap histmap;
00425 virtual void updateHistory( UniSetTypes::SensorMessage* sm );
00426 virtual void saveHistory();
00427
00428 void buildHistoryList( xmlNode* cnode );
00429 void checkHistoryFilter( UniXML_iterator& it );
00430 bool isActivated();
00431
00432
00433 DIOStateList::iterator ditPulsar;
00434 IOController_i::SensorInfo siPulsar;
00435 UniversalIO::IOTypes iotypePulsar;
00436 int msecPulsar;
00437
00438 UniSetTypes::uniset_mutex act_mutex;
00439
00440 private:
00441 HistorySlot m_historySignal;
00442 };
00443
00444 #endif // SharedMemory_H_
00445