UniSet  2.6.0
UniExchange.h
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 // -----------------------------------------------------------------------------
00017 #ifndef UniExchange_H_
00018 #define UniExchange_H_
00019 // -----------------------------------------------------------------------------
00020 #include <list>
00021 #include <memory>
00022 #include "UniXML.h"
00023 #include "IOController.h"
00024 #include "SMInterface.h"
00025 #include "SharedMemory.h"
00026 #include "PassiveTimer.h"
00027 // --------------------------------------------------------------------------
00028 namespace uniset
00029 {
00030 // -----------------------------------------------------------------------------
00053 // -----------------------------------------------------------------------------
00054 class UniExchange:
00055     public IOController
00056 {
00057     public:
00058         UniExchange( uniset::ObjectId id, uniset::ObjectId shmID,
00059                      const std::shared_ptr<SharedMemory>& ic = nullptr, const std::string& prefix = "unet" );
00060         virtual ~UniExchange();
00061 
00062         void execute();
00063 
00064         static std::shared_ptr<UniExchange> init_exchange( int argc, const char* const* argv,
00065                 uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
00066                 const std::string& prefix = "unet" );
00067 
00069         static void help_print( int argc, const char** argv );
00070 
00071         virtual IOController_i::ShortMapSeq* getSensors() override;
00072 
00073     protected:
00074 
00075         virtual void sysCommand( const uniset::SystemMessage* sm ) override;
00076         virtual void askSensors( UniversalIO::UIOCommand cmd );
00077         virtual void sigterm( int signo ) override;
00078 
00079         xmlNode* cnode = { 0 };
00080         std::string s_field = { "" };
00081         std::string s_fvalue = { "" };
00082         std::shared_ptr<SMInterface> shm;
00083 
00084         struct SInfo
00085         {
00086             // т.к. содержится rwmutex с запрещённым конструктором копирования
00087             // приходится здесь тоже объявлять разрешенными только операции "перемещения"
00088             SInfo( const SInfo& r ) = delete;
00089             SInfo& operator=(const SInfo& r) = delete;
00090             SInfo( SInfo&& r ) = default;
00091             SInfo& operator=(SInfo&& r) = default;
00092 
00093             SInfo():
00094                 val(0),
00095                 id(uniset::DefaultObjectId),
00096                 type(UniversalIO::UnknownIOType)
00097             {}
00098 
00099             IOController::IOStateList::iterator ioit;
00100             long val;
00101             long id;
00102             UniversalIO::IOType type;
00103             uniset::uniset_rwmutex val_lock;
00104         };
00105 
00106         typedef std::vector<SInfo> SList;
00107 
00108         struct NetNodeInfo
00109         {
00110             // т.к. содержится SList в котором rwmutex с запрещённым конструктором копирования
00111             // приходится здесь тоже объявлять разрешенными только операции "перемещения"
00112             NetNodeInfo( const NetNodeInfo& r ) = delete;
00113             NetNodeInfo& operator=(const NetNodeInfo& r) = delete;
00114             NetNodeInfo( NetNodeInfo&& r ) = default;
00115             NetNodeInfo& operator=(NetNodeInfo&& r) = default;
00116 
00117             NetNodeInfo();
00118 
00119             CORBA::Object_var oref;
00120             IOController_i_var shm;
00121             uniset::ObjectId id;
00122             uniset::ObjectId node;
00123             uniset::ObjectId sidConnection; 
00124             IOController::IOStateList::iterator conn_it;
00125             SList smap;
00126 
00127             void update(IOController_i::ShortMapSeq_var& map, const std::shared_ptr<SMInterface>& shm );
00128         };
00129 
00130         typedef std::list<NetNodeInfo> NetNodeList;
00131         NetNodeList nlst;
00132 
00133         void readConfiguration();
00134         bool readItem( const std::shared_ptr<UniXML>& xml, UniXML::iterator& it, xmlNode* sec );
00135         bool initItem( UniXML::iterator& it );
00136         void updateLocalData();
00137         void initIterators();
00138 
00139         timeout_t polltime = { 200 };
00140         PassiveTimer ptUpdate;
00141         bool init_ok = { false };
00142 
00143         SList mymap;
00144         size_t maxIndex = { 0 };
00145         timeout_t smReadyTimeout = { 15000 }; // msec
00146 
00147     private:
00148 };
00149 // --------------------------------------------------------------------------
00150 } // end of namespace uniset
00151 // -----------------------------------------------------------------------------
00152 #endif // UniExchange_H_