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