UniSet
1.4.0
|
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 // функция определяет "готовность" 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 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; // ID 00316 HistoryList hlst; // history list 00317 int size; 00318 std::string filter; // filter field 00319 UniSetTypes::ObjectId fuse_id; // fuse sesnsor 00320 bool fuse_invert; 00321 bool fuse_use_val; 00322 long fuse_val; 00323 // timestamp 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 // вводим не просто map, а "map списка историй". 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 virtual void localSaveValue( AIOStateList::iterator& it, const IOController_i::SensorInfo& si, 00355 CORBA::Long newvalue, UniSetTypes::ObjectId sup_id ); 00356 virtual void localSaveState( DIOStateList::iterator& it, const IOController_i::SensorInfo& si, 00357 CORBA::Boolean newstate, UniSetTypes::ObjectId sup_id ); 00358 virtual void localSetState( DIOStateList::iterator& it, const IOController_i::SensorInfo& si, 00359 CORBA::Boolean newstate, UniSetTypes::ObjectId sup_id ); 00360 virtual void localSetValue( AIOStateList::iterator& it, const IOController_i::SensorInfo& si, 00361 CORBA::Long value, UniSetTypes::ObjectId sup_id ); 00362 00363 00364 // действия при завершении работы 00365 virtual void sigterm( int signo ); 00366 bool activateObject(); 00367 // virtual void logging(UniSetTypes::SensorMessage& sm){} 00368 // virtual void dumpToDB(){} 00369 bool readItem( UniXML& xml, UniXML_iterator& it, xmlNode* sec ); 00370 00371 void buildEventList( xmlNode* cnode ); 00372 void readEventList( std::string oname ); 00373 00374 UniSetTypes::uniset_mutex mutex_start; 00375 00376 struct HeartBeatInfo 00377 { 00378 HeartBeatInfo(): 00379 a_sid(UniSetTypes::DefaultObjectId), 00380 d_sid(UniSetTypes::DefaultObjectId), 00381 reboot_msec(UniSetTimer::WaitUpTime), 00382 timer_running(false), 00383 ptReboot(UniSetTimer::WaitUpTime) 00384 {} 00385 00386 UniSetTypes::ObjectId a_sid; // аналоговый счётчик 00387 UniSetTypes::ObjectId d_sid; // дискретный датчик состояния процесса 00388 AIOStateList::iterator ait; 00389 DIOStateList::iterator dit; 00390 00391 int reboot_msec; 00396 bool timer_running; 00397 PassiveTimer ptReboot; 00398 }; 00399 00400 enum Timers 00401 { 00402 tmHeartBeatCheck, 00403 tmEvent, 00404 tmHistory, 00405 tmPulsar 00406 }; 00407 00408 int heartbeatCheckTime; 00409 std::string heartbeat_node; 00410 int histSaveTime; 00411 00412 void checkHeartBeat(); 00413 00414 typedef std::list<HeartBeatInfo> HeartBeatList; 00415 HeartBeatList hlist; // список датчиков "сердцебиения" 00416 UniSetTypes::uniset_mutex hbmutex; 00417 WDTInterface* wdt; 00418 bool activated; 00419 bool workready; 00420 00421 typedef std::list<UniSetTypes::ObjectId> EventList; 00422 EventList elst; 00423 std::string e_filter; 00424 int evntPause; 00425 int activateTimeout; 00426 00427 virtual void loggingInfo(UniSetTypes::SensorMessage& sm); 00428 virtual void dumpOrdersList(const IOController_i::SensorInfo& si, const IONotifyController::ConsumerList& lst){} 00429 virtual void dumpThresholdList(const IOController_i::SensorInfo& si, const IONotifyController::ThresholdExtList& lst){} 00430 00431 bool dblogging; 00432 00433 History hist; 00434 HistoryFuseMap histmap; 00436 virtual void updateHistory( UniSetTypes::SensorMessage* sm ); 00437 virtual void saveHistory(); 00438 00439 void buildHistoryList( xmlNode* cnode ); 00440 void checkHistoryFilter( UniXML_iterator& it ); 00441 bool isActivated(); 00442 00443 00444 DIOStateList::iterator ditPulsar; 00445 IOController_i::SensorInfo siPulsar; 00446 UniversalIO::IOTypes iotypePulsar; 00447 int msecPulsar; 00448 00449 UniSetTypes::uniset_mutex act_mutex; 00450 00451 private: 00452 HistorySlot m_historySignal; 00453 }; 00454 // ----------------------------------------------------------------------------- 00455 #endif // SharedMemory_H_ 00456 // -----------------------------------------------------------------------------