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