|
UniSet
2.6.0
|
00001 /* 00002 * Copyright (c) 2015 Pavel Vainerman. 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU Lesser General Public License as 00006 * published by the Free Software Foundation, version 2.1. 00007 * 00008 * This program is distributed in the hope that it will be useful, but 00009 * WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 * Lesser General Lesser Public License for more details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public License 00014 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00015 */ 00016 // -------------------------------------------------------------------------- 00021 // -------------------------------------------------------------------------- 00022 #ifndef UniSetActivator_H_ 00023 #define UniSetActivator_H_ 00024 // -------------------------------------------------------------------------- 00025 #include <deque> 00026 #include <memory> 00027 #include <omniORB4/CORBA.h> 00028 #include "UniSetTypes.h" 00029 #include "UniSetObject.h" 00030 #include "UniSetManager.h" 00031 #include "OmniThreadCreator.h" 00032 #include "UHttpRequestHandler.h" 00033 #include "UHttpServer.h" 00034 //---------------------------------------------------------------------------------------- 00035 namespace uniset 00036 { 00037 //---------------------------------------------------------------------------------------- 00038 class UniSetActivator; 00039 typedef std::shared_ptr<UniSetActivator> UniSetActivatorPtr; 00040 //---------------------------------------------------------------------------------------- 00056 class UniSetActivator: 00057 public UniSetManager 00058 #ifndef DISABLE_REST_API 00059 , public uniset::UHttp::IHttpRequestRegistry 00060 #endif 00061 { 00062 public: 00063 00064 static UniSetActivatorPtr Instance(); 00065 void Destroy(); 00066 00067 std::shared_ptr<UniSetActivator> get_aptr(); 00068 // ------------------------------------ 00069 virtual ~UniSetActivator(); 00070 00071 virtual void run(bool thread); 00072 virtual void stop(); 00073 virtual void uaDestroy(int signo = 0); 00074 00075 virtual uniset::ObjectType getType() override 00076 { 00077 return uniset::ObjectType("UniSetActivator"); 00078 } 00079 00080 typedef sigc::signal<void, int> TerminateEvent_Signal; 00081 TerminateEvent_Signal signal_terminate_event(); 00082 00083 inline bool noUseGdbForStackTrace() const 00084 { 00085 return _noUseGdbForStackTrace; 00086 } 00087 00088 inline const std::string getAbortScript() 00089 { 00090 return abortScript; 00091 } 00092 00093 #ifndef DISABLE_REST_API 00094 // Поддрежка REST API (IHttpRequestRegistry) 00095 virtual Poco::JSON::Object::Ptr httpGetByName( const std::string& name , const Poco::URI::QueryParameters& p ) override; 00096 virtual Poco::JSON::Array::Ptr httpGetObjectsList( const Poco::URI::QueryParameters& p ) override; 00097 virtual Poco::JSON::Object::Ptr httpHelpByName( const std::string& name, const Poco::URI::QueryParameters& p ) override; 00098 virtual Poco::JSON::Object::Ptr httpRequestByName( const std::string& name, const std::string& req, const Poco::URI::QueryParameters& p ) override; 00099 #endif 00100 00101 protected: 00102 00103 virtual void work(); 00104 00105 CORBA::ORB_ptr getORB(); 00106 00107 virtual void sysCommand( const uniset::SystemMessage* sm ) override; 00108 00109 // уносим в protected, т.к. Activator должен быть только один.. 00110 UniSetActivator(); 00111 00112 static std::shared_ptr<UniSetActivator> inst; 00113 00114 private: 00115 friend void uniset::terminate_thread(); 00116 friend void uniset::finished_thread(); 00117 friend std::shared_ptr<uniset::Configuration> uniset::uniset_init( int argc, const char* const* argv, const std::string& xmlfile ); 00118 00119 static void terminated(int signo); 00120 static void normalexit(); 00121 static void normalterminate(); 00122 static void set_signals(bool ask); 00123 void term( int signo ); 00124 void init(); 00125 00126 std::shared_ptr< OmniThreadCreator<UniSetActivator> > orbthr; 00127 00128 CORBA::ORB_var orb; 00129 TerminateEvent_Signal s_term; 00130 00131 std::atomic_bool omDestroy; 00132 pid_t thid = { 0 }; // id orb потока 00133 00134 bool _noUseGdbForStackTrace = { false }; 00135 00136 std::string abortScript = { "" }; // скрипт вызываемый при прерывании программы (SIGSEGV,SIGABRT) 00137 00138 #ifndef DISABLE_REST_API 00139 std::shared_ptr<uniset::UHttp::UHttpServer> httpserv; 00140 std::string httpHost = { "" }; 00141 int httpPort = { 0 }; 00142 #endif 00143 }; 00144 // ------------------------------------------------------------------------- 00145 } // end of uniset namespace 00146 //---------------------------------------------------------------------------------------- 00147 #endif 00148 //----------------------------------------------------------------------------------------
1.7.6.1