UniSet @VERSION@
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 <vector>
28#include <omniORB4/CORBA.h>
29#include "UniSetTypes.h"
30#include "UniSetObject.h"
31#include "UniSetManager.h"
32#include "OmniThreadCreator.h"
33#include "UHttpRequestHandler.h"
34#include "UHttpServer.h"
35//----------------------------------------------------------------------------------------
36namespace uniset
37{
60 //----------------------------------------------------------------------------------------
61 class UniSetActivator;
62 typedef std::shared_ptr<UniSetActivator> UniSetActivatorPtr;
63 //----------------------------------------------------------------------------------------
77 public UniSetManager
78#ifndef DISABLE_REST_API
80#endif
81 {
82 public:
83
84 static UniSetActivatorPtr Instance();
85
87 static void help_print();
88
89 virtual ~UniSetActivator();
90
91 // запуск системы
92 // async = true - асинхронный запуск (создаётся отдельный поток).
93 // terminate_control = true - управление процессом завершения (обработка сигналов завершения)
94 void run( bool async, bool terminate_control = true );
95
96 // штатное завершение работы
97 void shutdown();
98
99 // ожидание завершения (если был запуск run(true))
100 void join();
101
102 // прерывание работы
103 void terminate();
104
105 virtual uniset::ObjectType getType() override
106 {
107 return uniset::ObjectType("UniSetActivator");
108 }
109
110
111#ifndef DISABLE_REST_API
112 // Поддержка REST API (IHttpRequestRegistry)
113 virtual Poco::JSON::Object::Ptr httpRequest( const UHttp::HttpRequestContext& ctx ) override;
114 virtual Poco::JSON::Array::Ptr httpGetObjectsList( const UHttp::HttpRequestContext& ctx ) override;
115 virtual Poco::JSON::Object::Ptr httpHelpRequest( const UHttp::HttpRequestContext& ctx ) override;
116#endif
117
118 protected:
119
120 void mainWork();
121
122 // уносим в protected, т.к. Activator должен быть только один..
124
125 static std::shared_ptr<UniSetActivator> inst;
126
127 private:
128 void init();
129 static void on_finish_timeout();
130 static void set_signals( bool set );
131
132 std::shared_ptr< OmniThreadCreator<UniSetActivator> > orbthr;
133
134 CORBA::ORB_var orb;
135 bool termControl = { true };
136
137#ifndef DISABLE_REST_API
138 std::shared_ptr<uniset::UHttp::UHttpServer> httpserv;
139 std::string httpHost = { "" };
140 int httpPort = { 0 };
141 std::string httpCORS_allow = { "*" };
142 std::string httpDefaultContentType = { "text/json; charset=UTF-8" };
143 std::vector<std::string> httpWhitelist;
144 std::vector<std::string> httpBlacklist;
145 std::vector<std::string> httpTrustedProxies;
146 bool httpBearerRequired = { false };
147 std::vector<std::string> httpBearerTokens;
148#endif
149 };
150 // -------------------------------------------------------------------------
151} // end of uniset namespace
152//----------------------------------------------------------------------------------------
153#endif
154//----------------------------------------------------------------------------------------
Definition UHttpRequestHandler.h:146
Definition UniSetActivator.h:81
void shutdown()
Definition UniSetActivator.cc:235
virtual Poco::JSON::Array::Ptr httpGetObjectsList(const UHttp::HttpRequestContext &ctx) override
Definition UniSetActivator.cc:462
static void help_print()
Definition UniSetActivator.cc:498
Definition UniSetManager.h:60
Definition AccessConfig.h:30
string< SizeOfObjectType > ObjectType
Definition UniSetTypes_i.idl:33
Definition UHttpRequestHandler.h:87