UniSet  2.2.1
IONotifyController.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 IONotifyController_H_
00026 #define IONotifyController_H_
00027 //---------------------------------------------------------------------------
00028 #include <memory>
00029 #include <unordered_map>
00030 #include <list>
00031 #include <string>
00032 
00033 #include "UniSetTypes.h"
00034 #include "IOController_i.hh"
00035 #include "IOController.h"
00036 
00037 //---------------------------------------------------------------------------
00038 class NCRestorer;
00039 //---------------------------------------------------------------------------
00118 //---------------------------------------------------------------------------
00129 class IONotifyController:
00130     public IOController,
00131     public POA_IONotifyController_i
00132 {
00133     public:
00134 
00135         IONotifyController(const std::string& name, const std::string& section, std::shared_ptr<NCRestorer> dumper = nullptr );
00136         IONotifyController(const UniSetTypes::ObjectId id, std::shared_ptr<NCRestorer> dumper = nullptr );
00137 
00138         virtual ~IONotifyController();
00139 
00140         virtual UniSetTypes::ObjectType getType() override
00141         {
00142             return UniSetTypes::ObjectType("IONotifyController");
00143         }
00144         virtual void askSensor(const UniSetTypes::ObjectId sid, const UniSetTypes::ConsumerInfo& ci, UniversalIO::UIOCommand cmd) override;
00145 
00146         virtual void askThreshold(const UniSetTypes::ObjectId sid, const UniSetTypes::ConsumerInfo& ci,
00147                                   UniSetTypes::ThresholdId tid,
00148                                   CORBA::Long lowLimit, CORBA::Long hiLimit, CORBA::Boolean invert,
00149                                   UniversalIO::UIOCommand cmd ) override;
00150 
00151         virtual IONotifyController_i::ThresholdInfo getThresholdInfo( const UniSetTypes::ObjectId sid, UniSetTypes::ThresholdId tid ) override;
00152         virtual IONotifyController_i::ThresholdList* getThresholds(const UniSetTypes::ObjectId sid ) override;
00153         virtual IONotifyController_i::ThresholdsListSeq* getThresholdsList() override;
00154 
00155         virtual UniSetTypes::IDSeq* askSensorsSeq(const UniSetTypes::IDSeq& lst,
00156                 const UniSetTypes::ConsumerInfo& ci, UniversalIO::UIOCommand cmd) override;
00157 
00158         // --------------------------------------------
00159 
00160         // функция для работы напрямую черех iterator (оптимизация)
00161         virtual void localSetValue( IOController::IOStateList::iterator& it,
00162                                     UniSetTypes::ObjectId sid,
00163                                     CORBA::Long value, UniSetTypes::ObjectId sup_id ) override;
00164 
00165         // --------------------------------------------
00166 
00168         struct ConsumerInfoExt:
00169             public    UniSetTypes::ConsumerInfo
00170         {
00171             ConsumerInfoExt( const UniSetTypes::ConsumerInfo& ci,
00172                              UniSetObject_i_ptr ref = 0, int maxAttemtps = 10 ):
00173                 UniSetTypes::ConsumerInfo(ci),
00174                 ref(ref), attempt(maxAttemtps) {}
00175 
00176             UniSetObject_i_var ref;
00177             int attempt;
00178 
00179             ConsumerInfoExt( const ConsumerInfoExt& ) = default;
00180             ConsumerInfoExt& operator=( const ConsumerInfoExt& ) = default;
00181             ConsumerInfoExt( ConsumerInfoExt&& ) = default;
00182             ConsumerInfoExt& operator=(ConsumerInfoExt&& ) = default;
00183         };
00184 
00185         typedef std::list<ConsumerInfoExt> ConsumerList;
00186 
00187         struct ConsumerListInfo
00188         {
00189             ConsumerListInfo(): mut("ConsumerInfoMutex") {}
00190             ConsumerList clst;
00191             UniSetTypes::uniset_rwmutex mut;
00192 
00193             ConsumerListInfo( const ConsumerListInfo& ) = delete;
00194             ConsumerListInfo& operator=( const ConsumerListInfo& ) = delete;
00195             ConsumerListInfo( ConsumerListInfo&& ) = default;
00196             ConsumerListInfo& operator=(ConsumerListInfo&& ) = default;
00197         };
00198 
00200         typedef std::unordered_map<UniSetTypes::KeyType, ConsumerListInfo> AskMap;
00201 
00202 
00204         struct ThresholdInfoExt:
00205             public IONotifyController_i::ThresholdInfo
00206         {
00207             ThresholdInfoExt( UniSetTypes::ThresholdId tid, CORBA::Long low, CORBA::Long hi, bool inv,
00208                               UniSetTypes::ObjectId _sid = UniSetTypes::DefaultObjectId ):
00209                 sid(_sid),
00210                 invert(inv)
00211             {
00212                 id       = tid;
00213                 hilimit  = hi;
00214                 lowlimit = low;
00215                 state    = IONotifyController_i::NormalThreshold;
00216             }
00217 
00218             ConsumerListInfo clst; 
00221             UniSetTypes::ObjectId sid;
00222 
00224             IOController::IOStateList::iterator sit;
00225 
00227             bool invert;
00228 
00229             inline bool operator== ( const ThresholdInfo& r ) const
00230             {
00231                 return ((id == r.id) &&
00232                         (hilimit == r.hilimit) &&
00233                         (lowlimit == r.lowlimit) &&
00234                         (invert == r.invert) );
00235             }
00236 
00237             operator IONotifyController_i::ThresholdInfo()
00238             {
00239                 IONotifyController_i::ThresholdInfo r;
00240                 r.id = id;
00241                 r.hilimit = hilimit;
00242                 r.lowlimit = lowlimit;
00243                 r.invert = invert;
00244                 r.tv_sec = tv_sec;
00245                 r.tv_usec = tv_usec;
00246                 r.state = state;
00247                 return r;
00248             }
00249 
00250             ThresholdInfoExt( const ThresholdInfoExt& ) = delete;
00251             ThresholdInfoExt& operator=( const ThresholdInfoExt& ) = delete;
00252             ThresholdInfoExt( ThresholdInfoExt&& ) = default;
00253             ThresholdInfoExt& operator=(ThresholdInfoExt&& ) = default;
00254         };
00255 
00257         typedef std::list<ThresholdInfoExt> ThresholdExtList;
00258 
00259         struct ThresholdsListInfo
00260         {
00261             ThresholdsListInfo() {}
00262             ThresholdsListInfo( const IOController_i::SensorInfo& si, ThresholdExtList&& list,
00263                                 UniversalIO::IOType t = UniversalIO::AI ):
00264                 si(si), type(t), list( std::move(list) ) {}
00265 
00266             UniSetTypes::uniset_rwmutex mut;
00267 
00268             IOController_i::SensorInfo si = { UniSetTypes::DefaultObjectId, UniSetTypes::DefaultObjectId };
00269             std::shared_ptr<USensorInfo> ait;
00270             UniversalIO::IOType type = { UniversalIO::AI };
00271             ThresholdExtList list;   
00272         };
00273 
00275         typedef std::unordered_map<UniSetTypes::KeyType, ThresholdsListInfo> AskThresholdMap;
00276 
00277     protected:
00278         IONotifyController();
00279         virtual bool activateObject() override;
00280         virtual void initItem( IOStateList::iterator& it, IOController* ic );
00281 
00282         // ФИЛЬТРЫ
00283         bool myIOFilter(std::shared_ptr<USensorInfo>& ai, CORBA::Long newvalue, UniSetTypes::ObjectId sup_id);
00284 
00286         virtual void send( ConsumerListInfo& lst, UniSetTypes::SensorMessage& sm );
00287 
00289         virtual void checkThreshold( IOStateList::iterator& li, const UniSetTypes::ObjectId sid, bool send = true );
00290 
00292         ThresholdExtList::iterator findThreshold( const UniSetTypes::ObjectId sid, const UniSetTypes::ThresholdId tid );
00293 
00295         virtual void loggingInfo( UniSetTypes::SensorMessage& sm );
00296 
00300         virtual void dumpOrdersList( const UniSetTypes::ObjectId sid, const IONotifyController::ConsumerListInfo& lst );
00301 
00305         virtual void dumpThresholdList( const UniSetTypes::ObjectId sid, const IONotifyController::ThresholdExtList& lst );
00306 
00308         virtual void readDump();
00309 
00310         std::shared_ptr<NCRestorer> restorer;
00311 
00312         void onChangeUndefinedState( std::shared_ptr<USensorInfo>& it, IOController* ic );
00313 
00314     private:
00315         friend class NCRestorer;
00316 
00317         //----------------------
00318         bool addConsumer(ConsumerListInfo& lst, const UniSetTypes::ConsumerInfo& cons );     
00319         bool removeConsumer(ConsumerListInfo& lst, const UniSetTypes::ConsumerInfo& cons );  
00320 
00322         void ask(AskMap& askLst, const UniSetTypes::ObjectId sid,
00323                  const UniSetTypes::ConsumerInfo& ci, UniversalIO::UIOCommand cmd);
00324 
00326         bool addThreshold(ThresholdExtList& lst, ThresholdInfoExt&& ti, const UniSetTypes::ConsumerInfo& ci);
00328         bool removeThreshold(ThresholdExtList& lst, ThresholdInfoExt& ti, const UniSetTypes::ConsumerInfo& ci);
00329 
00330         AskMap askIOList; 
00331         AskThresholdMap askTMap; 
00334         UniSetTypes::uniset_rwmutex askIOMutex;
00336         UniSetTypes::uniset_rwmutex trshMutex;
00337 
00338         int maxAttemtps; 
00340         sigc::connection conInit;
00341         sigc::connection conUndef;
00342 };
00343 // --------------------------------------------------------------------------
00344 #endif
00345 // --------------------------------------------------------------------------