UniSet  2.7.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  void run( bool async );
76 
77  // штатное завершение работы
78  void shutdown();
79 
80  // прерывание работы
81  void terminate();
82 
83  virtual uniset::ObjectType getType() override
84  {
85  return uniset::ObjectType("UniSetActivator");
86  }
87 
88 
89 #ifndef DISABLE_REST_API
90  // Поддрежка REST API (IHttpRequestRegistry)
91  virtual Poco::JSON::Object::Ptr httpGetByName( const std::string& name , const Poco::URI::QueryParameters& p ) override;
92  virtual Poco::JSON::Array::Ptr httpGetObjectsList( const Poco::URI::QueryParameters& p ) override;
93  virtual Poco::JSON::Object::Ptr httpHelpByName( const std::string& name, const Poco::URI::QueryParameters& p ) override;
94  virtual Poco::JSON::Object::Ptr httpRequestByName( const std::string& name, const std::string& req, const Poco::URI::QueryParameters& p ) override;
95 #endif
96 
97  protected:
98 
99  void work();
100 
101  // уносим в protected, т.к. Activator должен быть только один..
102  UniSetActivator();
103 
104  static std::shared_ptr<UniSetActivator> inst;
105 
106  private:
107  void init();
108  static void on_finish_timeout();
109  static void set_signals( bool set );
110 
111  std::shared_ptr< OmniThreadCreator<UniSetActivator> > orbthr;
112 
113  CORBA::ORB_var orb;
114 
115 #ifndef DISABLE_REST_API
116  std::shared_ptr<uniset::UHttp::UHttpServer> httpserv;
117  std::string httpHost = { "" };
118  int httpPort = { 0 };
119  std::string httpCORS_allow = { "*" };
120 #endif
121  };
122  // -------------------------------------------------------------------------
123 } // end of uniset namespace
124 //----------------------------------------------------------------------------------------
125 #endif
126 //----------------------------------------------------------------------------------------
Definition: CallbackTimer.h:29
Definition: UHttpRequestHandler.h:96
Definition: UniSetActivator.h:61
virtual Poco::JSON::Array::Ptr httpGetObjectsList(const Poco::URI::QueryParameters &p) override
Definition: UniSetActivator.cc:392
Definition: UniSetManager.h:57
void shutdown()
Definition: UniSetActivator.cc:186
string< SizeOfObjectType > ObjectType
Definition: UniSetTypes_i.idl:33