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)
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),
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);
118 const CORBA::String_var ior = _orb->object_to_string(o);
119 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession",
120 _instanceName.c_str());
123 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
126 //=============================================================================
127 /*! \brief Standard Constructor for standalone Component, used in derived class
129 * Connection to Registry and Notification
130 * \param orb Object Request broker given by Container
131 * \param poa Portable Object Adapter from Container (normally root_poa)
132 * \param container container CORBA reference
133 * \param instanceName unique instance name for this object (see Container_i)
134 * \param interfaceName component class name
135 * \param notif use of notification
136 * \param regist (true or false) use of registry (default true)
138 //=============================================================================
140 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
141 PortableServer::POA_ptr poa,
142 Engines::Container_ptr container,
143 const char *instanceName,
144 const char *interfaceName,
147 _instanceName(instanceName),
148 _interfaceName(interfaceName),
149 _myConnexionToRegistry(0),
157 _CanceledThread(false)
159 MESSAGE("Component constructor with instanceName "<< _instanceName);
160 _orb = CORBA::ORB::_duplicate(orb);
161 _poa = PortableServer::POA::_duplicate(poa);
162 _container=Engines::Container::_duplicate(container);
165 _contId=_poa->reference_to_id(container);
167 catch(PortableServer::POA::WrongAdapter)
169 //not created by this poa
172 const CORBA::String_var ior = _orb->object_to_string(_container);
174 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession", _instanceName.c_str());
175 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
179 //=============================================================================
181 * Destructor: call Container for decrement of instances count.
182 * When instances count falls to 0, the container tries to remove the
183 * component library (dlclose)
185 //=============================================================================
187 Engines_Component_i::~Engines_Component_i()
189 MESSAGE("Component destructor");
190 Engines_Container_i::decInstanceCnt(_interfaceName);
191 if(_myConnexionToRegistry)delete _myConnexionToRegistry;
192 if(_notifSupplier)delete _notifSupplier;
195 //=============================================================================
197 * CORBA method: return name of the instance, unique in this Container
199 //=============================================================================
201 char* Engines_Component_i::instanceName()
203 return CORBA::string_dup(_instanceName.c_str()) ;
206 //=============================================================================
208 * CORBA method: return name of the component class
210 //=============================================================================
212 char* Engines_Component_i::interfaceName()
214 return CORBA::string_dup(_interfaceName.c_str()) ;
217 //=============================================================================
219 * CORBA method: Get study Id
220 * \return -1: not initialised (Internal Error)
221 * 0: multistudy component instance
222 * >0: study id associated to this instance
224 //=============================================================================
226 CORBA::Long Engines_Component_i::getStudyId()
231 //=============================================================================
233 * CORBA method: Test if instance is alive and responds
235 //=============================================================================
237 void Engines_Component_i::ping()
240 MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid "
243 MESSAGE("Engines_Component_i::ping() pid "<< _getpid()<< " threadid "
244 << pthread_self().p );
248 //=============================================================================
250 * CORBA method: Deactivate this instance. CORBA object is deactivated (do not
251 * respond any more to CORBA calls), the connection to Regsitry is removed
252 * (Registry informed of deactivation), internal server reference counter on
253 * the derived servant class is decremented, to allow destruction of the class
254 * (delete) by POA, when there are no more references.
255 * -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
257 //=============================================================================
259 void Engines_Component_i::destroy()
261 MESSAGE("Engines_Component_i::destroy()");
262 //SCRUTE(_refcount_value());
264 if(_myConnexionToRegistry)delete _myConnexionToRegistry;
265 _myConnexionToRegistry = 0 ;
266 if(_notifSupplier)delete _notifSupplier;
268 _poa->deactivate_object(*_id);
271 //SCRUTE(_refcount_value());
273 //SCRUTE(_refcount_value());
274 MESSAGE("Engines_Component_i::destroyed") ;
277 //=============================================================================
279 * CORBA method: return CORBA reference of the Container
282 //=============================================================================
284 Engines::Container_ptr Engines_Component_i::GetContainerRef()
286 return Engines::Container::_duplicate(_container);
289 //=============================================================================
292 * Gives a sequence of (key=string,value=any) to the component.
293 * Base class component stores the sequence in a map.
294 * The map is cleared before.
295 * This map is for use by derived classes.
296 * \param dico sequence of (key=string,value=any)
298 //=============================================================================
300 void Engines_Component_i::setProperties(const Engines::FieldsDict& dico)
303 for (CORBA::ULong i=0; i<dico.length(); i++)
305 std::string cle(dico[i].key);
306 _fieldsDict[cle] = dico[i].value;
310 //=============================================================================
313 * returns a previously stored map (key=string,value=any) as a sequence.
314 * (see setProperties)
316 //=============================================================================
318 Engines::FieldsDict* Engines_Component_i::getProperties()
320 Engines::FieldsDict_var copie = new Engines::FieldsDict;
321 copie->length(_fieldsDict.size());
322 map<std::string,CORBA::Any>::iterator it;
324 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++)
326 std::string cle((*it).first);
327 copie[i].key = CORBA::string_dup(cle.c_str());
328 copie[i].value = _fieldsDict[cle];
330 return copie._retn();
333 //=============================================================================
335 * CORBA method: used by Supervision to give names to this instance
337 //=============================================================================
339 void Engines_Component_i::Names( const char * graphName ,
340 const char * nodeName )
342 _graphName = graphName ;
343 _nodeName = nodeName ;
344 // MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
345 // << _nodeName << "' )");
348 //=============================================================================
350 * CORBA method: used in Supervision
352 //=============================================================================
354 bool Engines_Component_i::Kill_impl()
356 // MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
357 // << " pid " << getpid() << " instanceName "
358 // << _instanceName.c_str() << " interface " << _interfaceName.c_str()
359 // << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
360 // << dec << " _ThreadId " << _ThreadId << " this " << hex << this
363 bool RetVal = false ;
365 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
367 RetVal = Killer( _ThreadId , SIGUSR2 ) ;
368 _ThreadId = (pthread_t ) -1 ;
372 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
374 RetVal = Killer( *_ThreadId , 0 ) ;
375 _ThreadId = (pthread_t* ) 0 ;
382 //=============================================================================
384 * CORBA method: used in Supervision
386 //=============================================================================
388 bool Engines_Component_i::Stop_impl()
391 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self()
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 );
397 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self().p
398 << " pid " << _getpid() << " instanceName "
399 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
400 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
401 << dec << " _ThreadId " << _ThreadId );
405 bool RetVal = false ;
407 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
409 RetVal = Killer( _ThreadId , 0 ) ;
410 _ThreadId = (pthread_t ) -1 ;
413 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
415 RetVal = Killer( *_ThreadId , 0 ) ;
416 _ThreadId = (pthread_t* ) 0 ;
422 //=============================================================================
424 * CORBA method: used in Supervision
426 //=============================================================================
428 bool Engines_Component_i::Suspend_impl()
431 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self()
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 );
437 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self().p
438 << " pid " << _getpid() << " instanceName "
439 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
440 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
441 << dec << " _ThreadId " << _ThreadId );
444 bool RetVal = false ;
446 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
448 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
458 RetVal = Killer( _ThreadId ,SIGINT ) ;
460 RetVal = Killer( *_ThreadId ,SIGINT ) ;
462 //if ( RetVal ) _Sleeping = true;
469 //=============================================================================
471 * CORBA method: used in Supervision
473 //=============================================================================
475 bool Engines_Component_i::Resume_impl()
478 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self()
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 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self().p
485 << " pid " << _getpid() << " instanceName "
486 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
487 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
488 << dec << " _ThreadId " << _ThreadId );
490 bool RetVal = false ;
492 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
494 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
510 //=============================================================================
514 //=============================================================================
516 CORBA::Long Engines_Component_i::CpuUsed_impl()
519 if ( _ThreadId || _Executed )
524 if ( pthread_self() != _ThreadId )
526 if ( pthread_self().p != _ThreadId->p )
534 // Get Cpu in the appropriate thread with that object !...
535 theEngines_Component = this ;
537 Killer( _ThreadId ,SIGUSR1 ) ;
539 Killer( *_ThreadId ,SIGUSR11 ) ;
542 cpu = _ThreadCpuUsed ;
546 _ThreadCpuUsed = CpuUsed() ;
547 cpu = _ThreadCpuUsed ;
548 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
549 // << _serviceName << " " << cpu << endl ;
554 cpu = _ThreadCpuUsed ;
555 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
556 // << _serviceName << " " << cpu<< endl ;
561 // cout<< pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId "
562 // <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<<endl;
568 //=============================================================================
570 * C++ method: return Container Servant
572 //=============================================================================
574 Engines_Container_i *Engines_Component_i::GetContainerPtr()
576 return dynamic_cast<Engines_Container_i*>(_poa->id_to_servant(*_contId)) ;
579 //=============================================================================
581 * C++ method: set study Id
582 * \param studyId 0 if instance is not associated to a study,
583 * >0 otherwise (== study id)
584 * \return true if the set of study Id is OK
585 * must be set once by Container, at instance creation,
586 * and cannot be changed after.
588 //=============================================================================
590 CORBA::Boolean Engines_Component_i::setStudyId(CORBA::Long studyId)
592 ASSERT( studyId >= 0);
593 CORBA::Boolean ret = false;
594 if (_studyId < 0) // --- not yet initialized
600 if ( _studyId == studyId) ret = true;
604 //=============================================================================
606 * C++ method: return CORBA instance id, the id is set in derived class
607 * constructor, when instance is activated.
609 //=============================================================================
611 PortableServer::ObjectId * Engines_Component_i::getId()
613 // MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
617 //=============================================================================
619 * C++ method: used by derived classes for supervision
621 //=============================================================================
623 void Engines_Component_i::beginService(const char *serviceName)
626 MESSAGE(pthread_self() << "Send BeginService notification for " <<serviceName
627 << endl << "Component instance : " << _instanceName << endl << endl);
629 MESSAGE(pthread_self().p << "Send BeginService notification for " <<serviceName
630 << endl << "Component instance : " << _instanceName << endl << 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 ") ;
655 // MESSAGE(pthread_self() << " Return from BeginService for " << serviceName
656 // << " ThreadId " << _ThreadId << " StartUsed " << _StartUsed
657 // << " _graphName " << _graphName << " _nodeName " << _nodeName );
659 // --- for supervisor : all strings given with setProperties
660 // are set in environment
661 bool overwrite = true;
662 map<std::string,CORBA::Any>::iterator it;
663 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
665 std::string cle((*it).first);
666 if ((*it).second.type()->kind() == CORBA::tk_string)
669 (*it).second >>= value;
670 // ---todo: replace __GNUC__ test by an autoconf macro AC_CHECK_FUNC.
672 // int ret = setenv(cle.c_str(), value, overwrite);
673 setenv(cle.c_str(), value, overwrite);
675 //CCRT porting : setenv not defined in stdlib.h
679 // char* cast because 1st arg of linux putenv function
680 // is not a const char* !
681 // int ret=putenv((char *)s.c_str());
682 putenv((char *)s.c_str());
683 //End of CCRT porting
685 MESSAGE("--- setenv: "<<cle<<" = "<< value);
690 //=============================================================================
692 * C++ method: used by derived classes for supervision
694 //=============================================================================
696 void Engines_Component_i::endService(const char *serviceName)
698 if ( !_CanceledThread )
699 _ThreadCpuUsed = CpuUsed_impl() ;
702 MESSAGE(pthread_self() << " Send EndService notification for " << serviceName
703 << endl << " Component instance : " << _instanceName << " StartUsed "
704 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << endl <<endl);
706 MESSAGE(pthread_self().p << " Send EndService notification for " << serviceName
707 << endl << " Component instance : " << _instanceName << " StartUsed "
708 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << endl <<endl);
713 //=============================================================================
715 * C++ method: -- CHECK IF USED --
717 //=============================================================================
719 char* Engines_Component_i::graphName()
721 return CORBA::string_dup( _graphName.c_str() ) ;
724 //=============================================================================
726 * C++ method: -- CHECK IF USED --
728 //=============================================================================
730 char* Engines_Component_i::nodeName()
732 return CORBA::string_dup( _nodeName.c_str() ) ;
735 //=============================================================================
737 * C++ method: used in Supervision (see kill_impl)
739 //=============================================================================
741 bool Engines_Component_i::Killer( pthread_t ThreadId , int signum )
751 if ( pthread_cancel( ThreadId ) )
753 perror("Killer pthread_cancel error") ;
759 MESSAGE(pthread_self() << "Killer : ThreadId " << ThreadId
760 << " pthread_canceled") ;
762 MESSAGE(pthread_self().p << "Killer : ThreadId " << ThreadId.p
763 << " pthread_canceled") ;
769 if ( pthread_kill( ThreadId , signum ) == -1 )
771 perror("Killer pthread_kill error") ;
777 MESSAGE(pthread_self() << "Killer : ThreadId " << ThreadId
778 << " pthread_killed(" << signum << ")") ;
780 MESSAGE(pthread_self().p << "Killer : ThreadId " << ThreadId.p
781 << " pthread_killed(" << signum << ")") ;
789 //=============================================================================
793 //=============================================================================
797 if ( theEngines_Component )
798 theEngines_Component->SetCurCpu() ;
801 //=============================================================================
805 //=============================================================================
807 void Engines_Component_i::SetCurCpu()
809 _ThreadCpuUsed = CpuUsed() ;
810 // MESSAGE(pthread_self() <<
811 // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ;
814 //=============================================================================
818 //=============================================================================
820 long Engines_Component_i::CpuUsed()
824 struct rusage usage ;
825 if ( _ThreadId || _Executed )
827 if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
829 perror("Engines_Component_i::CpuUsed") ;
832 cpu = usage.ru_utime.tv_sec - _StartUsed ;
833 // cout << pthread_self() << " Engines_Component_i::CpuUsed " << " "
834 // << _serviceName << usage.ru_utime.tv_sec << " - " << _StartUsed
835 // << " = " << cpu << endl ;
839 // cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId "
840 // << _ThreadId << " " << _serviceName<< " _StartUsed "
841 // << _StartUsed << endl ;
844 // NOT implementet yet
851 void CallCancelThread()
853 if ( theEngines_Component )
854 theEngines_Component->CancelThread() ;
857 //=============================================================================
861 //=============================================================================
863 void Engines_Component_i::CancelThread()
865 _CanceledThread = true;
868 //=============================================================================
870 * C++ method: Send message to event channel
872 //=============================================================================
874 void Engines_Component_i::sendMessage(const char *event_type,
877 _notifSupplier->Send(_graphName.c_str(), _nodeName.c_str(), event_type, message);
880 //=============================================================================
882 * C++ method: return standard library name built on component name
884 //=============================================================================
886 string Engines_Component_i::GetDynLibraryName(const char *componentName)
894 //=============================================================================
896 * C++ method: DumpPython default implementation
898 //=============================================================================
900 Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Object_ptr theStudy,
901 CORBA::Boolean isPublished,
902 CORBA::Boolean& isValidScript)
904 const char* aScript = "def RebuildData(theStudy): pass";
905 char* aBuffer = new char[strlen(aScript)+1];
906 strcpy(aBuffer, aScript);
907 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
908 int aBufferSize = strlen(aBuffer)+1;
909 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
910 isValidScript = true;
911 return aStreamFile._retn();
914 Engines::Salome_file_ptr
915 Engines_Component_i::getInputFileToService(const char* service_name,
916 const char* Salome_file_name)
918 // Try to find the service, if it doesn't exist, we throw an exception.
919 _Service_file_map_it = _Input_Service_file_map.find(service_name);
920 if (_Service_file_map_it == _Input_Service_file_map.end()) {
921 SALOME::ExceptionStruct es;
922 es.type = SALOME::INTERNAL_ERROR;
923 es.text = "service doesn't have salome files";
924 throw SALOME::SALOME_Exception(es);
926 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
928 // Try to find the Salome_file ...
929 _Salome_file_map_it = _map->find(Salome_file_name);
930 if (_Salome_file_map_it == _map->end()) {
931 SALOME::ExceptionStruct es;
932 es.type = SALOME::INTERNAL_ERROR;
933 es.text = "service doesn't have this Salome_file";
934 throw SALOME::SALOME_Exception(es);
936 Salome_file_i * Sfile = (*_map)[Salome_file_name];
938 return Sfile->_this();
941 Engines::Salome_file_ptr
942 Engines_Component_i::setInputFileToService(const char* service_name,
943 const char* Salome_file_name)
945 // Try to find the service, if it doesn't exist, we add it.
946 _Service_file_map_it = _Input_Service_file_map.find(service_name);
947 if (_Service_file_map_it == _Input_Service_file_map.end()) {
948 _t_Salome_file_map * _map = new _t_Salome_file_map();
949 _Input_Service_file_map[service_name] = _map;
951 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
953 // Try to find the Salome_file ...
954 _Salome_file_map_it = _map->find(Salome_file_name);
955 if (_Salome_file_map_it == _map->end()) {
956 Salome_file_i * Sfile = new Salome_file_i();
957 Engines::Container_ptr container = this->GetContainerRef();
958 Sfile->setContainer(Engines::Container::_duplicate(container));
959 (*_map)[Salome_file_name] = Sfile;
962 Salome_file_i * Sfile = (*_map)[Salome_file_name];
963 return Sfile->_this();
967 Engines_Component_i::checkInputFilesToService(const char* service_name)
969 // Try to find the service, if it doesn't exist, nothing to do.
970 _Service_file_map_it = _Input_Service_file_map.find(service_name);
971 if (_Service_file_map_it != _Input_Service_file_map.end()) {
972 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
973 _t_Salome_file_map::iterator begin = _map->begin();
974 _t_Salome_file_map::iterator end = _map->end();
976 for(;begin!=end;begin++) {
977 Salome_file_i * file = begin->second;
978 std::string file_port_name = begin->first;
979 configureSalome_file(service_name, file_port_name, file);
985 Engines::Salome_file_ptr
986 Engines_Component_i::getOutputFileToService(const char* service_name,
987 const char* Salome_file_name)
989 // Try to find the service, if it doesn't exist, we throw an exception.
990 _Service_file_map_it = _Output_Service_file_map.find(service_name);
991 if (_Service_file_map_it == _Output_Service_file_map.end()) {
992 SALOME::ExceptionStruct es;
993 es.type = SALOME::INTERNAL_ERROR;
994 es.text = "service doesn't have salome files";
995 throw SALOME::SALOME_Exception(es);
997 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
999 // Try to find the Salome_file ...
1000 _Salome_file_map_it = _map->find(Salome_file_name);
1001 if (_Salome_file_map_it == _map->end()) {
1002 SALOME::ExceptionStruct es;
1003 es.type = SALOME::INTERNAL_ERROR;
1004 es.text = "service doesn't have this Salome_file";
1005 throw SALOME::SALOME_Exception(es);
1007 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1009 return Sfile->_this();
1012 Engines::Salome_file_ptr
1013 Engines_Component_i::setOutputFileToService(const char* service_name,
1014 const char* Salome_file_name)
1016 // Try to find the service, if it doesn't exist, we add it.
1017 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1018 if (_Service_file_map_it == _Output_Service_file_map.end()) {
1019 _t_Salome_file_map * _map = new _t_Salome_file_map();
1020 _Output_Service_file_map[service_name] = _map;
1022 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1024 // Try to find the Salome_file ...
1025 _Salome_file_map_it = _map->find(Salome_file_name);
1026 if (_Salome_file_map_it == _map->end()) {
1027 Salome_file_i * Sfile = new Salome_file_i();
1028 Engines::Container_ptr container = this->GetContainerRef();
1029 Sfile->setContainer(Engines::Container::_duplicate(container));
1030 (*_map)[Salome_file_name] = Sfile;
1033 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1034 return Sfile->_this();
1038 Engines_Component_i::checkOutputFilesToService(const char* service_name)
1040 // Try to find the service, if it doesn't exist, nothing to do.
1041 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1042 if (_Service_file_map_it != _Output_Service_file_map.end()) {
1043 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1044 _t_Salome_file_map::iterator begin = _map->begin();
1045 _t_Salome_file_map::iterator end = _map->end();
1047 for(;begin!=end;begin++) {
1048 Salome_file_i * file = begin->second;
1049 std::string file_port_name = begin->first;
1050 configureSalome_file(service_name, file_port_name, file);
1057 //=============================================================================
1059 * C++ method: used to configure the Salome_file into the runtime.
1060 * \param service_name name of the service that use this Salome_file
1061 * \param file_port_name name of the Salome_file
1062 * \param file Salome_file C++ object
1064 //=============================================================================
1066 Engines_Component_i::configureSalome_file(std::string service_name,
1067 std::string file_port_name,
1068 Salome_file_i * file)
1070 // By default this method does nothing