UniSet  2.6.0
NCRestorer.h
1 /*
2  * Copyright (c) 2015 Pavel Vainerman.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation, version 2.1.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Lesser Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 // --------------------------------------------------------------------------
21 // --------------------------------------------------------------------------
22 #ifndef NCRestorer_H_
23 #define NCRestorer_H_
24 // ------------------------------------------------------------------------------------------
25 #include <memory>
26 #include <sigc++/sigc++.h>
27 #include <string>
28 #include "UniXML.h"
29 #include "Restorer.h"
30 #include "IOController.h"
31 #include "IONotifyController.h"
32 // ------------------------------------------------------------------------------------------
33 namespace uniset
34 {
41  class NCRestorer
42  {
43  public:
44 
45  NCRestorer();
46  virtual ~NCRestorer();
47 
48  struct SInfo:
50  {
51  SInfo( const SInfo& ) = delete;
52  const SInfo& operator=(const SInfo& ) = delete;
53  SInfo( SInfo&& ) = default;
54  SInfo& operator=(SInfo&& ) = default;
55 
56  SInfo( IOController_i::SensorInfo& si, UniversalIO::IOType& t,
57  uniset::Message::Message::Priority& p, long& def ) noexcept
58  {
59  this->si = si;
60  this->type = t;
61  this->priority = p;
62  this->default_val = def;
63  }
64 
65  SInfo() noexcept
66  {
67  this->type = UniversalIO::DI;
68  this->priority = uniset::Message::Medium;
69  this->default_val = 0;
70  }
71 
72  SInfo& operator=(const IOController_i::SensorIOInfo& inf);
73  SInfo( const IOController_i::SensorIOInfo& inf );
74  };
75 
76  virtual void read( IONotifyController* ic, const std::string& fn = "" ) = 0;
77  virtual void dump(const IONotifyController* ic, std::shared_ptr<SInfo>& inf, const IONotifyController::ConsumerListInfo& lst) = 0;
78  virtual void dumpThreshold(const IONotifyController* ic, std::shared_ptr<SInfo>& inf, const IONotifyController::ThresholdExtList& lst) = 0;
79 
80  protected:
81 
82  // добавление списка заказчиков
83  static void addlist( IONotifyController* ic, std::shared_ptr<IOController::USensorInfo>& inf, IONotifyController::ConsumerListInfo&& lst, bool force = false );
84 
85  // добавление списка порогов и заказчиков
86  static void addthresholdlist( IONotifyController* ic, std::shared_ptr<IOController::USensorInfo>& inf, IONotifyController::ThresholdExtList&& lst, bool force = false );
87 
88  static inline void ioRegistration( IONotifyController* ic, std::shared_ptr<IOController::USensorInfo>& inf, bool force = false )
89  {
90  ic->ioRegistration(inf, force);
91  }
92 
93  static inline IOController::IOStateList::iterator ioFind( IONotifyController* ic, uniset::ObjectId k ) noexcept
94  {
95  return ic->myiofind(k);
96  }
97 
98  static inline IOController::IOStateList::iterator ioEnd( IONotifyController* ic ) noexcept
99  {
100  return ic->myioEnd();
101  }
102  static inline IOController::IOStateList::iterator ioBegin( IONotifyController* ic ) noexcept
103  {
104  return ic->myioBegin();
105  }
106 
107  static void init_depends_signals( IONotifyController* ic );
108  };
109  // ------------------------------------------------------------------------------------------
116  public Restorer_XML,
117  public NCRestorer
118  {
119  public:
120 
124  NCRestorer_XML( const std::string& fname );
125 
131  NCRestorer_XML( const std::string& fname, const std::string& sensor_filterField, const std::string& sensor_filterValue = "" );
132 
133  virtual ~NCRestorer_XML();
134  NCRestorer_XML();
135 
137  void setThresholdsFilter( const std::string& filterField, const std::string& filterValue = "" );
138 
139  bool setFileName( const std::string& file, bool create );
140  inline std::string getFileName() const noexcept
141  {
142  return fname;
143  }
144 
154  void setReadThresholdItem( ReaderSlot sl );
155 
156  typedef sigc::slot<bool, const std::shared_ptr<UniXML>&, UniXML::iterator&, xmlNode*, std::shared_ptr<IOController::USensorInfo>&> NCReaderSlot;
157 
158  void setNCReadItem( NCReaderSlot sl );
159 
160  virtual void read( IONotifyController* ic, const std::string& filename = "" );
161  virtual void read( IONotifyController* ic, const std::shared_ptr<UniXML>& xml );
162 
163  virtual void dump(const IONotifyController* ic, std::shared_ptr<NCRestorer::SInfo>& inf, const IONotifyController::ConsumerListInfo& lst) override;
164  virtual void dumpThreshold(const IONotifyController* ic, std::shared_ptr<NCRestorer::SInfo>& inf, const IONotifyController::ThresholdExtList& lst) override;
165 
166  protected:
167 
168  bool check_thresholds_item( UniXML::iterator& it ) const;
169  void read_consumers( const std::shared_ptr<UniXML>& xml, xmlNode* node, std::shared_ptr<NCRestorer_XML::SInfo>& inf, IONotifyController* ic );
170  void read_list( const std::shared_ptr<UniXML>& xml, xmlNode* node, IONotifyController* ic);
171  void read_thresholds( const std::shared_ptr<UniXML>& xml, xmlNode* node, IONotifyController* ic);
172  void init( const std::string& fname );
173 
174  bool getBaseInfo( const std::shared_ptr<UniXML>& xml, xmlNode* it, IOController_i::SensorInfo& si );
175  bool getSensorInfo( const std::shared_ptr<UniXML>& xml, xmlNode* snode, std::shared_ptr<NCRestorer_XML::SInfo>& si );
176  bool getConsumerList( const std::shared_ptr<UniXML>& xml, xmlNode* node, IONotifyController::ConsumerListInfo& lst);
177  bool getThresholdInfo(const std::shared_ptr<UniXML>& xml, xmlNode* tnode, IONotifyController::ThresholdInfoExt& ti);
178 
179  static void set_dumptime( const std::shared_ptr<UniXML>& xml, xmlNode* node );
180  static xmlNode* bind_node( const std::shared_ptr<UniXML>& xml, xmlNode* root, const std::string& nodename, const std::string& nm = "");
181  static xmlNode* rebind_node( const std::shared_ptr<UniXML>& xml, xmlNode* root, const std::string& nodename, const std::string& nm = "");
182 
183  std::string s_filterField = { "" };
184  std::string s_filterValue = { "" };
185  std::string t_filterField = { "" };
186  std::string t_filterValue = { "" };
187 
188  std::string fname = { "" };
189  std::shared_ptr<UniXML> uxml;
190  ReaderSlot rtslot;
191  NCReaderSlot ncrslot;
192 
193  private:
194  };
195  // -------------------------------------------------------------------------
196 } // end of uniset namespace
197 // ------------------------------------------------------------------------------------------
198 #endif