UniSet  2.6.0
UObject_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-01+03:00
00012 // -----------------------------------------------------------------------------
00013 #ifndef UObject_SK_H_
00014 #define UObject_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 UObject_SK:
00029     public uniset::UniSetObject
00030 {
00031     public:
00032         UObject_SK( uniset::ObjectId id, xmlNode* node = uniset::uniset_conf()->getNode("UObject"), const std::string& argprefix = "" );
00033         UObject_SK();
00034         virtual ~UObject_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
00047         {
00048             return mylog;
00049         }
00050         inline std::shared_ptr<uniset::LogAgregator> logAgregator() noexcept
00051         {
00052             return loga;
00053         }
00054 
00055         void init_dlog( std::shared_ptr<DebugStream> d ) noexcept;
00056 
00057         // "синтаксический сахар"..для логов
00058 #ifndef myinfo
00059 #define myinfo if( log()->debugging(Debug::INFO) ) log()->info()
00060 #endif
00061 #ifndef mywarn
00062 #define mywarn if( log()->debugging(Debug::WARN) ) log()->warn()
00063 #endif
00064 #ifndef mycrit
00065 #define mycrit if( log()->debugging(Debug::CRIT) ) log()->crit()
00066 #endif
00067 #ifndef mylog1
00068 #define mylog1 if( log()->debugging(Debug::LEVEL1) ) log()->level1()
00069 #endif
00070 #ifndef mylog2
00071 #define mylog2 if( log()->debugging(Debug::LEVEL2) ) log()->level2()
00072 #endif
00073 #ifndef mylog3
00074 #define mylog3 if( log()->debugging(Debug::LEVEL3) ) log()->level3()
00075 #endif
00076 #ifndef mylog4
00077 #define mylog4 if( log()->debugging(Debug::LEVEL4) ) log()->level4()
00078 #endif
00079 #ifndef mylog5
00080 #define mylog5 if( log()->debugging(Debug::LEVEL5) ) log()->level5()
00081 #endif
00082 #ifndef mylog6
00083 #define mylog6 if( log()->debugging(Debug::LEVEL6) ) log()->level6()
00084 #endif
00085 #ifndef mylog7
00086 #define mylog7 if( log()->debugging(Debug::LEVEL7) ) log()->level7()
00087 #endif
00088 #ifndef mylog8
00089 #define mylog8 if( log()->debugging(Debug::LEVEL8) ) log()->level8()
00090 #endif
00091 #ifndef mylog9
00092 #define mylog9 if( log()->debugging(Debug::LEVEL9) ) log()->level9()
00093 #endif
00094 #ifndef mylogany
00095 #define mylogany log()->any()
00096 #endif
00097 #ifndef vmonit
00098 #define vmonit( var ) vmon.add( #var, var )
00099 #endif
00100 
00101         // Вспомогательные функции для удобства логирования
00102         // ------------------------------------------------------------
00110         std::string dumpIO();
00111 
00116         std::string str( uniset::ObjectId id, bool showLinkName = true ) const;
00117 
00122         std::string strval( uniset::ObjectId id, bool showLinkName = true ) const;
00123 
00125         inline std::string dumpVars()
00126         {
00127             return std::move(vmon.pretty_str());
00128         }
00129         // ------------------------------------------------------------
00130         std::string help() noexcept;
00131 
00132 
00133 #ifndef DISABLE_REST_API
00134         // HTTP API
00135         virtual Poco::JSON::Object::Ptr httpGet( const Poco::URI::QueryParameters& p ) override;
00136         virtual Poco::JSON::Object::Ptr httpRequest( const std::string& req, const Poco::URI::QueryParameters& p ) override;
00137         virtual Poco::JSON::Object::Ptr httpHelp( const Poco::URI::QueryParameters& p ) override;
00138 #endif
00139 
00140 
00141         // Используемые идентификаторы
00142 
00143 
00144         // Используемые идентификаторы сообщений
00145 
00146 
00147         // Текущее значение
00148 
00149 
00150         // --- public variables ---
00151 
00152 
00153         // --- end of public variables ---
00154 
00155     protected:
00156         // --- protected variables ---
00157 
00158 
00159         // ---- end of protected variables ----
00160 
00161 
00162         virtual void callback() noexcept override;
00163         virtual void processingMessage( const uniset::VoidMessage* msg ) override;
00164         virtual void sysCommand( const uniset::SystemMessage* sm ) {};
00165         virtual void askSensors( UniversalIO::UIOCommand cmd ) {}
00166         virtual void sensorInfo( const uniset::SensorMessage* sm ) override {}
00167         virtual void timerInfo( const uniset::TimerMessage* tm ) override {}
00168         virtual void sigterm( int signo ) override;
00169         virtual bool activateObject() override;
00170         virtual std::string getMonitInfo()
00171         {
00172             return "";    
00173         }
00174 
00175 #ifndef DISABLE_REST_API
00176         virtual void httpGetUserData( Poco::JSON::Object::Ptr& jdata ) {} 
00177         virtual Poco::JSON::Object::Ptr httpDumpIO();
00178         virtual Poco::JSON::Object::Ptr httpRequestLog( const Poco::URI::QueryParameters& p );
00179 #endif
00180 
00181         // Выполнение очередного шага программы
00182         virtual void step() {}
00183 
00184         void preAskSensors( UniversalIO::UIOCommand cmd );
00185         void preSysCommand( const uniset::SystemMessage* sm );
00186 
00187         virtual void testMode( bool state );
00188         void updateOutputs( bool force );
00189 
00190         void waitSM( int wait_msec, uniset::ObjectId testID = uniset::DefaultObjectId );
00191         uniset::ObjectId getSMTestID();
00192 
00193         void resetMsg();
00194         uniset::Trigger trResetMsg;
00195         uniset::PassiveTimer ptResetMsg;
00196         int resetMsgTime;
00197 
00198         int sleep_msec; 
00199         bool active;
00200 
00201         const std::string argprefix;
00202         uniset::ObjectId smTestID; 
00204         // управление датчиком "сердцебиения"
00205         uniset::PassiveTimer ptHeartBeat;               
00206         uniset::ObjectId idHeartBeat;       
00207         long maxHeartBeat;                      
00209         xmlNode* confnode;
00211         int getIntProp(const std::string& name)
00212         {
00213             return uniset::uniset_conf()->getIntProp(confnode, name);
00214         }
00216         inline const std::string getProp(const std::string& name)
00217         {
00218             return uniset::uniset_conf()->getProp(confnode, name);
00219         }
00220 
00221         uniset::timeout_t smReadyTimeout;   
00222         std::atomic_bool activated;
00223         uniset::timeout_t activateTimeout;  
00224         uniset::PassiveTimer ptStartUpTimeout;  
00225         int askPause; 
00227         IOController_i::SensorInfo si;
00228         bool forceOut; 
00230         std::shared_ptr<uniset::LogAgregator> loga;
00231         std::shared_ptr<DebugStream> mylog;
00232         std::shared_ptr<uniset::LogServer> logserv;
00233         std::string logserv_host = {""};
00234         int logserv_port = {0};
00235 
00236         uniset::VMonitor vmon;
00237 
00238 
00239 
00240     private:
00241 
00242         // --- private variables ---
00243         // --- end of private variables ---
00244 
00245         // предыдущее значение (для работы UpdateValue())
00246 
00247 
00248         // Текущее значение (rw-переменные)
00249 
00250 
00251         // Используемые идентификаторы сообщений
00252 
00253         // ------------ private функции ---------------
00254         void updatePreviousValues() noexcept;
00255         void preSensorInfo( const uniset::SensorMessage* sm );
00256         void preTimerInfo( const uniset::TimerMessage* tm );
00257         void initFromSM();
00258         void checkSensors();
00259         // --------------------------------------------
00260 
00261         class StatHashFn
00262         {
00263             public:
00264                 size_t operator() (const uniset::ObjectId& key) const
00265                 {
00266                     return std::hash<long>()(key);
00267                 }
00268         };
00269 
00270         std::unordered_map<const uniset::ObjectId, size_t, StatHashFn> smStat; 
00271         size_t processingMessageCatchCount = { 0 }; 
00274         bool end_private; // вспомогательное поле (для внутреннего использования при генерировании кода)
00275 };
00276 
00277 // -----------------------------------------------------------------------------
00278 #endif // UObject_SK_H_