UniSet  2.6.0
TestProc_SK.h
00001 
00002 // --------------------------------------------------------------------------
00003 /*
00004  DO NOT EDIT THIS FILE. IT IS AUTOGENERATED FILE.
00005  ALL YOUR CHANGES WILL BE LOST.
00006  
00007  НЕ РЕДАКТИРУЙТЕ ЭТОТ ФАЙЛ. ЭТОТ ФАЙЛ СОЗДАН АВТОМАТИЧЕСКИ.
00008  ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
00009 */ 
00010 // --------------------------------------------------------------------------
00011 // generate timestamp: 2016-12-09
00012 // -----------------------------------------------------------------------------
00013 #ifndef TestProc_SK_H_
00014 #define TestProc_SK_H_
00015 // -----------------------------------------------------------------------------
00016 #include <memory>
00017 #include <string>
00018 #include <unordered_map>
00019 #include <sstream>
00020 #include "UniSetObject.h"
00021 #include "UniXML.h"
00022 #include "Trigger.h"
00023 #include "DebugStream.h"
00024 #include "LogServer.h"
00025 #include "LogAgregator.h"
00026 #include "VMonitor.h"
00027 // -----------------------------------------------------------------------------
00028 class TestProc_SK:
00029     public uniset::UniSetObject
00030 {
00031     public:
00032         TestProc_SK( uniset::ObjectId id, xmlNode* node=uniset::uniset_conf()->getNode("TestProc"), const std::string& argprefix="" );
00033         TestProc_SK();
00034         virtual ~TestProc_SK();
00035 
00036         
00037         long getValue( uniset::ObjectId sid );
00038         void setValue( uniset::ObjectId sid, long value );
00039         void askSensor( uniset::ObjectId sid, UniversalIO::UIOCommand, uniset::ObjectId node = uniset::uniset_conf()->getLocalNode() );
00040         void updateValues();
00041 
00042         virtual uniset::SimpleInfo* getInfo( const char* userparam ) override;
00043 
00044         virtual bool setMsg( uniset::ObjectId code, bool state = true ) noexcept;
00045 
00046         inline std::shared_ptr<DebugStream> log() noexcept { return mylog; }
00047         inline std::shared_ptr<uniset::LogAgregator> logAgregator() noexcept { return loga; }
00048 
00049         void init_dlog( std::shared_ptr<DebugStream> d ) noexcept;
00050 
00051         // "синтаксический сахар"..для логов
00052         #ifndef myinfo 
00053             #define myinfo if( log()->debugging(Debug::INFO) ) log()->info() 
00054         #endif
00055         #ifndef mywarn
00056             #define mywarn if( log()->debugging(Debug::WARN) ) log()->warn()
00057         #endif
00058         #ifndef mycrit
00059             #define mycrit if( log()->debugging(Debug::CRIT) ) log()->crit()
00060         #endif
00061         #ifndef mylog1
00062             #define mylog1 if( log()->debugging(Debug::LEVEL1) ) log()->level1()
00063         #endif
00064         #ifndef mylog2
00065             #define mylog2 if( log()->debugging(Debug::LEVEL2) ) log()->level2()
00066         #endif
00067         #ifndef mylog3
00068             #define mylog3 if( log()->debugging(Debug::LEVEL3) ) log()->level3()
00069         #endif
00070         #ifndef mylog4
00071             #define mylog4 if( log()->debugging(Debug::LEVEL4) ) log()->level4()
00072         #endif
00073         #ifndef mylog5
00074             #define mylog5 if( log()->debugging(Debug::LEVEL5) ) log()->level5()
00075         #endif
00076         #ifndef mylog6
00077             #define mylog6 if( log()->debugging(Debug::LEVEL6) ) log()->level6()
00078         #endif
00079         #ifndef mylog7
00080             #define mylog7 if( log()->debugging(Debug::LEVEL7) ) log()->level7()
00081         #endif
00082         #ifndef mylog8
00083             #define mylog8 if( log()->debugging(Debug::LEVEL8) ) log()->level8()
00084         #endif
00085         #ifndef mylog9
00086             #define mylog9 if( log()->debugging(Debug::LEVEL9) ) log()->level9()
00087         #endif
00088         #ifndef mylogany
00089             #define mylogany log()->any()
00090         #endif
00091         #ifndef vmonit
00092             #define vmonit( var ) vmon.add( #var, var )
00093         #endif
00094         
00095         // Вспомогательные функции для удобства логирования
00096         // ------------------------------------------------------------
00104         std::string dumpIO();
00105         
00110         std::string str( uniset::ObjectId id, bool showLinkName=true ) const;
00111         
00116         std::string strval( uniset::ObjectId id, bool showLinkName=true ) const;        
00117         
00119         inline std::string dumpVars(){ return std::move(vmon.pretty_str()); }
00120         // ------------------------------------------------------------
00121         std::string help() noexcept;
00122 
00123 
00124 #ifndef DISABLE_REST_API
00125         // HTTP API
00126         virtual Poco::JSON::Object::Ptr httpGet( const Poco::URI::QueryParameters& p ) override;
00127         virtual Poco::JSON::Object::Ptr httpRequest( const std::string& req, const Poco::URI::QueryParameters& p ) override;
00128         virtual Poco::JSON::Object::Ptr httpHelp( const Poco::URI::QueryParameters& p ) override;
00129 #endif
00130 
00131 
00132         // Используемые идентификаторы
00133         
00134 
00135         // Используемые идентификаторы сообщений
00136         
00137 
00138         // Текущее значение
00139         
00140 
00141         // --- public variables ---
00142         
00143         
00144         // --- end of public variables ---
00145 
00146     protected:
00147         // --- protected variables ---
00148         
00149         
00150         // ---- end of protected variables ----
00151 
00152         
00153         virtual void callback() noexcept override;
00154         virtual void processingMessage( const uniset::VoidMessage* msg ) override;
00155         virtual void sysCommand( const uniset::SystemMessage* sm ){};
00156         virtual void askSensors( UniversalIO::UIOCommand cmd ){}
00157         virtual void sensorInfo( const uniset::SensorMessage* sm ) override{}
00158         virtual void timerInfo( const uniset::TimerMessage* tm ) override{}
00159         virtual void sigterm( int signo ) override;
00160         virtual bool activateObject() override;
00161         virtual std::string getMonitInfo(){ return ""; } 
00163 #ifndef DISABLE_REST_API
00164         virtual void httpGetUserData( Poco::JSON::Object::Ptr& jdata ){} 
00165         virtual Poco::JSON::Object::Ptr httpDumpIO();
00166         virtual Poco::JSON::Object::Ptr httpRequestLog( const Poco::URI::QueryParameters& p );
00167 #endif
00168 
00169         // Выполнение очередного шага программы
00170         virtual void step(){}
00171 
00172         void preAskSensors( UniversalIO::UIOCommand cmd );
00173         void preSysCommand( const uniset::SystemMessage* sm );
00174         
00175         virtual void testMode( bool state );
00176         void updateOutputs( bool force );
00177 
00178         void waitSM( int wait_msec, uniset::ObjectId testID = uniset::DefaultObjectId );
00179         uniset::ObjectId getSMTestID();
00180 
00181         void resetMsg();
00182         uniset::Trigger trResetMsg;
00183         uniset::PassiveTimer ptResetMsg;
00184         int resetMsgTime;
00185 
00186         int sleep_msec; 
00187         bool active;
00188 
00189         const std::string argprefix;
00190         uniset::ObjectId smTestID; 
00192         // управление датчиком "сердцебиения"
00193         uniset::PassiveTimer ptHeartBeat;               
00194         uniset::ObjectId idHeartBeat;       
00195         long maxHeartBeat;                      
00197         xmlNode* confnode;
00199         int getIntProp(const std::string& name) { return uniset::uniset_conf()->getIntProp(confnode, name); }
00201         inline const std::string getProp(const std::string& name) { return uniset::uniset_conf()->getProp(confnode, name); }
00202 
00203         uniset::timeout_t smReadyTimeout;   
00204         std::atomic_bool activated;
00205         uniset::timeout_t activateTimeout;  
00206         uniset::PassiveTimer ptStartUpTimeout;  
00207         int askPause; 
00209         IOController_i::SensorInfo si;
00210         bool forceOut; 
00212         std::shared_ptr<uniset::LogAgregator> loga;
00213         std::shared_ptr<DebugStream> mylog;
00214         std::shared_ptr<uniset::LogServer> logserv;
00215         std::string logserv_host = {""};
00216         int logserv_port = {0};
00217 
00218         uniset::VMonitor vmon;
00219 
00220         
00221 
00222     private:
00223         
00224         // --- private variables ---
00225         // --- end of private variables ---
00226 
00227         // предыдущее значение (для работы UpdateValue())
00228         
00229         
00230         // Текущее значение (rw-переменные)
00231         
00232 
00233         // Используемые идентификаторы сообщений
00234         
00235         // ------------ private функции ---------------
00236         void updatePreviousValues() noexcept;
00237         void preSensorInfo( const uniset::SensorMessage* sm );
00238         void preTimerInfo( const uniset::TimerMessage* tm );
00239         void initFromSM();
00240         void checkSensors();
00241         // --------------------------------------------
00242         
00243         class StatHashFn
00244         {
00245             public:
00246             size_t operator() (const uniset::ObjectId& key) const
00247             {
00248                 return std::hash<long>()(key);
00249             }
00250         };
00251         
00252         std::unordered_map<const uniset::ObjectId,size_t, StatHashFn> smStat; 
00253         size_t processingMessageCatchCount = { 0 }; 
00256         bool end_private; // вспомогательное поле (для внутреннего использования при генерировании кода)
00257 };
00258 
00259 // -----------------------------------------------------------------------------
00260 #endif // TestProc_SK_H_