UniSet  2.0.0
NCRestorer.h
См. документацию.
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 <sigc++/sigc++.h>
00029 #include <string>
00030 #include "UniXML.h"
00031 #include "Restorer.h"
00032 #include "IOController.h"
00033 #include "IONotifyController.h"
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                     UniSetTypes::Message::Message::Priority& p, long& def )
00058             {
00059                 this->si = si;
00060                 this->type = t;
00061                 this->priority = p;
00062                 this->default_val = def;
00063             }
00064 
00065             SInfo()
00066             {
00067                 this->type = UniversalIO::DI;
00068                 this->priority = UniSetTypes::Message::Medium;
00069                 this->default_val = 0;
00070             }
00071 
00072             SInfo &operator=(IOController_i::SensorIOInfo& inf);
00073         };
00074 
00075         virtual void read( IONotifyController* ic, const std::string& fn="" )=0;
00076         virtual void dump(const IONotifyController* ic, SInfo& inf, const IONotifyController::ConsumerListInfo& lst)=0;
00077         virtual void dumpThreshold(const IONotifyController* ic, SInfo& inf, const IONotifyController::ThresholdExtList& lst)=0;
00078 
00079     protected:
00080 
00081         // добавление списка заказчиков
00082         static void addlist( IONotifyController* ic, SInfo&& inf, IONotifyController::ConsumerListInfo&& lst, bool force=false );
00083 
00084         // добавление списка порогов и заказчиков
00085         static void addthresholdlist( IONotifyController* ic, SInfo&& inf, IONotifyController::ThresholdExtList&& lst, bool force=false );
00086 
00087         static inline void ioRegistration( IONotifyController* ic, IOController::USensorInfo&& inf, bool force=false )
00088         {
00089             ic->ioRegistration( std::move(inf),force);
00090         }
00091 
00092         static inline IOController::IOStateList::iterator ioFind( IONotifyController* ic, UniSetTypes::KeyType k )
00093         {
00094             return ic->myiofind(k);
00095         }
00096 
00097         static inline IOController::IOStateList::iterator ioEnd( IONotifyController* ic )
00098         {
00099             return ic->myioEnd();
00100         }
00101         static inline IOController::IOStateList::iterator ioBegin( IONotifyController* ic )
00102         {
00103             return ic->myioBegin();
00104         }
00105 
00106         static void init_depends_signals( IONotifyController* ic );
00107 };
00108 // ------------------------------------------------------------------------------------------
00114 class NCRestorer_XML:
00115     public Restorer_XML,
00116     public NCRestorer
00117 {
00118     public:
00119 
00123         NCRestorer_XML( const std::string& fname );
00124 
00130         NCRestorer_XML( const std::string& fname, const std::string& sensor_filterField, const std::string& sensor_filterValue="" );
00131 
00132         virtual ~NCRestorer_XML();
00133         NCRestorer_XML();
00134 
00136         void setThresholdsFilter( const std::string& filterField, const std::string& filterValue="" );
00137 
00138         bool setFileName( const std::string& file, bool create );
00139         inline std::string getFileName(){ return fname; }
00140 
00150         void setReadThresholdItem( ReaderSlot sl );
00151 
00152         typedef sigc::slot<bool,const std::shared_ptr<UniXML>&,UniXML::iterator&,xmlNode*,SInfo&> NCReaderSlot;
00153 
00154         void setNCReadItem( NCReaderSlot sl );
00155 
00156         virtual void read( IONotifyController* ic, const std::string& filename="" );
00157         virtual void read( IONotifyController* ic, const std::shared_ptr<UniXML>& xml );
00158 
00159         virtual void dump(const IONotifyController* ic, SInfo& inf, const IONotifyController::ConsumerListInfo& lst);
00160         virtual void dumpThreshold(const IONotifyController* ic, SInfo& inf, const IONotifyController::ThresholdExtList& lst);
00161 
00162     protected:
00163 
00164         bool check_thresholds_item( UniXML::iterator& it );
00165         void read_consumers( const std::shared_ptr<UniXML>& xml, xmlNode* node, NCRestorer_XML::SInfo&& inf, IONotifyController* ic );
00166         void read_list( const std::shared_ptr<UniXML>& xml, xmlNode* node, IONotifyController* ic);
00167         void read_thresholds( const std::shared_ptr<UniXML>& xml, xmlNode* node, IONotifyController* ic);
00168         void init( const std::string& fname );
00169 
00170         bool getBaseInfo( const std::shared_ptr<UniXML>& xml, xmlNode* it, IOController_i::SensorInfo& si );
00171         bool getSensorInfo( const std::shared_ptr<UniXML>& xml, xmlNode* snode, SInfo& si );
00172         bool getConsumerList( const std::shared_ptr<UniXML>& xml,xmlNode* node, IONotifyController::ConsumerListInfo& lst);
00173         bool getThresholdInfo(const std::shared_ptr<UniXML>& xml,xmlNode* tnode, IONotifyController::ThresholdInfoExt& ti);
00174 
00175         static void set_dumptime( const std::shared_ptr<UniXML>& xml, xmlNode* node );
00176         static xmlNode* bind_node( const std::shared_ptr<UniXML>& xml, xmlNode* root, const std::string& nodename, const std::string& nm="");
00177         static xmlNode* rebind_node( const std::shared_ptr<UniXML>& xml, xmlNode* root, const std::string& nodename, const std::string& nm="");
00178 
00179         std::string s_filterField;
00180         std::string s_filterValue;
00181         std::string c_filterField;
00182         std::string c_filterValue;
00183         std::string t_filterField;
00184         std::string t_filterValue;
00185 
00186         std::string fname;
00187         std::shared_ptr<UniXML> uxml;
00188         ReaderSlot rtslot;
00189         NCReaderSlot ncrslot;
00190 
00191     private:
00192 };
00193 // ------------------------------------------------------------------------------------------
00194 #endif