UniSet  2.6.0
UniSetManager.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 // --------------------------------------------------------------------------
21 // --------------------------------------------------------------------------
22 #ifndef UniSetManager_H_
23 #define UniSetManager_H_
24 // --------------------------------------------------------------------------
25 #include <omniORB4/CORBA.h>
26 #include <memory>
27 #include "UniSetTypes.h"
28 #include "UniSetObject.h"
29 #include "UniSetManager_i.hh"
30 //---------------------------------------------------------------------------
31 namespace uniset
32 {
33  //---------------------------------------------------------------------------
34  class UniSetActivator;
35 
36  class UniSetManager;
37  typedef std::list< std::shared_ptr<UniSetManager> > UniSetManagerList;
38  //---------------------------------------------------------------------------
58  public UniSetObject,
59  public POA_UniSetManager_i
60  {
61  public:
63  UniSetManager( const std::string& name, const std::string& section );
64  virtual ~UniSetManager();
65 
66  std::shared_ptr<UniSetManager> get_mptr();
67 
68  virtual uniset::ObjectType getType() override
69  {
70  return uniset::ObjectType("UniSetManager");
71  }
72 
73  // ------ функции объявленные в интерфейсе(IDL) ------
74  virtual void broadcast( const uniset::TransportMessage& msg) override;
75  virtual uniset::SimpleInfoSeq* getObjectsInfo( CORBA::Long MaxLength = 300, const char* userparam = 0 ) override ;
76 
77  // --------------------------
78  virtual bool add( const std::shared_ptr<UniSetObject>& obj );
79  virtual bool remove( const std::shared_ptr<UniSetObject>& obj );
80  // --------------------------
84  const std::shared_ptr<UniSetManager> itemM(const uniset::ObjectId id);
85 
89  const std::shared_ptr<UniSetObject> itemO( const uniset::ObjectId id );
90 
91  // Функции для работы со списками подчиненных объектов
92  // ---------------
93  UniSetManagerList::const_iterator beginMList();
94  UniSetManagerList::const_iterator endMList();
95  ObjectsList::const_iterator beginOList();
96  ObjectsList::const_iterator endOList();
97 
98  size_t objectsCount() const; // количество подчиненных объектов
99  // ---------------
100 
101  PortableServer::POA_ptr getPOA();
102  PortableServer::POAManager_ptr getPOAManager();
103 
104  protected:
105 
106  UniSetManager();
107 
108  virtual bool addManager( const std::shared_ptr<UniSetManager>& mngr );
109  virtual bool removeManager( const std::shared_ptr<UniSetManager>& mngr );
110  virtual bool addObject( const std::shared_ptr<UniSetObject>& obj );
111  virtual bool removeObject( const std::shared_ptr<UniSetObject>& obj );
112 
113  enum OManagerCommand { deactiv, activ, initial, term };
114  friend std::ostream& operator<<(std::ostream& os, uniset::UniSetManager::OManagerCommand& cmd );
115 
116  // работа со списком объектов
117  void objects(OManagerCommand cmd);
118  // работа со списком менеджеров
119  void managers(OManagerCommand cmd);
120 
121  virtual void sigterm( int signo ) override;
122 
123  void initPOA( const std::weak_ptr<UniSetManager>& rmngr );
124 
126  virtual bool activateObject() override;
128  virtual bool deactivateObject() override;
129 
130  const std::shared_ptr<UniSetObject> findObject( const std::string& name );
131  const std::shared_ptr<UniSetManager> findManager( const std::string& name );
132 
133  // рекурсивный поиск по всем объекам
134  const std::shared_ptr<UniSetObject> deepFindObject( const std::string& name );
135 
136  // рекурсивное наполнение списка объектов
137  void getAllObjectsList( std::vector<std::shared_ptr<UniSetObject>>& vec, size_t lim = 1000 );
138 
139  typedef UniSetManagerList::iterator MListIterator;
140 
141  int getObjectsInfo(const std::shared_ptr<UniSetManager>& mngr, uniset::SimpleInfoSeq* seq,
142  int begin, const long uplimit, const char* userparam );
143 
144  PortableServer::POA_var poa;
145  PortableServer::POAManager_var pman;
146 
147  private:
148 
149  int sig;
150  UniSetManagerList mlist;
151  ObjectsList olist;
152 
153  uniset::uniset_rwmutex olistMutex;
154  uniset::uniset_rwmutex mlistMutex;
155  };
156  // -------------------------------------------------------------------------
157 } // end of uniset namespace
158 #endif