1 // Copyright (C) 2007-2010 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
23 // SALOME Container : implementation of container and engine for Kernel
24 // File : Component_i.cxx
25 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
28 //#define private protected // for pd_refCount trace
30 #include "SALOME_Component_i.hxx"
31 #include "SALOME_Container_i.hxx"
32 #include "RegistryConnexion.hxx"
33 #include "Basics_Utils.hxx"
39 #include "utilities.h"
43 #include <sys/resource.h>
46 #include <sys/timeb.h>
51 extern bool _Sleeping ;
52 static Engines_Component_i * theEngines_Component ;
54 bool Engines_Component_i::_isMultiStudy = true;
55 bool Engines_Component_i::_isMultiInstance = false;
57 /*! \class Engines_Component_i
58 * \brief C++ implementation of Engines::Component interface
62 //=============================================================================
64 * Default constructor, not for use
66 //=============================================================================
68 Engines_Component_i::Engines_Component_i():_myConnexionToRegistry(0), _notifSupplier(0), _id(0)
71 MESSAGE("Default Constructor, not for normal use...");
74 //=============================================================================
75 /*! \brief Standard Constructor for generic Component, used in derived class
77 * Connection to Registry and Notification
78 * \param orb Object Request broker given by Container
79 * \param poa Portable Object Adapter from Container (normally root_poa)
80 * \param contId container CORBA id inside the server
81 * \param instanceName unique instance name for this object (see Container_i)
82 * \param interfaceName component class name
83 * \param notif use of notification
84 * \param regist (true or false) use of registry (default true)
86 //=============================================================================
88 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
89 PortableServer::POA_ptr poa,
90 PortableServer::ObjectId * contId,
91 const char *instanceName,
92 const char *interfaceName,
95 _instanceName(instanceName),
96 _interfaceName(interfaceName),
97 _myConnexionToRegistry(0),
107 _CanceledThread(false)
109 MESSAGE("Component constructor with instanceName "<< _instanceName);
110 _orb = CORBA::ORB::_duplicate(orb);
111 _poa = PortableServer::POA::_duplicate(poa);
113 CORBA::Object_var o = _poa->id_to_reference(*contId); // container ior...
114 _container=Engines::Container::_narrow(o);
119 const CORBA::String_var ior = _orb->object_to_string(o);
120 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession",
121 _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);
168 const CORBA::String_var ior = _orb->object_to_string(_container);
170 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession", _instanceName.c_str());
172 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
177 //=============================================================================
179 * Destructor: call Container for decrement of instances count.
180 * When instances count falls to 0, the container tries to remove the
181 * component library (dlclose)
183 //=============================================================================
185 Engines_Component_i::~Engines_Component_i()
187 MESSAGE("Component destructor");
188 Engines_Container_i::decInstanceCnt(_interfaceName);
189 if(_myConnexionToRegistry)delete _myConnexionToRegistry;
190 _myConnexionToRegistry = 0 ;
197 SCRUTE(_notifSupplier->_refcount_value());
198 PortableServer::POA_var poa=_notifSupplier->_default_POA();
199 PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_notifSupplier);
200 poa->deactivate_object(anObjectId.in());
201 SCRUTE(_notifSupplier->_refcount_value());
202 _notifSupplier->_remove_ref();
206 //=============================================================================
208 * CORBA method: return name of the instance, unique in this Container
210 //=============================================================================
212 char* Engines_Component_i::instanceName()
214 return CORBA::string_dup(_instanceName.c_str()) ;
217 //=============================================================================
219 * CORBA method: return name of the component class
221 //=============================================================================
223 char* Engines_Component_i::interfaceName()
225 return CORBA::string_dup(_interfaceName.c_str()) ;
228 //=============================================================================
230 * CORBA method: Get study Id
231 * \return -1: not initialised (Internal Error)
232 * 0: multistudy component instance
233 * >0: study id associated to this instance
235 //=============================================================================
237 CORBA::Long Engines_Component_i::getStudyId()
242 //=============================================================================
244 * CORBA method: Test if instance is alive and responds
246 //=============================================================================
248 void Engines_Component_i::ping()
251 MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid "
254 MESSAGE("Engines_Component_i::ping() pid "<< _getpid()<< " threadid "
255 << pthread_self().p );
259 //=============================================================================
261 * CORBA method: Deactivate this instance. CORBA object is deactivated (do not
262 * respond any more to CORBA calls), the connection to Regsitry is removed
263 * (Registry informed of deactivation), internal server reference counter on
264 * the derived servant class is decremented, to allow destruction of the class
265 * (delete) by POA, when there are no more references.
266 * -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
268 //=============================================================================
270 void Engines_Component_i::destroy()
272 MESSAGE("Engines_Component_i::destroy()");
273 //SCRUTE(_refcount_value());
274 _poa->deactivate_object(*_id);
275 //SCRUTE(_refcount_value());
277 //SCRUTE(_refcount_value());
278 MESSAGE("Engines_Component_i::destroyed") ;
281 //=============================================================================
283 * CORBA method: return CORBA reference of the Container
286 //=============================================================================
288 Engines::Container_ptr Engines_Component_i::GetContainerRef()
290 return Engines::Container::_duplicate(_container);
293 //=============================================================================
296 * Gives a sequence of (key=string,value=any) to the component.
297 * Base class component stores the sequence in a map.
298 * The map is cleared before.
299 * This map is for use by derived classes.
300 * \param dico sequence of (key=string,value=any)
302 //=============================================================================
304 void Engines_Component_i::setProperties(const Engines::FieldsDict& dico)
307 for (CORBA::ULong i=0; i<dico.length(); i++)
309 std::string cle(dico[i].key);
310 _fieldsDict[cle] = dico[i].value;
314 //=============================================================================
317 * returns a previously stored map (key=string,value=any) as a sequence.
318 * (see setProperties)
320 //=============================================================================
322 Engines::FieldsDict* Engines_Component_i::getProperties()
324 Engines::FieldsDict_var copie = new Engines::FieldsDict;
325 copie->length(_fieldsDict.size());
326 std::map<std::string,CORBA::Any>::iterator it;
328 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++)
330 std::string cle((*it).first);
331 copie[i].key = CORBA::string_dup(cle.c_str());
332 copie[i].value = _fieldsDict[cle];
334 return copie._retn();
337 //=============================================================================
339 * CORBA method: used by Supervision to give names to this instance
341 //=============================================================================
343 void Engines_Component_i::Names( const char * graphName ,
344 const char * nodeName )
346 _graphName = graphName ;
347 _nodeName = nodeName ;
348 // MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
349 // << _nodeName << "' )");
352 //=============================================================================
354 * CORBA method: used in Supervision
356 //=============================================================================
358 bool Engines_Component_i::Kill_impl()
360 // MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
361 // << " pid " << getpid() << " instanceName "
362 // << _instanceName.c_str() << " interface " << _interfaceName.c_str()
363 // << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
364 // << dec << " _ThreadId " << _ThreadId << " this " << hex << this
367 bool RetVal = false ;
369 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
371 RetVal = Killer( _ThreadId , SIGUSR2 ) ;
372 _ThreadId = (pthread_t ) -1 ;
376 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
378 RetVal = Killer( *_ThreadId , 0 ) ;
379 _ThreadId = (pthread_t* ) 0 ;
386 //=============================================================================
388 * CORBA method: used in Supervision
390 //=============================================================================
392 bool Engines_Component_i::Stop_impl()
395 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self()
396 << " pid " << getpid() << " instanceName "
397 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
398 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
399 << std::dec << " _ThreadId " << _ThreadId );
401 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self().p
402 << " pid " << _getpid() << " instanceName "
403 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
404 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
405 << std::dec << " _ThreadId " << _ThreadId );
409 bool RetVal = false ;
411 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
413 RetVal = Killer( _ThreadId , 0 ) ;
414 _ThreadId = (pthread_t ) -1 ;
417 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
419 RetVal = Killer( *_ThreadId , 0 ) ;
420 _ThreadId = (pthread_t* ) 0 ;
426 //=============================================================================
428 * CORBA method: used in Supervision
430 //=============================================================================
432 bool Engines_Component_i::Suspend_impl()
435 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self()
436 << " pid " << getpid() << " instanceName "
437 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
438 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
439 << std::dec << " _ThreadId " << _ThreadId );
441 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self().p
442 << " pid " << _getpid() << " instanceName "
443 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
444 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
445 << std::dec << " _ThreadId " << _ThreadId );
448 bool RetVal = false ;
450 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
452 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
462 RetVal = Killer( _ThreadId ,SIGINT ) ;
464 RetVal = Killer( *_ThreadId ,SIGINT ) ;
466 //if ( RetVal ) _Sleeping = true;
473 //=============================================================================
475 * CORBA method: used in Supervision
477 //=============================================================================
479 bool Engines_Component_i::Resume_impl()
482 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self()
483 << " pid " << getpid() << " instanceName "
484 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
485 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
486 << std::dec << " _ThreadId " << _ThreadId );
488 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self().p
489 << " pid " << _getpid() << " instanceName "
490 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
491 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
492 << std::dec << " _ThreadId " << _ThreadId );
494 bool RetVal = false ;
496 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
498 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
514 //=============================================================================
518 //=============================================================================
520 CORBA::Long Engines_Component_i::CpuUsed_impl()
523 if ( _ThreadId || _Executed )
528 if ( pthread_self() != _ThreadId )
530 if ( pthread_self().p != _ThreadId->p )
538 // Get Cpu in the appropriate thread with that object !...
539 theEngines_Component = this ;
541 Killer( _ThreadId ,SIGUSR1 ) ;
543 Killer( *_ThreadId ,SIGUSR11 ) ;
546 cpu = _ThreadCpuUsed ;
550 _ThreadCpuUsed = CpuUsed() ;
551 cpu = _ThreadCpuUsed ;
552 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
553 // << _serviceName << " " << cpu << endl ;
558 cpu = _ThreadCpuUsed ;
559 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
560 // << _serviceName << " " << cpu<< endl ;
565 // cout<< pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId "
566 // <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<<endl;
572 //=============================================================================
574 * C++ method: return Container Servant
576 //=============================================================================
578 Engines_Container_i *Engines_Component_i::GetContainerPtr()
580 PortableServer::ObjectId_var contId=_poa->reference_to_id(_container);
581 return dynamic_cast<Engines_Container_i*>(_poa->id_to_servant(contId)) ;
584 //=============================================================================
586 * C++ method: set study Id
587 * \param studyId 0 if instance is not associated to a study,
588 * >0 otherwise (== study id)
589 * \return true if the set of study Id is OK
590 * must be set once by Container, at instance creation,
591 * and cannot be changed after.
593 //=============================================================================
595 CORBA::Boolean Engines_Component_i::setStudyId(CORBA::Long studyId)
597 ASSERT( studyId >= 0);
598 CORBA::Boolean ret = false;
599 if (_studyId < 0) // --- not yet initialized
605 if ( _studyId == studyId) ret = true;
609 //=============================================================================
611 * C++ method: return CORBA instance id, the id is set in derived class
612 * constructor, when instance is activated.
614 //=============================================================================
616 PortableServer::ObjectId * Engines_Component_i::getId()
618 // MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
622 //=============================================================================
624 * C++ method: used by derived classes for supervision
626 //=============================================================================
628 void Engines_Component_i::beginService(const char *serviceName)
630 std::cerr << "beginService for " << serviceName << " Component instance : " << _instanceName << std::endl;
633 _ThreadId = pthread_self() ;
635 _ThreadId = new pthread_t;
636 _ThreadId->p = pthread_self().p ;
637 _ThreadId->x = pthread_self().x ;
640 _StartUsed = CpuUsed_impl() ;
643 _serviceName = serviceName ;
644 theEngines_Component = this ;
645 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) )
647 perror("pthread_setcanceltype ") ;
650 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) )
652 perror("pthread_setcancelstate ") ;
656 // --- all strings given with setProperties are set in environment
657 std::map<std::string,CORBA::Any>::iterator it;
658 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
660 std::string cle((*it).first);
661 if ((*it).second.type()->kind() == CORBA::tk_string)
664 (*it).second >>= value;
668 putenv((char *)s.c_str());
669 MESSAGE("--- setenv: "<<cle<<" = "<< value);
674 //=============================================================================
676 * C++ method: used by derived classes for supervision
678 //=============================================================================
680 void Engines_Component_i::endService(const char *serviceName)
682 if ( !_CanceledThread )
683 _ThreadCpuUsed = CpuUsed_impl() ;
685 float cpus=_ThreadCpuUsed/1000.;
686 std::cerr << "endService for " << serviceName << " Component instance : " << _instanceName ;
687 std::cerr << " Cpu Used: " << cpus << " (s) " << std::endl;
688 MESSAGE("Send EndService notification for " << serviceName
689 << std::endl << " Component instance : " << _instanceName << " StartUsed "
690 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << std::endl <<std::endl);
694 //=============================================================================
696 * C++ method: -- CHECK IF USED --
698 //=============================================================================
700 char* Engines_Component_i::graphName()
702 return CORBA::string_dup( _graphName.c_str() ) ;
705 //=============================================================================
707 * C++ method: -- CHECK IF USED --
709 //=============================================================================
711 char* Engines_Component_i::nodeName()
713 return CORBA::string_dup( _nodeName.c_str() ) ;
716 //=============================================================================
718 * C++ method: used in Supervision (see kill_impl)
720 //=============================================================================
722 bool Engines_Component_i::Killer( pthread_t ThreadId , int signum )
732 if ( pthread_cancel( ThreadId ) )
734 perror("Killer pthread_cancel error") ;
740 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_canceled") ;
742 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_canceled") ;
748 if ( pthread_kill( ThreadId , signum ) == -1 )
750 perror("Killer pthread_kill error") ;
756 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_killed(" << signum << ")") ;
758 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_killed(" << signum << ")") ;
767 void CallCancelThread();
769 //=============================================================================
773 //=============================================================================
777 if ( theEngines_Component )
778 theEngines_Component->SetCurCpu() ;
781 //=============================================================================
785 //=============================================================================
787 void Engines_Component_i::SetCurCpu()
789 _ThreadCpuUsed = CpuUsed() ;
790 // MESSAGE(pthread_self() <<
791 // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ;
794 //=============================================================================
798 //=============================================================================
800 long Engines_Component_i::CpuUsed()
804 struct rusage usage ;
805 if ( _ThreadId || _Executed )
807 if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
809 perror("Engines_Component_i::CpuUsed") ;
812 //cpu time is calculated in millisecond (user+system times)
813 cpu = usage.ru_utime.tv_sec*1000 +usage.ru_utime.tv_usec/1000;
814 cpu = cpu+ usage.ru_stime.tv_sec*1000 +usage.ru_stime.tv_usec/1000;
816 // std::cout << pthread_self() << " Engines_Component_i::CpuUsed " << " "
817 // << _serviceName << usage.ru_utime.tv_sec << " - " << _StartUsed
818 // << " = " << cpu << std::endl ;
822 // std::cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId "
823 // << _ThreadId << " " << _serviceName<< " _StartUsed "
824 // << _StartUsed << std::endl ;
827 // NOT implementet yet
834 void CallCancelThread()
836 if ( theEngines_Component )
837 theEngines_Component->CancelThread() ;
840 //=============================================================================
844 //=============================================================================
846 void Engines_Component_i::CancelThread()
848 _CanceledThread = true;
851 //=============================================================================
853 * C++ method: Send message to event channel
855 //=============================================================================
857 void Engines_Component_i::sendMessage(const char *event_type,
860 _notifSupplier->Send(_graphName.c_str(), _nodeName.c_str(), event_type, message);
863 //=============================================================================
865 * C++ method: return standard library name built on component name
867 //=============================================================================
869 std::string Engines_Component_i::GetDynLibraryName(const char *componentName)
871 std::string ret="lib";
877 //=============================================================================
879 * C++ method: DumpPython default implementation
881 //=============================================================================
883 Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Object_ptr theStudy,
884 CORBA::Boolean isPublished,
885 CORBA::Boolean isMultiFile,
886 CORBA::Boolean& isValidScript)
888 const char* aScript = isMultiFile ? "def RebuildData(theStudy): pass" : "";
889 char* aBuffer = new char[strlen(aScript)+1];
890 strcpy(aBuffer, aScript);
891 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
892 int aBufferSize = strlen(aBuffer)+1;
893 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
894 isValidScript = true;
895 return aStreamFile._retn();
898 Engines::Salome_file_ptr
899 Engines_Component_i::getInputFileToService(const char* service_name,
900 const char* Salome_file_name)
902 // Try to find the service, if it doesn't exist, we throw an exception.
903 _Service_file_map_it = _Input_Service_file_map.find(service_name);
904 if (_Service_file_map_it == _Input_Service_file_map.end()) {
905 SALOME::ExceptionStruct es;
906 es.type = SALOME::INTERNAL_ERROR;
907 es.text = "service doesn't have salome files";
908 throw SALOME::SALOME_Exception(es);
910 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
912 // Try to find the Salome_file ...
913 _Salome_file_map_it = _map->find(Salome_file_name);
914 if (_Salome_file_map_it == _map->end()) {
915 SALOME::ExceptionStruct es;
916 es.type = SALOME::INTERNAL_ERROR;
917 es.text = "service doesn't have this Salome_file";
918 throw SALOME::SALOME_Exception(es);
920 Salome_file_i * Sfile = (*_map)[Salome_file_name];
922 return Sfile->_this();
925 Engines::Salome_file_ptr
926 Engines_Component_i::setInputFileToService(const char* service_name,
927 const char* Salome_file_name)
929 // Try to find the service, if it doesn't exist, we add it.
930 _Service_file_map_it = _Input_Service_file_map.find(service_name);
931 if (_Service_file_map_it == _Input_Service_file_map.end()) {
932 _t_Salome_file_map * _map = new _t_Salome_file_map();
933 _Input_Service_file_map[service_name] = _map;
935 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
937 // Try to find the Salome_file ...
938 _Salome_file_map_it = _map->find(Salome_file_name);
939 if (_Salome_file_map_it == _map->end()) {
940 Salome_file_i * Sfile = new Salome_file_i();
941 Engines::Container_ptr container = this->GetContainerRef();
942 Sfile->setContainer(Engines::Container::_duplicate(container));
943 (*_map)[Salome_file_name] = Sfile;
946 Salome_file_i * Sfile = (*_map)[Salome_file_name];
947 return Sfile->_this();
951 Engines_Component_i::checkInputFilesToService(const char* service_name)
953 // Try to find the service, if it doesn't exist, nothing to do.
954 _Service_file_map_it = _Input_Service_file_map.find(service_name);
955 if (_Service_file_map_it != _Input_Service_file_map.end()) {
956 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
957 _t_Salome_file_map::iterator begin = _map->begin();
958 _t_Salome_file_map::iterator end = _map->end();
960 for(;begin!=end;begin++) {
961 Salome_file_i * file = begin->second;
962 std::string file_port_name = begin->first;
963 configureSalome_file(service_name, file_port_name, file);
969 Engines::Salome_file_ptr
970 Engines_Component_i::getOutputFileToService(const char* service_name,
971 const char* Salome_file_name)
973 // Try to find the service, if it doesn't exist, we throw an exception.
974 _Service_file_map_it = _Output_Service_file_map.find(service_name);
975 if (_Service_file_map_it == _Output_Service_file_map.end()) {
976 SALOME::ExceptionStruct es;
977 es.type = SALOME::INTERNAL_ERROR;
978 es.text = "service doesn't have salome files";
979 throw SALOME::SALOME_Exception(es);
981 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
983 // Try to find the Salome_file ...
984 _Salome_file_map_it = _map->find(Salome_file_name);
985 if (_Salome_file_map_it == _map->end()) {
986 SALOME::ExceptionStruct es;
987 es.type = SALOME::INTERNAL_ERROR;
988 es.text = "service doesn't have this Salome_file";
989 throw SALOME::SALOME_Exception(es);
991 Salome_file_i * Sfile = (*_map)[Salome_file_name];
993 return Sfile->_this();
996 Engines::Salome_file_ptr
997 Engines_Component_i::setOutputFileToService(const char* service_name,
998 const char* Salome_file_name)
1000 // Try to find the service, if it doesn't exist, we add it.
1001 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1002 if (_Service_file_map_it == _Output_Service_file_map.end()) {
1003 _t_Salome_file_map * _map = new _t_Salome_file_map();
1004 _Output_Service_file_map[service_name] = _map;
1006 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1008 // Try to find the Salome_file ...
1009 _Salome_file_map_it = _map->find(Salome_file_name);
1010 if (_Salome_file_map_it == _map->end()) {
1011 Salome_file_i * Sfile = new Salome_file_i();
1012 Engines::Container_ptr container = this->GetContainerRef();
1013 Sfile->setContainer(Engines::Container::_duplicate(container));
1014 (*_map)[Salome_file_name] = Sfile;
1017 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1018 return Sfile->_this();
1022 Engines_Component_i::checkOutputFilesToService(const char* service_name)
1024 // Try to find the service, if it doesn't exist, nothing to do.
1025 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1026 if (_Service_file_map_it != _Output_Service_file_map.end()) {
1027 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1028 _t_Salome_file_map::iterator begin = _map->begin();
1029 _t_Salome_file_map::iterator end = _map->end();
1031 for(;begin!=end;begin++) {
1032 Salome_file_i * file = begin->second;
1033 std::string file_port_name = begin->first;
1034 configureSalome_file(service_name, file_port_name, file);
1041 //=============================================================================
1043 * C++ method: used to configure the Salome_file into the runtime.
1044 * \param service_name name of the service that use this Salome_file
1045 * \param file_port_name name of the Salome_file
1046 * \param file Salome_file C++ object
1048 //=============================================================================
1050 Engines_Component_i::configureSalome_file(std::string service_name,
1051 std::string file_port_name,
1052 Salome_file_i * file)
1054 // By default this method does nothing
1057 //=============================================================================
1059 * C++ method: return the name of the container associated with this component
1060 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1061 * \return the container name (reformatted)
1063 //=============================================================================
1064 std::string Engines_Component_i::getContainerName()
1066 return _containerName;
1068 //=============================================================================
1070 * C++ method: set the name of the container associated with this component (attribute _containerName)
1071 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1072 * \return the container name (reformatted)
1074 //=============================================================================
1075 void Engines_Component_i::setContainerName()
1077 CORBA::String_var containerName=_container->name();
1078 std::string name(containerName);
1080 std::string::size_type slash =name.find_first_of('/');
1081 if(slash != std::string::npos)
1083 _containerName=name;