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;
559 //=============================================================================
563 //=============================================================================
564 SALOME::GenericObj_ptr Engines_Component_i::FindObjectByInternalEntry( const char* theEntry )
566 return SALOME::GenericObj_ptr();
569 //=============================================================================
571 * C++ method: return Container Servant
573 //=============================================================================
575 Engines_Container_i *Engines_Component_i::GetContainerPtr()
577 PortableServer::ObjectId_var contId=_poa->reference_to_id(_container);
578 return dynamic_cast<Engines_Container_i*>(_poa->id_to_servant(contId)) ;
581 //=============================================================================
583 * C++ method: set study Id
584 * \param studyId 0 if instance is not associated to a study,
585 * >0 otherwise (== study id)
586 * \return true if the set of study Id is OK
587 * must be set once by Container, at instance creation,
588 * and cannot be changed after.
590 //=============================================================================
592 CORBA::Boolean Engines_Component_i::setStudyId(CORBA::Long studyId)
594 ASSERT( studyId >= 0);
595 CORBA::Boolean ret = false;
596 if (_studyId < 0) // --- not yet initialized
602 if ( _studyId == studyId) ret = true;
606 //=============================================================================
608 * C++ method: return CORBA instance id, the id is set in derived class
609 * constructor, when instance is activated.
611 //=============================================================================
613 PortableServer::ObjectId * Engines_Component_i::getId()
615 // MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
619 //=============================================================================
621 * C++ method: used by derived classes for supervision
623 //=============================================================================
625 void Engines_Component_i::beginService(const char *serviceName)
627 std::cerr << "beginService for " << serviceName << " Component instance : " << _instanceName << std::endl;
630 _ThreadId = pthread_self() ;
632 _ThreadId = new pthread_t;
633 _ThreadId->p = pthread_self().p ;
634 _ThreadId->x = pthread_self().x ;
637 _StartUsed = CpuUsed_impl() ;
640 _serviceName = serviceName ;
641 theEngines_Component = this ;
642 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) )
644 perror("pthread_setcanceltype ") ;
647 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) )
649 perror("pthread_setcancelstate ") ;
653 // --- all strings given with setProperties are set in environment
654 map<std::string,CORBA::Any>::iterator it;
655 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
657 std::string cle((*it).first);
658 if ((*it).second.type()->kind() == CORBA::tk_string)
661 (*it).second >>= value;
665 putenv((char *)s.c_str());
666 MESSAGE("--- setenv: "<<cle<<" = "<< value);
671 //=============================================================================
673 * C++ method: used by derived classes for supervision
675 //=============================================================================
677 void Engines_Component_i::endService(const char *serviceName)
679 if ( !_CanceledThread )
680 _ThreadCpuUsed = CpuUsed_impl() ;
682 float cpus=_ThreadCpuUsed/1000.;
683 std::cerr << "endService for " << serviceName << " Component instance : " << _instanceName ;
684 std::cerr << " Cpu Used: " << cpus << " (s) " << std::endl;
685 MESSAGE("Send EndService notification for " << serviceName
686 << endl << " Component instance : " << _instanceName << " StartUsed "
687 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << endl <<endl);
691 //=============================================================================
693 * C++ method: -- CHECK IF USED --
695 //=============================================================================
697 char* Engines_Component_i::graphName()
699 return CORBA::string_dup( _graphName.c_str() ) ;
702 //=============================================================================
704 * C++ method: -- CHECK IF USED --
706 //=============================================================================
708 char* Engines_Component_i::nodeName()
710 return CORBA::string_dup( _nodeName.c_str() ) ;
713 //=============================================================================
715 * C++ method: used in Supervision (see kill_impl)
717 //=============================================================================
719 bool Engines_Component_i::Killer( pthread_t ThreadId , int signum )
729 if ( pthread_cancel( ThreadId ) )
731 perror("Killer pthread_cancel error") ;
737 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_canceled") ;
739 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_canceled") ;
745 if ( pthread_kill( ThreadId , signum ) == -1 )
747 perror("Killer pthread_kill error") ;
753 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_killed(" << signum << ")") ;
755 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_killed(" << signum << ")") ;
763 //=============================================================================
767 //=============================================================================
771 if ( theEngines_Component )
772 theEngines_Component->SetCurCpu() ;
775 //=============================================================================
779 //=============================================================================
781 void Engines_Component_i::SetCurCpu()
783 _ThreadCpuUsed = CpuUsed() ;
784 // MESSAGE(pthread_self() <<
785 // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ;
788 //=============================================================================
792 //=============================================================================
794 long Engines_Component_i::CpuUsed()
798 struct rusage usage ;
799 if ( _ThreadId || _Executed )
801 if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
803 perror("Engines_Component_i::CpuUsed") ;
806 //cpu time is calculated in millisecond (user+system times)
807 cpu = usage.ru_utime.tv_sec*1000 +usage.ru_utime.tv_usec/1000;
808 cpu = cpu+ usage.ru_stime.tv_sec*1000 +usage.ru_stime.tv_usec/1000;
810 // cout << pthread_self() << " Engines_Component_i::CpuUsed " << " "
811 // << _serviceName << usage.ru_utime.tv_sec << " - " << _StartUsed
812 // << " = " << cpu << endl ;
816 // cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId "
817 // << _ThreadId << " " << _serviceName<< " _StartUsed "
818 // << _StartUsed << endl ;
821 // NOT implementet yet
828 void CallCancelThread()
830 if ( theEngines_Component )
831 theEngines_Component->CancelThread() ;
834 //=============================================================================
838 //=============================================================================
840 void Engines_Component_i::CancelThread()
842 _CanceledThread = true;
845 //=============================================================================
847 * C++ method: Send message to event channel
849 //=============================================================================
851 void Engines_Component_i::sendMessage(const char *event_type,
854 _notifSupplier->Send(_graphName.c_str(), _nodeName.c_str(), event_type, message);
857 //=============================================================================
859 * C++ method: return standard library name built on component name
861 //=============================================================================
863 string Engines_Component_i::GetDynLibraryName(const char *componentName)
871 //=============================================================================
873 * C++ method: DumpPython default implementation
875 //=============================================================================
877 Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Object_ptr theStudy,
878 CORBA::Boolean isPublished,
879 CORBA::Boolean& isValidScript)
881 const char* aScript = "def RebuildData(theStudy): pass";
882 char* aBuffer = new char[strlen(aScript)+1];
883 strcpy(aBuffer, aScript);
884 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
885 int aBufferSize = strlen(aBuffer)+1;
886 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
887 isValidScript = true;
888 return aStreamFile._retn();
891 Engines::Salome_file_ptr
892 Engines_Component_i::getInputFileToService(const char* service_name,
893 const char* Salome_file_name)
895 // Try to find the service, if it doesn't exist, we throw an exception.
896 _Service_file_map_it = _Input_Service_file_map.find(service_name);
897 if (_Service_file_map_it == _Input_Service_file_map.end()) {
898 SALOME::ExceptionStruct es;
899 es.type = SALOME::INTERNAL_ERROR;
900 es.text = "service doesn't have salome files";
901 throw SALOME::SALOME_Exception(es);
903 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
905 // Try to find the Salome_file ...
906 _Salome_file_map_it = _map->find(Salome_file_name);
907 if (_Salome_file_map_it == _map->end()) {
908 SALOME::ExceptionStruct es;
909 es.type = SALOME::INTERNAL_ERROR;
910 es.text = "service doesn't have this Salome_file";
911 throw SALOME::SALOME_Exception(es);
913 Salome_file_i * Sfile = (*_map)[Salome_file_name];
915 return Sfile->_this();
918 Engines::Salome_file_ptr
919 Engines_Component_i::setInputFileToService(const char* service_name,
920 const char* Salome_file_name)
922 // Try to find the service, if it doesn't exist, we add it.
923 _Service_file_map_it = _Input_Service_file_map.find(service_name);
924 if (_Service_file_map_it == _Input_Service_file_map.end()) {
925 _t_Salome_file_map * _map = new _t_Salome_file_map();
926 _Input_Service_file_map[service_name] = _map;
928 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
930 // Try to find the Salome_file ...
931 _Salome_file_map_it = _map->find(Salome_file_name);
932 if (_Salome_file_map_it == _map->end()) {
933 Salome_file_i * Sfile = new Salome_file_i();
934 Engines::Container_ptr container = this->GetContainerRef();
935 Sfile->setContainer(Engines::Container::_duplicate(container));
936 (*_map)[Salome_file_name] = Sfile;
939 Salome_file_i * Sfile = (*_map)[Salome_file_name];
940 return Sfile->_this();
944 Engines_Component_i::checkInputFilesToService(const char* service_name)
946 // Try to find the service, if it doesn't exist, nothing to do.
947 _Service_file_map_it = _Input_Service_file_map.find(service_name);
948 if (_Service_file_map_it != _Input_Service_file_map.end()) {
949 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
950 _t_Salome_file_map::iterator begin = _map->begin();
951 _t_Salome_file_map::iterator end = _map->end();
953 for(;begin!=end;begin++) {
954 Salome_file_i * file = begin->second;
955 std::string file_port_name = begin->first;
956 configureSalome_file(service_name, file_port_name, file);
962 Engines::Salome_file_ptr
963 Engines_Component_i::getOutputFileToService(const char* service_name,
964 const char* Salome_file_name)
966 // Try to find the service, if it doesn't exist, we throw an exception.
967 _Service_file_map_it = _Output_Service_file_map.find(service_name);
968 if (_Service_file_map_it == _Output_Service_file_map.end()) {
969 SALOME::ExceptionStruct es;
970 es.type = SALOME::INTERNAL_ERROR;
971 es.text = "service doesn't have salome files";
972 throw SALOME::SALOME_Exception(es);
974 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
976 // Try to find the Salome_file ...
977 _Salome_file_map_it = _map->find(Salome_file_name);
978 if (_Salome_file_map_it == _map->end()) {
979 SALOME::ExceptionStruct es;
980 es.type = SALOME::INTERNAL_ERROR;
981 es.text = "service doesn't have this Salome_file";
982 throw SALOME::SALOME_Exception(es);
984 Salome_file_i * Sfile = (*_map)[Salome_file_name];
986 return Sfile->_this();
989 Engines::Salome_file_ptr
990 Engines_Component_i::setOutputFileToService(const char* service_name,
991 const char* Salome_file_name)
993 // Try to find the service, if it doesn't exist, we add it.
994 _Service_file_map_it = _Output_Service_file_map.find(service_name);
995 if (_Service_file_map_it == _Output_Service_file_map.end()) {
996 _t_Salome_file_map * _map = new _t_Salome_file_map();
997 _Output_Service_file_map[service_name] = _map;
999 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1001 // Try to find the Salome_file ...
1002 _Salome_file_map_it = _map->find(Salome_file_name);
1003 if (_Salome_file_map_it == _map->end()) {
1004 Salome_file_i * Sfile = new Salome_file_i();
1005 Engines::Container_ptr container = this->GetContainerRef();
1006 Sfile->setContainer(Engines::Container::_duplicate(container));
1007 (*_map)[Salome_file_name] = Sfile;
1010 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1011 return Sfile->_this();
1015 Engines_Component_i::checkOutputFilesToService(const char* service_name)
1017 // Try to find the service, if it doesn't exist, nothing to do.
1018 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1019 if (_Service_file_map_it != _Output_Service_file_map.end()) {
1020 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1021 _t_Salome_file_map::iterator begin = _map->begin();
1022 _t_Salome_file_map::iterator end = _map->end();
1024 for(;begin!=end;begin++) {
1025 Salome_file_i * file = begin->second;
1026 std::string file_port_name = begin->first;
1027 configureSalome_file(service_name, file_port_name, file);
1034 //=============================================================================
1036 * C++ method: used to configure the Salome_file into the runtime.
1037 * \param service_name name of the service that use this Salome_file
1038 * \param file_port_name name of the Salome_file
1039 * \param file Salome_file C++ object
1041 //=============================================================================
1043 Engines_Component_i::configureSalome_file(std::string service_name,
1044 std::string file_port_name,
1045 Salome_file_i * file)
1047 // By default this method does nothing
1050 //=============================================================================
1052 * C++ method: return the name of the container associated with this component
1053 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1054 * \return the container name (reformatted)
1056 //=============================================================================
1057 std::string Engines_Component_i::getContainerName()
1059 CORBA::String_var containerName=_container->name();
1060 std::string name(containerName);
1062 string::size_type slash =name.find_first_of('/');
1063 if(slash != std::string::npos)