1 // SALOME Container : implementation of container and engine for Kernel
3 // Copyright (C) 2003 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
24 // File : Component_i.cxx
25 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
29 //#define private protected // for pd_refCount trace
30 #include "SALOME_Component_i.hxx"
31 #include "SALOME_Container_i.hxx"
32 #include "RegistryConnexion.hxx"
39 #include "utilities.h"
43 #include <sys/resource.h>
46 #include <sys/timeb.h>
54 extern bool _Sleeping ;
55 static Engines_Component_i * theEngines_Component ;
57 bool Engines_Component_i::_isMultiStudy = true;
58 bool Engines_Component_i::_isMultiInstance = false;
60 //=============================================================================
62 * Default constructor, not for use
64 //=============================================================================
66 Engines_Component_i::Engines_Component_i()
69 MESSAGE("Default Constructor, not for normal use...");
72 //=============================================================================
74 * Standard Constructor for generic Component, used in derived class
75 * Connection to Registry and Notification
76 * \param orb Object Request broker given by Container
77 * \param poa Portable Object Adapter from Container (normally root_poa)
78 * \param contId container CORBA id inside the server
79 * \param instanceName unique instance name for this object (see Container_i)
80 * \param interfaceName component class name
81 * \param notif use of notification
83 //=============================================================================
85 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
86 PortableServer::POA_ptr poa,
87 PortableServer::ObjectId * contId,
88 const char *instanceName,
89 const char *interfaceName,
91 _instanceName(instanceName),
92 _interfaceName(interfaceName),
93 _myConnexionToRegistry(0),
100 _CanceledThread(false)
102 MESSAGE("Component constructor with instanceName "<< _instanceName);
103 //SCRUTE(pd_refCount);
104 _orb = CORBA::ORB::_duplicate(orb);
105 _poa = PortableServer::POA::_duplicate(poa);
107 CORBA::Object_var o = _poa->id_to_reference(*contId); // container ior...
108 const CORBA::String_var ior = _orb->object_to_string(o);
109 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession",
110 _instanceName.c_str());
112 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
113 //SCRUTE(pd_refCount);
116 //=============================================================================
118 * Standard constructor for parallel component
119 * Connection Notification (no connection to Registry !)
120 * \param orb Object Request broker given by Container
121 * \param poa Portable Object Adapter from Container (normally root_poa)
122 * \param contId container CORBA id inside the server
123 * \param instanceName unique instance name for this object (see Container_i)
124 * \param interfaceName component class name
125 * \param flag not used...
126 * \param notif use of notification
128 //=============================================================================
130 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
131 PortableServer::POA_ptr poa,
132 PortableServer::ObjectId * contId,
133 const char *instanceName,
134 const char *interfaceName,
137 _instanceName(instanceName),
138 _interfaceName(interfaceName),
139 _myConnexionToRegistry(0),
146 _CanceledThread(false)
148 _orb = CORBA::ORB::_duplicate(orb);
149 _poa = PortableServer::POA::_duplicate(poa);
152 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
155 //=============================================================================
157 * Destructor: call Container for decrement of instances count.
158 * When instances count falls to 0, the container tries to remove the
159 * component library (dlclose)
161 //=============================================================================
163 Engines_Component_i::~Engines_Component_i()
165 MESSAGE("Component destructor");
166 Engines_Container_i::decInstanceCnt(_interfaceName);
169 //=============================================================================
171 * CORBA method: return name of the instance, unique in this Container
173 //=============================================================================
175 char* Engines_Component_i::instanceName()
177 return CORBA::string_dup(_instanceName.c_str()) ;
180 //=============================================================================
182 * CORBA method: return name of the component class
184 //=============================================================================
186 char* Engines_Component_i::interfaceName()
188 return CORBA::string_dup(_interfaceName.c_str()) ;
191 //=============================================================================
193 * CORBA method: Get study Id
194 * \return -1: not initialised (Internal Error)
195 * 0: multistudy component instance
196 * >0: study id associated to this instance
198 //=============================================================================
200 CORBA::Long Engines_Component_i::getStudyId()
205 //=============================================================================
207 * CORBA method: Test if instance is alive and responds
209 //=============================================================================
211 void Engines_Component_i::ping()
214 MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid "
217 MESSAGE("Engines_Component_i::ping() pid "<< _getpid()<< " threadid "
218 << pthread_self().p );
222 //=============================================================================
224 * CORBA method: Deactivate this instance. CORBA object is deactivated (do not
225 * respond any more to CORBA calls), the connection to Regsitry is removed
226 * (Registry informed of deactivation), internal server reference counter on
227 * the derived servant class is decremented, to allow destruction of the class
228 * (delete) by POA, when there are no more references.
229 * -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
231 //=============================================================================
233 void Engines_Component_i::destroy()
235 MESSAGE("Engines_Component_i::destroy()");
236 //SCRUTE(pd_refCount);
238 delete _notifSupplier;
241 delete _myConnexionToRegistry;
242 _myConnexionToRegistry = 0 ;
243 _poa->deactivate_object(*_id) ;
244 CORBA::release(_poa) ;
246 //SCRUTE(pd_refCount);
247 _thisObj->_remove_ref();
248 //SCRUTE(pd_refCount);
249 MESSAGE("Engines_Component_i::destroyed") ;
252 //=============================================================================
254 * CORBA method: return CORBA reference of the Container
257 //=============================================================================
259 Engines::Container_ptr Engines_Component_i::GetContainerRef()
261 // MESSAGE("Engines_Component_i::GetContainerRef");
262 CORBA::Object_ptr o = _poa->id_to_reference(*_contId) ;
263 return Engines::Container::_narrow(o);
266 //=============================================================================
269 * Gives a sequence of (key=string,value=any) to the component.
270 * Base class component stores the sequence in a map.
271 * The map is cleared before.
272 * This map is for use by derived classes.
273 * \param dico sequence of (key=string,value=any)
275 //=============================================================================
277 void Engines_Component_i::setProperties(const Engines::FieldsDict& dico)
280 for (CORBA::ULong i=0; i<dico.length(); i++)
282 std::string cle(dico[i].key);
283 _fieldsDict[cle] = dico[i].value;
287 //=============================================================================
290 * returns a previously stored map (key=string,value=any) as a sequence.
291 * (see setProperties)
293 //=============================================================================
295 Engines::FieldsDict* Engines_Component_i::getProperties()
297 Engines::FieldsDict_var copie = new Engines::FieldsDict;
298 copie->length(_fieldsDict.size());
299 map<std::string,CORBA::Any>::iterator it;
301 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++)
303 std::string cle((*it).first);
304 copie[i].key = CORBA::string_dup(cle.c_str());
305 copie[i].value = _fieldsDict[cle];
307 return copie._retn();
310 //=============================================================================
312 * CORBA method: used by Supervision to give names to this instance
314 //=============================================================================
316 void Engines_Component_i::Names( const char * graphName ,
317 const char * nodeName )
319 _graphName = graphName ;
320 _nodeName = nodeName ;
321 // MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
322 // << _nodeName << "' )");
325 //=============================================================================
327 * CORBA method: used in Supervision
329 //=============================================================================
331 bool Engines_Component_i::Kill_impl()
333 // MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
334 // << " pid " << getpid() << " instanceName "
335 // << _instanceName.c_str() << " interface " << _interfaceName.c_str()
336 // << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
337 // << dec << " _ThreadId " << _ThreadId << " this " << hex << this
340 bool RetVal = false ;
342 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
344 RetVal = Killer( _ThreadId , SIGUSR2 ) ;
345 _ThreadId = (pthread_t ) -1 ;
349 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
351 RetVal = Killer( *_ThreadId , 0 ) ;
352 _ThreadId = (pthread_t* ) 0 ;
359 //=============================================================================
361 * CORBA method: used in Supervision
363 //=============================================================================
365 bool Engines_Component_i::Stop_impl()
368 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self()
369 << " pid " << getpid() << " instanceName "
370 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
371 << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
372 << dec << " _ThreadId " << _ThreadId );
374 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self().p
375 << " pid " << _getpid() << " instanceName "
376 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
377 << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
378 << dec << " _ThreadId " << _ThreadId );
382 bool RetVal = false ;
384 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
386 RetVal = Killer( _ThreadId , 0 ) ;
387 _ThreadId = (pthread_t ) -1 ;
390 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
392 RetVal = Killer( *_ThreadId , 0 ) ;
393 _ThreadId = (pthread_t* ) 0 ;
399 //=============================================================================
401 * CORBA method: used in Supervision
403 //=============================================================================
405 bool Engines_Component_i::Suspend_impl()
408 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self()
409 << " pid " << getpid() << " instanceName "
410 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
411 << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
412 << dec << " _ThreadId " << _ThreadId );
414 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self().p
415 << " pid " << _getpid() << " instanceName "
416 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
417 << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
418 << dec << " _ThreadId " << _ThreadId );
421 bool RetVal = false ;
423 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
425 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
435 RetVal = Killer( _ThreadId ,SIGINT ) ;
437 RetVal = Killer( *_ThreadId ,SIGINT ) ;
439 //if ( RetVal ) _Sleeping = true;
446 //=============================================================================
448 * CORBA method: used in Supervision
450 //=============================================================================
452 bool Engines_Component_i::Resume_impl()
455 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self()
456 << " pid " << getpid() << " instanceName "
457 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
458 << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
459 << dec << " _ThreadId " << _ThreadId );
461 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self().p
462 << " pid " << _getpid() << " instanceName "
463 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
464 << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
465 << dec << " _ThreadId " << _ThreadId );
467 bool RetVal = false ;
469 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
471 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
487 //=============================================================================
491 //=============================================================================
493 CORBA::Long Engines_Component_i::CpuUsed_impl()
496 if ( _ThreadId || _Executed )
501 if ( pthread_self() != _ThreadId )
503 if ( pthread_self().p != _ThreadId->p )
511 // Get Cpu in the appropriate thread with that object !...
512 theEngines_Component = this ;
514 Killer( _ThreadId ,SIGUSR1 ) ;
516 Killer( *_ThreadId ,SIGUSR11 ) ;
519 cpu = _ThreadCpuUsed ;
523 _ThreadCpuUsed = CpuUsed() ;
524 cpu = _ThreadCpuUsed ;
525 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
526 // << _serviceName << " " << cpu << endl ;
531 cpu = _ThreadCpuUsed ;
532 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
533 // << _serviceName << " " << cpu<< endl ;
538 // cout<< pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId "
539 // <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<<endl;
545 //=============================================================================
547 * C++ method: return Container Servant
549 //=============================================================================
551 Engines_Container_i *Engines_Component_i::GetContainerPtr()
553 return dynamic_cast<Engines_Container_i*>(_poa->id_to_servant(*_contId)) ;
556 //=============================================================================
558 * C++ method: set study Id
559 * \param studyId 0 if instance is not associated to a study,
560 * >0 otherwise (== study id)
561 * \return true if the set of study Id is OK
562 * must be set once by Container, at instance creation,
563 * and cannot be changed after.
565 //=============================================================================
567 CORBA::Boolean Engines_Component_i::setStudyId(CORBA::Long studyId)
569 ASSERT( studyId >= 0);
570 CORBA::Boolean ret = false;
571 if (_studyId < 0) // --- not yet initialized
577 if ( _studyId == studyId) ret = true;
581 //=============================================================================
583 * C++ method: return CORBA instance id, the id is set in derived class
584 * constructor, when instance is activated.
586 //=============================================================================
588 PortableServer::ObjectId * Engines_Component_i::getId()
590 // MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
594 //=============================================================================
596 * C++ method: used by derived classes for supervision
598 //=============================================================================
600 void Engines_Component_i::beginService(const char *serviceName)
603 MESSAGE(pthread_self() << "Send BeginService notification for " <<serviceName
604 << endl << "Component instance : " << _instanceName << endl << endl);
606 MESSAGE(pthread_self().p << "Send BeginService notification for " <<serviceName
607 << endl << "Component instance : " << _instanceName << endl << endl);
610 _ThreadId = pthread_self() ;
612 _ThreadId = new pthread_t;
613 _ThreadId->p = pthread_self().p ;
614 _ThreadId->x = pthread_self().x ;
617 _StartUsed = CpuUsed_impl() ;
620 _serviceName = serviceName ;
621 theEngines_Component = this ;
622 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) )
624 perror("pthread_setcanceltype ") ;
627 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) )
629 perror("pthread_setcancelstate ") ;
632 // MESSAGE(pthread_self() << " Return from BeginService for " << serviceName
633 // << " ThreadId " << _ThreadId << " StartUsed " << _StartUsed
634 // << " _graphName " << _graphName << " _nodeName " << _nodeName );
636 // --- for supervisor : all strings given with setProperties
637 // are set in environment
638 bool overwrite = true;
639 map<std::string,CORBA::Any>::iterator it;
640 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
642 std::string cle((*it).first);
643 if ((*it).second.type()->kind() == CORBA::tk_string)
646 (*it).second >>= value;
647 // ---todo: replace __GNUC__ test by an autoconf macro AC_CHECK_FUNC.
649 // int ret = setenv(cle.c_str(), value, overwrite);
650 setenv(cle.c_str(), value, overwrite);
652 //CCRT porting : setenv not defined in stdlib.h
656 // char* cast because 1st arg of linux putenv function
657 // is not a const char* !
658 // int ret=putenv((char *)s.c_str());
659 putenv((char *)s.c_str());
660 //End of CCRT porting
662 MESSAGE("--- setenv: "<<cle<<" = "<< value);
667 //=============================================================================
669 * C++ method: used by derived classes for supervision
671 //=============================================================================
673 void Engines_Component_i::endService(const char *serviceName)
675 if ( !_CanceledThread )
676 _ThreadCpuUsed = CpuUsed_impl() ;
679 MESSAGE(pthread_self() << " Send EndService notification for " << serviceName
680 << endl << " Component instance : " << _instanceName << " StartUsed "
681 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << endl <<endl);
683 MESSAGE(pthread_self().p << " Send EndService notification for " << serviceName
684 << endl << " Component instance : " << _instanceName << " StartUsed "
685 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << endl <<endl);
690 //=============================================================================
692 * C++ method: -- CHECK IF USED --
694 //=============================================================================
696 char* Engines_Component_i::graphName()
698 return CORBA::string_dup( _graphName.c_str() ) ;
701 //=============================================================================
703 * C++ method: -- CHECK IF USED --
705 //=============================================================================
707 char* Engines_Component_i::nodeName()
709 return CORBA::string_dup( _nodeName.c_str() ) ;
712 //=============================================================================
714 * C++ method: used in Supervision (see kill_impl)
716 //=============================================================================
718 bool Engines_Component_i::Killer( pthread_t ThreadId , int signum )
728 if ( pthread_cancel( ThreadId ) )
730 perror("Killer pthread_cancel error") ;
736 MESSAGE(pthread_self() << "Killer : ThreadId " << ThreadId
737 << " pthread_canceled") ;
739 MESSAGE(pthread_self().p << "Killer : ThreadId " << ThreadId.p
740 << " pthread_canceled") ;
746 if ( pthread_kill( ThreadId , signum ) == -1 )
748 perror("Killer pthread_kill error") ;
754 MESSAGE(pthread_self() << "Killer : ThreadId " << ThreadId
755 << " pthread_killed(" << signum << ")") ;
757 MESSAGE(pthread_self().p << "Killer : ThreadId " << ThreadId.p
758 << " pthread_killed(" << signum << ")") ;
766 //=============================================================================
770 //=============================================================================
774 if ( theEngines_Component )
775 theEngines_Component->SetCurCpu() ;
778 //=============================================================================
782 //=============================================================================
784 void Engines_Component_i::SetCurCpu()
786 _ThreadCpuUsed = CpuUsed() ;
787 // MESSAGE(pthread_self() <<
788 // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ;
791 //=============================================================================
795 //=============================================================================
797 long Engines_Component_i::CpuUsed()
801 struct rusage usage ;
802 if ( _ThreadId || _Executed )
804 if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
806 perror("Engines_Component_i::CpuUsed") ;
809 cpu = usage.ru_utime.tv_sec - _StartUsed ;
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(), nodeName(), 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