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 //=============================================================================
61 * Default constructor, not for use
63 //=============================================================================
65 Engines_Component_i::Engines_Component_i():_myConnexionToRegistry(0), _notifSupplier(0)
68 MESSAGE("Default Constructor, not for normal use...");
71 //=============================================================================
73 * Standard Constructor for generic Component, used in derived class
74 * Connection to Registry and Notification
75 * \param orb Object Request broker given by Container
76 * \param poa Portable Object Adapter from Container (normally root_poa)
77 * \param contId container CORBA id inside the server
78 * \param instanceName unique instance name for this object (see Container_i)
79 * \param interfaceName component class name
80 * \param notif use of notification
82 //=============================================================================
84 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
85 PortableServer::POA_ptr poa,
86 PortableServer::ObjectId * contId,
87 const char *instanceName,
88 const char *interfaceName,
90 _instanceName(instanceName),
91 _interfaceName(interfaceName),
92 _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 _container=Engines::Container::_narrow(o);
109 const CORBA::String_var ior = _orb->object_to_string(o);
110 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession",
111 _instanceName.c_str());
113 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
114 //SCRUTE(pd_refCount);
117 //=============================================================================
119 * Standard Constructor for standalone Component, used in derived class
120 * Connection to Registry and Notification
121 * \param orb Object Request broker given by Container
122 * \param poa Portable Object Adapter from Container (normally root_poa)
123 * \param container container CORBA reference
124 * \param instanceName unique instance name for this object (see Container_i)
125 * \param interfaceName component class name
126 * \param notif use of notification
127 * \param regist (true or false) use of registry (default true)
129 //=============================================================================
131 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
132 PortableServer::POA_ptr poa,
133 Engines::Container_ptr container,
134 const char *instanceName,
135 const char *interfaceName,
138 _instanceName(instanceName),
139 _interfaceName(interfaceName),
140 _myConnexionToRegistry(0),
148 _CanceledThread(false)
150 MESSAGE("Component constructor with instanceName "<< _instanceName);
151 _orb = CORBA::ORB::_duplicate(orb);
152 _poa = PortableServer::POA::_duplicate(poa);
153 _container=Engines::Container::_duplicate(container);
156 _contId=_poa->reference_to_id(container);
158 catch(PortableServer::POA::WrongAdapter)
160 //not created by this poa
163 const CORBA::String_var ior = _orb->object_to_string(_container);
165 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession", _instanceName.c_str());
166 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
170 //=============================================================================
172 * Standard constructor for parallel component
173 * Connection Notification (no connection to Registry !)
174 * \param orb Object Request broker given by Container
175 * \param poa Portable Object Adapter from Container (normally root_poa)
176 * \param contId container CORBA id inside the server
177 * \param instanceName unique instance name for this object (see Container_i)
178 * \param interfaceName component class name
179 * \param flag not used...
180 * \param notif use of notification
182 //=============================================================================
184 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
185 PortableServer::POA_ptr poa,
186 PortableServer::ObjectId * contId,
187 const char *instanceName,
188 const char *interfaceName,
191 _instanceName(instanceName),
192 _interfaceName(interfaceName),
193 _myConnexionToRegistry(0),
201 _CanceledThread(false)
203 _orb = CORBA::ORB::_duplicate(orb);
204 _poa = PortableServer::POA::_duplicate(poa);
206 CORBA::Object_var o = _poa->id_to_reference(*contId); // container ior...
207 _container=Engines::Container::_narrow(o);
209 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
212 //=============================================================================
214 * Destructor: call Container for decrement of instances count.
215 * When instances count falls to 0, the container tries to remove the
216 * component library (dlclose)
218 //=============================================================================
220 Engines_Component_i::~Engines_Component_i()
222 MESSAGE("Component destructor");
223 Engines_Container_i::decInstanceCnt(_interfaceName);
224 if(_myConnexionToRegistry)delete _myConnexionToRegistry;
225 if(_notifSupplier)delete _notifSupplier;
228 //=============================================================================
230 * CORBA method: return name of the instance, unique in this Container
232 //=============================================================================
234 char* Engines_Component_i::instanceName()
236 return CORBA::string_dup(_instanceName.c_str()) ;
239 //=============================================================================
241 * CORBA method: return name of the component class
243 //=============================================================================
245 char* Engines_Component_i::interfaceName()
247 return CORBA::string_dup(_interfaceName.c_str()) ;
250 //=============================================================================
252 * CORBA method: Get study Id
253 * \return -1: not initialised (Internal Error)
254 * 0: multistudy component instance
255 * >0: study id associated to this instance
257 //=============================================================================
259 CORBA::Long Engines_Component_i::getStudyId()
264 //=============================================================================
266 * CORBA method: Test if instance is alive and responds
268 //=============================================================================
270 void Engines_Component_i::ping()
273 MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid "
276 MESSAGE("Engines_Component_i::ping() pid "<< _getpid()<< " threadid "
277 << pthread_self().p );
281 //=============================================================================
283 * CORBA method: Deactivate this instance. CORBA object is deactivated (do not
284 * respond any more to CORBA calls), the connection to Regsitry is removed
285 * (Registry informed of deactivation), internal server reference counter on
286 * the derived servant class is decremented, to allow destruction of the class
287 * (delete) by POA, when there are no more references.
288 * -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
290 //=============================================================================
292 void Engines_Component_i::destroy()
294 MESSAGE("Engines_Component_i::destroy()");
295 //SCRUTE(pd_refCount);
297 if(_myConnexionToRegistry)delete _myConnexionToRegistry;
298 _myConnexionToRegistry = 0 ;
299 if(_notifSupplier)delete _notifSupplier;
303 //SCRUTE(pd_refCount);
304 _thisObj->_remove_ref();
305 //SCRUTE(pd_refCount);
306 MESSAGE("Engines_Component_i::destroyed") ;
309 //=============================================================================
311 * CORBA method: return CORBA reference of the Container
314 //=============================================================================
316 Engines::Container_ptr Engines_Component_i::GetContainerRef()
318 return Engines::Container::_duplicate(_container);
321 //=============================================================================
324 * Gives a sequence of (key=string,value=any) to the component.
325 * Base class component stores the sequence in a map.
326 * The map is cleared before.
327 * This map is for use by derived classes.
328 * \param dico sequence of (key=string,value=any)
330 //=============================================================================
332 void Engines_Component_i::setProperties(const Engines::FieldsDict& dico)
335 for (CORBA::ULong i=0; i<dico.length(); i++)
337 std::string cle(dico[i].key);
338 _fieldsDict[cle] = dico[i].value;
342 //=============================================================================
345 * returns a previously stored map (key=string,value=any) as a sequence.
346 * (see setProperties)
348 //=============================================================================
350 Engines::FieldsDict* Engines_Component_i::getProperties()
352 Engines::FieldsDict_var copie = new Engines::FieldsDict;
353 copie->length(_fieldsDict.size());
354 map<std::string,CORBA::Any>::iterator it;
356 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++)
358 std::string cle((*it).first);
359 copie[i].key = CORBA::string_dup(cle.c_str());
360 copie[i].value = _fieldsDict[cle];
362 return copie._retn();
365 //=============================================================================
367 * CORBA method: used by Supervision to give names to this instance
369 //=============================================================================
371 void Engines_Component_i::Names( const char * graphName ,
372 const char * nodeName )
374 _graphName = graphName ;
375 _nodeName = nodeName ;
376 // MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
377 // << _nodeName << "' )");
380 //=============================================================================
382 * CORBA method: used in Supervision
384 //=============================================================================
386 bool Engines_Component_i::Kill_impl()
388 // MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
389 // << " pid " << getpid() << " instanceName "
390 // << _instanceName.c_str() << " interface " << _interfaceName.c_str()
391 // << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
392 // << dec << " _ThreadId " << _ThreadId << " this " << hex << this
395 bool RetVal = false ;
397 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
399 RetVal = Killer( _ThreadId , SIGUSR2 ) ;
400 _ThreadId = (pthread_t ) -1 ;
404 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
406 RetVal = Killer( *_ThreadId , 0 ) ;
407 _ThreadId = (pthread_t* ) 0 ;
414 //=============================================================================
416 * CORBA method: used in Supervision
418 //=============================================================================
420 bool Engines_Component_i::Stop_impl()
423 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self()
424 << " pid " << getpid() << " instanceName "
425 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
426 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
427 << dec << " _ThreadId " << _ThreadId );
429 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self().p
430 << " pid " << _getpid() << " instanceName "
431 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
432 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
433 << dec << " _ThreadId " << _ThreadId );
437 bool RetVal = false ;
439 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
441 RetVal = Killer( _ThreadId , 0 ) ;
442 _ThreadId = (pthread_t ) -1 ;
445 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
447 RetVal = Killer( *_ThreadId , 0 ) ;
448 _ThreadId = (pthread_t* ) 0 ;
454 //=============================================================================
456 * CORBA method: used in Supervision
458 //=============================================================================
460 bool Engines_Component_i::Suspend_impl()
463 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self()
464 << " pid " << getpid() << " instanceName "
465 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
466 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
467 << dec << " _ThreadId " << _ThreadId );
469 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self().p
470 << " pid " << _getpid() << " instanceName "
471 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
472 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
473 << dec << " _ThreadId " << _ThreadId );
476 bool RetVal = false ;
478 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
480 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
490 RetVal = Killer( _ThreadId ,SIGINT ) ;
492 RetVal = Killer( *_ThreadId ,SIGINT ) ;
494 //if ( RetVal ) _Sleeping = true;
501 //=============================================================================
503 * CORBA method: used in Supervision
505 //=============================================================================
507 bool Engines_Component_i::Resume_impl()
510 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self()
511 << " pid " << getpid() << " instanceName "
512 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
513 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
514 << dec << " _ThreadId " << _ThreadId );
516 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self().p
517 << " pid " << _getpid() << " instanceName "
518 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
519 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
520 << dec << " _ThreadId " << _ThreadId );
522 bool RetVal = false ;
524 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
526 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
542 //=============================================================================
546 //=============================================================================
548 CORBA::Long Engines_Component_i::CpuUsed_impl()
551 if ( _ThreadId || _Executed )
556 if ( pthread_self() != _ThreadId )
558 if ( pthread_self().p != _ThreadId->p )
566 // Get Cpu in the appropriate thread with that object !...
567 theEngines_Component = this ;
569 Killer( _ThreadId ,SIGUSR1 ) ;
571 Killer( *_ThreadId ,SIGUSR11 ) ;
574 cpu = _ThreadCpuUsed ;
578 _ThreadCpuUsed = CpuUsed() ;
579 cpu = _ThreadCpuUsed ;
580 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
581 // << _serviceName << " " << cpu << endl ;
586 cpu = _ThreadCpuUsed ;
587 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
588 // << _serviceName << " " << cpu<< endl ;
593 // cout<< pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId "
594 // <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<<endl;
600 //=============================================================================
602 * C++ method: return Container Servant
604 //=============================================================================
606 Engines_Container_i *Engines_Component_i::GetContainerPtr()
608 return dynamic_cast<Engines_Container_i*>(_poa->id_to_servant(*_contId)) ;
611 //=============================================================================
613 * C++ method: set study Id
614 * \param studyId 0 if instance is not associated to a study,
615 * >0 otherwise (== study id)
616 * \return true if the set of study Id is OK
617 * must be set once by Container, at instance creation,
618 * and cannot be changed after.
620 //=============================================================================
622 CORBA::Boolean Engines_Component_i::setStudyId(CORBA::Long studyId)
624 ASSERT( studyId >= 0);
625 CORBA::Boolean ret = false;
626 if (_studyId < 0) // --- not yet initialized
632 if ( _studyId == studyId) ret = true;
636 //=============================================================================
638 * C++ method: return CORBA instance id, the id is set in derived class
639 * constructor, when instance is activated.
641 //=============================================================================
643 PortableServer::ObjectId * Engines_Component_i::getId()
645 // MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
649 //=============================================================================
651 * C++ method: used by derived classes for supervision
653 //=============================================================================
655 void Engines_Component_i::beginService(const char *serviceName)
658 MESSAGE(pthread_self() << "Send BeginService notification for " <<serviceName
659 << endl << "Component instance : " << _instanceName << endl << endl);
661 MESSAGE(pthread_self().p << "Send BeginService notification for " <<serviceName
662 << endl << "Component instance : " << _instanceName << endl << endl);
665 _ThreadId = pthread_self() ;
667 _ThreadId = new pthread_t;
668 _ThreadId->p = pthread_self().p ;
669 _ThreadId->x = pthread_self().x ;
672 _StartUsed = CpuUsed_impl() ;
675 _serviceName = serviceName ;
676 theEngines_Component = this ;
677 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) )
679 perror("pthread_setcanceltype ") ;
682 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) )
684 perror("pthread_setcancelstate ") ;
687 // MESSAGE(pthread_self() << " Return from BeginService for " << serviceName
688 // << " ThreadId " << _ThreadId << " StartUsed " << _StartUsed
689 // << " _graphName " << _graphName << " _nodeName " << _nodeName );
691 // --- for supervisor : all strings given with setProperties
692 // are set in environment
693 bool overwrite = true;
694 map<std::string,CORBA::Any>::iterator it;
695 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
697 std::string cle((*it).first);
698 if ((*it).second.type()->kind() == CORBA::tk_string)
701 (*it).second >>= value;
702 // ---todo: replace __GNUC__ test by an autoconf macro AC_CHECK_FUNC.
704 // int ret = setenv(cle.c_str(), value, overwrite);
705 setenv(cle.c_str(), value, overwrite);
707 //CCRT porting : setenv not defined in stdlib.h
711 // char* cast because 1st arg of linux putenv function
712 // is not a const char* !
713 // int ret=putenv((char *)s.c_str());
714 putenv((char *)s.c_str());
715 //End of CCRT porting
717 MESSAGE("--- setenv: "<<cle<<" = "<< value);
722 //=============================================================================
724 * C++ method: used by derived classes for supervision
726 //=============================================================================
728 void Engines_Component_i::endService(const char *serviceName)
730 if ( !_CanceledThread )
731 _ThreadCpuUsed = CpuUsed_impl() ;
734 MESSAGE(pthread_self() << " Send EndService notification for " << serviceName
735 << endl << " Component instance : " << _instanceName << " StartUsed "
736 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << endl <<endl);
738 MESSAGE(pthread_self().p << " Send EndService notification for " << serviceName
739 << endl << " Component instance : " << _instanceName << " StartUsed "
740 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << endl <<endl);
745 //=============================================================================
747 * C++ method: -- CHECK IF USED --
749 //=============================================================================
751 char* Engines_Component_i::graphName()
753 return CORBA::string_dup( _graphName.c_str() ) ;
756 //=============================================================================
758 * C++ method: -- CHECK IF USED --
760 //=============================================================================
762 char* Engines_Component_i::nodeName()
764 return CORBA::string_dup( _nodeName.c_str() ) ;
767 //=============================================================================
769 * C++ method: used in Supervision (see kill_impl)
771 //=============================================================================
773 bool Engines_Component_i::Killer( pthread_t ThreadId , int signum )
783 if ( pthread_cancel( ThreadId ) )
785 perror("Killer pthread_cancel error") ;
791 MESSAGE(pthread_self() << "Killer : ThreadId " << ThreadId
792 << " pthread_canceled") ;
794 MESSAGE(pthread_self().p << "Killer : ThreadId " << ThreadId.p
795 << " pthread_canceled") ;
801 if ( pthread_kill( ThreadId , signum ) == -1 )
803 perror("Killer pthread_kill error") ;
809 MESSAGE(pthread_self() << "Killer : ThreadId " << ThreadId
810 << " pthread_killed(" << signum << ")") ;
812 MESSAGE(pthread_self().p << "Killer : ThreadId " << ThreadId.p
813 << " pthread_killed(" << signum << ")") ;
821 //=============================================================================
825 //=============================================================================
829 if ( theEngines_Component )
830 theEngines_Component->SetCurCpu() ;
833 //=============================================================================
837 //=============================================================================
839 void Engines_Component_i::SetCurCpu()
841 _ThreadCpuUsed = CpuUsed() ;
842 // MESSAGE(pthread_self() <<
843 // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ;
846 //=============================================================================
850 //=============================================================================
852 long Engines_Component_i::CpuUsed()
856 struct rusage usage ;
857 if ( _ThreadId || _Executed )
859 if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
861 perror("Engines_Component_i::CpuUsed") ;
864 cpu = usage.ru_utime.tv_sec - _StartUsed ;
865 // cout << pthread_self() << " Engines_Component_i::CpuUsed " << " "
866 // << _serviceName << usage.ru_utime.tv_sec << " - " << _StartUsed
867 // << " = " << cpu << endl ;
871 // cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId "
872 // << _ThreadId << " " << _serviceName<< " _StartUsed "
873 // << _StartUsed << endl ;
876 // NOT implementet yet
883 void CallCancelThread()
885 if ( theEngines_Component )
886 theEngines_Component->CancelThread() ;
889 //=============================================================================
893 //=============================================================================
895 void Engines_Component_i::CancelThread()
897 _CanceledThread = true;
900 //=============================================================================
902 * C++ method: Send message to event channel
904 //=============================================================================
906 void Engines_Component_i::sendMessage(const char *event_type,
909 _notifSupplier->Send(_graphName.c_str(), _nodeName.c_str(), event_type, message);
912 //=============================================================================
914 * C++ method: return standard library name built on component name
916 //=============================================================================
918 string Engines_Component_i::GetDynLibraryName(const char *componentName)
926 //=============================================================================
928 * C++ method: DumpPython default implementation
930 //=============================================================================
932 Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Object_ptr theStudy,
933 CORBA::Boolean isPublished,
934 CORBA::Boolean& isValidScript)
936 const char* aScript = "def RebuildData(theStudy): pass";
937 char* aBuffer = new char[strlen(aScript)+1];
938 strcpy(aBuffer, aScript);
939 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
940 int aBufferSize = strlen(aBuffer)+1;
941 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
942 isValidScript = true;
943 return aStreamFile._retn();
946 Engines::Salome_file_ptr
947 Engines_Component_i::getInputFileToService(const char* service_name,
948 const char* Salome_file_name)
950 // Try to find the service, if it doesn't exist, we throw an exception.
951 _Service_file_map_it = _Input_Service_file_map.find(service_name);
952 if (_Service_file_map_it == _Input_Service_file_map.end()) {
953 SALOME::ExceptionStruct es;
954 es.type = SALOME::INTERNAL_ERROR;
955 es.text = "service doesn't have salome files";
956 throw SALOME::SALOME_Exception(es);
958 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
960 // Try to find the Salome_file ...
961 _Salome_file_map_it = _map->find(Salome_file_name);
962 if (_Salome_file_map_it == _map->end()) {
963 SALOME::ExceptionStruct es;
964 es.type = SALOME::INTERNAL_ERROR;
965 es.text = "service doesn't have this Salome_file";
966 throw SALOME::SALOME_Exception(es);
968 Salome_file_i * Sfile = (*_map)[Salome_file_name];
970 return Sfile->_this();
973 Engines::Salome_file_ptr
974 Engines_Component_i::setInputFileToService(const char* service_name,
975 const char* Salome_file_name)
977 // Try to find the service, if it doesn't exist, we add it.
978 _Service_file_map_it = _Input_Service_file_map.find(service_name);
979 if (_Service_file_map_it == _Input_Service_file_map.end()) {
980 _t_Salome_file_map * _map = new _t_Salome_file_map();
981 _Input_Service_file_map[service_name] = _map;
983 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
985 // Try to find the Salome_file ...
986 _Salome_file_map_it = _map->find(Salome_file_name);
987 if (_Salome_file_map_it == _map->end()) {
988 Salome_file_i * Sfile = new Salome_file_i();
989 Engines::Container_ptr container = this->GetContainerRef();
990 Sfile->setContainer(Engines::Container::_duplicate(container));
991 (*_map)[Salome_file_name] = Sfile;
994 Salome_file_i * Sfile = (*_map)[Salome_file_name];
995 return Sfile->_this();
999 Engines_Component_i::checkInputFilesToService(const char* service_name)
1001 // Try to find the service, if it doesn't exist, nothing to do.
1002 _Service_file_map_it = _Input_Service_file_map.find(service_name);
1003 if (_Service_file_map_it != _Input_Service_file_map.end()) {
1004 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
1005 _t_Salome_file_map::iterator begin = _map->begin();
1006 _t_Salome_file_map::iterator end = _map->end();
1008 for(;begin!=end;begin++) {
1009 Salome_file_i * file = begin->second;
1010 std::string file_port_name = begin->first;
1011 configureSalome_file(service_name, file_port_name, file);
1017 Engines::Salome_file_ptr
1018 Engines_Component_i::getOutputFileToService(const char* service_name,
1019 const char* Salome_file_name)
1021 // Try to find the service, if it doesn't exist, we throw an exception.
1022 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1023 if (_Service_file_map_it == _Output_Service_file_map.end()) {
1024 SALOME::ExceptionStruct es;
1025 es.type = SALOME::INTERNAL_ERROR;
1026 es.text = "service doesn't have salome files";
1027 throw SALOME::SALOME_Exception(es);
1029 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1031 // Try to find the Salome_file ...
1032 _Salome_file_map_it = _map->find(Salome_file_name);
1033 if (_Salome_file_map_it == _map->end()) {
1034 SALOME::ExceptionStruct es;
1035 es.type = SALOME::INTERNAL_ERROR;
1036 es.text = "service doesn't have this Salome_file";
1037 throw SALOME::SALOME_Exception(es);
1039 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1041 return Sfile->_this();
1044 Engines::Salome_file_ptr
1045 Engines_Component_i::setOutputFileToService(const char* service_name,
1046 const char* Salome_file_name)
1048 // Try to find the service, if it doesn't exist, we add it.
1049 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1050 if (_Service_file_map_it == _Output_Service_file_map.end()) {
1051 _t_Salome_file_map * _map = new _t_Salome_file_map();
1052 _Output_Service_file_map[service_name] = _map;
1054 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1056 // Try to find the Salome_file ...
1057 _Salome_file_map_it = _map->find(Salome_file_name);
1058 if (_Salome_file_map_it == _map->end()) {
1059 Salome_file_i * Sfile = new Salome_file_i();
1060 Engines::Container_ptr container = this->GetContainerRef();
1061 Sfile->setContainer(Engines::Container::_duplicate(container));
1062 (*_map)[Salome_file_name] = Sfile;
1065 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1066 return Sfile->_this();
1070 Engines_Component_i::checkOutputFilesToService(const char* service_name)
1072 // Try to find the service, if it doesn't exist, nothing to do.
1073 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1074 if (_Service_file_map_it != _Output_Service_file_map.end()) {
1075 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1076 _t_Salome_file_map::iterator begin = _map->begin();
1077 _t_Salome_file_map::iterator end = _map->end();
1079 for(;begin!=end;begin++) {
1080 Salome_file_i * file = begin->second;
1081 std::string file_port_name = begin->first;
1082 configureSalome_file(service_name, file_port_name, file);
1089 //=============================================================================
1091 * C++ method: used to configure the Salome_file into the runtime.
1092 * \param service_name name of the service that use this Salome_file
1093 * \param file_port_name name of the Salome_file
1094 * \param file Salome_file C++ object
1096 //=============================================================================
1098 Engines_Component_i::configureSalome_file(std::string service_name,
1099 std::string file_port_name,
1100 Salome_file_i * file)
1102 // By default this method does nothing