UniSet  2.6.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  //----------------------------------------------------------------------------------------
61  public UniSetManager
62 #ifndef DISABLE_REST_API
64 #endif
65  {
66  public:
67 
68  static UniSetActivatorPtr Instance();
69  void Destroy();
70 
71  std::shared_ptr<UniSetActivator> get_aptr();
72  // ------------------------------------
73  virtual ~UniSetActivator();
74 
75  virtual void run(bool thread);
76  virtual void stop();
77  virtual void uaDestroy(int signo = 0);
78 
79  virtual uniset::ObjectType getType() override
80  {
81  return uniset::ObjectType("UniSetActivator");
82  }
83 
84  typedef sigc::signal<void, int> TerminateEvent_Signal;
85  TerminateEvent_Signal signal_terminate_event();
86 
87  inline bool noUseGdbForStackTrace() const
88  {
89  return _noUseGdbForStackTrace;
90  }
91 
92  inline const std::string getAbortScript()
93  {
94  return abortScript;
95  }
96 
97 #ifndef DISABLE_REST_API
98  // Поддрежка REST API (IHttpRequestRegistry)
99  virtual Poco::JSON::Object::Ptr httpGetByName( const std::string& name , const Poco::URI::QueryParameters& p ) override;
100  virtual Poco::JSON::Array::Ptr httpGetObjectsList( const Poco::URI::QueryParameters& p ) override;
101  virtual Poco::JSON::Object::Ptr httpHelpByName( const std::string& name, const Poco::URI::QueryParameters& p ) override;
102  virtual Poco::JSON::Object::Ptr httpRequestByName( const std::string& name, const std::string& req, const Poco::URI::QueryParameters& p ) override;
103 #endif
104 
105  protected:
106 
107  virtual void work();
108 
109  CORBA::ORB_ptr getORB();
110 
111  virtual void sysCommand( const uniset::SystemMessage* sm ) override;
112 
113  // уносим в protected, т.к. Activator должен быть только один..
114  UniSetActivator();
115 
116  static std::shared_ptr<UniSetActivator> inst;
117 
118  private:
119  friend void uniset::terminate_thread();
120  friend void uniset::finished_thread();
121  friend std::shared_ptr<uniset::Configuration> uniset::uniset_init( int argc, const char* const* argv, const std::string& xmlfile );
122 
123  static void terminated(int signo);
124  static void normalexit();
125  static void normalterminate();
126  static void set_signals(bool ask);
127  void term( int signo );
128  void init();
129 
130  std::shared_ptr< OmniThreadCreator<UniSetActivator> > orbthr;
131 
132  CORBA::ORB_var orb;
133  TerminateEvent_Signal s_term;
134 
135  std::atomic_bool omDestroy;
136  pid_t thid = { 0 }; // id orb потока
137 
138  bool _noUseGdbForStackTrace = { false };
139 
140  std::string abortScript = { "" }; // скрипт вызываемый при прерывании программы (SIGSEGV,SIGABRT)
141 
142 #ifndef DISABLE_REST_API
143  std::shared_ptr<uniset::UHttp::UHttpServer> httpserv;
144  std::string httpHost = { "" };
145  int httpPort = { 0 };
146 #endif
147  };
148  // -------------------------------------------------------------------------
149 } // end of uniset namespace
150 //----------------------------------------------------------------------------------------
151 #endif
152 //----------------------------------------------------------------------------------------