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);
121 const CORBA::String_var ior = _orb->object_to_string(o);
122 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession",
123 _instanceName.c_str());
127 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
130 //=============================================================================
131 /*! \brief Standard Constructor for standalone Component, used in derived class
133 * Connection to Registry and Notification
134 * \param orb Object Request broker given by Container
135 * \param poa Portable Object Adapter from Container (normally root_poa)
136 * \param container container CORBA reference
137 * \param instanceName unique instance name for this object (see Container_i)
138 * \param interfaceName component class name
139 * \param notif use of notification
140 * \param regist (true or false) use of registry (default true)
142 //=============================================================================
144 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
145 PortableServer::POA_ptr poa,
146 Engines::Container_ptr container,
147 const char *instanceName,
148 const char *interfaceName,
151 _instanceName(instanceName),
152 _interfaceName(interfaceName),
153 _myConnexionToRegistry(0),
163 _CanceledThread(false)
165 MESSAGE("Component constructor with instanceName "<< _instanceName);
166 _orb = CORBA::ORB::_duplicate(orb);
167 _poa = PortableServer::POA::_duplicate(poa);
168 _container=Engines::Container::_duplicate(container);
170 const CORBA::String_var ior = _orb->object_to_string(_container);
172 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession", _instanceName.c_str());
174 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
179 //=============================================================================
181 * Destructor: call Container for decrement of instances count.
182 * When instances count falls to 0, the container tries to remove the
183 * component library (dlclose)
185 //=============================================================================
187 Engines_Component_i::~Engines_Component_i()
189 MESSAGE("Component destructor");
190 Engines_Container_i::decInstanceCnt(_interfaceName);
191 if(_myConnexionToRegistry)delete _myConnexionToRegistry;
192 _myConnexionToRegistry = 0 ;
199 SCRUTE(_notifSupplier->_refcount_value());
200 PortableServer::POA_var poa=_notifSupplier->_default_POA();
201 PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_notifSupplier);
202 poa->deactivate_object(anObjectId.in());
203 SCRUTE(_notifSupplier->_refcount_value());
204 _notifSupplier->_remove_ref();
208 //=============================================================================
210 * CORBA method: return name of the instance, unique in this Container
212 //=============================================================================
214 char* Engines_Component_i::instanceName()
216 return CORBA::string_dup(_instanceName.c_str()) ;
219 //=============================================================================
221 * CORBA method: return name of the component class
223 //=============================================================================
225 char* Engines_Component_i::interfaceName()
227 return CORBA::string_dup(_interfaceName.c_str()) ;
230 //=============================================================================
232 * CORBA method: Get study Id
233 * \return -1: not initialised (Internal Error)
234 * 0: multistudy component instance
235 * >0: study id associated to this instance
237 //=============================================================================
239 CORBA::Long Engines_Component_i::getStudyId()
244 //=============================================================================
246 * CORBA method: Test if instance is alive and responds
248 //=============================================================================
250 void Engines_Component_i::ping()
253 MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid "
256 MESSAGE("Engines_Component_i::ping() pid "<< _getpid()<< " threadid "
257 << pthread_self().p );
261 //=============================================================================
263 * CORBA method: Deactivate this instance. CORBA object is deactivated (do not
264 * respond any more to CORBA calls), the connection to Regsitry is removed
265 * (Registry informed of deactivation), internal server reference counter on
266 * the derived servant class is decremented, to allow destruction of the class
267 * (delete) by POA, when there are no more references.
268 * -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
270 //=============================================================================
272 void Engines_Component_i::destroy()
274 MESSAGE("Engines_Component_i::destroy()");
275 //SCRUTE(_refcount_value());
276 _poa->deactivate_object(*_id);
277 //SCRUTE(_refcount_value());
279 //SCRUTE(_refcount_value());
280 MESSAGE("Engines_Component_i::destroyed") ;
283 //=============================================================================
285 * CORBA method: return CORBA reference of the Container
288 //=============================================================================
290 Engines::Container_ptr Engines_Component_i::GetContainerRef()
292 return Engines::Container::_duplicate(_container);
295 //=============================================================================
298 * Gives a sequence of (key=string,value=any) to the component.
299 * Base class component stores the sequence in a map.
300 * The map is cleared before.
301 * This map is for use by derived classes.
302 * \param dico sequence of (key=string,value=any)
304 //=============================================================================
306 void Engines_Component_i::setProperties(const Engines::FieldsDict& dico)
309 for (CORBA::ULong i=0; i<dico.length(); i++)
311 std::string cle(dico[i].key);
312 _fieldsDict[cle] = dico[i].value;
316 //=============================================================================
319 * returns a previously stored map (key=string,value=any) as a sequence.
320 * (see setProperties)
322 //=============================================================================
324 Engines::FieldsDict* Engines_Component_i::getProperties()
326 Engines::FieldsDict_var copie = new Engines::FieldsDict;
327 copie->length(_fieldsDict.size());
328 map<std::string,CORBA::Any>::iterator it;
330 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++)
332 std::string cle((*it).first);
333 copie[i].key = CORBA::string_dup(cle.c_str());
334 copie[i].value = _fieldsDict[cle];
336 return copie._retn();
339 //=============================================================================
341 * CORBA method: used by Supervision to give names to this instance
343 //=============================================================================
345 void Engines_Component_i::Names( const char * graphName ,
346 const char * nodeName )
348 _graphName = graphName ;
349 _nodeName = nodeName ;
350 // MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
351 // << _nodeName << "' )");
354 //=============================================================================
356 * CORBA method: used in Supervision
358 //=============================================================================
360 bool Engines_Component_i::Kill_impl()
362 // MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
363 // << " pid " << getpid() << " instanceName "
364 // << _instanceName.c_str() << " interface " << _interfaceName.c_str()
365 // << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
366 // << dec << " _ThreadId " << _ThreadId << " this " << hex << this
369 bool RetVal = false ;
371 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
373 RetVal = Killer( _ThreadId , SIGUSR2 ) ;
374 _ThreadId = (pthread_t ) -1 ;
378 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
380 RetVal = Killer( *_ThreadId , 0 ) ;
381 _ThreadId = (pthread_t* ) 0 ;
388 //=============================================================================
390 * CORBA method: used in Supervision
392 //=============================================================================
394 bool Engines_Component_i::Stop_impl()
397 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self()
398 << " pid " << getpid() << " instanceName "
399 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
400 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
401 << dec << " _ThreadId " << _ThreadId );
403 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self().p
404 << " pid " << _getpid() << " instanceName "
405 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
406 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
407 << dec << " _ThreadId " << _ThreadId );
411 bool RetVal = false ;
413 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
415 RetVal = Killer( _ThreadId , 0 ) ;
416 _ThreadId = (pthread_t ) -1 ;
419 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
421 RetVal = Killer( *_ThreadId , 0 ) ;
422 _ThreadId = (pthread_t* ) 0 ;
428 //=============================================================================
430 * CORBA method: used in Supervision
432 //=============================================================================
434 bool Engines_Component_i::Suspend_impl()
437 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self()
438 << " pid " << getpid() << " instanceName "
439 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
440 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
441 << dec << " _ThreadId " << _ThreadId );
443 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self().p
444 << " pid " << _getpid() << " instanceName "
445 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
446 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
447 << dec << " _ThreadId " << _ThreadId );
450 bool RetVal = false ;
452 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
454 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
464 RetVal = Killer( _ThreadId ,SIGINT ) ;
466 RetVal = Killer( *_ThreadId ,SIGINT ) ;
468 //if ( RetVal ) _Sleeping = true;
475 //=============================================================================
477 * CORBA method: used in Supervision
479 //=============================================================================
481 bool Engines_Component_i::Resume_impl()
484 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self()
485 << " pid " << getpid() << " instanceName "
486 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
487 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
488 << dec << " _ThreadId " << _ThreadId );
490 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self().p
491 << " pid " << _getpid() << " instanceName "
492 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
493 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
494 << dec << " _ThreadId " << _ThreadId );
496 bool RetVal = false ;
498 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
500 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
516 //=============================================================================
520 //=============================================================================
522 CORBA::Long Engines_Component_i::CpuUsed_impl()
525 if ( _ThreadId || _Executed )
530 if ( pthread_self() != _ThreadId )
532 if ( pthread_self().p != _ThreadId->p )
540 // Get Cpu in the appropriate thread with that object !...
541 theEngines_Component = this ;
543 Killer( _ThreadId ,SIGUSR1 ) ;
545 Killer( *_ThreadId ,SIGUSR11 ) ;
548 cpu = _ThreadCpuUsed ;
552 _ThreadCpuUsed = CpuUsed() ;
553 cpu = _ThreadCpuUsed ;
554 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
555 // << _serviceName << " " << cpu << endl ;
560 cpu = _ThreadCpuUsed ;
561 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
562 // << _serviceName << " " << cpu<< endl ;
567 // cout<< pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId "
568 // <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<<endl;
574 //=============================================================================
576 * C++ method: return Container Servant
578 //=============================================================================
580 Engines_Container_i *Engines_Component_i::GetContainerPtr()
582 PortableServer::ObjectId_var contId=_poa->reference_to_id(_container);
583 return dynamic_cast<Engines_Container_i*>(_poa->id_to_servant(contId)) ;
586 //=============================================================================
588 * C++ method: set study Id
589 * \param studyId 0 if instance is not associated to a study,
590 * >0 otherwise (== study id)
591 * \return true if the set of study Id is OK
592 * must be set once by Container, at instance creation,
593 * and cannot be changed after.
595 //=============================================================================
597 CORBA::Boolean Engines_Component_i::setStudyId(CORBA::Long studyId)
599 ASSERT( studyId >= 0);
600 CORBA::Boolean ret = false;
601 if (_studyId < 0) // --- not yet initialized
607 if ( _studyId == studyId) ret = true;
611 //=============================================================================
613 * C++ method: return CORBA instance id, the id is set in derived class
614 * constructor, when instance is activated.
616 //=============================================================================
618 PortableServer::ObjectId * Engines_Component_i::getId()
620 // MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
624 //=============================================================================
626 * C++ method: used by derived classes for supervision
628 //=============================================================================
630 void Engines_Component_i::beginService(const char *serviceName)
632 std::cerr << "beginService for " << serviceName << " Component instance : " << _instanceName << std::endl;
635 _ThreadId = pthread_self() ;
637 _ThreadId = new pthread_t;
638 _ThreadId->p = pthread_self().p ;
639 _ThreadId->x = pthread_self().x ;
642 _StartUsed = CpuUsed_impl() ;
645 _serviceName = serviceName ;
646 theEngines_Component = this ;
647 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) )
649 perror("pthread_setcanceltype ") ;
652 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) )
654 perror("pthread_setcancelstate ") ;
658 // --- all strings given with setProperties are set in environment
659 map<std::string,CORBA::Any>::iterator it;
660 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
662 std::string cle((*it).first);
663 if ((*it).second.type()->kind() == CORBA::tk_string)
666 (*it).second >>= value;
670 putenv((char *)s.c_str());
671 MESSAGE("--- setenv: "<<cle<<" = "<< value);
676 //=============================================================================
678 * C++ method: used by derived classes for supervision
680 //=============================================================================
682 void Engines_Component_i::endService(const char *serviceName)
684 if ( !_CanceledThread )
685 _ThreadCpuUsed = CpuUsed_impl() ;
687 float cpus=_ThreadCpuUsed/1000.;
688 std::cerr << "endService for " << serviceName << " Component instance : " << _instanceName ;
689 std::cerr << " Cpu Used: " << cpus << " (s) " << std::endl;
690 MESSAGE("Send EndService notification for " << serviceName
691 << endl << " Component instance : " << _instanceName << " StartUsed "
692 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << endl <<endl);
696 //=============================================================================
698 * C++ method: -- CHECK IF USED --
700 //=============================================================================
702 char* Engines_Component_i::graphName()
704 return CORBA::string_dup( _graphName.c_str() ) ;
707 //=============================================================================
709 * C++ method: -- CHECK IF USED --
711 //=============================================================================
713 char* Engines_Component_i::nodeName()
715 return CORBA::string_dup( _nodeName.c_str() ) ;
718 //=============================================================================
720 * C++ method: used in Supervision (see kill_impl)
722 //=============================================================================
724 bool Engines_Component_i::Killer( pthread_t ThreadId , int signum )
734 if ( pthread_cancel( ThreadId ) )
736 perror("Killer pthread_cancel error") ;
742 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_canceled") ;
744 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_canceled") ;
750 if ( pthread_kill( ThreadId , signum ) == -1 )
752 perror("Killer pthread_kill error") ;
758 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_killed(" << signum << ")") ;
760 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_killed(" << signum << ")") ;
769 void CallCancelThread();
771 //=============================================================================
775 //=============================================================================
779 if ( theEngines_Component )
780 theEngines_Component->SetCurCpu() ;
783 //=============================================================================
787 //=============================================================================
789 void Engines_Component_i::SetCurCpu()
791 _ThreadCpuUsed = CpuUsed() ;
792 // MESSAGE(pthread_self() <<
793 // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ;
796 //=============================================================================
800 //=============================================================================
802 long Engines_Component_i::CpuUsed()
806 struct rusage usage ;
807 if ( _ThreadId || _Executed )
809 if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
811 perror("Engines_Component_i::CpuUsed") ;
814 //cpu time is calculated in millisecond (user+system times)
815 cpu = usage.ru_utime.tv_sec*1000 +usage.ru_utime.tv_usec/1000;
816 cpu = cpu+ usage.ru_stime.tv_sec*1000 +usage.ru_stime.tv_usec/1000;
818 // cout << pthread_self() << " Engines_Component_i::CpuUsed " << " "
819 // << _serviceName << usage.ru_utime.tv_sec << " - " << _StartUsed
820 // << " = " << cpu << endl ;
824 // cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId "
825 // << _ThreadId << " " << _serviceName<< " _StartUsed "
826 // << _StartUsed << endl ;
829 // NOT implementet yet
836 void CallCancelThread()
838 if ( theEngines_Component )
839 theEngines_Component->CancelThread() ;
842 //=============================================================================
846 //=============================================================================
848 void Engines_Component_i::CancelThread()
850 _CanceledThread = true;
853 //=============================================================================
855 * C++ method: Send message to event channel
857 //=============================================================================
859 void Engines_Component_i::sendMessage(const char *event_type,
862 _notifSupplier->Send(_graphName.c_str(), _nodeName.c_str(), event_type, message);
865 //=============================================================================
867 * C++ method: return standard library name built on component name
869 //=============================================================================
871 string Engines_Component_i::GetDynLibraryName(const char *componentName)
879 //=============================================================================
881 * C++ method: DumpPython default implementation
883 //=============================================================================
885 Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Object_ptr theStudy,
886 CORBA::Boolean isPublished,
887 CORBA::Boolean& isValidScript)
889 const char* aScript = "def RebuildData(theStudy): pass";
890 char* aBuffer = new char[strlen(aScript)+1];
891 strcpy(aBuffer, aScript);
892 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
893 int aBufferSize = strlen(aBuffer)+1;
894 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
895 isValidScript = true;
896 return aStreamFile._retn();
899 Engines::Salome_file_ptr
900 Engines_Component_i::getInputFileToService(const char* service_name,
901 const char* Salome_file_name)
903 // Try to find the service, if it doesn't exist, we throw an exception.
904 _Service_file_map_it = _Input_Service_file_map.find(service_name);
905 if (_Service_file_map_it == _Input_Service_file_map.end()) {
906 SALOME::ExceptionStruct es;
907 es.type = SALOME::INTERNAL_ERROR;
908 es.text = "service doesn't have salome files";
909 throw SALOME::SALOME_Exception(es);
911 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
913 // Try to find the Salome_file ...
914 _Salome_file_map_it = _map->find(Salome_file_name);
915 if (_Salome_file_map_it == _map->end()) {
916 SALOME::ExceptionStruct es;
917 es.type = SALOME::INTERNAL_ERROR;
918 es.text = "service doesn't have this Salome_file";
919 throw SALOME::SALOME_Exception(es);
921 Salome_file_i * Sfile = (*_map)[Salome_file_name];
923 return Sfile->_this();
926 Engines::Salome_file_ptr
927 Engines_Component_i::setInputFileToService(const char* service_name,
928 const char* Salome_file_name)
930 // Try to find the service, if it doesn't exist, we add it.
931 _Service_file_map_it = _Input_Service_file_map.find(service_name);
932 if (_Service_file_map_it == _Input_Service_file_map.end()) {
933 _t_Salome_file_map * _map = new _t_Salome_file_map();
934 _Input_Service_file_map[service_name] = _map;
936 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
938 // Try to find the Salome_file ...
939 _Salome_file_map_it = _map->find(Salome_file_name);
940 if (_Salome_file_map_it == _map->end()) {
941 Salome_file_i * Sfile = new Salome_file_i();
942 Engines::Container_ptr container = this->GetContainerRef();
943 Sfile->setContainer(Engines::Container::_duplicate(container));
944 (*_map)[Salome_file_name] = Sfile;
947 Salome_file_i * Sfile = (*_map)[Salome_file_name];
948 return Sfile->_this();
952 Engines_Component_i::checkInputFilesToService(const char* service_name)
954 // Try to find the service, if it doesn't exist, nothing to do.
955 _Service_file_map_it = _Input_Service_file_map.find(service_name);
956 if (_Service_file_map_it != _Input_Service_file_map.end()) {
957 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
958 _t_Salome_file_map::iterator begin = _map->begin();
959 _t_Salome_file_map::iterator end = _map->end();
961 for(;begin!=end;begin++) {
962 Salome_file_i * file = begin->second;
963 std::string file_port_name = begin->first;
964 configureSalome_file(service_name, file_port_name, file);
970 Engines::Salome_file_ptr
971 Engines_Component_i::getOutputFileToService(const char* service_name,
972 const char* Salome_file_name)
974 // Try to find the service, if it doesn't exist, we throw an exception.
975 _Service_file_map_it = _Output_Service_file_map.find(service_name);
976 if (_Service_file_map_it == _Output_Service_file_map.end()) {
977 SALOME::ExceptionStruct es;
978 es.type = SALOME::INTERNAL_ERROR;
979 es.text = "service doesn't have salome files";
980 throw SALOME::SALOME_Exception(es);
982 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
984 // Try to find the Salome_file ...
985 _Salome_file_map_it = _map->find(Salome_file_name);
986 if (_Salome_file_map_it == _map->end()) {
987 SALOME::ExceptionStruct es;
988 es.type = SALOME::INTERNAL_ERROR;
989 es.text = "service doesn't have this Salome_file";
990 throw SALOME::SALOME_Exception(es);
992 Salome_file_i * Sfile = (*_map)[Salome_file_name];
994 return Sfile->_this();
997 Engines::Salome_file_ptr
998 Engines_Component_i::setOutputFileToService(const char* service_name,
999 const char* Salome_file_name)
1001 // Try to find the service, if it doesn't exist, we add it.
1002 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1003 if (_Service_file_map_it == _Output_Service_file_map.end()) {
1004 _t_Salome_file_map * _map = new _t_Salome_file_map();
1005 _Output_Service_file_map[service_name] = _map;
1007 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1009 // Try to find the Salome_file ...
1010 _Salome_file_map_it = _map->find(Salome_file_name);
1011 if (_Salome_file_map_it == _map->end()) {
1012 Salome_file_i * Sfile = new Salome_file_i();
1013 Engines::Container_ptr container = this->GetContainerRef();
1014 Sfile->setContainer(Engines::Container::_duplicate(container));
1015 (*_map)[Salome_file_name] = Sfile;
1018 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1019 return Sfile->_this();
1023 Engines_Component_i::checkOutputFilesToService(const char* service_name)
1025 // Try to find the service, if it doesn't exist, nothing to do.
1026 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1027 if (_Service_file_map_it != _Output_Service_file_map.end()) {
1028 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1029 _t_Salome_file_map::iterator begin = _map->begin();
1030 _t_Salome_file_map::iterator end = _map->end();
1032 for(;begin!=end;begin++) {
1033 Salome_file_i * file = begin->second;
1034 std::string file_port_name = begin->first;
1035 configureSalome_file(service_name, file_port_name, file);
1042 //=============================================================================
1044 * C++ method: used to configure the Salome_file into the runtime.
1045 * \param service_name name of the service that use this Salome_file
1046 * \param file_port_name name of the Salome_file
1047 * \param file Salome_file C++ object
1049 //=============================================================================
1051 Engines_Component_i::configureSalome_file(std::string service_name,
1052 std::string file_port_name,
1053 Salome_file_i * file)
1055 // By default this method does nothing
1058 //=============================================================================
1060 * C++ method: return the name of the container associated with this component
1061 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1062 * \return the container name (reformatted)
1064 //=============================================================================
1065 std::string Engines_Component_i::getContainerName()
1067 return _containerName;
1069 //=============================================================================
1071 * C++ method: set the name of the container associated with this component (attribute _containerName)
1072 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1073 * \return the container name (reformatted)
1075 //=============================================================================
1076 void Engines_Component_i::setContainerName()
1078 CORBA::String_var containerName=_container->name();
1079 std::string name(containerName);
1081 string::size_type slash =name.find_first_of('/');
1082 if(slash != std::string::npos)
1084 _containerName=name;