Commit ce6224ef authored by Pavel Vainerman's avatar Pavel Vainerman

(UActivator): рефакторинг процесса завершения.

Переделал обработку через libev. Убрал (пока) всё лишнее (создание дампа, защитный kill).
parent 30930362
...@@ -25,9 +25,11 @@ ...@@ -25,9 +25,11 @@
#include <deque> #include <deque>
#include <memory> #include <memory>
#include <omniORB4/CORBA.h> #include <omniORB4/CORBA.h>
#include <ev++.h>
#include "UniSetTypes.h" #include "UniSetTypes.h"
#include "UniSetObject.h" #include "UniSetObject.h"
#include "UniSetManager.h" #include "UniSetManager.h"
#include "EventLoopServer.h"
#include "OmniThreadCreator.h" #include "OmniThreadCreator.h"
#include "UHttpRequestHandler.h" #include "UHttpRequestHandler.h"
#include "UHttpServer.h" #include "UHttpServer.h"
...@@ -58,6 +60,7 @@ namespace uniset ...@@ -58,6 +60,7 @@ namespace uniset
* *
*/ */
class UniSetActivator: class UniSetActivator:
public EventLoopServer,
public UniSetManager public UniSetManager
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
, public uniset::UHttp::IHttpRequestRegistry , public uniset::UHttp::IHttpRequestRegistry
...@@ -67,24 +70,16 @@ namespace uniset ...@@ -67,24 +70,16 @@ namespace uniset
static UniSetActivatorPtr Instance(); static UniSetActivatorPtr Instance();
std::shared_ptr<UniSetActivator> get_aptr();
// ------------------------------------
virtual ~UniSetActivator(); virtual ~UniSetActivator();
virtual void run(bool thread); void run( bool async );
virtual void stop(); void stop();
virtual void uaDestroy(int signo = 0);
virtual uniset::ObjectType getType() override virtual uniset::ObjectType getType() override
{ {
return uniset::ObjectType("UniSetActivator"); return uniset::ObjectType("UniSetActivator");
} }
typedef sigc::signal<void, int> TerminateEvent_Signal;
TerminateEvent_Signal signal_terminate_event();
bool noUseGdbForStackTrace() const;
const std::string getAbortScript() const;
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
// Поддрежка REST API (IHttpRequestRegistry) // Поддрежка REST API (IHttpRequestRegistry)
...@@ -98,38 +93,25 @@ namespace uniset ...@@ -98,38 +93,25 @@ namespace uniset
virtual void work(); virtual void work();
CORBA::ORB_ptr getORB();
virtual void sysCommand( const uniset::SystemMessage* sm ) override;
// уносим в protected, т.к. Activator должен быть только один.. // уносим в protected, т.к. Activator должен быть только один..
UniSetActivator(); UniSetActivator();
static std::shared_ptr<UniSetActivator> inst; static std::shared_ptr<UniSetActivator> inst;
private: private:
friend void uniset::terminate_thread();
friend void uniset::finished_thread();
friend std::shared_ptr<uniset::Configuration> uniset::uniset_init( int argc, const char* const* argv, const std::string& xmlfile );
static void terminated(int signo);
static void normalexit();
static void normalterminate();
static void set_signals(bool ask);
void term( int signo );
void init(); void init();
static void evsignal( ev::sig& signal, int signo );
virtual void evprepare() override;
virtual void evfinish() override;
std::shared_ptr< OmniThreadCreator<UniSetActivator> > orbthr; std::shared_ptr< OmniThreadCreator<UniSetActivator> > orbthr;
CORBA::ORB_var orb; CORBA::ORB_var orb;
TerminateEvent_Signal s_term;
std::atomic_bool omDestroy;
pid_t thid = { 0 }; // id orb потока
bool _noUseGdbForStackTrace = { false };
std::string abortScript = { "" }; // скрипт вызываемый при прерывании программы (SIGSEGV,SIGABRT) ev::sig sigINT;
ev::sig sigTERM;
ev::sig sigABRT;
ev::sig sigQUIT;
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
std::shared_ptr<uniset::UHttp::UHttpServer> httpserv; std::shared_ptr<uniset::UHttp::UHttpServer> httpserv;
......
...@@ -78,23 +78,6 @@ namespace uniset ...@@ -78,23 +78,6 @@ namespace uniset
virtual bool add( const std::shared_ptr<UniSetObject>& obj ); virtual bool add( const std::shared_ptr<UniSetObject>& obj );
virtual bool remove( const std::shared_ptr<UniSetObject>& obj ); virtual bool remove( const std::shared_ptr<UniSetObject>& obj );
// -------------------------- // --------------------------
/*! Получение доступа к подчиненному менеджеру по идентификатору
* \return shared_ptr<>, если объект не найден будет возвращен shared_ptr<> = nullptr
*/
const std::shared_ptr<UniSetManager> itemM(const uniset::ObjectId id);
/*! Получение доступа к подчиненному объекту по идентификатору
* \return shared_ptr<>, если объект не найден будет возвращен shared_ptr<> = nullptr
*/
const std::shared_ptr<UniSetObject> itemO( const uniset::ObjectId id );
// Функции для работы со списками подчиненных объектов
// ---------------
UniSetManagerList::const_iterator beginMList();
UniSetManagerList::const_iterator endMList();
ObjectsList::const_iterator beginOList();
ObjectsList::const_iterator endOList();
size_t objectsCount() const; // количество подчиненных объектов size_t objectsCount() const; // количество подчиненных объектов
// --------------- // ---------------
...@@ -127,14 +110,14 @@ namespace uniset ...@@ -127,14 +110,14 @@ namespace uniset
//! \note Переопределяя не забывайте вызвать базовую //! \note Переопределяя не забывайте вызвать базовую
virtual bool deactivateObject() override; virtual bool deactivateObject() override;
const std::shared_ptr<UniSetObject> findObject( const std::string& name ); const std::shared_ptr<UniSetObject> findObject( const std::string& name ) const;
const std::shared_ptr<UniSetManager> findManager( const std::string& name ); const std::shared_ptr<UniSetManager> findManager( const std::string& name ) const;
// рекурсивный поиск по всем объекам // рекурсивный поиск по всем объекам
const std::shared_ptr<UniSetObject> deepFindObject( const std::string& name ); const std::shared_ptr<UniSetObject> deepFindObject( const std::string& name ) const;
// рекурсивное наполнение списка объектов // рекурсивное наполнение списка объектов
void getAllObjectsList( std::vector<std::shared_ptr<UniSetObject>>& vec, size_t lim = 1000 ); void getAllObjectsList(std::vector<std::shared_ptr<UniSetObject> >& vec, size_t lim = 1000 );
typedef UniSetManagerList::iterator MListIterator; typedef UniSetManagerList::iterator MListIterator;
...@@ -144,14 +127,21 @@ namespace uniset ...@@ -144,14 +127,21 @@ namespace uniset
PortableServer::POA_var poa; PortableServer::POA_var poa;
PortableServer::POAManager_var pman; PortableServer::POAManager_var pman;
// Функции для работы со списками подчиненных объектов
// ---------------
UniSetManagerList::const_iterator beginMList();
UniSetManagerList::const_iterator endMList();
ObjectsList::const_iterator beginOList();
ObjectsList::const_iterator endOList();
private: private:
int sig; int sig;
UniSetManagerList mlist; UniSetManagerList mlist;
ObjectsList olist; ObjectsList olist;
uniset::uniset_rwmutex olistMutex; mutable uniset::uniset_rwmutex olistMutex;
uniset::uniset_rwmutex mlistMutex; mutable uniset::uniset_rwmutex mlistMutex;
}; };
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
} // end of uniset namespace } // end of uniset namespace
......
...@@ -1452,8 +1452,8 @@ namespace uniset ...@@ -1452,8 +1452,8 @@ namespace uniset
return uniset::uconf; return uniset::uconf;
} }
atexit( UniSetActivator::normalexit ); // atexit( UniSetActivator::normalexit );
set_terminate( UniSetActivator::normalterminate ); // ловушка для неизвестных исключений // set_terminate( UniSetActivator::normalterminate ); // ловушка для неизвестных исключений
string confile = uniset::getArgParam( "--confile", argc, argv, xmlfile ); string confile = uniset::getArgParam( "--confile", argc, argv, xmlfile );
uniset::uconf = make_shared<Configuration>(argc, argv, confile); uniset::uconf = make_shared<Configuration>(argc, argv, confile);
......
...@@ -465,7 +465,7 @@ bool UniSetManager::deactivateObject() ...@@ -465,7 +465,7 @@ bool UniSetManager::deactivateObject()
return true; return true;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
const std::shared_ptr<UniSetObject> UniSetManager::findObject( const string& name ) const std::shared_ptr<UniSetObject> UniSetManager::findObject( const string& name ) const
{ {
uniset_rwmutex_rlock lock(olistMutex); uniset_rwmutex_rlock lock(olistMutex);
...@@ -478,7 +478,7 @@ const std::shared_ptr<UniSetObject> UniSetManager::findObject( const string& nam ...@@ -478,7 +478,7 @@ const std::shared_ptr<UniSetObject> UniSetManager::findObject( const string& nam
return nullptr; return nullptr;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
const std::shared_ptr<UniSetManager> UniSetManager::findManager( const string& name ) const std::shared_ptr<UniSetManager> UniSetManager::findManager( const string& name ) const
{ {
uniset_rwmutex_rlock lock(mlistMutex); uniset_rwmutex_rlock lock(mlistMutex);
...@@ -491,7 +491,7 @@ const std::shared_ptr<UniSetManager> UniSetManager::findManager( const string& n ...@@ -491,7 +491,7 @@ const std::shared_ptr<UniSetManager> UniSetManager::findManager( const string& n
return nullptr; return nullptr;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
const std::shared_ptr<UniSetObject> UniSetManager::deepFindObject( const string& name ) const std::shared_ptr<UniSetObject> UniSetManager::deepFindObject( const string& name ) const
{ {
{ {
auto obj = findObject(name); auto obj = findObject(name);
...@@ -617,7 +617,7 @@ bool UniSetManager::removeManager( const std::shared_ptr<UniSetManager>& child ) ...@@ -617,7 +617,7 @@ bool UniSetManager::removeManager( const std::shared_ptr<UniSetManager>& child )
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
#if 0
const std::shared_ptr<UniSetManager> UniSetManager::itemM( const ObjectId id ) const std::shared_ptr<UniSetManager> UniSetManager::itemM( const ObjectId id )
{ {
...@@ -652,7 +652,7 @@ const std::shared_ptr<UniSetObject> UniSetManager::itemO( const ObjectId id ) ...@@ -652,7 +652,7 @@ const std::shared_ptr<UniSetObject> UniSetManager::itemO( const ObjectId id )
return nullptr; // std::shared_ptr<UniSetObject>(); return nullptr; // std::shared_ptr<UniSetObject>();
} }
#endif
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
int UniSetManager::getObjectsInfo( const std::shared_ptr<UniSetManager>& mngr, SimpleInfoSeq* seq, int UniSetManager::getObjectsInfo( const std::shared_ptr<UniSetManager>& mngr, SimpleInfoSeq* seq,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment