Salome HOME
PR: from Sergey Mozokhin, Supervisor problem, crash after killing a dataflow execution.
[modules/kernel.git] / src / Container / SALOME_Container_i.hxx
1 //  SALOME Container : implementation of container and engine for Kernel
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : SALOME_Container_i.hxx
25 //  Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
26 //  Module : SALOME
27 //  $Header$
28
29 #ifndef _SALOME_CONTAINER_I_HXX_
30 #define _SALOME_CONTAINER_I_HXX_
31
32 #include <SALOMEconfig.h>
33 #include CORBA_SERVER_HEADER(SALOME_Component)
34
35 #include <iostream>
36 #include <signal.h>
37 #include <stdlib.h>
38 #ifndef WNT
39 #include <unistd.h>
40 #endif
41 #include <sys/types.h>
42 #include <omnithread.h>
43 #include <map>
44 #include <string>
45
46 class SALOME_NamingService;
47
48
49 #if defined CONTAINER_EXPORTS
50 #if defined WIN32
51 #define CONTAINER_EXPORT __declspec( dllexport )
52 #else
53 #define CONTAINER_EXPORT
54 #endif
55 #else
56 #if defined WNT
57 #define CONTAINER_EXPORT __declspec( dllimport )
58 #else
59 #define CONTAINER_EXPORT
60 #endif
61 #endif
62
63 class CONTAINER_EXPORT Engines_Container_i:
64   public virtual POA_Engines::Container,
65   public virtual PortableServer::RefCountServantBase
66 {
67 public:
68   Engines_Container_i();
69   Engines_Container_i(CORBA::ORB_ptr orb, 
70                       PortableServer::POA_var poa,
71                       char * containerName ,
72                       int argc, char* argv[],
73                       bool activAndRegist = true,
74                       bool isServantAloneInProcess = true);
75   virtual ~Engines_Container_i();
76
77   // --- CORBA methods
78
79   virtual bool load_component_Library(const char* componentName);
80
81   virtual Engines::Component_ptr
82   create_component_instance( const char* componentName,
83                              CORBA::Long studyId); // 0 for multiStudy
84
85   Engines::Component_ptr
86   find_component_instance( const char* registeredName,
87                            CORBA::Long studyId); // 0 for multiStudy
88
89   Engines::Component_ptr
90   load_impl(const char* nameToRegister,
91             const char* componentName);
92
93
94   void remove_impl(Engines::Component_ptr component_i);
95   void finalize_removal();
96
97   virtual void ping();
98   char* name();
99   virtual void Shutdown();
100   char* getHostName();
101   CORBA::Long getPID();
102   //! Kill current container
103   bool Kill_impl();
104
105   Engines::fileRef_ptr createFileRef(const char* origFileName);
106   Engines::fileTransfer_ptr getFileTransfer();
107
108
109   // --- local C++ methods
110
111   Engines::Component_ptr
112   find_or_create_instance( std::string genericRegisterName,
113                            std::string componentLibraryName);
114
115   Engines::Component_ptr
116   createInstance(std::string genericRegisterName,
117                  void *handle,
118                  int studyId);
119
120   static bool isPythonContainer(const char* ContainerName);
121   static void decInstanceCnt(std::string genericRegisterName);
122   //??? char* machineName();
123
124   // --- needed for parallel components, Numerical Platon
125
126   int getArgc() { return _argc; }
127   char **getArgv() { return _argv; }
128
129 protected:
130
131   static std::map<std::string, int> _cntInstances_map;
132   static std::map<std::string, void *> _library_map; // library names, loaded
133   static std::map<std::string, void *> _toRemove_map;// library names to remove
134   static omni_mutex _numInstanceMutex ; // lib and instance protection
135
136   bool _isSupervContainer;
137
138   SALOME_NamingService *_NS ;
139   std::string _library_path;
140   std::string _containerName;
141   CORBA::ORB_var _orb;
142   PortableServer::POA_var _poa;
143   PortableServer::ObjectId * _id ;
144   int _numInstance ;
145   std::map<std::string,Engines::Component_var> _listInstances_map;
146   std::map<std::string,Engines::fileRef_var> _fileRef_map;
147   Engines::fileTransfer_var _fileTransfer;
148
149   int    _argc ;
150   char** _argv ;
151   long   _pid;
152   bool   _isServantAloneInProcess;
153 };
154
155 #endif
156