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