UniSet  2.24.2
UObject_SK.h
1 
2 // --------------------------------------------------------------------------
3 /*
4  DO NOT EDIT THIS FILE. IT IS AUTOGENERATED FILE.
5  ALL YOUR CHANGES WILL BE LOST.
6 
7  НЕ РЕДАКТИРУЙТЕ ЭТОТ ФАЙЛ. ЭТОТ ФАЙЛ СОЗДАН АВТОМАТИЧЕСКИ.
8  ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
9 */
10 // --------------------------------------------------------------------------
11 // generate timestamp: 2021-01-06+03:00
12 // -----------------------------------------------------------------------------
13 #ifndef UObject_SK_H_
14 #define UObject_SK_H_
15 // -----------------------------------------------------------------------------
16 #include <memory>
17 #include <string>
18 #include <unordered_map>
19 #include <sstream>
20 #include "UniSetObject.h"
21 #include "UniXML.h"
22 #include "Trigger.h"
23 #include "DebugStream.h"
24 #include "LogServer.h"
25 #include "LogAgregator.h"
26 #include "VMonitor.h"
27 // -----------------------------------------------------------------------------
28 class UObject_SK:
30 {
31  public:
32  UObject_SK( uniset::ObjectId id, xmlNode* node = uniset::uniset_conf()->getNode("UObject"), const std::string& argprefix = "", xmlNode* globalConfNode = nullptr );
33  UObject_SK();
34  virtual ~UObject_SK();
35 
36 
37  long getValue( uniset::ObjectId sid );
38  void setValue( uniset::ObjectId sid, long value );
39  void askSensor( uniset::ObjectId sid, UniversalIO::UIOCommand, uniset::ObjectId node = uniset::uniset_conf()->getLocalNode() );
40  void updateValues();
41 
42  virtual uniset::SimpleInfo* getInfo( const char* userparam ) override;
43 
44  virtual bool setMsg( uniset::ObjectId code, bool state = true ) noexcept;
45 
46  inline std::shared_ptr<DebugStream> log() noexcept
47  {
48  return mylog;
49  }
50  inline std::shared_ptr<uniset::LogAgregator> logAgregator() noexcept
51  {
52  return loga;
53  }
54 
55  void init_dlog( std::shared_ptr<DebugStream> d ) noexcept;
56 
57  // "синтаксический сахар"..для логов
58 #ifndef myinfo
59 #define myinfo if( log()->debugging(Debug::INFO) ) log()->info()
60 #endif
61 #ifndef mywarn
62 #define mywarn if( log()->debugging(Debug::WARN) ) log()->warn()
63 #endif
64 #ifndef mycrit
65 #define mycrit if( log()->debugging(Debug::CRIT) ) log()->crit()
66 #endif
67 #ifndef mylog1
68 #define mylog1 if( log()->debugging(Debug::LEVEL1) ) log()->level1()
69 #endif
70 #ifndef mylog2
71 #define mylog2 if( log()->debugging(Debug::LEVEL2) ) log()->level2()
72 #endif
73 #ifndef mylog3
74 #define mylog3 if( log()->debugging(Debug::LEVEL3) ) log()->level3()
75 #endif
76 #ifndef mylog4
77 #define mylog4 if( log()->debugging(Debug::LEVEL4) ) log()->level4()
78 #endif
79 #ifndef mylog5
80 #define mylog5 if( log()->debugging(Debug::LEVEL5) ) log()->level5()
81 #endif
82 #ifndef mylog6
83 #define mylog6 if( log()->debugging(Debug::LEVEL6) ) log()->level6()
84 #endif
85 #ifndef mylog7
86 #define mylog7 if( log()->debugging(Debug::LEVEL7) ) log()->level7()
87 #endif
88 #ifndef mylog8
89 #define mylog8 if( log()->debugging(Debug::LEVEL8) ) log()->level8()
90 #endif
91 #ifndef mylog9
92 #define mylog9 if( log()->debugging(Debug::LEVEL9) ) log()->level9()
93 #endif
94 #ifndef mylogany
95 #define mylogany log()->any()
96 #endif
97 #ifndef vmonit
98 #define vmonit( var ) vmon.add( #var, var )
99 #endif
100 
101  // Вспомогательные функции для удобства логирования
102  // ------------------------------------------------------------
110  std::string dumpIO();
111 
116  std::string str( uniset::ObjectId id, bool showLinkName = true ) const;
117 
122  std::string strval( uniset::ObjectId id, bool showLinkName = true ) const;
123 
128  std::string msgstr( uniset::ObjectId id, bool showLinkName = true ) const;
129 
130 
132  inline std::string dumpVars()
133  {
134  return vmon.pretty_str();
135  }
136  // ------------------------------------------------------------
137  std::string help() const noexcept;
138 
139 
140 #ifndef DISABLE_REST_API
141  // HTTP API
142  virtual Poco::JSON::Object::Ptr httpGet( const Poco::URI::QueryParameters& p ) override;
143  virtual Poco::JSON::Object::Ptr httpRequest( const std::string& req, const Poco::URI::QueryParameters& p ) override;
144  virtual Poco::JSON::Object::Ptr httpHelp( const Poco::URI::QueryParameters& p ) override;
145 #endif
146 
147 
148  // Используемые идентификаторы
149 
150 
151  // Используемые идентификаторы сообщений
152 
153 
154  // Текущее значение
155 
156 
157  // --- public variables ---
158 
159 
160  // --- end of public variables ---
161 
162  protected:
163  // --- protected variables ---
164 
165 
166  // ---- end of protected variables ----
167 
168 
169  virtual void callback() noexcept override;
170  virtual void processingMessage( const uniset::VoidMessage* msg ) override;
171  virtual void sysCommand( const uniset::SystemMessage* sm ) override {}
172  virtual void askSensors( UniversalIO::UIOCommand cmd ) {}
173  virtual void sensorInfo( const uniset::SensorMessage* sm ) override {}
174  virtual void timerInfo( const uniset::TimerMessage* tm ) override {}
175  virtual bool activateObject() override;
176  virtual bool deactivateObject() override;
177  virtual std::string getMonitInfo() const
178  {
179  return "";
180  }
181  virtual std::string getTypeOfMessage( int t ) const
182  {
183  return uniset::strTypeOfMessage(t);
184  }
185 
186 #ifndef DISABLE_REST_API
187  virtual void httpGetUserData( Poco::JSON::Object::Ptr& jdata ) {}
188  virtual Poco::JSON::Object::Ptr httpDumpIO();
189  virtual Poco::JSON::Object::Ptr httpRequestLog( const Poco::URI::QueryParameters& p );
190  virtual Poco::JSON::Object::Ptr request_params_set( const std::string& req, const Poco::URI::QueryParameters& p ) override;
191  virtual Poco::JSON::Object::Ptr request_params_get( const std::string& req, const Poco::URI::QueryParameters& p ) override;
192 #endif
193 
194  // Выполнение очередного шага программы
195  virtual void step() {}
196 
197  void preAskSensors( UniversalIO::UIOCommand cmd );
198  void preSysCommand( const uniset::SystemMessage* sm );
199 
200  virtual void testMode( bool state );
201  void updateOutputs( bool force );
202 
203  bool waitSM( int wait_msec, uniset::ObjectId testID = uniset::DefaultObjectId );
204  uniset::ObjectId getSMTestID() const;
205 
206  void resetMsg();
207  uniset::Trigger trResetMsg;
208  uniset::PassiveTimer ptResetMsg;
209  int resetMsgTime;
210 
212  bool active;
213 
214  const std::string argprefix;
217  // управление датчиком "сердцебиения"
218  uniset::PassiveTimer ptHeartBeat;
222  xmlNode* confnode;
224  int getIntProp(const std::string& name)
225  {
226  return uniset::uniset_conf()->getIntProp(confnode, name);
227  }
229  inline const std::string getProp(const std::string& name)
230  {
231  return uniset::uniset_conf()->getProp(confnode, name);
232  }
233 
234  uniset::timeout_t smReadyTimeout;
235  std::atomic_bool activated = { false };
236  std::atomic_bool cancelled = { false };
237  uniset::timeout_t activateTimeout;
239  int askPause;
242  bool forceOut;
244  std::shared_ptr<uniset::LogAgregator> loga;
245  std::shared_ptr<DebugStream> mylog;
246  std::shared_ptr<uniset::LogServer> logserv;
247  std::string logserv_host = {""};
248  int logserv_port = {0};
249 
250  uniset::VMonitor vmon;
251 
252 
253 
254  private:
255 
256  // --- private variables ---
257  // --- end of private variables ---
258 
259  // предыдущее значение (для работы UpdateValue())
260 
261 
262  // Текущее значение (rw-переменные)
263 
264 
265  // Используемые идентификаторы сообщений
266 
267  // ------------ private функции ---------------
268  void updatePreviousValues() noexcept;
269  void preSensorInfo( const uniset::SensorMessage* sm );
270  void preTimerInfo( const uniset::TimerMessage* tm );
271  void initFromSM();
272  void checkSensors();
273  // --------------------------------------------
274 
275  class StatHashFn
276  {
277  public:
278  size_t operator() (const uniset::ObjectId& key) const
279  {
280  return std::hash<long>()(key);
281  }
282  };
283 
284  std::unordered_map<const uniset::ObjectId, size_t, StatHashFn> smStat;
285  size_t processingMessageCatchCount = { 0 };
287  std::unordered_map<long, size_t> msgTypeStat;
289  std::string ostate = { "" };
292  bool end_private; // вспомогательное поле (для внутреннего использования при генерировании кода)
293 };
294 
295 // -----------------------------------------------------------------------------
296 #endif // UObject_SK_H_
Definition: UObject_SK.h:30
virtual void processingMessage(const uniset::VoidMessage *msg) override
std::string dumpIO()
virtual void httpGetUserData(Poco::JSON::Object::Ptr &jdata)
Definition: UObject_SK.h:187
int askPause
Definition: UObject_SK.h:239
bool forceOut
Definition: UObject_SK.h:242
uniset::timeout_t smReadyTimeout
Definition: UObject_SK.h:234
virtual void callback() noexcept override
std::string str(uniset::ObjectId id, bool showLinkName=true) const
virtual bool deactivateObject() override
Деактивация объекта (переопределяется для необходимых действий при завершении работы)
xmlNode * confnode
Definition: UObject_SK.h:222
virtual std::string getTypeOfMessage(int t) const
Definition: UObject_SK.h:181
int getIntProp(const std::string &name)
Definition: UObject_SK.h:224
uniset::timeout_t activateTimeout
Definition: UObject_SK.h:237
const std::string getProp(const std::string &name)
Definition: UObject_SK.h:229
int sleep_msec
Definition: UObject_SK.h:211
uniset::PassiveTimer ptStartUpTimeout
Definition: UObject_SK.h:238
virtual std::string getMonitInfo() const
Definition: UObject_SK.h:177
std::string dumpVars()
Definition: UObject_SK.h:132
long maxHeartBeat
Definition: UObject_SK.h:220
std::string strval(uniset::ObjectId id, bool showLinkName=true) const
uniset::ObjectId smTestID
Definition: UObject_SK.h:215
uniset::ObjectId idHeartBeat
Definition: UObject_SK.h:219
virtual bool activateObject() override
Активизация объекта (переопределяется для необходимых действий после активизации)
std::string msgstr(uniset::ObjectId id, bool showLinkName=true) const
Пассивный таймер
Definition: PassiveTimer.h:94
Definition: MessageType.h:127
Definition: MessageType.h:171
Definition: MessageType.h:214
Definition: Trigger.h:31
Definition: UniSetObject.h:80
Definition: VMonitor.h:117
std::string pretty_str(int namewidth=NameWidth, int colnum=ColCount) const
Definition: VMonitor.cc:186
Definition: CommonEventLoop.h:15
KeyType key(const uniset::ObjectId id, const uniset::ObjectId node)
Definition: UniSetTypes.cc:746
const ObjectId DefaultObjectId
Definition: UniSetTypes.h:70
std::shared_ptr< Configuration > uniset_conf() noexcept
Definition: Configuration.cc:90
long ObjectId
Definition: UniSetTypes_i.idl:30
Definition: IOController_i.idl:58
Definition: UniSetTypes_i.idl:65