1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SALOME Container : implementation of container and engine for Kernel
23 // File : Component_i.cxx
24 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
27 //#define private protected // for pd_refCount trace
29 #include "SALOME_Component_i.hxx"
30 #include "SALOME_Container_i.hxx"
31 #include "RegistryConnexion.hxx"
32 #include "Basics_Utils.hxx"
38 #include "utilities.h"
42 #include <sys/resource.h>
45 #include <sys/timeb.h>
53 extern bool _Sleeping ;
54 static Engines_Component_i * theEngines_Component ;
56 bool Engines_Component_i::_isMultiStudy = true;
57 bool Engines_Component_i::_isMultiInstance = false;
59 /*! \class Engines_Component_i
60 * \brief C++ implementation of Engines::Component interface
64 //=============================================================================
66 * Default constructor, not for use
68 //=============================================================================
70 Engines_Component_i::Engines_Component_i():_myConnexionToRegistry(0), _notifSupplier(0), _id(0)
73 MESSAGE("Default Constructor, not for normal use...");
76 //=============================================================================
77 /*! \brief Standard Constructor for generic Component, used in derived class
79 * Connection to Registry and Notification
80 * \param orb Object Request broker given by Container
81 * \param poa Portable Object Adapter from Container (normally root_poa)
82 * \param contId container CORBA id inside the server
83 * \param instanceName unique instance name for this object (see Container_i)
84 * \param interfaceName component class name
85 * \param notif use of notification
86 * \param regist (true or false) use of registry (default true)
88 //=============================================================================
90 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
91 PortableServer::POA_ptr poa,
92 PortableServer::ObjectId * contId,
93 const char *instanceName,
94 const char *interfaceName,
97 _instanceName(instanceName),
98 _interfaceName(interfaceName),
99 _myConnexionToRegistry(0),
109 _CanceledThread(false)
111 MESSAGE("Component constructor with instanceName "<< _instanceName);
112 _orb = CORBA::ORB::_duplicate(orb);
113 _poa = PortableServer::POA::_duplicate(poa);
115 CORBA::Object_var o = _poa->id_to_reference(*contId); // container ior...
116 _container=Engines::Container::_narrow(o);
120 const CORBA::String_var ior = _orb->object_to_string(o);
121 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession",
122 _instanceName.c_str());
125 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
128 //=============================================================================
129 /*! \brief Standard Constructor for standalone Component, used in derived class
131 * Connection to Registry and Notification
132 * \param orb Object Request broker given by Container
133 * \param poa Portable Object Adapter from Container (normally root_poa)
134 * \param container container CORBA reference
135 * \param instanceName unique instance name for this object (see Container_i)
136 * \param interfaceName component class name
137 * \param notif use of notification
138 * \param regist (true or false) use of registry (default true)
140 //=============================================================================
142 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
143 PortableServer::POA_ptr poa,
144 Engines::Container_ptr container,
145 const char *instanceName,
146 const char *interfaceName,
149 _instanceName(instanceName),
150 _interfaceName(interfaceName),
151 _myConnexionToRegistry(0),
161 _CanceledThread(false)
163 MESSAGE("Component constructor with instanceName "<< _instanceName);
164 _orb = CORBA::ORB::_duplicate(orb);
165 _poa = PortableServer::POA::_duplicate(poa);
166 _container=Engines::Container::_duplicate(container);
167 const CORBA::String_var ior = _orb->object_to_string(_container);
169 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession", _instanceName.c_str());
170 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
174 //=============================================================================
176 * Destructor: call Container for decrement of instances count.
177 * When instances count falls to 0, the container tries to remove the
178 * component library (dlclose)
180 //=============================================================================
182 Engines_Component_i::~Engines_Component_i()
184 MESSAGE("Component destructor");
185 Engines_Container_i::decInstanceCnt(_interfaceName);
186 if(_myConnexionToRegistry)delete _myConnexionToRegistry;
187 _myConnexionToRegistry = 0 ;
188 if(_notifSupplier)delete _notifSupplier;
194 //=============================================================================
196 * CORBA method: return name of the instance, unique in this Container
198 //=============================================================================
200 char* Engines_Component_i::instanceName()
202 return CORBA::string_dup(_instanceName.c_str()) ;
205 //=============================================================================
207 * CORBA method: return name of the component class
209 //=============================================================================
211 char* Engines_Component_i::interfaceName()
213 return CORBA::string_dup(_interfaceName.c_str()) ;
216 //=============================================================================
218 * CORBA method: Get study Id
219 * \return -1: not initialised (Internal Error)
220 * 0: multistudy component instance
221 * >0: study id associated to this instance
223 //=============================================================================
225 CORBA::Long Engines_Component_i::getStudyId()
230 //=============================================================================
232 * CORBA method: Test if instance is alive and responds
234 //=============================================================================
236 void Engines_Component_i::ping()
239 MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid "
242 MESSAGE("Engines_Component_i::ping() pid "<< _getpid()<< " threadid "
243 << pthread_self().p );
247 //=============================================================================
249 * CORBA method: Deactivate this instance. CORBA object is deactivated (do not
250 * respond any more to CORBA calls), the connection to Regsitry is removed
251 * (Registry informed of deactivation), internal server reference counter on
252 * the derived servant class is decremented, to allow destruction of the class
253 * (delete) by POA, when there are no more references.
254 * -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
256 //=============================================================================
258 void Engines_Component_i::destroy()
260 MESSAGE("Engines_Component_i::destroy()");
261 //SCRUTE(_refcount_value());
262 _poa->deactivate_object(*_id);
263 //SCRUTE(_refcount_value());
265 //SCRUTE(_refcount_value());
266 MESSAGE("Engines_Component_i::destroyed") ;
269 //=============================================================================
271 * CORBA method: return CORBA reference of the Container
274 //=============================================================================
276 Engines::Container_ptr Engines_Component_i::GetContainerRef()
278 return Engines::Container::_duplicate(_container);
281 //=============================================================================
284 * Gives a sequence of (key=string,value=any) to the component.
285 * Base class component stores the sequence in a map.
286 * The map is cleared before.
287 * This map is for use by derived classes.
288 * \param dico sequence of (key=string,value=any)
290 //=============================================================================
292 void Engines_Component_i::setProperties(const Engines::FieldsDict& dico)
295 for (CORBA::ULong i=0; i<dico.length(); i++)
297 std::string cle(dico[i].key);
298 _fieldsDict[cle] = dico[i].value;
302 //=============================================================================
305 * returns a previously stored map (key=string,value=any) as a sequence.
306 * (see setProperties)
308 //=============================================================================
310 Engines::FieldsDict* Engines_Component_i::getProperties()
312 Engines::FieldsDict_var copie = new Engines::FieldsDict;
313 copie->length(_fieldsDict.size());
314 map<std::string,CORBA::Any>::iterator it;
316 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++)
318 std::string cle((*it).first);
319 copie[i].key = CORBA::string_dup(cle.c_str());
320 copie[i].value = _fieldsDict[cle];
322 return copie._retn();
325 //=============================================================================
327 * CORBA method: used by Supervision to give names to this instance
329 //=============================================================================
331 void Engines_Component_i::Names( const char * graphName ,
332 const char * nodeName )
334 _graphName = graphName ;
335 _nodeName = nodeName ;
336 // MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
337 // << _nodeName << "' )");
340 //=============================================================================
342 * CORBA method: used in Supervision
344 //=============================================================================
346 bool Engines_Component_i::Kill_impl()
348 // MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
349 // << " pid " << getpid() << " instanceName "
350 // << _instanceName.c_str() << " interface " << _interfaceName.c_str()
351 // << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
352 // << dec << " _ThreadId " << _ThreadId << " this " << hex << this
355 bool RetVal = false ;
357 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
359 RetVal = Killer( _ThreadId , SIGUSR2 ) ;
360 _ThreadId = (pthread_t ) -1 ;
364 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
366 RetVal = Killer( *_ThreadId , 0 ) ;
367 _ThreadId = (pthread_t* ) 0 ;
374 //=============================================================================
376 * CORBA method: used in Supervision
378 //=============================================================================
380 bool Engines_Component_i::Stop_impl()
383 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self()
384 << " pid " << getpid() << " instanceName "
385 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
386 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
387 << dec << " _ThreadId " << _ThreadId );
389 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self().p
390 << " pid " << _getpid() << " instanceName "
391 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
392 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
393 << dec << " _ThreadId " << _ThreadId );
397 bool RetVal = false ;
399 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
401 RetVal = Killer( _ThreadId , 0 ) ;
402 _ThreadId = (pthread_t ) -1 ;
405 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
407 RetVal = Killer( *_ThreadId , 0 ) ;
408 _ThreadId = (pthread_t* ) 0 ;
414 //=============================================================================
416 * CORBA method: used in Supervision
418 //=============================================================================
420 bool Engines_Component_i::Suspend_impl()
423 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self()
424 << " pid " << getpid() << " instanceName "
425 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
426 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
427 << dec << " _ThreadId " << _ThreadId );
429 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self().p
430 << " pid " << _getpid() << " instanceName "
431 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
432 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
433 << dec << " _ThreadId " << _ThreadId );
436 bool RetVal = false ;
438 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
440 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
450 RetVal = Killer( _ThreadId ,SIGINT ) ;
452 RetVal = Killer( *_ThreadId ,SIGINT ) ;
454 //if ( RetVal ) _Sleeping = true;
461 //=============================================================================
463 * CORBA method: used in Supervision
465 //=============================================================================
467 bool Engines_Component_i::Resume_impl()
470 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self()
471 << " pid " << getpid() << " instanceName "
472 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
473 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
474 << dec << " _ThreadId " << _ThreadId );
476 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self().p
477 << " pid " << _getpid() << " instanceName "
478 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
479 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
480 << dec << " _ThreadId " << _ThreadId );
482 bool RetVal = false ;
484 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
486 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
502 //=============================================================================
506 //=============================================================================
508 CORBA::Long Engines_Component_i::CpuUsed_impl()
511 if ( _ThreadId || _Executed )
516 if ( pthread_self() != _ThreadId )
518 if ( pthread_self().p != _ThreadId->p )
526 // Get Cpu in the appropriate thread with that object !...
527 theEngines_Component = this ;
529 Killer( _ThreadId ,SIGUSR1 ) ;
531 Killer( *_ThreadId ,SIGUSR11 ) ;
534 cpu = _ThreadCpuUsed ;
538 _ThreadCpuUsed = CpuUsed() ;
539 cpu = _ThreadCpuUsed ;
540 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
541 // << _serviceName << " " << cpu << endl ;
546 cpu = _ThreadCpuUsed ;
547 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
548 // << _serviceName << " " << cpu<< endl ;
553 // cout<< pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId "
554 // <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<<endl;
560 //=============================================================================
562 * C++ method: return Container Servant
564 //=============================================================================
566 Engines_Container_i *Engines_Component_i::GetContainerPtr()
568 PortableServer::ObjectId_var contId=_poa->reference_to_id(_container);
569 return dynamic_cast<Engines_Container_i*>(_poa->id_to_servant(contId)) ;
572 //=============================================================================
574 * C++ method: set study Id
575 * \param studyId 0 if instance is not associated to a study,
576 * >0 otherwise (== study id)
577 * \return true if the set of study Id is OK
578 * must be set once by Container, at instance creation,
579 * and cannot be changed after.
581 //=============================================================================
583 CORBA::Boolean Engines_Component_i::setStudyId(CORBA::Long studyId)
585 ASSERT( studyId >= 0);
586 CORBA::Boolean ret = false;
587 if (_studyId < 0) // --- not yet initialized
593 if ( _studyId == studyId) ret = true;
597 //=============================================================================
599 * C++ method: return CORBA instance id, the id is set in derived class
600 * constructor, when instance is activated.
602 //=============================================================================
604 PortableServer::ObjectId * Engines_Component_i::getId()
606 // MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
610 //=============================================================================
612 * C++ method: used by derived classes for supervision
614 //=============================================================================
616 void Engines_Component_i::beginService(const char *serviceName)
618 std::cerr << "beginService for " << serviceName << " Component instance : " << _instanceName << std::endl;
621 _ThreadId = pthread_self() ;
623 _ThreadId = new pthread_t;
624 _ThreadId->p = pthread_self().p ;
625 _ThreadId->x = pthread_self().x ;
628 _StartUsed = CpuUsed_impl() ;
631 _serviceName = serviceName ;
632 theEngines_Component = this ;
633 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) )
635 perror("pthread_setcanceltype ") ;
638 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) )
640 perror("pthread_setcancelstate ") ;
644 // --- all strings given with setProperties are set in environment
645 map<std::string,CORBA::Any>::iterator it;
646 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
648 std::string cle((*it).first);
649 if ((*it).second.type()->kind() == CORBA::tk_string)
652 (*it).second >>= value;
656 putenv((char *)s.c_str());
657 MESSAGE("--- setenv: "<<cle<<" = "<< value);
662 //=============================================================================
664 * C++ method: used by derived classes for supervision
666 //=============================================================================
668 void Engines_Component_i::endService(const char *serviceName)
670 if ( !_CanceledThread )
671 _ThreadCpuUsed = CpuUsed_impl() ;
673 float cpus=_ThreadCpuUsed/1000.;
674 std::cerr << "endService for " << serviceName << " Component instance : " << _instanceName ;
675 std::cerr << " Cpu Used: " << cpus << " (s) " << std::endl;
676 MESSAGE("Send EndService notification for " << serviceName
677 << endl << " Component instance : " << _instanceName << " StartUsed "
678 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << endl <<endl);
682 //=============================================================================
684 * C++ method: -- CHECK IF USED --
686 //=============================================================================
688 char* Engines_Component_i::graphName()
690 return CORBA::string_dup( _graphName.c_str() ) ;
693 //=============================================================================
695 * C++ method: -- CHECK IF USED --
697 //=============================================================================
699 char* Engines_Component_i::nodeName()
701 return CORBA::string_dup( _nodeName.c_str() ) ;
704 //=============================================================================
706 * C++ method: used in Supervision (see kill_impl)
708 //=============================================================================
710 bool Engines_Component_i::Killer( pthread_t ThreadId , int signum )
720 if ( pthread_cancel( ThreadId ) )
722 perror("Killer pthread_cancel error") ;
728 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_canceled") ;
730 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_canceled") ;
736 if ( pthread_kill( ThreadId , signum ) == -1 )
738 perror("Killer pthread_kill error") ;
744 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_killed(" << signum << ")") ;
746 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_killed(" << signum << ")") ;
754 //=============================================================================
758 //=============================================================================
762 if ( theEngines_Component )
763 theEngines_Component->SetCurCpu() ;
766 //=============================================================================
770 //=============================================================================
772 void Engines_Component_i::SetCurCpu()
774 _ThreadCpuUsed = CpuUsed() ;
775 // MESSAGE(pthread_self() <<
776 // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ;
779 //=============================================================================
783 //=============================================================================
785 long Engines_Component_i::CpuUsed()
789 struct rusage usage ;
790 if ( _ThreadId || _Executed )
792 if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
794 perror("Engines_Component_i::CpuUsed") ;
797 //cpu time is calculated in millisecond (user+system times)
798 cpu = usage.ru_utime.tv_sec*1000 +usage.ru_utime.tv_usec/1000;
799 cpu = cpu+ usage.ru_stime.tv_sec*1000 +usage.ru_stime.tv_usec/1000;
801 // cout << pthread_self() << " Engines_Component_i::CpuUsed " << " "
802 // << _serviceName << usage.ru_utime.tv_sec << " - " << _StartUsed
803 // << " = " << cpu << endl ;
807 // cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId "
808 // << _ThreadId << " " << _serviceName<< " _StartUsed "
809 // << _StartUsed << endl ;
812 // NOT implementet yet
819 void CallCancelThread()
821 if ( theEngines_Component )
822 theEngines_Component->CancelThread() ;
825 //=============================================================================
829 //=============================================================================
831 void Engines_Component_i::CancelThread()
833 _CanceledThread = true;
836 //=============================================================================
838 * C++ method: Send message to event channel
840 //=============================================================================
842 void Engines_Component_i::sendMessage(const char *event_type,
845 _notifSupplier->Send(_graphName.c_str(), _nodeName.c_str(), event_type, message);
848 //=============================================================================
850 * C++ method: return standard library name built on component name
852 //=============================================================================
854 string Engines_Component_i::GetDynLibraryName(const char *componentName)
862 //=============================================================================
864 * C++ method: DumpPython default implementation
866 //=============================================================================
868 Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Object_ptr theStudy,
869 CORBA::Boolean isPublished,
870 CORBA::Boolean& isValidScript)
872 const char* aScript = "def RebuildData(theStudy): pass";
873 char* aBuffer = new char[strlen(aScript)+1];
874 strcpy(aBuffer, aScript);
875 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
876 int aBufferSize = strlen(aBuffer)+1;
877 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
878 isValidScript = true;
879 return aStreamFile._retn();
882 Engines::Salome_file_ptr
883 Engines_Component_i::getInputFileToService(const char* service_name,
884 const char* Salome_file_name)
886 // Try to find the service, if it doesn't exist, we throw an exception.
887 _Service_file_map_it = _Input_Service_file_map.find(service_name);
888 if (_Service_file_map_it == _Input_Service_file_map.end()) {
889 SALOME::ExceptionStruct es;
890 es.type = SALOME::INTERNAL_ERROR;
891 es.text = "service doesn't have salome files";
892 throw SALOME::SALOME_Exception(es);
894 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
896 // Try to find the Salome_file ...
897 _Salome_file_map_it = _map->find(Salome_file_name);
898 if (_Salome_file_map_it == _map->end()) {
899 SALOME::ExceptionStruct es;
900 es.type = SALOME::INTERNAL_ERROR;
901 es.text = "service doesn't have this Salome_file";
902 throw SALOME::SALOME_Exception(es);
904 Salome_file_i * Sfile = (*_map)[Salome_file_name];
906 return Sfile->_this();
909 Engines::Salome_file_ptr
910 Engines_Component_i::setInputFileToService(const char* service_name,
911 const char* Salome_file_name)
913 // Try to find the service, if it doesn't exist, we add it.
914 _Service_file_map_it = _Input_Service_file_map.find(service_name);
915 if (_Service_file_map_it == _Input_Service_file_map.end()) {
916 _t_Salome_file_map * _map = new _t_Salome_file_map();
917 _Input_Service_file_map[service_name] = _map;
919 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
921 // Try to find the Salome_file ...
922 _Salome_file_map_it = _map->find(Salome_file_name);
923 if (_Salome_file_map_it == _map->end()) {
924 Salome_file_i * Sfile = new Salome_file_i();
925 Engines::Container_ptr container = this->GetContainerRef();
926 Sfile->setContainer(Engines::Container::_duplicate(container));
927 (*_map)[Salome_file_name] = Sfile;
930 Salome_file_i * Sfile = (*_map)[Salome_file_name];
931 return Sfile->_this();
935 Engines_Component_i::checkInputFilesToService(const char* service_name)
937 // Try to find the service, if it doesn't exist, nothing to do.
938 _Service_file_map_it = _Input_Service_file_map.find(service_name);
939 if (_Service_file_map_it != _Input_Service_file_map.end()) {
940 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
941 _t_Salome_file_map::iterator begin = _map->begin();
942 _t_Salome_file_map::iterator end = _map->end();
944 for(;begin!=end;begin++) {
945 Salome_file_i * file = begin->second;
946 std::string file_port_name = begin->first;
947 configureSalome_file(service_name, file_port_name, file);
953 Engines::Salome_file_ptr
954 Engines_Component_i::getOutputFileToService(const char* service_name,
955 const char* Salome_file_name)
957 // Try to find the service, if it doesn't exist, we throw an exception.
958 _Service_file_map_it = _Output_Service_file_map.find(service_name);
959 if (_Service_file_map_it == _Output_Service_file_map.end()) {
960 SALOME::ExceptionStruct es;
961 es.type = SALOME::INTERNAL_ERROR;
962 es.text = "service doesn't have salome files";
963 throw SALOME::SALOME_Exception(es);
965 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
967 // Try to find the Salome_file ...
968 _Salome_file_map_it = _map->find(Salome_file_name);
969 if (_Salome_file_map_it == _map->end()) {
970 SALOME::ExceptionStruct es;
971 es.type = SALOME::INTERNAL_ERROR;
972 es.text = "service doesn't have this Salome_file";
973 throw SALOME::SALOME_Exception(es);
975 Salome_file_i * Sfile = (*_map)[Salome_file_name];
977 return Sfile->_this();
980 Engines::Salome_file_ptr
981 Engines_Component_i::setOutputFileToService(const char* service_name,
982 const char* Salome_file_name)
984 // Try to find the service, if it doesn't exist, we add it.
985 _Service_file_map_it = _Output_Service_file_map.find(service_name);
986 if (_Service_file_map_it == _Output_Service_file_map.end()) {
987 _t_Salome_file_map * _map = new _t_Salome_file_map();
988 _Output_Service_file_map[service_name] = _map;
990 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
992 // Try to find the Salome_file ...
993 _Salome_file_map_it = _map->find(Salome_file_name);
994 if (_Salome_file_map_it == _map->end()) {
995 Salome_file_i * Sfile = new Salome_file_i();
996 Engines::Container_ptr container = this->GetContainerRef();
997 Sfile->setContainer(Engines::Container::_duplicate(container));
998 (*_map)[Salome_file_name] = Sfile;
1001 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1002 return Sfile->_this();
1006 Engines_Component_i::checkOutputFilesToService(const char* service_name)
1008 // Try to find the service, if it doesn't exist, nothing to do.
1009 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1010 if (_Service_file_map_it != _Output_Service_file_map.end()) {
1011 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1012 _t_Salome_file_map::iterator begin = _map->begin();
1013 _t_Salome_file_map::iterator end = _map->end();
1015 for(;begin!=end;begin++) {
1016 Salome_file_i * file = begin->second;
1017 std::string file_port_name = begin->first;
1018 configureSalome_file(service_name, file_port_name, file);
1025 //=============================================================================
1027 * C++ method: used to configure the Salome_file into the runtime.
1028 * \param service_name name of the service that use this Salome_file
1029 * \param file_port_name name of the Salome_file
1030 * \param file Salome_file C++ object
1032 //=============================================================================
1034 Engines_Component_i::configureSalome_file(std::string service_name,
1035 std::string file_port_name,
1036 Salome_file_i * file)
1038 // By default this method does nothing
1041 //=============================================================================
1043 * C++ method: return the name of the container associated with this component
1044 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1045 * \return the container name (reformatted)
1047 //=============================================================================
1048 std::string Engines_Component_i::getContainerName()
1050 CORBA::String_var containerName=_container->name();
1051 std::string name(containerName);
1053 string::size_type slash =name.find_first_of('/');
1054 if(slash != std::string::npos)