UniSet  2.0.0
UniSetActivator.h
См. документацию.
00001 /* This file is part of the UniSet project
00002  * Copyright (c) 2002 Free Software Foundation, Inc.
00003  * Copyright (c) 2002 Pavel Vainerman
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018  */
00019 // --------------------------------------------------------------------------
00024 // --------------------------------------------------------------------------
00025 #ifndef UniSetActivator_H_
00026 #define UniSetActivator_H_
00027 // --------------------------------------------------------------------------
00028 #include <deque>
00029 #include <memory>
00030 #include <omniORB4/CORBA.h>
00031 #include <cc++/socket.h>
00032 #include "UniSetTypes.h"
00033 #include "UniSetObject.h"
00034 #include "UniSetManager.h"
00035 #include "ThreadCreator.h"
00036 
00037 //#include "OmniThreadCreator.h"
00038 //----------------------------------------------------------------------------------------
00039 class UniSetActivator;
00040 typedef std::shared_ptr<UniSetActivator> UniSetActivatorPtr;
00041 //----------------------------------------------------------------------------------------
00055 class UniSetActivator:
00056     public UniSetManager
00057 {
00058     public:
00059 
00060         static UniSetActivatorPtr Instance( const UniSetTypes::ObjectId id=UniSetTypes::DefaultObjectId );
00061         void Destroy();
00062 
00063         // ------------------------------------
00064         virtual ~UniSetActivator();
00065 
00066         virtual void run(bool thread);
00067         virtual void stop();
00068         virtual void oaDestroy(int signo=0);
00069         void waitDestroy();
00070 
00071         inline void oakill(int signo){ raise(signo);}
00072 
00073         virtual UniSetTypes::ObjectType getType() override { return UniSetTypes::ObjectType("UniSetActivator"); }
00074 
00075         typedef sigc::signal<void,int> TerminateEvent_Signal;
00076         TerminateEvent_Signal signal_terminate_event();
00077 
00078     protected:
00079 
00083         enum AskSigCommand    {
00084                                 Ask,     
00085                                 Denial 
00086                             };
00087 
00096 //        void askSignal(int signo, AskSigCommand cmd=Ask);
00097 
00098         virtual void work();
00099 
00100         inline CORBA::ORB_ptr getORB()
00101         {
00102             return orb;
00103         }
00104 
00105         virtual void sysCommand( const UniSetTypes::SystemMessage *sm ) override;
00106 
00107 
00108         // уносим в protected, т.к. Activator должен быть только один..
00109         UniSetActivator();
00110         UniSetActivator( const UniSetTypes::ObjectId id );
00111 
00112         static std::shared_ptr<UniSetActivator> inst;
00113 
00114     private:
00115 
00116 //        static void processingSignal(int signo);
00117         static void terminated(int signo);
00118         static void finishterm(int signo);
00119         static void normalexit();
00120         static void normalterminate();
00121         static void set_signals(bool ask);
00122         void term( int signo );
00123         void init();
00124 
00125         friend class ThreadCreator<UniSetActivator>;
00126         ThreadCreator<UniSetActivator> *orbthr;
00127 
00128         CORBA::ORB_var orb;
00129         TerminateEvent_Signal s_term;
00130 
00131         bool omDestroy;
00132         bool sig;
00133         pid_t thpid; // pid orb потока
00134 
00135         struct Info
00136         {
00137             Info( pid_t p ):msgpid(p){}
00138             
00139             pid_t msgpid;    // pid порожденого потока обработки сообщений
00140         };
00141 
00142         struct OInfo:
00143             public Info
00144         {
00145             OInfo( UniSetObject* o, pid_t p ):Info(p),obj(o){}
00146             UniSetObject* obj;
00147         };
00148 
00149         struct MInfo:
00150             public Info
00151         {
00152             MInfo( UniSetManager* m, pid_t p ):Info(p),mnr(m){}
00153             UniSetManager* mnr;
00154         };
00155 
00156         std::deque<OInfo> lstOInfo;
00157         std::deque<MInfo> lstMInfo;
00158         void getinfo();
00159 };
00160 
00161 /*
00162 template<class TClass>
00163 int    UniSetActivator::attach(TClass* p, void(TClass:: *f)(void*) )
00164 {
00165     if( next >= MAX_CHILD_THREAD )
00166         return -1;
00167 
00168     callpull[next] = new OmniThreadCreator<TClass>( p, f);
00169     next++;
00170     return 0;
00171 }
00172 */
00173 #endif