Salome HOME
08afa42af91766f239ebf24f3d780e192580b59f
[modules/kernel.git] / src / Container / SALOME_Container_i.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 //  SALOME Container : implementation of container and engine for Kernel
23 //  File   : SALOME_Container_i.hxx
24 //  Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
25 //  Module : SALOME
26 //  $Header$
27 //
28 #ifndef _SALOME_CONTAINER_I_HXX_
29 #define _SALOME_CONTAINER_I_HXX_
30
31 #include "SALOME_Container.hxx"
32
33 #include <SALOMEconfig.h>
34 #include CORBA_SERVER_HEADER(SALOME_Component)
35
36 #include <iostream>
37 #include <signal.h>
38 #include <stdlib.h>
39 #ifndef WIN32
40 #include <unistd.h>
41 #endif
42 #include <sys/types.h>
43 #include <omnithread.h>
44 #include <map>
45 #include <string>
46
47 class SALOME_NamingService;
48
49 class CONTAINER_EXPORT Engines_Container_i:
50   public virtual POA_Engines::Container,
51   public virtual PortableServer::ServantBase
52 {
53 public:
54   Engines_Container_i();
55   Engines_Container_i(CORBA::ORB_ptr orb, 
56                       PortableServer::POA_ptr poa,
57                       char * containerName ,
58                       int argc, char* argv[],
59                       bool activAndRegist = true,
60                       bool isServantAloneInProcess = true);
61   virtual ~Engines_Container_i();
62
63   // --- CORBA methods
64
65   virtual bool load_component_Library(const char* componentName);
66
67   virtual Engines::Component_ptr
68   create_component_instance( const char* componentName,
69                              CORBA::Long studyId); // 0 for multiStudy
70
71   Engines::Component_ptr
72   find_component_instance( const char* registeredName,
73                            CORBA::Long studyId); // 0 for multiStudy
74
75   Engines::Component_ptr
76   load_impl(const char* nameToRegister,
77             const char* componentName);
78
79
80   void remove_impl(Engines::Component_ptr component_i);
81   void finalize_removal();
82
83   virtual void ping();
84   char* name();
85   char* workingdir();
86   char* logfilename();
87   void logfilename(const char* name);
88
89   virtual void Shutdown();
90   char* getHostName();
91   CORBA::Long getPID();
92   //! Kill current container
93   bool Kill_impl();
94
95   Engines::fileRef_ptr createFileRef(const char* origFileName);
96   Engines::fileTransfer_ptr getFileTransfer();
97
98   virtual Engines::Salome_file_ptr createSalome_file(const char* origFileName);
99   // --- local C++ methods
100
101   Engines::Component_ptr
102   find_or_create_instance( std::string genericRegisterName,
103                            std::string componentLibraryName);
104
105   Engines::Component_ptr
106   createInstance(std::string genericRegisterName,
107                  void *handle,
108                  int studyId);
109
110   static bool isPythonContainer(const char* ContainerName);
111   static void decInstanceCnt(std::string genericRegisterName);
112   //??? char* machineName();
113
114   // --- needed for parallel components, Numerical Platon
115
116   int getArgc() { return _argc; }
117   char **getArgv() { return _argv; }
118
119 protected:
120
121   static std::map<std::string, int> _cntInstances_map;
122   static std::map<std::string, void *> _library_map; // library names, loaded
123   static std::map<std::string, void *> _toRemove_map;// library names to remove
124   static omni_mutex _numInstanceMutex ; // lib and instance protection
125
126   bool _isSupervContainer;
127
128   SALOME_NamingService *_NS ;
129   std::string _library_path;
130   std::string _containerName;
131   std::string _logfilename;
132   CORBA::ORB_var _orb;
133   PortableServer::POA_var _poa;
134   PortableServer::ObjectId * _id ;
135   int _numInstance ;
136   std::map<std::string,Engines::Component_var> _listInstances_map;
137   std::map<std::string,Engines::fileRef_var> _fileRef_map;
138   std::map<std::string,Engines::Salome_file_var> _Salome_file_map;
139   Engines::fileTransfer_var _fileTransfer;
140
141   int    _argc ;
142   char** _argv ;
143   long   _pid;
144   bool   _isServantAloneInProcess;
145 };
146
147 #endif
148