UniSet  2.6.0
SMInterface.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 SMInterface_H_
00018 #define SMInterface_H_
00019 //--------------------------------------------------------------------------
00020 #include <string>
00021 #include <memory>
00022 #include "UniSetTypes.h"
00023 #include "Mutex.h"
00024 #include "IONotifyController.h"
00025 #include "UInterface.h"
00026 // --------------------------------------------------------------------------
00027 namespace uniset
00028 {
00029 // --------------------------------------------------------------------------
00030 class SMInterface
00031 {
00032     public:
00033 
00034         SMInterface( uniset::ObjectId _shmID, const std::shared_ptr<UInterface>& ui,
00035                      uniset::ObjectId myid, const std::shared_ptr<IONotifyController> ic = nullptr );
00036         ~SMInterface();
00037 
00038         void setValue ( uniset::ObjectId, long value );
00039         void setUndefinedState( const IOController_i::SensorInfo& si, bool undefined, uniset::ObjectId supplier );
00040 
00041         long getValue ( uniset::ObjectId id );
00042 
00043         void askSensor( uniset::ObjectId id, UniversalIO::UIOCommand cmd,
00044                         uniset::ObjectId backid = uniset::DefaultObjectId );
00045 
00046         IOController_i::SensorInfoSeq* getSensorsMap();
00047         IONotifyController_i::ThresholdsListSeq* getThresholdsList();
00048 
00049         void localSetValue( IOController::IOStateList::iterator& it,
00050                             uniset::ObjectId sid,
00051                             CORBA::Long newvalue, uniset::ObjectId sup_id );
00052 
00053         long localGetValue( IOController::IOStateList::iterator& it,
00054                             uniset::ObjectId sid );
00055 
00060         void localSetUndefinedState( IOController::IOStateList::iterator& it,
00061                                      bool undefined, uniset::ObjectId sid );
00062 
00063         // специальные функции
00064         IOController::IOStateList::iterator ioEnd();
00065         void initIterator( IOController::IOStateList::iterator& it );
00066 
00067         bool exist();
00068         bool waitSMready( int msec, int pause = 5000 );
00069         bool waitSMworking( uniset::ObjectId, int msec, int pause = 3000 );
00070 
00071         inline bool isLocalwork()
00072         {
00073             return (ic == NULL);
00074         }
00075         inline uniset::ObjectId ID()
00076         {
00077             return myid;
00078         }
00079         inline const std::shared_ptr<IONotifyController> SM()
00080         {
00081             return ic;
00082         }
00083         inline uniset::ObjectId getSMID()
00084         {
00085             return shmID;
00086         }
00087 
00088     protected:
00089         const std::shared_ptr<IONotifyController> ic;
00090         const std::shared_ptr<UInterface> ui;
00091         CORBA::Object_var oref;
00092         uniset::ObjectId shmID;
00093         uniset::ObjectId myid;
00094         uniset::uniset_rwmutex shmMutex;
00095 };
00096 // --------------------------------------------------------------------------
00097 } // end of namespace uniset
00098 //--------------------------------------------------------------------------
00099 #endif