UniSet
1.4.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 //--------------------------------------------------------------------------- 00108 class IONotifyController: 00109 public IOController, 00110 public POA_IONotifyController_i 00111 { 00112 public: 00113 00114 IONotifyController(const std::string name, const std::string section, NCRestorer* dumper=0); 00115 IONotifyController(UniSetTypes::ObjectId id, NCRestorer* dumper=0); 00116 00117 virtual ~IONotifyController(); 00118 00119 virtual UniSetTypes::ObjectType getType(){ return UniSetTypes::getObjectType("IONotifyController"); } 00120 00121 virtual void askSensor(const IOController_i::SensorInfo& si, const UniSetTypes::ConsumerInfo& ci, UniversalIO::UIOCommand cmd); 00122 virtual void askState(const IOController_i::SensorInfo& si, const UniSetTypes::ConsumerInfo& ci, UniversalIO::UIOCommand cmd); 00123 virtual void askValue(const IOController_i::SensorInfo& si, const UniSetTypes::ConsumerInfo& ci, UniversalIO::UIOCommand cmd); 00124 00125 virtual void askThreshold(const IOController_i::SensorInfo& si, const UniSetTypes::ConsumerInfo& ci, 00126 UniSetTypes::ThresholdId tid, 00127 CORBA::Long lowLimit, CORBA::Long hiLimit, CORBA::Long sensibility, 00128 UniversalIO::UIOCommand cmd ); 00129 00130 virtual void askOutput(const IOController_i::SensorInfo& si, const UniSetTypes::ConsumerInfo& ci, UniversalIO::UIOCommand cmd); 00131 00132 virtual UniSetTypes::IDSeq* askSensorsSeq(const UniSetTypes::IDSeq& lst, 00133 const UniSetTypes::ConsumerInfo& ci, UniversalIO::UIOCommand cmd); 00134 00135 00136 // ----------------------------------------------- 00137 typedef sigc::signal<void,UniSetTypes::SensorMessage*> ChangeSignal; 00138 ChangeSignal signal_change_state(){ return changeSignal; } 00139 00140 // -------------------- !!!!!!!!! --------------------------------- 00141 virtual IONotifyController_i::ThresholdsListSeq* getThresholdsList(); 00142 00143 00145 struct ConsumerInfoExt: 00146 public UniSetTypes::ConsumerInfo 00147 { 00148 ConsumerInfoExt( const UniSetTypes::ConsumerInfo& ci, 00149 UniSetObject_i_ptr ref=0, int maxAttemtps = 10 ): 00150 UniSetTypes::ConsumerInfo(ci), 00151 ref(ref),attempt(maxAttemtps){} 00152 00153 UniSetObject_i_var ref; 00154 int attempt; 00155 }; 00156 00157 typedef std::list<ConsumerInfoExt> ConsumerList; 00158 00160 struct ThresholdInfoExt: 00161 public IONotifyController_i::ThresholdInfo 00162 { 00163 ThresholdInfoExt( UniSetTypes::ThresholdId tid, CORBA::Long low, CORBA::Long hi, CORBA::Long sb, 00164 UniSetTypes::ObjectId _sid=UniSetTypes::DefaultObjectId, 00165 bool inv = false ): 00166 sid(_sid), 00167 inverse(inv) 00168 { 00169 id = tid; 00170 hilimit = hi; 00171 lowlimit = low; 00172 sensibility = sb; 00173 state = IONotifyController_i::NormalThreshold; 00174 } 00175 00176 ConsumerList clst; 00177 00181 UniSetTypes::ObjectId sid; 00182 00186 IOController::DIOStateList::iterator itSID; 00187 00189 bool inverse; 00190 00191 inline bool operator== ( const ThresholdInfo& r ) const 00192 { 00193 return ((id == r.id) && 00194 (hilimit == r.hilimit) && 00195 (lowlimit == r.lowlimit) && 00196 (sensibility == r.sensibility) ); 00197 } 00198 }; 00199 00200 00201 typedef std::list<ThresholdInfoExt> ThresholdExtList; 00202 00204 typedef std::map<UniSetTypes::KeyType,ConsumerList> AskMap; 00205 00206 struct ThresholdsListInfo 00207 { 00208 ThresholdsListInfo(){} 00209 ThresholdsListInfo( IOController_i::SensorInfo& si, ThresholdExtList& list, 00210 UniversalIO::IOTypes t=UniversalIO::AnalogInput ): 00211 si(si),type(t),list(list){} 00212 00213 IOController_i::SensorInfo si; 00214 AIOStateList::iterator ait; 00215 UniversalIO::IOTypes type; 00216 ThresholdExtList list; 00217 }; 00218 00220 typedef std::map<UniSetTypes::KeyType,ThresholdsListInfo> AskThresholdMap; 00221 00222 virtual void localSaveValue( IOController::AIOStateList::iterator& it, 00223 const IOController_i::SensorInfo& si, 00224 CORBA::Long newvalue, UniSetTypes::ObjectId sup_id ); 00225 00226 virtual void localSaveState( IOController::DIOStateList::iterator& it, 00227 const IOController_i::SensorInfo& si, 00228 CORBA::Boolean newstate, UniSetTypes::ObjectId sup_id ); 00229 00230 virtual void localSetState( IOController::DIOStateList::iterator& it, 00231 const IOController_i::SensorInfo& si, 00232 CORBA::Boolean newstate, UniSetTypes::ObjectId sup_id ); 00233 00234 virtual void localSetValue( IOController::AIOStateList::iterator& it, 00235 const IOController_i::SensorInfo& si, 00236 CORBA::Long value, UniSetTypes::ObjectId sup_id ); 00237 00238 protected: 00239 IONotifyController(); 00240 virtual bool activateObject(); 00241 00242 // ФИЛЬТРЫ 00243 bool myAFilter(const UniAnalogIOInfo& ai, CORBA::Long newvalue, UniSetTypes::ObjectId sup_id); 00244 bool myDFilter(const UniDigitalIOInfo& ai, CORBA::Boolean newstate, UniSetTypes::ObjectId sup_id); 00245 00247 virtual void send(ConsumerList& lst, UniSetTypes::SensorMessage& sm); 00248 00249 00251 virtual void checkThreshold( AIOStateList::iterator& li, 00252 const IOController_i::SensorInfo& si, bool send=true ); 00253 00255 ThresholdExtList::iterator findThreshold( UniSetTypes::KeyType k, UniSetTypes::ThresholdId tid ); 00256 00257 00259 virtual void loggingInfo(UniSetTypes::SensorMessage& sm); 00260 00264 virtual void dumpOrdersList(const IOController_i::SensorInfo& si, const IONotifyController::ConsumerList& lst); 00265 00269 virtual void dumpThresholdList(const IOController_i::SensorInfo& si, const IONotifyController::ThresholdExtList& lst); 00270 00272 virtual void readDump(); 00273 00275 virtual void buildDependsList(); 00276 00277 NCRestorer* restorer; 00278 00279 void onChangeUndefined( DependsList::iterator it, bool undefined ); 00280 00281 UniSetTypes::uniset_mutex sig_mutex; 00282 ChangeSignal changeSignal; 00283 00284 private: 00285 friend class NCRestorer; 00286 00287 //---------------------- 00288 bool addConsumer(ConsumerList& lst, const UniSetTypes::ConsumerInfo& cons ); 00289 bool removeConsumer(ConsumerList& lst, const UniSetTypes::ConsumerInfo& cons ); 00290 00292 void ask(AskMap& askLst, const IOController_i::SensorInfo& si, 00293 const UniSetTypes::ConsumerInfo& ci, UniversalIO::UIOCommand cmd); 00294 00296 bool addThreshold(ThresholdExtList& lst, ThresholdInfoExt& ti, const UniSetTypes::ConsumerInfo& cons); 00298 bool removeThreshold(ThresholdExtList& lst, ThresholdInfoExt& ti, const UniSetTypes::ConsumerInfo& ci); 00299 00300 00301 AskMap askDIOList; 00302 AskMap askAIOList; 00303 AskThresholdMap askTMap; 00305 // Выходы 00306 AskMap askDOList; 00307 AskMap askAOList; 00310 UniSetTypes::uniset_mutex askDMutex; 00312 UniSetTypes::uniset_mutex askAMutex; 00314 UniSetTypes::uniset_mutex trshMutex; 00316 UniSetTypes::uniset_mutex askAOMutex; 00318 UniSetTypes::uniset_mutex askDOMutex; 00319 00320 int maxAttemtps; 00321 }; 00322 00323 #endif