include/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 );
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         // функция определяет "готовность" SM к работе.
00269         // должна использоваться другими процессами, для того, 
00270         // чтобы понять, когда можно получать от SM данные.
00271         virtual CORBA::Boolean exist();
00272 
00273         void addReadItem( Restorer_XML::ReaderSlot sl );
00274         
00275 
00276         // ------------  HISTORY  --------------------
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                 {
00307                       struct timezone tz;
00308                       gettimeofday(&fuse_tm,&tz);
00309                 }
00310             
00311             long id;                        // ID
00312             HistoryList hlst;               // history list
00313             int size;
00314             std::string filter;             // filter field
00315             UniSetTypes::ObjectId fuse_id;  // fuse sesnsor
00316             bool fuse_invert;
00317             bool fuse_use_val;
00318             long fuse_val;
00319             struct timeval fuse_tm;         // timestamp
00320         };
00321         
00322         friend std::ostream& operator<<( std::ostream& os, const HistoryInfo& h );
00323         
00324         typedef std::list<HistoryInfo> History;
00325 
00326         typedef sigc::signal<void,HistoryInfo*> HistorySlot;
00327         HistorySlot signal_history(); 
00329         inline int getHistoryStep(){ return histSaveTime; } 
00331     protected:
00332         typedef std::list<Restorer_XML::ReaderSlot> ReadSlotList;
00333         ReadSlotList lstRSlot;
00334 
00335         virtual void processingMessage( UniSetTypes::VoidMessage *msg );
00336         virtual void sysCommand( UniSetTypes::SystemMessage *sm );
00337         virtual void sensorInfo( UniSetTypes::SensorMessage *sm );
00338         virtual void timerInfo( UniSetTypes::TimerMessage *tm );
00339         virtual void askSensors( UniversalIO::UIOCommand cmd );
00340         virtual void sendEvent( UniSetTypes::SystemMessage& sm );
00341 
00342         virtual void localSaveValue( AIOStateList::iterator& it, const IOController_i::SensorInfo& si,
00343                                         CORBA::Long newvalue, UniSetTypes::ObjectId sup_id );
00344         virtual void localSaveState( DIOStateList::iterator& it, const IOController_i::SensorInfo& si,
00345                                         CORBA::Boolean newstate, UniSetTypes::ObjectId sup_id );
00346         virtual void localSetState( DIOStateList::iterator& it, const IOController_i::SensorInfo& si,
00347                                         CORBA::Boolean newstate, UniSetTypes::ObjectId sup_id );
00348         virtual void localSetValue( AIOStateList::iterator& it, const IOController_i::SensorInfo& si,
00349                                         CORBA::Long value, UniSetTypes::ObjectId sup_id );
00350 
00351 
00352         // действия при завершении работы
00353         virtual void sigterm( int signo );
00354         bool activateObject();
00355 //      virtual void logging(UniSetTypes::SensorMessage& sm){}
00356 //      virtual void dumpToDB(){}
00357         bool readItem( UniXML& xml, UniXML_iterator& it, xmlNode* sec );
00358 
00359     
00360         void buildEventList( xmlNode* cnode );
00361         void readEventList( std::string oname );
00362         
00363         UniSetTypes::uniset_mutex mutex_start;
00364         
00365         struct HeartBeatInfo
00366         {
00367             HeartBeatInfo():
00368                 a_sid(UniSetTypes::DefaultObjectId),
00369                 d_sid(UniSetTypes::DefaultObjectId),
00370                 reboot_msec(UniSetTimer::WaitUpTime),
00371                 timer_running(false),
00372                 ptReboot(UniSetTimer::WaitUpTime)
00373             {}
00374             
00375             UniSetTypes::ObjectId a_sid; // аналоговый счётчик
00376             UniSetTypes::ObjectId d_sid; // дискретный датчик состояния процесса
00377             AIOStateList::iterator ait;
00378             DIOStateList::iterator dit;
00379 
00380             int reboot_msec; 
00385             bool timer_running;
00386             PassiveTimer ptReboot;
00387         };
00388 
00389         enum Timers
00390         {
00391             tmHeartBeatCheck,
00392             tmEvent,
00393             tmHistory,
00394             tmPulsar
00395         };
00396         
00397         int heartbeatCheckTime;
00398         std::string heartbeat_node;
00399         int histSaveTime;
00400         
00401         void checkHeartBeat();
00402 
00403         typedef std::list<HeartBeatInfo> HeartBeatList;
00404         HeartBeatList hlist; // список датчиков "сердцебиения"
00405         UniSetTypes::uniset_mutex hbmutex;
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 
00424         virtual void updateHistory( UniSetTypes::SensorMessage* sm );
00425         virtual void saveHistory();
00426 
00427         void buildHistoryList( xmlNode* cnode );
00428         void checkHistoryFilter( UniXML_iterator& it );
00429         bool isActivated();
00430 
00431 
00432         DIOStateList::iterator ditPulsar;
00433         IOController_i::SensorInfo siPulsar;
00434         UniversalIO::IOTypes iotypePulsar;
00435         int msecPulsar;
00436         
00437         UniSetTypes::uniset_mutex act_mutex;
00438 
00439     private:
00440         HistorySlot m_historySignal;
00441 };
00442 // -----------------------------------------------------------------------------
00443 #endif // SharedMemory_H_
00444 // -----------------------------------------------------------------------------

Документация по UniSet. Последние изменения: Mon Dec 26 11:26:57 2011. Создано системой  doxygen 1.5.9