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