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(pd_refCount);
264 if(_myConnexionToRegistry)delete _myConnexionToRegistry;
265 _myConnexionToRegistry = 0 ;
266 if(_notifSupplier)delete _notifSupplier;
270 //SCRUTE(pd_refCount);
271 _thisObj->_remove_ref();
272 //SCRUTE(pd_refCount);
273 MESSAGE("Engines_Component_i::destroyed") ;
276 //=============================================================================
278 * CORBA method: return CORBA reference of the Container
281 //=============================================================================
283 Engines::Container_ptr Engines_Component_i::GetContainerRef()
285 return Engines::Container::_duplicate(_container);
288 //=============================================================================
291 * Gives a sequence of (key=string,value=any) to the component.
292 * Base class component stores the sequence in a map.
293 * The map is cleared before.
294 * This map is for use by derived classes.
295 * \param dico sequence of (key=string,value=any)
297 //=============================================================================
299 void Engines_Component_i::setProperties(const Engines::FieldsDict& dico)
302 for (CORBA::ULong i=0; i<dico.length(); i++)
304 std::string cle(dico[i].key);
305 _fieldsDict[cle] = dico[i].value;
309 //=============================================================================
312 * returns a previously stored map (key=string,value=any) as a sequence.
313 * (see setProperties)
315 //=============================================================================
317 Engines::FieldsDict* Engines_Component_i::getProperties()
319 Engines::FieldsDict_var copie = new Engines::FieldsDict;
320 copie->length(_fieldsDict.size());
321 map<std::string,CORBA::Any>::iterator it;
323 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++)
325 std::string cle((*it).first);
326 copie[i].key = CORBA::string_dup(cle.c_str());
327 copie[i].value = _fieldsDict[cle];
329 return copie._retn();
332 //=============================================================================
334 * CORBA method: used by Supervision to give names to this instance
336 //=============================================================================
338 void Engines_Component_i::Names( const char * graphName ,
339 const char * nodeName )
341 _graphName = graphName ;
342 _nodeName = nodeName ;
343 // MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
344 // << _nodeName << "' )");
347 //=============================================================================
349 * CORBA method: used in Supervision
351 //=============================================================================
353 bool Engines_Component_i::Kill_impl()
355 // MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
356 // << " pid " << getpid() << " instanceName "
357 // << _instanceName.c_str() << " interface " << _interfaceName.c_str()
358 // << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
359 // << dec << " _ThreadId " << _ThreadId << " this " << hex << this
362 bool RetVal = false ;
364 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
366 RetVal = Killer( _ThreadId , SIGUSR2 ) ;
367 _ThreadId = (pthread_t ) -1 ;
371 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
373 RetVal = Killer( *_ThreadId , 0 ) ;
374 _ThreadId = (pthread_t* ) 0 ;
381 //=============================================================================
383 * CORBA method: used in Supervision
385 //=============================================================================
387 bool Engines_Component_i::Stop_impl()
390 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self()
391 << " pid " << getpid() << " instanceName "
392 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
393 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
394 << dec << " _ThreadId " << _ThreadId );
396 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self().p
397 << " pid " << _getpid() << " instanceName "
398 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
399 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
400 << dec << " _ThreadId " << _ThreadId );
404 bool RetVal = false ;
406 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
408 RetVal = Killer( _ThreadId , 0 ) ;
409 _ThreadId = (pthread_t ) -1 ;
412 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
414 RetVal = Killer( *_ThreadId , 0 ) ;
415 _ThreadId = (pthread_t* ) 0 ;
421 //=============================================================================
423 * CORBA method: used in Supervision
425 //=============================================================================
427 bool Engines_Component_i::Suspend_impl()
430 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self()
431 << " pid " << getpid() << " instanceName "
432 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
433 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
434 << dec << " _ThreadId " << _ThreadId );
436 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self().p
437 << " pid " << _getpid() << " instanceName "
438 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
439 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
440 << dec << " _ThreadId " << _ThreadId );
443 bool RetVal = false ;
445 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
447 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
457 RetVal = Killer( _ThreadId ,SIGINT ) ;
459 RetVal = Killer( *_ThreadId ,SIGINT ) ;
461 //if ( RetVal ) _Sleeping = true;
468 //=============================================================================
470 * CORBA method: used in Supervision
472 //=============================================================================
474 bool Engines_Component_i::Resume_impl()
477 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self()
478 << " pid " << getpid() << " instanceName "
479 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
480 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
481 << dec << " _ThreadId " << _ThreadId );
483 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self().p
484 << " pid " << _getpid() << " instanceName "
485 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
486 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
487 << dec << " _ThreadId " << _ThreadId );
489 bool RetVal = false ;
491 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
493 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
509 //=============================================================================
513 //=============================================================================
515 CORBA::Long Engines_Component_i::CpuUsed_impl()
518 if ( _ThreadId || _Executed )
523 if ( pthread_self() != _ThreadId )
525 if ( pthread_self().p != _ThreadId->p )
533 // Get Cpu in the appropriate thread with that object !...
534 theEngines_Component = this ;
536 Killer( _ThreadId ,SIGUSR1 ) ;
538 Killer( *_ThreadId ,SIGUSR11 ) ;
541 cpu = _ThreadCpuUsed ;
545 _ThreadCpuUsed = CpuUsed() ;
546 cpu = _ThreadCpuUsed ;
547 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
548 // << _serviceName << " " << cpu << endl ;
553 cpu = _ThreadCpuUsed ;
554 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
555 // << _serviceName << " " << cpu<< endl ;
560 // cout<< pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId "
561 // <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<<endl;
567 //=============================================================================
569 * C++ method: return Container Servant
571 //=============================================================================
573 Engines_Container_i *Engines_Component_i::GetContainerPtr()
575 return dynamic_cast<Engines_Container_i*>(_poa->id_to_servant(*_contId)) ;
578 //=============================================================================
580 * C++ method: set study Id
581 * \param studyId 0 if instance is not associated to a study,
582 * >0 otherwise (== study id)
583 * \return true if the set of study Id is OK
584 * must be set once by Container, at instance creation,
585 * and cannot be changed after.
587 //=============================================================================
589 CORBA::Boolean Engines_Component_i::setStudyId(CORBA::Long studyId)
591 ASSERT( studyId >= 0);
592 CORBA::Boolean ret = false;
593 if (_studyId < 0) // --- not yet initialized
599 if ( _studyId == studyId) ret = true;
603 //=============================================================================
605 * C++ method: return CORBA instance id, the id is set in derived class
606 * constructor, when instance is activated.
608 //=============================================================================
610 PortableServer::ObjectId * Engines_Component_i::getId()
612 // MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
616 //=============================================================================
618 * C++ method: used by derived classes for supervision
620 //=============================================================================
622 void Engines_Component_i::beginService(const char *serviceName)
625 MESSAGE(pthread_self() << "Send BeginService notification for " <<serviceName
626 << endl << "Component instance : " << _instanceName << endl << endl);
628 MESSAGE(pthread_self().p << "Send BeginService notification for " <<serviceName
629 << endl << "Component instance : " << _instanceName << endl << endl);
632 _ThreadId = pthread_self() ;
634 _ThreadId = new pthread_t;
635 _ThreadId->p = pthread_self().p ;
636 _ThreadId->x = pthread_self().x ;
639 _StartUsed = CpuUsed_impl() ;
642 _serviceName = serviceName ;
643 theEngines_Component = this ;
644 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) )
646 perror("pthread_setcanceltype ") ;
649 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) )
651 perror("pthread_setcancelstate ") ;
654 // MESSAGE(pthread_self() << " Return from BeginService for " << serviceName
655 // << " ThreadId " << _ThreadId << " StartUsed " << _StartUsed
656 // << " _graphName " << _graphName << " _nodeName " << _nodeName );
658 // --- for supervisor : all strings given with setProperties
659 // are set in environment
660 bool overwrite = true;
661 map<std::string,CORBA::Any>::iterator it;
662 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
664 std::string cle((*it).first);
665 if ((*it).second.type()->kind() == CORBA::tk_string)
668 (*it).second >>= value;
669 // ---todo: replace __GNUC__ test by an autoconf macro AC_CHECK_FUNC.
671 // int ret = setenv(cle.c_str(), value, overwrite);
672 setenv(cle.c_str(), value, overwrite);
674 //CCRT porting : setenv not defined in stdlib.h
678 // char* cast because 1st arg of linux putenv function
679 // is not a const char* !
680 // int ret=putenv((char *)s.c_str());
681 putenv((char *)s.c_str());
682 //End of CCRT porting
684 MESSAGE("--- setenv: "<<cle<<" = "<< value);
689 //=============================================================================
691 * C++ method: used by derived classes for supervision
693 //=============================================================================
695 void Engines_Component_i::endService(const char *serviceName)
697 if ( !_CanceledThread )
698 _ThreadCpuUsed = CpuUsed_impl() ;
701 MESSAGE(pthread_self() << " Send EndService notification for " << serviceName
702 << endl << " Component instance : " << _instanceName << " StartUsed "
703 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << endl <<endl);
705 MESSAGE(pthread_self().p << " Send EndService notification for " << serviceName
706 << endl << " Component instance : " << _instanceName << " StartUsed "
707 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << endl <<endl);
712 //=============================================================================
714 * C++ method: -- CHECK IF USED --
716 //=============================================================================
718 char* Engines_Component_i::graphName()
720 return CORBA::string_dup( _graphName.c_str() ) ;
723 //=============================================================================
725 * C++ method: -- CHECK IF USED --
727 //=============================================================================
729 char* Engines_Component_i::nodeName()
731 return CORBA::string_dup( _nodeName.c_str() ) ;
734 //=============================================================================
736 * C++ method: used in Supervision (see kill_impl)
738 //=============================================================================
740 bool Engines_Component_i::Killer( pthread_t ThreadId , int signum )
750 if ( pthread_cancel( ThreadId ) )
752 perror("Killer pthread_cancel error") ;
758 MESSAGE(pthread_self() << "Killer : ThreadId " << ThreadId
759 << " pthread_canceled") ;
761 MESSAGE(pthread_self().p << "Killer : ThreadId " << ThreadId.p
762 << " pthread_canceled") ;
768 if ( pthread_kill( ThreadId , signum ) == -1 )
770 perror("Killer pthread_kill error") ;
776 MESSAGE(pthread_self() << "Killer : ThreadId " << ThreadId
777 << " pthread_killed(" << signum << ")") ;
779 MESSAGE(pthread_self().p << "Killer : ThreadId " << ThreadId.p
780 << " pthread_killed(" << signum << ")") ;
788 //=============================================================================
792 //=============================================================================
796 if ( theEngines_Component )
797 theEngines_Component->SetCurCpu() ;
800 //=============================================================================
804 //=============================================================================
806 void Engines_Component_i::SetCurCpu()
808 _ThreadCpuUsed = CpuUsed() ;
809 // MESSAGE(pthread_self() <<
810 // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ;
813 //=============================================================================
817 //=============================================================================
819 long Engines_Component_i::CpuUsed()
823 struct rusage usage ;
824 if ( _ThreadId || _Executed )
826 if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
828 perror("Engines_Component_i::CpuUsed") ;
831 cpu = usage.ru_utime.tv_sec - _StartUsed ;
832 // cout << pthread_self() << " Engines_Component_i::CpuUsed " << " "
833 // << _serviceName << usage.ru_utime.tv_sec << " - " << _StartUsed
834 // << " = " << cpu << endl ;
838 // cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId "
839 // << _ThreadId << " " << _serviceName<< " _StartUsed "
840 // << _StartUsed << endl ;
843 // NOT implementet yet
850 void CallCancelThread()
852 if ( theEngines_Component )
853 theEngines_Component->CancelThread() ;
856 //=============================================================================
860 //=============================================================================
862 void Engines_Component_i::CancelThread()
864 _CanceledThread = true;
867 //=============================================================================
869 * C++ method: Send message to event channel
871 //=============================================================================
873 void Engines_Component_i::sendMessage(const char *event_type,
876 _notifSupplier->Send(_graphName.c_str(), _nodeName.c_str(), event_type, message);
879 //=============================================================================
881 * C++ method: return standard library name built on component name
883 //=============================================================================
885 string Engines_Component_i::GetDynLibraryName(const char *componentName)
893 //=============================================================================
895 * C++ method: DumpPython default implementation
897 //=============================================================================
899 Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Object_ptr theStudy,
900 CORBA::Boolean isPublished,
901 CORBA::Boolean& isValidScript)
903 const char* aScript = "def RebuildData(theStudy): pass";
904 char* aBuffer = new char[strlen(aScript)+1];
905 strcpy(aBuffer, aScript);
906 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
907 int aBufferSize = strlen(aBuffer)+1;
908 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
909 isValidScript = true;
910 return aStreamFile._retn();
913 Engines::Salome_file_ptr
914 Engines_Component_i::getInputFileToService(const char* service_name,
915 const char* Salome_file_name)
917 // Try to find the service, if it doesn't exist, we throw an exception.
918 _Service_file_map_it = _Input_Service_file_map.find(service_name);
919 if (_Service_file_map_it == _Input_Service_file_map.end()) {
920 SALOME::ExceptionStruct es;
921 es.type = SALOME::INTERNAL_ERROR;
922 es.text = "service doesn't have salome files";
923 throw SALOME::SALOME_Exception(es);
925 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
927 // Try to find the Salome_file ...
928 _Salome_file_map_it = _map->find(Salome_file_name);
929 if (_Salome_file_map_it == _map->end()) {
930 SALOME::ExceptionStruct es;
931 es.type = SALOME::INTERNAL_ERROR;
932 es.text = "service doesn't have this Salome_file";
933 throw SALOME::SALOME_Exception(es);
935 Salome_file_i * Sfile = (*_map)[Salome_file_name];
937 return Sfile->_this();
940 Engines::Salome_file_ptr
941 Engines_Component_i::setInputFileToService(const char* service_name,
942 const char* Salome_file_name)
944 // Try to find the service, if it doesn't exist, we add it.
945 _Service_file_map_it = _Input_Service_file_map.find(service_name);
946 if (_Service_file_map_it == _Input_Service_file_map.end()) {
947 _t_Salome_file_map * _map = new _t_Salome_file_map();
948 _Input_Service_file_map[service_name] = _map;
950 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
952 // Try to find the Salome_file ...
953 _Salome_file_map_it = _map->find(Salome_file_name);
954 if (_Salome_file_map_it == _map->end()) {
955 Salome_file_i * Sfile = new Salome_file_i();
956 Engines::Container_ptr container = this->GetContainerRef();
957 Sfile->setContainer(Engines::Container::_duplicate(container));
958 (*_map)[Salome_file_name] = Sfile;
961 Salome_file_i * Sfile = (*_map)[Salome_file_name];
962 return Sfile->_this();
966 Engines_Component_i::checkInputFilesToService(const char* service_name)
968 // Try to find the service, if it doesn't exist, nothing to do.
969 _Service_file_map_it = _Input_Service_file_map.find(service_name);
970 if (_Service_file_map_it != _Input_Service_file_map.end()) {
971 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
972 _t_Salome_file_map::iterator begin = _map->begin();
973 _t_Salome_file_map::iterator end = _map->end();
975 for(;begin!=end;begin++) {
976 Salome_file_i * file = begin->second;
977 std::string file_port_name = begin->first;
978 configureSalome_file(service_name, file_port_name, file);
984 Engines::Salome_file_ptr
985 Engines_Component_i::getOutputFileToService(const char* service_name,
986 const char* Salome_file_name)
988 // Try to find the service, if it doesn't exist, we throw an exception.
989 _Service_file_map_it = _Output_Service_file_map.find(service_name);
990 if (_Service_file_map_it == _Output_Service_file_map.end()) {
991 SALOME::ExceptionStruct es;
992 es.type = SALOME::INTERNAL_ERROR;
993 es.text = "service doesn't have salome files";
994 throw SALOME::SALOME_Exception(es);
996 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
998 // Try to find the Salome_file ...
999 _Salome_file_map_it = _map->find(Salome_file_name);
1000 if (_Salome_file_map_it == _map->end()) {
1001 SALOME::ExceptionStruct es;
1002 es.type = SALOME::INTERNAL_ERROR;
1003 es.text = "service doesn't have this Salome_file";
1004 throw SALOME::SALOME_Exception(es);
1006 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1008 return Sfile->_this();
1011 Engines::Salome_file_ptr
1012 Engines_Component_i::setOutputFileToService(const char* service_name,
1013 const char* Salome_file_name)
1015 // Try to find the service, if it doesn't exist, we add it.
1016 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1017 if (_Service_file_map_it == _Output_Service_file_map.end()) {
1018 _t_Salome_file_map * _map = new _t_Salome_file_map();
1019 _Output_Service_file_map[service_name] = _map;
1021 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1023 // Try to find the Salome_file ...
1024 _Salome_file_map_it = _map->find(Salome_file_name);
1025 if (_Salome_file_map_it == _map->end()) {
1026 Salome_file_i * Sfile = new Salome_file_i();
1027 Engines::Container_ptr container = this->GetContainerRef();
1028 Sfile->setContainer(Engines::Container::_duplicate(container));
1029 (*_map)[Salome_file_name] = Sfile;
1032 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1033 return Sfile->_this();
1037 Engines_Component_i::checkOutputFilesToService(const char* service_name)
1039 // Try to find the service, if it doesn't exist, nothing to do.
1040 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1041 if (_Service_file_map_it != _Output_Service_file_map.end()) {
1042 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1043 _t_Salome_file_map::iterator begin = _map->begin();
1044 _t_Salome_file_map::iterator end = _map->end();
1046 for(;begin!=end;begin++) {
1047 Salome_file_i * file = begin->second;
1048 std::string file_port_name = begin->first;
1049 configureSalome_file(service_name, file_port_name, file);
1056 //=============================================================================
1058 * C++ method: used to configure the Salome_file into the runtime.
1059 * \param service_name name of the service that use this Salome_file
1060 * \param file_port_name name of the Salome_file
1061 * \param file Salome_file C++ object
1063 //=============================================================================
1065 Engines_Component_i::configureSalome_file(std::string service_name,
1066 std::string file_port_name,
1067 Salome_file_i * file)
1069 // By default this method does nothing