UniSet  2.8.0
UniSetActivator.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 UniSetActivator_H_
23 #define UniSetActivator_H_
24 // --------------------------------------------------------------------------
25 #include <deque>
26 #include <memory>
27 #include <omniORB4/CORBA.h>
28 #include "UniSetTypes.h"
29 #include "UniSetObject.h"
30 #include "UniSetManager.h"
31 #include "OmniThreadCreator.h"
32 #include "UHttpRequestHandler.h"
33 #include "UHttpServer.h"
34 //----------------------------------------------------------------------------------------
35 namespace uniset
36 {
37  //----------------------------------------------------------------------------------------
38  class UniSetActivator;
39  typedef std::shared_ptr<UniSetActivator> UniSetActivatorPtr;
40  //----------------------------------------------------------------------------------------
62  public UniSetManager
63 #ifndef DISABLE_REST_API
65 #endif
66  {
67  public:
68 
69  static UniSetActivatorPtr Instance();
70 
71  virtual ~UniSetActivator();
72 
73  // запуск системы
74  // async = true - асинхронный запуск (создаётся отдельный поток).
75  // terminate_control = true - управление процессом завершения (обработка сигналов завершения)
76  void run( bool async, bool terminate_control = true );
77 
78  // штатное завершение работы
79  void shutdown();
80 
81  // ожидание завершения (если был запуск run(true))
82  void join();
83 
84  // прерывание работы
85  void terminate();
86 
87  virtual uniset::ObjectType getType() override
88  {
89  return uniset::ObjectType("UniSetActivator");
90  }
91 
92 
93 #ifndef DISABLE_REST_API
94  // Поддержка REST API (IHttpRequestRegistry)
95  virtual Poco::JSON::Object::Ptr httpGetByName( const std::string& name , const Poco::URI::QueryParameters& p ) override;
96  virtual Poco::JSON::Array::Ptr httpGetObjectsList( const Poco::URI::QueryParameters& p ) override;
97  virtual Poco::JSON::Object::Ptr httpHelpByName( const std::string& name, const Poco::URI::QueryParameters& p ) override;
98  virtual Poco::JSON::Object::Ptr httpRequestByName( const std::string& name, const std::string& req, const Poco::URI::QueryParameters& p ) override;
99 #endif
100 
101  protected:
102 
103  void mainWork();
104 
105  // уносим в protected, т.к. Activator должен быть только один..
106  UniSetActivator();
107 
108  static std::shared_ptr<UniSetActivator> inst;
109 
110  private:
111  void init();
112  static void on_finish_timeout();
113  static void set_signals( bool set );
114 
115  std::shared_ptr< OmniThreadCreator<UniSetActivator> > orbthr;
116 
117  CORBA::ORB_var orb;
118  bool termControl = { true };
119 
120 #ifndef DISABLE_REST_API
121  std::shared_ptr<uniset::UHttp::UHttpServer> httpserv;
122  std::string httpHost = { "" };
123  int httpPort = { 0 };
124  std::string httpCORS_allow = { "*" };
125 #endif
126  };
127  // -------------------------------------------------------------------------
128 } // end of uniset namespace
129 //----------------------------------------------------------------------------------------
130 #endif
131 //----------------------------------------------------------------------------------------
Definition: CommonEventLoop.h:14
Definition: UHttpRequestHandler.h:96
Definition: UniSetActivator.h:61
virtual Poco::JSON::Array::Ptr httpGetObjectsList(const Poco::URI::QueryParameters &p) override
Definition: UniSetActivator.cc:415
Definition: UniSetManager.h:57
void shutdown()
Definition: UniSetActivator.cc:196
string< SizeOfObjectType > ObjectType
Definition: UniSetTypes_i.idl:33