UniSet  2.24.2
SMInterface.h
1 /*
2  * Copyright (c) 2015 Pavel Vainerman.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation, version 2.1.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Lesser Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 //--------------------------------------------------------------------------
17 #ifndef SMInterface_H_
18 #define SMInterface_H_
19 //--------------------------------------------------------------------------
20 #include <string>
21 #include <memory>
22 #include <atomic>
23 #include "UniSetTypes.h"
24 #include "Mutex.h"
25 #include "IONotifyController.h"
26 #include "UInterface.h"
27 // --------------------------------------------------------------------------
28 namespace uniset
29 {
30  // --------------------------------------------------------------------------
32  {
33  public:
34 
35  SMInterface( uniset::ObjectId _shmID, const std::shared_ptr<UInterface>& ui,
36  uniset::ObjectId myid, const std::shared_ptr<IONotifyController> ic = nullptr );
37  ~SMInterface();
38 
39  void setValue ( uniset::ObjectId, long value );
40  void setUndefinedState( const IOController_i::SensorInfo& si, bool undefined, uniset::ObjectId supplier );
41 
42  long getValue ( uniset::ObjectId id );
43 
44  void askSensor( uniset::ObjectId id, UniversalIO::UIOCommand cmd,
46 
47  IOController_i::SensorInfoSeq* getSensorsMap();
48  IONotifyController_i::ThresholdsListSeq* getThresholdsList();
49 
50  void localSetValue( IOController::IOStateList::iterator& it,
51  uniset::ObjectId sid,
52  CORBA::Long newvalue, uniset::ObjectId sup_id );
53 
54  long localGetValue( IOController::IOStateList::iterator& it,
55  uniset::ObjectId sid );
56 
61  void localSetUndefinedState( IOController::IOStateList::iterator& it,
62  bool undefined, uniset::ObjectId sid );
63 
64  // специальные функции
65  IOController::IOStateList::iterator ioEnd();
66  void initIterator( IOController::IOStateList::iterator& it );
67 
68  bool exist();
69  bool waitSMready( int msec, int pause = 5000 );
70  bool waitSMworking( uniset::ObjectId, int msec, int pause = 3000 );
71  bool waitSMreadyWithCancellation( int msec, std::atomic_bool& cancelFlag, int pause = 5000 );
72 
73  inline bool isLocalwork() const noexcept
74  {
75  return (ic == NULL);
76  }
77  inline uniset::ObjectId ID() const noexcept
78  {
79  return myid;
80  }
81  inline const std::shared_ptr<IONotifyController> SM() noexcept
82  {
83  return ic;
84  }
85  inline uniset::ObjectId getSMID() const noexcept
86  {
87  return shmID;
88  }
89 
90 #ifndef DISABLE_REST_API
91  std::string apiRequest( const std::string& query );
92 #endif
93 
94  protected:
95  const std::shared_ptr<IONotifyController> ic;
96  const std::shared_ptr<UInterface> ui;
97  CORBA::Object_var oref;
98  uniset::ObjectId shmID;
99  uniset::ObjectId myid;
100  uniset::uniset_rwmutex shmMutex;
101  };
102  // --------------------------------------------------------------------------
103 } // end of namespace uniset
104 //--------------------------------------------------------------------------
105 #endif
Definition: SMInterface.h:32
void localSetUndefinedState(IOController::IOStateList::iterator &it, bool undefined, uniset::ObjectId sid)
Definition: SMInterface.cc:250
Definition: Mutex.h:32
Definition: CommonEventLoop.h:15
const ObjectId DefaultObjectId
Definition: UniSetTypes.h:70
long ObjectId
Definition: UniSetTypes_i.idl:30
Definition: IOController_i.idl:58