UniSet  2.6.0
MQPerfTest/TestProc_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: 2017-01-15
12 // -----------------------------------------------------------------------------
13 #ifndef TestProc_SK_H_
14 #define TestProc_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 TestProc_SK:
30 {
31  public:
32  TestProc_SK( uniset::ObjectId id, xmlNode* node=uniset::uniset_conf()->getNode("TestProc"), const std::string& argprefix="" );
33  TestProc_SK();
34  virtual ~TestProc_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 { return mylog; }
47  inline std::shared_ptr<uniset::LogAgregator> logAgregator() noexcept { return loga; }
48 
49  void init_dlog( std::shared_ptr<DebugStream> d ) noexcept;
50 
51  // "синтаксический сахар"..для логов
52  #ifndef myinfo
53  #define myinfo if( log()->debugging(Debug::INFO) ) log()->info()
54  #endif
55  #ifndef mywarn
56  #define mywarn if( log()->debugging(Debug::WARN) ) log()->warn()
57  #endif
58  #ifndef mycrit
59  #define mycrit if( log()->debugging(Debug::CRIT) ) log()->crit()
60  #endif
61  #ifndef mylog1
62  #define mylog1 if( log()->debugging(Debug::LEVEL1) ) log()->level1()
63  #endif
64  #ifndef mylog2
65  #define mylog2 if( log()->debugging(Debug::LEVEL2) ) log()->level2()
66  #endif
67  #ifndef mylog3
68  #define mylog3 if( log()->debugging(Debug::LEVEL3) ) log()->level3()
69  #endif
70  #ifndef mylog4
71  #define mylog4 if( log()->debugging(Debug::LEVEL4) ) log()->level4()
72  #endif
73  #ifndef mylog5
74  #define mylog5 if( log()->debugging(Debug::LEVEL5) ) log()->level5()
75  #endif
76  #ifndef mylog6
77  #define mylog6 if( log()->debugging(Debug::LEVEL6) ) log()->level6()
78  #endif
79  #ifndef mylog7
80  #define mylog7 if( log()->debugging(Debug::LEVEL7) ) log()->level7()
81  #endif
82  #ifndef mylog8
83  #define mylog8 if( log()->debugging(Debug::LEVEL8) ) log()->level8()
84  #endif
85  #ifndef mylog9
86  #define mylog9 if( log()->debugging(Debug::LEVEL9) ) log()->level9()
87  #endif
88  #ifndef mylogany
89  #define mylogany log()->any()
90  #endif
91  #ifndef vmonit
92  #define vmonit( var ) vmon.add( #var, var )
93  #endif
94 
95  // Вспомогательные функции для удобства логирования
96  // ------------------------------------------------------------
104  std::string dumpIO();
105 
110  std::string str( uniset::ObjectId id, bool showLinkName=true ) const;
111 
116  std::string strval( uniset::ObjectId id, bool showLinkName=true ) const;
117 
119  inline std::string dumpVars(){ return vmon.pretty_str(); }
120  // ------------------------------------------------------------
121  std::string help() noexcept;
122 
123 
124 
125  // Используемые идентификаторы
126 
127 
128  // Используемые идентификаторы сообщений
129 
130 
131  // Текущее значение
132 
133 
134  // --- public variables ---
135 
136 
137  // --- end of public variables ---
138 
139  protected:
140  // --- protected variables ---
141 
142 
143  // ---- end of protected variables ----
144 
145 
146  virtual void callback() noexcept override;
147  virtual void processingMessage( const uniset::VoidMessage* msg ) override;
148  virtual void sysCommand( const uniset::SystemMessage* sm ){};
149  virtual void askSensors( UniversalIO::UIOCommand cmd ){}
150  virtual void sensorInfo( const uniset::SensorMessage* sm ) override{}
151  virtual void timerInfo( const uniset::TimerMessage* tm ) override{}
152  virtual void sigterm( int signo ) override;
153  virtual bool activateObject() override;
154  virtual std::string getMonitInfo(){ return ""; }
156  // Выполнение очередного шага программы
157  virtual void step(){}
158 
159  void preAskSensors( UniversalIO::UIOCommand cmd );
160  void preSysCommand( const uniset::SystemMessage* sm );
161 
162  virtual void testMode( bool state );
163  void updateOutputs( bool force );
164 
165  void waitSM( int wait_msec, uniset::ObjectId testID = uniset::DefaultObjectId );
166  uniset::ObjectId getSMTestID();
167 
168  void resetMsg();
169  uniset::Trigger trResetMsg;
170  uniset::PassiveTimer ptResetMsg;
171  int resetMsgTime;
172 
173  int sleep_msec;
174  bool active;
175 
176  const std::string argprefix;
179  // управление датчиком "сердцебиения"
180  uniset::PassiveTimer ptHeartBeat;
182  long maxHeartBeat;
184  xmlNode* confnode;
186  int getIntProp(const std::string& name) { return uniset::uniset_conf()->getIntProp(confnode, name); }
188  inline const std::string getProp(const std::string& name) { return uniset::uniset_conf()->getProp(confnode, name); }
189 
190  uniset::timeout_t smReadyTimeout;
191  std::atomic_bool activated;
192  uniset::timeout_t activateTimeout;
194  int askPause;
197  bool forceOut;
199  std::shared_ptr<uniset::LogAgregator> loga;
200  std::shared_ptr<DebugStream> mylog;
201  std::shared_ptr<uniset::LogServer> logserv;
202  std::string logserv_host = {""};
203  int logserv_port = {0};
204 
205  uniset::VMonitor vmon;
206 
207 
208 
209  private:
210 
211  // --- private variables ---
212  // --- end of private variables ---
213 
214  // предыдущее значение (для работы UpdateValue())
215 
216 
217  // Текущее значение (rw-переменные)
218 
219 
220  // Используемые идентификаторы сообщений
221 
222  // ------------ private функции ---------------
223  void updatePreviousValues() noexcept;
224  void preSensorInfo( const uniset::SensorMessage* sm );
225  void preTimerInfo( const uniset::TimerMessage* tm );
226  void initFromSM();
227  void checkSensors();
228  // --------------------------------------------
229 
230  class StatHashFn
231  {
232  public:
233  size_t operator() (const uniset::ObjectId& key) const
234  {
235  return std::hash<long>()(key);
236  }
237  };
238 
239  std::unordered_map<const uniset::ObjectId,size_t, StatHashFn> smStat;
240  size_t processingMessageCatchCount = { 0 };
242  std::string ostate = { "" };
245  bool end_private; // вспомогательное поле (для внутреннего использования при генерировании кода)
246 };
247 
248 // -----------------------------------------------------------------------------
249 #endif // TestProc_SK_H_