|
UniSet
2.0.0
|
00001 // ----------------------------------------------------------------------------- 00002 #ifndef SharedMemory_H_ 00003 #define SharedMemory_H_ 00004 // ----------------------------------------------------------------------------- 00005 #include <string> 00006 #include <deque> 00007 #include "IONotifyController_LT.h" 00008 #include "Mutex.h" 00009 #include "PassiveTimer.h" 00010 #include "NCRestorer.h" 00011 #include "WDTInterface.h" 00012 // ----------------------------------------------------------------------------- 00013 00255 class SharedMemory: 00256 public IONotifyController_LT 00257 { 00258 public: 00259 SharedMemory( UniSetTypes::ObjectId id, const std::string& datafile, const std::string& confname="" ); 00260 virtual ~SharedMemory(); 00261 00263 static SharedMemory* init_smemory( int argc, const char* const* argv ); 00265 static void help_print( int argc, const char* const* argv ); 00266 00267 // функция определяет "готовность" SM к работе. 00268 // должна использоваться другими процессами, для того, 00269 // чтобы понять, когда можно получать от SM данные. 00270 virtual CORBA::Boolean exist(); 00271 00272 void addReadItem( Restorer_XML::ReaderSlot sl ); 00273 00274 00275 // ------------ HISTORY -------------------- 00276 typedef std::deque<long> HBuffer; 00277 00278 struct HistoryItem 00279 { 00280 HistoryItem():id(UniSetTypes::DefaultObjectId){} 00281 00282 inline void init( unsigned int size, long val ) 00283 { 00284 if( size > 0 ) 00285 buf.assign(size,val); 00286 } 00287 00288 UniSetTypes::ObjectId id; 00289 HBuffer buf; 00290 00291 IOStateList::iterator ioit; 00292 00293 void add( long val, size_t size ) 00294 { 00295 // т.е. буфер у нас уже заданного размера 00296 // то просто удаляем очередную точку в начале 00297 // и добавляем в конце 00298 buf.pop_front(); 00299 buf.push_back(val); 00300 } 00301 }; 00302 00303 typedef std::list<HistoryItem> HistoryList; 00304 00305 struct HistoryInfo 00306 { 00307 HistoryInfo(): 00308 id(0), 00309 size(0),filter(""), 00310 fuse_id(UniSetTypes::DefaultObjectId), 00311 fuse_invert(false),fuse_use_val(false),fuse_val(0), 00312 fuse_sec(0),fuse_usec(0) 00313 { 00314 struct timeval tv; 00315 struct timezone tz; 00316 gettimeofday(&tv,&tz); 00317 fuse_sec = tv.tv_sec; 00318 fuse_usec = tv.tv_usec; 00319 } 00320 00321 long id; // ID 00322 HistoryList hlst; // history list 00323 int size; 00324 std::string filter; // filter field 00325 UniSetTypes::ObjectId fuse_id; // fuse sesnsor 00326 bool fuse_invert; 00327 bool fuse_use_val; 00328 long fuse_val; 00329 // timestamp 00330 long fuse_sec; 00331 long fuse_usec; 00332 }; 00333 00334 friend std::ostream& operator<<( std::ostream& os, const HistoryInfo& h ); 00335 00336 typedef std::list<HistoryInfo> History; 00337 00338 // т.к. могуть быть одинаковые "детонаторы" для разных "историй" то, 00339 // вводим не просто map, а "map списка историй". 00340 // точнее итераторов-историй. 00341 typedef std::list<History::iterator> HistoryItList; 00342 typedef std::map<UniSetTypes::ObjectId,HistoryItList> HistoryFuseMap; 00343 00344 typedef sigc::signal<void,HistoryInfo*> HistorySlot; 00345 HistorySlot signal_history(); 00347 inline int getHistoryStep(){ return histSaveTime; } 00349 protected: 00350 typedef std::list<Restorer_XML::ReaderSlot> ReadSlotList; 00351 ReadSlotList lstRSlot; 00352 00353 virtual void sysCommand( const UniSetTypes::SystemMessage *sm ) override; 00354 virtual void timerInfo( const UniSetTypes::TimerMessage *tm ) override; 00355 virtual void askSensors( UniversalIO::UIOCommand cmd ); 00356 void sendEvent( UniSetTypes::SystemMessage& sm ); 00357 00358 // действия при завершении работы 00359 virtual void sigterm( int signo ) override; 00360 virtual bool activateObject() override; 00361 // virtual void logging(UniSetTypes::SensorMessage& sm){} 00362 // virtual void dumpToDB(){} 00363 bool readItem( const std::shared_ptr<UniXML>& xml, UniXML::iterator& it, xmlNode* sec ); 00364 00365 void buildEventList( xmlNode* cnode ); 00366 void readEventList( const std::string& oname ); 00367 00368 UniSetTypes::uniset_rwmutex mutex_start; 00369 00370 struct HeartBeatInfo 00371 { 00372 HeartBeatInfo(): 00373 a_sid(UniSetTypes::DefaultObjectId), 00374 d_sid(UniSetTypes::DefaultObjectId), 00375 reboot_msec(UniSetTimer::WaitUpTime), 00376 timer_running(false), 00377 ptReboot(UniSetTimer::WaitUpTime) 00378 {} 00379 00380 UniSetTypes::ObjectId a_sid; // аналоговый счётчик 00381 UniSetTypes::ObjectId d_sid; // дискретный датчик состояния процесса 00382 IOStateList::iterator ioit; 00383 00384 int reboot_msec; 00389 bool timer_running; 00390 PassiveTimer ptReboot; 00391 }; 00392 00393 enum Timers 00394 { 00395 tmHeartBeatCheck, 00396 tmEvent, 00397 tmHistory, 00398 tmPulsar 00399 }; 00400 00401 int heartbeatCheckTime; 00402 std::string heartbeat_node; 00403 int histSaveTime; 00404 00405 void checkHeartBeat(); 00406 00407 typedef std::list<HeartBeatInfo> HeartBeatList; 00408 HeartBeatList hlist; // список датчиков "сердцебиения" 00409 WDTInterface* wdt; 00410 std::atomic_bool activated; 00411 std::atomic_bool workready; 00412 00413 typedef std::list<UniSetTypes::ObjectId> EventList; 00414 EventList elst; 00415 std::string e_filter; 00416 int evntPause; 00417 int activateTimeout; 00418 00419 virtual void loggingInfo( UniSetTypes::SensorMessage& sm ) override; 00420 virtual void dumpOrdersList( const UniSetTypes::ObjectId sid, const IONotifyController::ConsumerListInfo& lst ) override {}; 00421 virtual void dumpThresholdList( const UniSetTypes::ObjectId sid, const IONotifyController::ThresholdExtList& lst ) override {} 00422 00423 bool dblogging; 00424 00425 History hist; 00426 HistoryFuseMap histmap; 00428 virtual void updateHistory( IOStateList::iterator& it, IOController* ); 00429 virtual void saveHistory(); 00430 00431 void buildHistoryList( xmlNode* cnode ); 00432 void checkHistoryFilter( UniXML::iterator& it ); 00433 00434 IOStateList::iterator itPulsar; 00435 UniSetTypes::ObjectId sidPulsar; 00436 int msecPulsar; 00437 00438 private: 00439 HistorySlot m_historySignal; 00440 }; 00441 // ----------------------------------------------------------------------------- 00442 #endif // SharedMemory_H_ 00443 // -----------------------------------------------------------------------------
1.7.6.1