UniSet  2.7.0
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: 2018-05-18+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 = "" );
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 ) {};
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 #endif
191 
192  // Выполнение очередного шага программы
193  virtual void step() {}
194 
195  void preAskSensors( UniversalIO::UIOCommand cmd );
196  void preSysCommand( const uniset::SystemMessage* sm );
197 
198  virtual void testMode( bool state );
199  void updateOutputs( bool force );
200 
201  bool waitSM( int wait_msec, uniset::ObjectId testID = uniset::DefaultObjectId );
202  uniset::ObjectId getSMTestID() const;
203 
204  void resetMsg();
205  uniset::Trigger trResetMsg;
206  uniset::PassiveTimer ptResetMsg;
207  int resetMsgTime;
208 
210  bool active;
211 
212  const std::string argprefix;
215  // управление датчиком "сердцебиения"
216  uniset::PassiveTimer ptHeartBeat;
220  xmlNode* confnode;
222  int getIntProp(const std::string& name)
223  {
224  return uniset::uniset_conf()->getIntProp(confnode, name);
225  }
227  inline const std::string getProp(const std::string& name)
228  {
229  return uniset::uniset_conf()->getProp(confnode, name);
230  }
231 
232  uniset::timeout_t smReadyTimeout;
233  std::atomic_bool activated = { false };
234  std::atomic_bool cancelled = { false };
235  uniset::timeout_t activateTimeout;
237  int askPause;
240  bool forceOut;
242  std::shared_ptr<uniset::LogAgregator> loga;
243  std::shared_ptr<DebugStream> mylog;
244  std::shared_ptr<uniset::LogServer> logserv;
245  std::string logserv_host = {""};
246  int logserv_port = {0};
247 
248  uniset::VMonitor vmon;
249 
250 
251 
252  private:
253 
254  // --- private variables ---
255  // --- end of private variables ---
256 
257  // предыдущее значение (для работы UpdateValue())
258 
259 
260  // Текущее значение (rw-переменные)
261 
262 
263  // Используемые идентификаторы сообщений
264 
265  // ------------ private функции ---------------
266  void updatePreviousValues() noexcept;
267  void preSensorInfo( const uniset::SensorMessage* sm );
268  void preTimerInfo( const uniset::TimerMessage* tm );
269  void initFromSM();
270  void checkSensors();
271  // --------------------------------------------
272 
273  class StatHashFn
274  {
275  public:
276  size_t operator() (const uniset::ObjectId& key) const
277  {
278  return std::hash<long>()(key);
279  }
280  };
281 
282  std::unordered_map<const uniset::ObjectId, size_t, StatHashFn> smStat;
283  size_t processingMessageCatchCount = { 0 };
285  std::unordered_map<long, size_t> msgTypeStat;
287  std::string ostate = { "" };
290  bool end_private; // вспомогательное поле (для внутреннего использования при генерировании кода)
291 };
292 
293 // -----------------------------------------------------------------------------
294 #endif // UObject_SK_H_
Пассивный таймер
Definition: PassiveTimer.h:92
virtual bool activateObject() override
Активизация объекта (переопределяется для необходимых действий после активизации) ...
virtual void callback() noexcept override
bool forceOut
Definition: UObject_SK.h:240
const std::string getProp(const std::string &name)
Definition: UObject_SK.h:227
int askPause
Definition: UObject_SK.h:237
xmlNode * confnode
Definition: UObject_SK.h:220
int getIntProp(const std::string &name)
Definition: UObject_SK.h:222
Definition: MessageType.h:168
Definition: UniSetObject.h:73
std::string dumpVars()
Definition: UObject_SK.h:132
Definition: VMonitor.h:116
virtual std::string getTypeOfMessage(int t) const
Definition: UObject_SK.h:181
uniset::timeout_t smReadyTimeout
Definition: UObject_SK.h:232
uniset::ObjectId smTestID
Definition: UObject_SK.h:213
std::shared_ptr< Configuration > uniset_conf() noexcept
Definition: Configuration.cc:90
const ObjectId DefaultObjectId
Definition: UniSetTypes.h:69
virtual std::string getMonitInfo() const
Definition: UObject_SK.h:177
std::string pretty_str(int namewidth=NameWidth, int colnum=ColCount) const
Definition: VMonitor.cc:186
std::string str(uniset::ObjectId id, bool showLinkName=true) const
Definition: Trigger.h:29
uniset::timeout_t activateTimeout
Definition: UObject_SK.h:235
std::string dumpIO()
Definition: MessageType.h:124
uniset::PassiveTimer ptStartUpTimeout
Definition: UObject_SK.h:236
Definition: MessageType.h:88
virtual void httpGetUserData(Poco::JSON::Object::Ptr &jdata)
Definition: UObject_SK.h:187
Definition: MessageType.h:211
uniset::ObjectId idHeartBeat
Definition: UObject_SK.h:217
Definition: IOController_i.idl:56
long maxHeartBeat
Definition: UObject_SK.h:218
Definition: UniSetTypes_i.idl:64
Definition: UObject_SK.h:28
std::string strval(uniset::ObjectId id, bool showLinkName=true) const
virtual bool deactivateObject() override
Деактивиция объекта (переопределяется для необходимых действий при завершении работы) ...
long ObjectId
Definition: UniSetTypes_i.idl:30
int sleep_msec
Definition: UObject_SK.h:209
virtual void processingMessage(const uniset::VoidMessage *msg) override
std::string msgstr(uniset::ObjectId id, bool showLinkName=true) const