|
UniSet
2.6.0
|
00001 /* 00002 * Copyright (c) 2015 Pavel Vainerman. 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU Lesser General Public License as 00006 * published by the Free Software Foundation, version 2.1. 00007 * 00008 * This program is distributed in the hope that it will be useful, but 00009 * WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 * Lesser General Lesser Public License for more details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public License 00014 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00015 */ 00016 // -------------------------------------------------------------------------- 00021 // -------------------------------------------------------------------------- 00022 #ifndef NCRestorer_H_ 00023 #define NCRestorer_H_ 00024 // ------------------------------------------------------------------------------------------ 00025 #include <memory> 00026 #include <sigc++/sigc++.h> 00027 #include <string> 00028 #include "UniXML.h" 00029 #include "Restorer.h" 00030 #include "IOController.h" 00031 #include "IONotifyController.h" 00032 // ------------------------------------------------------------------------------------------ 00033 namespace uniset 00034 { 00041 class NCRestorer 00042 { 00043 public: 00044 00045 NCRestorer(); 00046 virtual ~NCRestorer(); 00047 00048 struct SInfo: 00049 public IOController::USensorInfo 00050 { 00051 SInfo( const SInfo& ) = delete; 00052 const SInfo& operator=(const SInfo& ) = delete; 00053 SInfo( SInfo&& ) = default; 00054 SInfo& operator=(SInfo&& ) = default; 00055 00056 SInfo( IOController_i::SensorInfo& si, UniversalIO::IOType& t, 00057 uniset::Message::Message::Priority& p, long& def ) noexcept 00058 { 00059 this->si = si; 00060 this->type = t; 00061 this->priority = p; 00062 this->default_val = def; 00063 } 00064 00065 SInfo() noexcept 00066 { 00067 this->type = UniversalIO::DI; 00068 this->priority = uniset::Message::Medium; 00069 this->default_val = 0; 00070 } 00071 00072 SInfo& operator=(const IOController_i::SensorIOInfo& inf); 00073 SInfo( const IOController_i::SensorIOInfo& inf ); 00074 }; 00075 00076 virtual void read( IONotifyController* ic, const std::string& fn = "" ) = 0; 00077 virtual void dump(const IONotifyController* ic, std::shared_ptr<SInfo>& inf, const IONotifyController::ConsumerListInfo& lst) = 0; 00078 virtual void dumpThreshold(const IONotifyController* ic, std::shared_ptr<SInfo>& inf, const IONotifyController::ThresholdExtList& lst) = 0; 00079 00080 protected: 00081 00082 // добавление списка заказчиков 00083 static void addlist( IONotifyController* ic, std::shared_ptr<IOController::USensorInfo>& inf, IONotifyController::ConsumerListInfo&& lst, bool force = false ); 00084 00085 // добавление списка порогов и заказчиков 00086 static void addthresholdlist( IONotifyController* ic, std::shared_ptr<IOController::USensorInfo>& inf, IONotifyController::ThresholdExtList&& lst, bool force = false ); 00087 00088 static inline void ioRegistration( IONotifyController* ic, std::shared_ptr<IOController::USensorInfo>& inf, bool force = false ) 00089 { 00090 ic->ioRegistration(inf, force); 00091 } 00092 00093 static inline IOController::IOStateList::iterator ioFind( IONotifyController* ic, uniset::ObjectId k ) noexcept 00094 { 00095 return ic->myiofind(k); 00096 } 00097 00098 static inline IOController::IOStateList::iterator ioEnd( IONotifyController* ic ) noexcept 00099 { 00100 return ic->myioEnd(); 00101 } 00102 static inline IOController::IOStateList::iterator ioBegin( IONotifyController* ic ) noexcept 00103 { 00104 return ic->myioBegin(); 00105 } 00106 00107 static void init_depends_signals( IONotifyController* ic ); 00108 }; 00109 // ------------------------------------------------------------------------------------------ 00115 class NCRestorer_XML: 00116 public Restorer_XML, 00117 public NCRestorer 00118 { 00119 public: 00120 00124 NCRestorer_XML( const std::string& fname ); 00125 00131 NCRestorer_XML( const std::string& fname, const std::string& sensor_filterField, const std::string& sensor_filterValue = "" ); 00132 00133 virtual ~NCRestorer_XML(); 00134 NCRestorer_XML(); 00135 00137 void setThresholdsFilter( const std::string& filterField, const std::string& filterValue = "" ); 00138 00139 bool setFileName( const std::string& file, bool create ); 00140 inline std::string getFileName() const noexcept 00141 { 00142 return fname; 00143 } 00144 00154 void setReadThresholdItem( ReaderSlot sl ); 00155 00156 typedef sigc::slot<bool, const std::shared_ptr<UniXML>&, UniXML::iterator&, xmlNode*, std::shared_ptr<IOController::USensorInfo>&> NCReaderSlot; 00157 00158 void setNCReadItem( NCReaderSlot sl ); 00159 00160 virtual void read( IONotifyController* ic, const std::string& filename = "" ); 00161 virtual void read( IONotifyController* ic, const std::shared_ptr<UniXML>& xml ); 00162 00163 virtual void dump(const IONotifyController* ic, std::shared_ptr<NCRestorer::SInfo>& inf, const IONotifyController::ConsumerListInfo& lst) override; 00164 virtual void dumpThreshold(const IONotifyController* ic, std::shared_ptr<NCRestorer::SInfo>& inf, const IONotifyController::ThresholdExtList& lst) override; 00165 00166 protected: 00167 00168 bool check_thresholds_item( UniXML::iterator& it ) const; 00169 void read_consumers( const std::shared_ptr<UniXML>& xml, xmlNode* node, std::shared_ptr<NCRestorer_XML::SInfo>& inf, IONotifyController* ic ); 00170 void read_list( const std::shared_ptr<UniXML>& xml, xmlNode* node, IONotifyController* ic); 00171 void read_thresholds( const std::shared_ptr<UniXML>& xml, xmlNode* node, IONotifyController* ic); 00172 void init( const std::string& fname ); 00173 00174 bool getBaseInfo( const std::shared_ptr<UniXML>& xml, xmlNode* it, IOController_i::SensorInfo& si ); 00175 bool getSensorInfo( const std::shared_ptr<UniXML>& xml, xmlNode* snode, std::shared_ptr<NCRestorer_XML::SInfo>& si ); 00176 bool getConsumerList( const std::shared_ptr<UniXML>& xml, xmlNode* node, IONotifyController::ConsumerListInfo& lst); 00177 bool getThresholdInfo(const std::shared_ptr<UniXML>& xml, xmlNode* tnode, IONotifyController::ThresholdInfoExt& ti); 00178 00179 static void set_dumptime( const std::shared_ptr<UniXML>& xml, xmlNode* node ); 00180 static xmlNode* bind_node( const std::shared_ptr<UniXML>& xml, xmlNode* root, const std::string& nodename, const std::string& nm = ""); 00181 static xmlNode* rebind_node( const std::shared_ptr<UniXML>& xml, xmlNode* root, const std::string& nodename, const std::string& nm = ""); 00182 00183 std::string s_filterField = { "" }; 00184 std::string s_filterValue = { "" }; 00185 std::string t_filterField = { "" }; 00186 std::string t_filterValue = { "" }; 00187 00188 std::string fname = { "" }; 00189 std::shared_ptr<UniXML> uxml; 00190 ReaderSlot rtslot; 00191 NCReaderSlot ncrslot; 00192 00193 private: 00194 }; 00195 // ------------------------------------------------------------------------- 00196 } // end of uniset namespace 00197 // ------------------------------------------------------------------------------------------ 00198 #endif
1.7.6.1