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());
126 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
129 //=============================================================================
130 /*! \brief Standard Constructor for standalone Component, used in derived class
132 * Connection to Registry and Notification
133 * \param orb Object Request broker given by Container
134 * \param poa Portable Object Adapter from Container (normally root_poa)
135 * \param container container CORBA reference
136 * \param instanceName unique instance name for this object (see Container_i)
137 * \param interfaceName component class name
138 * \param notif use of notification
139 * \param regist (true or false) use of registry (default true)
141 //=============================================================================
143 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
144 PortableServer::POA_ptr poa,
145 Engines::Container_ptr container,
146 const char *instanceName,
147 const char *interfaceName,
150 _instanceName(instanceName),
151 _interfaceName(interfaceName),
152 _myConnexionToRegistry(0),
162 _CanceledThread(false)
164 MESSAGE("Component constructor with instanceName "<< _instanceName);
165 _orb = CORBA::ORB::_duplicate(orb);
166 _poa = PortableServer::POA::_duplicate(poa);
167 _container=Engines::Container::_duplicate(container);
169 const CORBA::String_var ior = _orb->object_to_string(_container);
171 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession", _instanceName.c_str());
172 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
176 //=============================================================================
178 * Destructor: call Container for decrement of instances count.
179 * When instances count falls to 0, the container tries to remove the
180 * component library (dlclose)
182 //=============================================================================
184 Engines_Component_i::~Engines_Component_i()
186 MESSAGE("Component destructor");
187 Engines_Container_i::decInstanceCnt(_interfaceName);
188 if(_myConnexionToRegistry)delete _myConnexionToRegistry;
189 _myConnexionToRegistry = 0 ;
190 if(_notifSupplier)delete _notifSupplier;
196 //=============================================================================
198 * CORBA method: return name of the instance, unique in this Container
200 //=============================================================================
202 char* Engines_Component_i::instanceName()
204 return CORBA::string_dup(_instanceName.c_str()) ;
207 //=============================================================================
209 * CORBA method: return name of the component class
211 //=============================================================================
213 char* Engines_Component_i::interfaceName()
215 return CORBA::string_dup(_interfaceName.c_str()) ;
218 //=============================================================================
220 * CORBA method: Get study Id
221 * \return -1: not initialised (Internal Error)
222 * 0: multistudy component instance
223 * >0: study id associated to this instance
225 //=============================================================================
227 CORBA::Long Engines_Component_i::getStudyId()
232 //=============================================================================
234 * CORBA method: Test if instance is alive and responds
236 //=============================================================================
238 void Engines_Component_i::ping()
241 MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid "
244 MESSAGE("Engines_Component_i::ping() pid "<< _getpid()<< " threadid "
245 << pthread_self().p );
249 //=============================================================================
251 * CORBA method: Deactivate this instance. CORBA object is deactivated (do not
252 * respond any more to CORBA calls), the connection to Regsitry is removed
253 * (Registry informed of deactivation), internal server reference counter on
254 * the derived servant class is decremented, to allow destruction of the class
255 * (delete) by POA, when there are no more references.
256 * -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
258 //=============================================================================
260 void Engines_Component_i::destroy()
262 MESSAGE("Engines_Component_i::destroy()");
263 //SCRUTE(_refcount_value());
264 _poa->deactivate_object(*_id);
265 //SCRUTE(_refcount_value());
267 //SCRUTE(_refcount_value());
268 MESSAGE("Engines_Component_i::destroyed") ;
271 //=============================================================================
273 * CORBA method: return CORBA reference of the Container
276 //=============================================================================
278 Engines::Container_ptr Engines_Component_i::GetContainerRef()
280 return Engines::Container::_duplicate(_container);
283 //=============================================================================
286 * Gives a sequence of (key=string,value=any) to the component.
287 * Base class component stores the sequence in a map.
288 * The map is cleared before.
289 * This map is for use by derived classes.
290 * \param dico sequence of (key=string,value=any)
292 //=============================================================================
294 void Engines_Component_i::setProperties(const Engines::FieldsDict& dico)
297 for (CORBA::ULong i=0; i<dico.length(); i++)
299 std::string cle(dico[i].key);
300 _fieldsDict[cle] = dico[i].value;
304 //=============================================================================
307 * returns a previously stored map (key=string,value=any) as a sequence.
308 * (see setProperties)
310 //=============================================================================
312 Engines::FieldsDict* Engines_Component_i::getProperties()
314 Engines::FieldsDict_var copie = new Engines::FieldsDict;
315 copie->length(_fieldsDict.size());
316 map<std::string,CORBA::Any>::iterator it;
318 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++)
320 std::string cle((*it).first);
321 copie[i].key = CORBA::string_dup(cle.c_str());
322 copie[i].value = _fieldsDict[cle];
324 return copie._retn();
327 //=============================================================================
329 * CORBA method: used by Supervision to give names to this instance
331 //=============================================================================
333 void Engines_Component_i::Names( const char * graphName ,
334 const char * nodeName )
336 _graphName = graphName ;
337 _nodeName = nodeName ;
338 // MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
339 // << _nodeName << "' )");
342 //=============================================================================
344 * CORBA method: used in Supervision
346 //=============================================================================
348 bool Engines_Component_i::Kill_impl()
350 // MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
351 // << " pid " << getpid() << " instanceName "
352 // << _instanceName.c_str() << " interface " << _interfaceName.c_str()
353 // << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
354 // << dec << " _ThreadId " << _ThreadId << " this " << hex << this
357 bool RetVal = false ;
359 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
361 RetVal = Killer( _ThreadId , SIGUSR2 ) ;
362 _ThreadId = (pthread_t ) -1 ;
366 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
368 RetVal = Killer( *_ThreadId , 0 ) ;
369 _ThreadId = (pthread_t* ) 0 ;
376 //=============================================================================
378 * CORBA method: used in Supervision
380 //=============================================================================
382 bool Engines_Component_i::Stop_impl()
385 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self()
386 << " pid " << getpid() << " instanceName "
387 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
388 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
389 << dec << " _ThreadId " << _ThreadId );
391 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self().p
392 << " pid " << _getpid() << " instanceName "
393 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
394 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
395 << dec << " _ThreadId " << _ThreadId );
399 bool RetVal = false ;
401 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
403 RetVal = Killer( _ThreadId , 0 ) ;
404 _ThreadId = (pthread_t ) -1 ;
407 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
409 RetVal = Killer( *_ThreadId , 0 ) ;
410 _ThreadId = (pthread_t* ) 0 ;
416 //=============================================================================
418 * CORBA method: used in Supervision
420 //=============================================================================
422 bool Engines_Component_i::Suspend_impl()
425 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self()
426 << " pid " << getpid() << " instanceName "
427 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
428 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
429 << dec << " _ThreadId " << _ThreadId );
431 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self().p
432 << " pid " << _getpid() << " instanceName "
433 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
434 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
435 << dec << " _ThreadId " << _ThreadId );
438 bool RetVal = false ;
440 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
442 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
452 RetVal = Killer( _ThreadId ,SIGINT ) ;
454 RetVal = Killer( *_ThreadId ,SIGINT ) ;
456 //if ( RetVal ) _Sleeping = true;
463 //=============================================================================
465 * CORBA method: used in Supervision
467 //=============================================================================
469 bool Engines_Component_i::Resume_impl()
472 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self()
473 << " pid " << getpid() << " instanceName "
474 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
475 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
476 << dec << " _ThreadId " << _ThreadId );
478 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self().p
479 << " pid " << _getpid() << " instanceName "
480 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
481 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
482 << dec << " _ThreadId " << _ThreadId );
484 bool RetVal = false ;
486 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
488 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
504 //=============================================================================
508 //=============================================================================
510 CORBA::Long Engines_Component_i::CpuUsed_impl()
513 if ( _ThreadId || _Executed )
518 if ( pthread_self() != _ThreadId )
520 if ( pthread_self().p != _ThreadId->p )
528 // Get Cpu in the appropriate thread with that object !...
529 theEngines_Component = this ;
531 Killer( _ThreadId ,SIGUSR1 ) ;
533 Killer( *_ThreadId ,SIGUSR11 ) ;
536 cpu = _ThreadCpuUsed ;
540 _ThreadCpuUsed = CpuUsed() ;
541 cpu = _ThreadCpuUsed ;
542 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
543 // << _serviceName << " " << cpu << endl ;
548 cpu = _ThreadCpuUsed ;
549 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
550 // << _serviceName << " " << cpu<< endl ;
555 // cout<< pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId "
556 // <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<<endl;
562 //=============================================================================
564 * C++ method: return Container Servant
566 //=============================================================================
568 Engines_Container_i *Engines_Component_i::GetContainerPtr()
570 PortableServer::ObjectId_var contId=_poa->reference_to_id(_container);
571 return dynamic_cast<Engines_Container_i*>(_poa->id_to_servant(contId)) ;
574 //=============================================================================
576 * C++ method: set study Id
577 * \param studyId 0 if instance is not associated to a study,
578 * >0 otherwise (== study id)
579 * \return true if the set of study Id is OK
580 * must be set once by Container, at instance creation,
581 * and cannot be changed after.
583 //=============================================================================
585 CORBA::Boolean Engines_Component_i::setStudyId(CORBA::Long studyId)
587 ASSERT( studyId >= 0);
588 CORBA::Boolean ret = false;
589 if (_studyId < 0) // --- not yet initialized
595 if ( _studyId == studyId) ret = true;
599 //=============================================================================
601 * C++ method: return CORBA instance id, the id is set in derived class
602 * constructor, when instance is activated.
604 //=============================================================================
606 PortableServer::ObjectId * Engines_Component_i::getId()
608 // MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
612 //=============================================================================
614 * C++ method: used by derived classes for supervision
616 //=============================================================================
618 void Engines_Component_i::beginService(const char *serviceName)
620 std::cerr << "beginService for " << serviceName << " Component instance : " << _instanceName << std::endl;
623 _ThreadId = pthread_self() ;
625 _ThreadId = new pthread_t;
626 _ThreadId->p = pthread_self().p ;
627 _ThreadId->x = pthread_self().x ;
630 _StartUsed = CpuUsed_impl() ;
633 _serviceName = serviceName ;
634 theEngines_Component = this ;
635 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) )
637 perror("pthread_setcanceltype ") ;
640 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) )
642 perror("pthread_setcancelstate ") ;
646 // --- all strings given with setProperties are set in environment
647 map<std::string,CORBA::Any>::iterator it;
648 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
650 std::string cle((*it).first);
651 if ((*it).second.type()->kind() == CORBA::tk_string)
654 (*it).second >>= value;
658 putenv((char *)s.c_str());
659 MESSAGE("--- setenv: "<<cle<<" = "<< value);
664 //=============================================================================
666 * C++ method: used by derived classes for supervision
668 //=============================================================================
670 void Engines_Component_i::endService(const char *serviceName)
672 if ( !_CanceledThread )
673 _ThreadCpuUsed = CpuUsed_impl() ;
675 float cpus=_ThreadCpuUsed/1000.;
676 std::cerr << "endService for " << serviceName << " Component instance : " << _instanceName ;
677 std::cerr << " Cpu Used: " << cpus << " (s) " << std::endl;
678 MESSAGE("Send EndService notification for " << serviceName
679 << endl << " Component instance : " << _instanceName << " StartUsed "
680 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << endl <<endl);
684 //=============================================================================
686 * C++ method: -- CHECK IF USED --
688 //=============================================================================
690 char* Engines_Component_i::graphName()
692 return CORBA::string_dup( _graphName.c_str() ) ;
695 //=============================================================================
697 * C++ method: -- CHECK IF USED --
699 //=============================================================================
701 char* Engines_Component_i::nodeName()
703 return CORBA::string_dup( _nodeName.c_str() ) ;
706 //=============================================================================
708 * C++ method: used in Supervision (see kill_impl)
710 //=============================================================================
712 bool Engines_Component_i::Killer( pthread_t ThreadId , int signum )
722 if ( pthread_cancel( ThreadId ) )
724 perror("Killer pthread_cancel error") ;
730 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_canceled") ;
732 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_canceled") ;
738 if ( pthread_kill( ThreadId , signum ) == -1 )
740 perror("Killer pthread_kill error") ;
746 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_killed(" << signum << ")") ;
748 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_killed(" << signum << ")") ;
756 //=============================================================================
760 //=============================================================================
764 if ( theEngines_Component )
765 theEngines_Component->SetCurCpu() ;
768 //=============================================================================
772 //=============================================================================
774 void Engines_Component_i::SetCurCpu()
776 _ThreadCpuUsed = CpuUsed() ;
777 // MESSAGE(pthread_self() <<
778 // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ;
781 //=============================================================================
785 //=============================================================================
787 long Engines_Component_i::CpuUsed()
791 struct rusage usage ;
792 if ( _ThreadId || _Executed )
794 if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
796 perror("Engines_Component_i::CpuUsed") ;
799 //cpu time is calculated in millisecond (user+system times)
800 cpu = usage.ru_utime.tv_sec*1000 +usage.ru_utime.tv_usec/1000;
801 cpu = cpu+ usage.ru_stime.tv_sec*1000 +usage.ru_stime.tv_usec/1000;
803 // cout << pthread_self() << " Engines_Component_i::CpuUsed " << " "
804 // << _serviceName << usage.ru_utime.tv_sec << " - " << _StartUsed
805 // << " = " << cpu << endl ;
809 // cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId "
810 // << _ThreadId << " " << _serviceName<< " _StartUsed "
811 // << _StartUsed << endl ;
814 // NOT implementet yet
821 void CallCancelThread()
823 if ( theEngines_Component )
824 theEngines_Component->CancelThread() ;
827 //=============================================================================
831 //=============================================================================
833 void Engines_Component_i::CancelThread()
835 _CanceledThread = true;
838 //=============================================================================
840 * C++ method: Send message to event channel
842 //=============================================================================
844 void Engines_Component_i::sendMessage(const char *event_type,
847 _notifSupplier->Send(_graphName.c_str(), _nodeName.c_str(), event_type, message);
850 //=============================================================================
852 * C++ method: return standard library name built on component name
854 //=============================================================================
856 string Engines_Component_i::GetDynLibraryName(const char *componentName)
864 //=============================================================================
866 * C++ method: DumpPython default implementation
868 //=============================================================================
870 Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Object_ptr theStudy,
871 CORBA::Boolean isPublished,
872 CORBA::Boolean& isValidScript)
874 const char* aScript = "def RebuildData(theStudy): pass";
875 char* aBuffer = new char[strlen(aScript)+1];
876 strcpy(aBuffer, aScript);
877 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
878 int aBufferSize = strlen(aBuffer)+1;
879 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
880 isValidScript = true;
881 return aStreamFile._retn();
884 Engines::Salome_file_ptr
885 Engines_Component_i::getInputFileToService(const char* service_name,
886 const char* Salome_file_name)
888 // Try to find the service, if it doesn't exist, we throw an exception.
889 _Service_file_map_it = _Input_Service_file_map.find(service_name);
890 if (_Service_file_map_it == _Input_Service_file_map.end()) {
891 SALOME::ExceptionStruct es;
892 es.type = SALOME::INTERNAL_ERROR;
893 es.text = "service doesn't have salome files";
894 throw SALOME::SALOME_Exception(es);
896 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
898 // Try to find the Salome_file ...
899 _Salome_file_map_it = _map->find(Salome_file_name);
900 if (_Salome_file_map_it == _map->end()) {
901 SALOME::ExceptionStruct es;
902 es.type = SALOME::INTERNAL_ERROR;
903 es.text = "service doesn't have this Salome_file";
904 throw SALOME::SALOME_Exception(es);
906 Salome_file_i * Sfile = (*_map)[Salome_file_name];
908 return Sfile->_this();
911 Engines::Salome_file_ptr
912 Engines_Component_i::setInputFileToService(const char* service_name,
913 const char* Salome_file_name)
915 // Try to find the service, if it doesn't exist, we add it.
916 _Service_file_map_it = _Input_Service_file_map.find(service_name);
917 if (_Service_file_map_it == _Input_Service_file_map.end()) {
918 _t_Salome_file_map * _map = new _t_Salome_file_map();
919 _Input_Service_file_map[service_name] = _map;
921 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
923 // Try to find the Salome_file ...
924 _Salome_file_map_it = _map->find(Salome_file_name);
925 if (_Salome_file_map_it == _map->end()) {
926 Salome_file_i * Sfile = new Salome_file_i();
927 Engines::Container_ptr container = this->GetContainerRef();
928 Sfile->setContainer(Engines::Container::_duplicate(container));
929 (*_map)[Salome_file_name] = Sfile;
932 Salome_file_i * Sfile = (*_map)[Salome_file_name];
933 return Sfile->_this();
937 Engines_Component_i::checkInputFilesToService(const char* service_name)
939 // Try to find the service, if it doesn't exist, nothing to do.
940 _Service_file_map_it = _Input_Service_file_map.find(service_name);
941 if (_Service_file_map_it != _Input_Service_file_map.end()) {
942 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
943 _t_Salome_file_map::iterator begin = _map->begin();
944 _t_Salome_file_map::iterator end = _map->end();
946 for(;begin!=end;begin++) {
947 Salome_file_i * file = begin->second;
948 std::string file_port_name = begin->first;
949 configureSalome_file(service_name, file_port_name, file);
955 Engines::Salome_file_ptr
956 Engines_Component_i::getOutputFileToService(const char* service_name,
957 const char* Salome_file_name)
959 // Try to find the service, if it doesn't exist, we throw an exception.
960 _Service_file_map_it = _Output_Service_file_map.find(service_name);
961 if (_Service_file_map_it == _Output_Service_file_map.end()) {
962 SALOME::ExceptionStruct es;
963 es.type = SALOME::INTERNAL_ERROR;
964 es.text = "service doesn't have salome files";
965 throw SALOME::SALOME_Exception(es);
967 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
969 // Try to find the Salome_file ...
970 _Salome_file_map_it = _map->find(Salome_file_name);
971 if (_Salome_file_map_it == _map->end()) {
972 SALOME::ExceptionStruct es;
973 es.type = SALOME::INTERNAL_ERROR;
974 es.text = "service doesn't have this Salome_file";
975 throw SALOME::SALOME_Exception(es);
977 Salome_file_i * Sfile = (*_map)[Salome_file_name];
979 return Sfile->_this();
982 Engines::Salome_file_ptr
983 Engines_Component_i::setOutputFileToService(const char* service_name,
984 const char* Salome_file_name)
986 // Try to find the service, if it doesn't exist, we add it.
987 _Service_file_map_it = _Output_Service_file_map.find(service_name);
988 if (_Service_file_map_it == _Output_Service_file_map.end()) {
989 _t_Salome_file_map * _map = new _t_Salome_file_map();
990 _Output_Service_file_map[service_name] = _map;
992 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
994 // Try to find the Salome_file ...
995 _Salome_file_map_it = _map->find(Salome_file_name);
996 if (_Salome_file_map_it == _map->end()) {
997 Salome_file_i * Sfile = new Salome_file_i();
998 Engines::Container_ptr container = this->GetContainerRef();
999 Sfile->setContainer(Engines::Container::_duplicate(container));
1000 (*_map)[Salome_file_name] = Sfile;
1003 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1004 return Sfile->_this();
1008 Engines_Component_i::checkOutputFilesToService(const char* service_name)
1010 // Try to find the service, if it doesn't exist, nothing to do.
1011 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1012 if (_Service_file_map_it != _Output_Service_file_map.end()) {
1013 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1014 _t_Salome_file_map::iterator begin = _map->begin();
1015 _t_Salome_file_map::iterator end = _map->end();
1017 for(;begin!=end;begin++) {
1018 Salome_file_i * file = begin->second;
1019 std::string file_port_name = begin->first;
1020 configureSalome_file(service_name, file_port_name, file);
1027 //=============================================================================
1029 * C++ method: used to configure the Salome_file into the runtime.
1030 * \param service_name name of the service that use this Salome_file
1031 * \param file_port_name name of the Salome_file
1032 * \param file Salome_file C++ object
1034 //=============================================================================
1036 Engines_Component_i::configureSalome_file(std::string service_name,
1037 std::string file_port_name,
1038 Salome_file_i * file)
1040 // By default this method does nothing
1043 //=============================================================================
1045 * C++ method: return the name of the container associated with this component
1046 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1047 * \return the container name (reformatted)
1049 //=============================================================================
1050 std::string Engines_Component_i::getContainerName()
1052 return _containerName;
1054 //=============================================================================
1056 * C++ method: set the name of the container associated with this component (attribute _containerName)
1057 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1058 * \return the container name (reformatted)
1060 //=============================================================================
1061 void Engines_Component_i::setContainerName()
1063 CORBA::String_var containerName=_container->name();
1064 std::string name(containerName);
1066 string::size_type slash =name.find_first_of('/');
1067 if(slash != std::string::npos)
1069 _containerName=name;