Salome HOME
CCAR: import_hook.py was too strict in ensure_list (ImportError raised)
[modules/kernel.git] / src / Container / SALOME_Container_i.hxx
1 //  Copyright (C) 2007-2010  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
23 //  SALOME Container : implementation of container and engine for Kernel
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 "SALOME_Container.hxx"
33
34 #include <SALOMEconfig.h>
35 #include CORBA_SERVER_HEADER(SALOME_Component)
36 #include CORBA_SERVER_HEADER(SALOME_PyNode)
37
38 #include <iostream>
39 #include <signal.h>
40 #include <stdlib.h>
41 #ifndef WIN32
42 #include <unistd.h>
43 #endif
44 #include <sys/types.h>
45 #include <omnithread.h>
46 #include <map>
47 #include <string>
48
49 class SALOME_NamingService;
50
51 class CONTAINER_EXPORT Engines_Container_i:
52   public virtual POA_Engines::Container,
53   public virtual PortableServer::ServantBase
54 {
55 public:
56   Engines_Container_i();
57   Engines_Container_i(CORBA::ORB_ptr orb, 
58                       PortableServer::POA_ptr poa,
59                       char * containerName ,
60                       int argc, char* argv[],
61                       bool activAndRegist = true,
62                       bool isServantAloneInProcess = true);
63   virtual ~Engines_Container_i();
64
65   // --- CORBA methods
66
67   virtual bool load_component_Library(const char* componentName, CORBA::String_out reason);
68
69   virtual Engines::Component_ptr
70   create_component_instance( const char* componentName,
71                              CORBA::Long studyId); // 0 for multiStudy
72
73   virtual Engines::Component_ptr
74   create_component_instance_env( const char* componentName,
75                                  CORBA::Long studyId,          // 0 for multiStudy
76                                  const Engines::FieldsDict& env,
77                                  CORBA::String_out reason); 
78   Engines::Component_ptr
79   find_component_instance( const char* registeredName,
80                            CORBA::Long studyId); // 0 for multiStudy
81
82   Engines::Component_ptr
83   load_impl(const char* nameToRegister,
84             const char* componentName);
85
86
87   void remove_impl(Engines::Component_ptr component_i);
88   void finalize_removal();
89
90   virtual void ping();
91   char* name();
92   char* workingdir();
93   char* logfilename();
94   void logfilename(const char* name);
95
96   virtual void Shutdown();
97   char* getHostName();
98   CORBA::Long getPID();
99   //! Kill current container
100   bool Kill_impl();
101
102   Engines::fileRef_ptr createFileRef(const char* origFileName);
103   Engines::fileTransfer_ptr getFileTransfer();
104
105   virtual Engines::Salome_file_ptr createSalome_file(const char* origFileName);
106   void copyFile(Engines::Container_ptr container, const char* remoteFile, const char* localFile);
107   Engines::PyNode_ptr createPyNode(const char* nodeName, const char* code);
108   Engines::PyScriptNode_ptr createPyScriptNode(const char* nodeName, const char* code);
109   // --- local C++ methods
110
111   Engines::Component_ptr
112   find_or_create_instance( std::string genericRegisterName,
113                            std::string componentLibraryName);
114
115   bool load_component_CppImplementation(const char* componentName,std::string& reason);
116   bool load_component_PythonImplementation(const char* componentName,std::string& reason);
117   bool load_component_ExecutableImplementation(const char* componentName,std::string& reason);
118
119   Engines::Component_ptr createPythonInstance(std::string CompName, int studyId, std::string& error);
120   Engines::Component_ptr createExecutableInstance(std::string CompName, int studyId, const Engines::FieldsDict& env, std::string& error);
121   Engines::Component_ptr createInstance(std::string genericRegisterName, void *handle, int studyId, std::string& error);
122
123   static bool isPythonContainer(const char* ContainerName);
124   static void decInstanceCnt(std::string genericRegisterName);
125   //??? char* machineName();
126
127   // --- needed for parallel components, Numerical Platon
128
129   int getArgc() { return _argc; }
130   char **getArgv() { return _argv; }
131
132 protected:
133
134   static std::map<std::string, int> _cntInstances_map;
135   static std::map<std::string, void *> _library_map; // library names, loaded
136   static std::map<std::string, void *> _toRemove_map;// library names to remove
137   static omni_mutex _numInstanceMutex ; // lib and instance protection
138
139   bool _isSupervContainer;
140
141   SALOME_NamingService *_NS ;
142   std::string _library_path;
143   std::string _containerName;
144   std::string _logfilename;
145   CORBA::ORB_var _orb;
146   PortableServer::POA_var _poa;
147   PortableServer::ObjectId * _id ;
148   int _numInstance ;
149   std::map<std::string,Engines::Component_var> _listInstances_map;
150   std::map<std::string,Engines::fileRef_var> _fileRef_map;
151   std::map<std::string,Engines::Salome_file_var> _Salome_file_map;
152   Engines::fileTransfer_var _fileTransfer;
153
154   int    _argc ;
155   char** _argv ;
156   long   _pid;
157   bool   _isServantAloneInProcess;
158 };
159
160 #endif
161