Salome HOME
Porting to Python 2.6 - add coding page specification for Python scripts
[modules/kernel.git] / src / Container / SALOME_Component_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_Component_i.hxx
24 //  Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
25 //  Module : SALOME
26 //  $Header$
27
28 #ifndef _SALOME_COMPONENT_I_HXX_
29 #define _SALOME_COMPONENT_I_HXX_
30
31 #include <SALOMEconfig.h>
32
33 #include "SALOME_Container.hxx"
34
35 #include <iostream>
36 #include <signal.h>
37 #include <stdlib.h>
38 #ifndef WIN32
39 #include <unistd.h>
40 #endif
41 #include <sys/types.h>
42 #include <string>
43 #include <map>
44 #include CORBA_SERVER_HEADER(SALOME_Component)
45 #include "NOTIFICATION.hxx"
46 #include "Salome_file_i.hxx"
47
48 class RegistryConnexion;
49 class Engines_Container_i;
50
51 class CONTAINER_EXPORT Engines_Component_i: 
52   public virtual POA_Engines::Component,
53   public virtual PortableServer::ServantBase
54 {
55 public:
56   Engines_Component_i();
57   Engines_Component_i(CORBA::ORB_ptr orb,
58                       PortableServer::POA_ptr poa,
59                       PortableServer::ObjectId * contId, 
60                       const char *instanceName, 
61                       const char *interfaceName,
62                       bool notif = false,
63                       bool regist = true);
64   //Constructor for standalone component
65   Engines_Component_i(CORBA::ORB_ptr orb,
66                       PortableServer::POA_ptr poa,
67                       Engines::Container_ptr container, 
68                       const char *instanceName, 
69                       const char *interfaceName,
70                       bool notif = false,
71                       bool regist = true);
72
73   virtual ~Engines_Component_i();
74
75   // --- CORBA methods
76
77   char* instanceName();
78   char* interfaceName();
79
80   void ping();
81   void destroy();
82
83   CORBA::Long getStudyId();
84   Engines::Container_ptr GetContainerRef();
85
86   void setProperties(const Engines::FieldsDict& dico);
87   Engines::FieldsDict* getProperties();
88
89   void Names( const char * graphName , const char * nodeName ) ;
90   bool Kill_impl();
91   bool Stop_impl();
92   bool Suspend_impl();
93   bool Resume_impl();
94   CORBA::Long CpuUsed_impl() ;
95
96   virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
97                                        CORBA::Boolean isPublished,
98                                        CORBA::Boolean& isValidScript);
99
100   // CORBA operations for Salome_file
101   virtual Engines::Salome_file_ptr getInputFileToService(const char* service_name, 
102                                                          const char* Salome_file_name);
103   virtual Engines::Salome_file_ptr getOutputFileToService(const char* service_name, 
104                                                           const char* Salome_file_name);
105
106   virtual void checkInputFilesToService(const char* service_name);
107   virtual Engines::Salome_file_ptr setInputFileToService(const char* service_name, 
108                                                          const char* Salome_file_name);
109
110   virtual void checkOutputFilesToService(const char* service_name);
111   virtual Engines::Salome_file_ptr setOutputFileToService(const char* service_name, 
112                                                           const char* Salome_file_name);
113
114   // Object information
115   virtual bool hasObjectInfo() { return false; }
116   virtual char* getObjectInfo(CORBA::Long studyId, const char* entry) { return CORBA::string_dup(""); }
117   
118   // --- local C++ methods
119
120   PortableServer::ObjectId * getId(); 
121   Engines_Container_i *GetContainerPtr();
122   std::string getContainerName();
123
124   virtual bool setStudyId(CORBA::Long studyId);
125   static bool isMultiStudy();
126   static bool isMultiInstance();
127   static std::string GetDynLibraryName(const char *componentName);
128
129   void beginService(const char *serviceName);
130   void endService(const char *serviceName);
131   void sendMessage(const char *event_type, const char *message);
132   char * graphName() ;
133   char * nodeName() ;
134   bool Killer( pthread_t ThreadId , int signum );
135   void SetCurCpu() ;
136   long CpuUsed() ;
137   void CancelThread() ;
138
139   virtual void configureSalome_file(std::string service_name,
140                                     std::string file_port_name,
141                                     Salome_file_i * file);
142
143
144 protected:
145   int _studyId; // -1: not initialised; 0: multiStudy; >0: study
146   static bool _isMultiStudy;
147   static bool _isMultiInstance;
148
149   std::string _instanceName ;
150   std::string _interfaceName ;
151
152   CORBA::ORB_var _orb;
153   PortableServer::POA_var _poa;
154   PortableServer::ObjectId * _id;
155   PortableServer::ObjectId * _contId;
156   Engines::Container_var _container;
157   Engines_Component_i * _thisObj ;
158   RegistryConnexion *_myConnexionToRegistry;
159   NOTIFICATION_Supplier* _notifSupplier;
160   std::map<std::string,CORBA::Any>_fieldsDict;
161
162   // Map Salome_file_name to Salome_file*
163   typedef std::map<std::string, Salome_file_i*> _t_Salome_file_map;
164   // Map Service_name to  _Salome_file_map
165   typedef std::map<std::string, Engines_Component_i::_t_Salome_file_map*> _t_Service_file_map;
166   
167   _t_Service_file_map _Input_Service_file_map;
168   _t_Service_file_map _Output_Service_file_map;
169   _t_Service_file_map::iterator _Service_file_map_it;
170   _t_Salome_file_map::iterator _Salome_file_map_it;
171
172   std::string _serviceName ;
173   std::string _graphName ;
174   std::string _nodeName ;
175
176 private:
177 #ifndef WIN32
178   pthread_t _ThreadId ;
179 #else
180   pthread_t* _ThreadId ;
181 #endif
182   long      _StartUsed ;
183   long      _ThreadCpuUsed ;
184   bool      _Executed ;
185   bool      _CanceledThread ;
186 };
187
188 #endif