1 // SALOME Container : implementation of container and engine for Kernel
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : Component_i.cxx
25 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
29 //#define private protected // for pd_refCount trace
30 #include "SALOME_Component_i.hxx"
31 #include "SALOME_Container_i.hxx"
32 #include "RegistryConnexion.hxx"
39 #include "utilities.h"
43 #include <sys/resource.h>
46 #include <sys/timeb.h>
54 extern bool _Sleeping ;
55 static Engines_Component_i * theEngines_Component ;
57 bool Engines_Component_i::_isMultiStudy = true;
58 bool Engines_Component_i::_isMultiInstance = false;
60 //=============================================================================
62 * Default constructor, not for use
64 //=============================================================================
66 Engines_Component_i::Engines_Component_i():_myConnexionToRegistry(0), _notifSupplier(0)
69 MESSAGE("Default Constructor, not for normal use...");
72 //=============================================================================
74 * Standard Constructor for generic Component, used in derived class
75 * Connection to Registry and Notification
76 * \param orb Object Request broker given by Container
77 * \param poa Portable Object Adapter from Container (normally root_poa)
78 * \param contId container CORBA id inside the server
79 * \param instanceName unique instance name for this object (see Container_i)
80 * \param interfaceName component class name
81 * \param notif use of notification
83 //=============================================================================
85 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
86 PortableServer::POA_ptr poa,
87 PortableServer::ObjectId * contId,
88 const char *instanceName,
89 const char *interfaceName,
91 _instanceName(instanceName),
92 _interfaceName(interfaceName),
93 _myConnexionToRegistry(0),
101 _CanceledThread(false)
103 MESSAGE("Component constructor with instanceName "<< _instanceName);
104 //SCRUTE(pd_refCount);
105 _orb = CORBA::ORB::_duplicate(orb);
106 _poa = PortableServer::POA::_duplicate(poa);
108 CORBA::Object_var o = _poa->id_to_reference(*contId); // container ior...
109 _container=Engines::Container::_narrow(o);
110 const CORBA::String_var ior = _orb->object_to_string(o);
111 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession",
112 _instanceName.c_str());
114 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
115 //SCRUTE(pd_refCount);
118 //=============================================================================
120 * Standard Constructor for standalone Component, used in derived class
121 * Connection to Registry and Notification
122 * \param orb Object Request broker given by Container
123 * \param poa Portable Object Adapter from Container (normally root_poa)
124 * \param container container CORBA reference
125 * \param instanceName unique instance name for this object (see Container_i)
126 * \param interfaceName component class name
127 * \param notif use of notification
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,
137 _instanceName(instanceName),
138 _interfaceName(interfaceName),
139 _myConnexionToRegistry(0),
147 _CanceledThread(false)
149 MESSAGE("Component constructor with instanceName "<< _instanceName);
150 _orb = CORBA::ORB::_duplicate(orb);
151 _poa = PortableServer::POA::_duplicate(poa);
152 _container=Engines::Container::_duplicate(container);
155 _contId=_poa->reference_to_id(container);
157 catch(PortableServer::POA::WrongAdapter)
159 //not created by this poa
162 const CORBA::String_var ior = _orb->object_to_string(_container);
163 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession", _instanceName.c_str());
164 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
168 //=============================================================================
170 * Standard constructor for parallel component
171 * Connection Notification (no connection to Registry !)
172 * \param orb Object Request broker given by Container
173 * \param poa Portable Object Adapter from Container (normally root_poa)
174 * \param contId container CORBA id inside the server
175 * \param instanceName unique instance name for this object (see Container_i)
176 * \param interfaceName component class name
177 * \param flag not used...
178 * \param notif use of notification
180 //=============================================================================
182 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
183 PortableServer::POA_ptr poa,
184 PortableServer::ObjectId * contId,
185 const char *instanceName,
186 const char *interfaceName,
189 _instanceName(instanceName),
190 _interfaceName(interfaceName),
191 _myConnexionToRegistry(0),
199 _CanceledThread(false)
201 _orb = CORBA::ORB::_duplicate(orb);
202 _poa = PortableServer::POA::_duplicate(poa);
205 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
208 //=============================================================================
210 * Destructor: call Container for decrement of instances count.
211 * When instances count falls to 0, the container tries to remove the
212 * component library (dlclose)
214 //=============================================================================
216 Engines_Component_i::~Engines_Component_i()
218 MESSAGE("Component destructor");
219 Engines_Container_i::decInstanceCnt(_interfaceName);
220 if(_myConnexionToRegistry)delete _myConnexionToRegistry;
221 if(_notifSupplier)delete _notifSupplier;
224 //=============================================================================
226 * CORBA method: return name of the instance, unique in this Container
228 //=============================================================================
230 char* Engines_Component_i::instanceName()
232 return CORBA::string_dup(_instanceName.c_str()) ;
235 //=============================================================================
237 * CORBA method: return name of the component class
239 //=============================================================================
241 char* Engines_Component_i::interfaceName()
243 return CORBA::string_dup(_interfaceName.c_str()) ;
246 //=============================================================================
248 * CORBA method: Get study Id
249 * \return -1: not initialised (Internal Error)
250 * 0: multistudy component instance
251 * >0: study id associated to this instance
253 //=============================================================================
255 CORBA::Long Engines_Component_i::getStudyId()
260 //=============================================================================
262 * CORBA method: Test if instance is alive and responds
264 //=============================================================================
266 void Engines_Component_i::ping()
269 MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid "
272 MESSAGE("Engines_Component_i::ping() pid "<< _getpid()<< " threadid "
273 << pthread_self().p );
277 //=============================================================================
279 * CORBA method: Deactivate this instance. CORBA object is deactivated (do not
280 * respond any more to CORBA calls), the connection to Regsitry is removed
281 * (Registry informed of deactivation), internal server reference counter on
282 * the derived servant class is decremented, to allow destruction of the class
283 * (delete) by POA, when there are no more references.
284 * -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
286 //=============================================================================
288 void Engines_Component_i::destroy()
290 MESSAGE("Engines_Component_i::destroy()");
291 //SCRUTE(pd_refCount);
293 delete _notifSupplier;
296 delete _myConnexionToRegistry;
297 _myConnexionToRegistry = 0 ;
298 _poa->deactivate_object(*_id) ;
300 //SCRUTE(pd_refCount);
301 _thisObj->_remove_ref();
302 //SCRUTE(pd_refCount);
303 MESSAGE("Engines_Component_i::destroyed") ;
306 //=============================================================================
308 * CORBA method: return CORBA reference of the Container
311 //=============================================================================
313 Engines::Container_ptr Engines_Component_i::GetContainerRef()
315 return Engines::Container::_duplicate(_container);
318 //=============================================================================
321 * Gives a sequence of (key=string,value=any) to the component.
322 * Base class component stores the sequence in a map.
323 * The map is cleared before.
324 * This map is for use by derived classes.
325 * \param dico sequence of (key=string,value=any)
327 //=============================================================================
329 void Engines_Component_i::setProperties(const Engines::FieldsDict& dico)
332 for (CORBA::ULong i=0; i<dico.length(); i++)
334 std::string cle(dico[i].key);
335 _fieldsDict[cle] = dico[i].value;
339 //=============================================================================
342 * returns a previously stored map (key=string,value=any) as a sequence.
343 * (see setProperties)
345 //=============================================================================
347 Engines::FieldsDict* Engines_Component_i::getProperties()
349 Engines::FieldsDict_var copie = new Engines::FieldsDict;
350 copie->length(_fieldsDict.size());
351 map<std::string,CORBA::Any>::iterator it;
353 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++)
355 std::string cle((*it).first);
356 copie[i].key = CORBA::string_dup(cle.c_str());
357 copie[i].value = _fieldsDict[cle];
359 return copie._retn();
362 //=============================================================================
364 * CORBA method: used by Supervision to give names to this instance
366 //=============================================================================
368 void Engines_Component_i::Names( const char * graphName ,
369 const char * nodeName )
371 _graphName = graphName ;
372 _nodeName = nodeName ;
373 // MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
374 // << _nodeName << "' )");
377 //=============================================================================
379 * CORBA method: used in Supervision
381 //=============================================================================
383 bool Engines_Component_i::Kill_impl()
385 // MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
386 // << " pid " << getpid() << " instanceName "
387 // << _instanceName.c_str() << " interface " << _interfaceName.c_str()
388 // << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
389 // << dec << " _ThreadId " << _ThreadId << " this " << hex << this
392 bool RetVal = false ;
394 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
396 RetVal = Killer( _ThreadId , SIGUSR2 ) ;
397 _ThreadId = (pthread_t ) -1 ;
401 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
403 RetVal = Killer( *_ThreadId , 0 ) ;
404 _ThreadId = (pthread_t* ) 0 ;
411 //=============================================================================
413 * CORBA method: used in Supervision
415 //=============================================================================
417 bool Engines_Component_i::Stop_impl()
420 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self()
421 << " pid " << getpid() << " instanceName "
422 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
423 << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
424 << dec << " _ThreadId " << _ThreadId );
426 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self().p
427 << " pid " << _getpid() << " instanceName "
428 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
429 << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
430 << dec << " _ThreadId " << _ThreadId );
434 bool RetVal = false ;
436 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
438 RetVal = Killer( _ThreadId , 0 ) ;
439 _ThreadId = (pthread_t ) -1 ;
442 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
444 RetVal = Killer( *_ThreadId , 0 ) ;
445 _ThreadId = (pthread_t* ) 0 ;
451 //=============================================================================
453 * CORBA method: used in Supervision
455 //=============================================================================
457 bool Engines_Component_i::Suspend_impl()
460 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self()
461 << " pid " << getpid() << " instanceName "
462 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
463 << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
464 << dec << " _ThreadId " << _ThreadId );
466 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self().p
467 << " pid " << _getpid() << " instanceName "
468 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
469 << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
470 << dec << " _ThreadId " << _ThreadId );
473 bool RetVal = false ;
475 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
477 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
487 RetVal = Killer( _ThreadId ,SIGINT ) ;
489 RetVal = Killer( *_ThreadId ,SIGINT ) ;
491 //if ( RetVal ) _Sleeping = true;
498 //=============================================================================
500 * CORBA method: used in Supervision
502 //=============================================================================
504 bool Engines_Component_i::Resume_impl()
507 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self()
508 << " pid " << getpid() << " instanceName "
509 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
510 << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
511 << dec << " _ThreadId " << _ThreadId );
513 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self().p
514 << " pid " << _getpid() << " instanceName "
515 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
516 << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
517 << dec << " _ThreadId " << _ThreadId );
519 bool RetVal = false ;
521 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
523 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
539 //=============================================================================
543 //=============================================================================
545 CORBA::Long Engines_Component_i::CpuUsed_impl()
548 if ( _ThreadId || _Executed )
553 if ( pthread_self() != _ThreadId )
555 if ( pthread_self().p != _ThreadId->p )
563 // Get Cpu in the appropriate thread with that object !...
564 theEngines_Component = this ;
566 Killer( _ThreadId ,SIGUSR1 ) ;
568 Killer( *_ThreadId ,SIGUSR11 ) ;
571 cpu = _ThreadCpuUsed ;
575 _ThreadCpuUsed = CpuUsed() ;
576 cpu = _ThreadCpuUsed ;
577 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
578 // << _serviceName << " " << cpu << endl ;
583 cpu = _ThreadCpuUsed ;
584 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
585 // << _serviceName << " " << cpu<< endl ;
590 // cout<< pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId "
591 // <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<<endl;
597 //=============================================================================
599 * C++ method: return Container Servant
601 //=============================================================================
603 Engines_Container_i *Engines_Component_i::GetContainerPtr()
605 return dynamic_cast<Engines_Container_i*>(_poa->id_to_servant(*_contId)) ;
608 //=============================================================================
610 * C++ method: set study Id
611 * \param studyId 0 if instance is not associated to a study,
612 * >0 otherwise (== study id)
613 * \return true if the set of study Id is OK
614 * must be set once by Container, at instance creation,
615 * and cannot be changed after.
617 //=============================================================================
619 CORBA::Boolean Engines_Component_i::setStudyId(CORBA::Long studyId)
621 ASSERT( studyId >= 0);
622 CORBA::Boolean ret = false;
623 if (_studyId < 0) // --- not yet initialized
629 if ( _studyId == studyId) ret = true;
633 //=============================================================================
635 * C++ method: return CORBA instance id, the id is set in derived class
636 * constructor, when instance is activated.
638 //=============================================================================
640 PortableServer::ObjectId * Engines_Component_i::getId()
642 // MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
646 //=============================================================================
648 * C++ method: used by derived classes for supervision
650 //=============================================================================
652 void Engines_Component_i::beginService(const char *serviceName)
655 MESSAGE(pthread_self() << "Send BeginService notification for " <<serviceName
656 << endl << "Component instance : " << _instanceName << endl << endl);
658 MESSAGE(pthread_self().p << "Send BeginService notification for " <<serviceName
659 << endl << "Component instance : " << _instanceName << endl << endl);
662 _ThreadId = pthread_self() ;
664 _ThreadId = new pthread_t;
665 _ThreadId->p = pthread_self().p ;
666 _ThreadId->x = pthread_self().x ;
669 _StartUsed = CpuUsed_impl() ;
672 _serviceName = serviceName ;
673 theEngines_Component = this ;
674 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) )
676 perror("pthread_setcanceltype ") ;
679 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) )
681 perror("pthread_setcancelstate ") ;
684 // MESSAGE(pthread_self() << " Return from BeginService for " << serviceName
685 // << " ThreadId " << _ThreadId << " StartUsed " << _StartUsed
686 // << " _graphName " << _graphName << " _nodeName " << _nodeName );
688 // --- for supervisor : all strings given with setProperties
689 // are set in environment
690 bool overwrite = true;
691 map<std::string,CORBA::Any>::iterator it;
692 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
694 std::string cle((*it).first);
695 if ((*it).second.type()->kind() == CORBA::tk_string)
698 (*it).second >>= value;
699 // ---todo: replace __GNUC__ test by an autoconf macro AC_CHECK_FUNC.
701 // int ret = setenv(cle.c_str(), value, overwrite);
702 setenv(cle.c_str(), value, overwrite);
704 //CCRT porting : setenv not defined in stdlib.h
708 // char* cast because 1st arg of linux putenv function
709 // is not a const char* !
710 // int ret=putenv((char *)s.c_str());
711 putenv((char *)s.c_str());
712 //End of CCRT porting
714 MESSAGE("--- setenv: "<<cle<<" = "<< value);
719 //=============================================================================
721 * C++ method: used by derived classes for supervision
723 //=============================================================================
725 void Engines_Component_i::endService(const char *serviceName)
727 if ( !_CanceledThread )
728 _ThreadCpuUsed = CpuUsed_impl() ;
731 MESSAGE(pthread_self() << " Send EndService notification for " << serviceName
732 << endl << " Component instance : " << _instanceName << " StartUsed "
733 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << endl <<endl);
735 MESSAGE(pthread_self().p << " Send EndService notification for " << serviceName
736 << endl << " Component instance : " << _instanceName << " StartUsed "
737 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << endl <<endl);
742 //=============================================================================
744 * C++ method: -- CHECK IF USED --
746 //=============================================================================
748 char* Engines_Component_i::graphName()
750 return CORBA::string_dup( _graphName.c_str() ) ;
753 //=============================================================================
755 * C++ method: -- CHECK IF USED --
757 //=============================================================================
759 char* Engines_Component_i::nodeName()
761 return CORBA::string_dup( _nodeName.c_str() ) ;
764 //=============================================================================
766 * C++ method: used in Supervision (see kill_impl)
768 //=============================================================================
770 bool Engines_Component_i::Killer( pthread_t ThreadId , int signum )
780 if ( pthread_cancel( ThreadId ) )
782 perror("Killer pthread_cancel error") ;
788 MESSAGE(pthread_self() << "Killer : ThreadId " << ThreadId
789 << " pthread_canceled") ;
791 MESSAGE(pthread_self().p << "Killer : ThreadId " << ThreadId.p
792 << " pthread_canceled") ;
798 if ( pthread_kill( ThreadId , signum ) == -1 )
800 perror("Killer pthread_kill error") ;
806 MESSAGE(pthread_self() << "Killer : ThreadId " << ThreadId
807 << " pthread_killed(" << signum << ")") ;
809 MESSAGE(pthread_self().p << "Killer : ThreadId " << ThreadId.p
810 << " pthread_killed(" << signum << ")") ;
818 //=============================================================================
822 //=============================================================================
826 if ( theEngines_Component )
827 theEngines_Component->SetCurCpu() ;
830 //=============================================================================
834 //=============================================================================
836 void Engines_Component_i::SetCurCpu()
838 _ThreadCpuUsed = CpuUsed() ;
839 // MESSAGE(pthread_self() <<
840 // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ;
843 //=============================================================================
847 //=============================================================================
849 long Engines_Component_i::CpuUsed()
853 struct rusage usage ;
854 if ( _ThreadId || _Executed )
856 if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
858 perror("Engines_Component_i::CpuUsed") ;
861 cpu = usage.ru_utime.tv_sec - _StartUsed ;
862 // cout << pthread_self() << " Engines_Component_i::CpuUsed " << " "
863 // << _serviceName << usage.ru_utime.tv_sec << " - " << _StartUsed
864 // << " = " << cpu << endl ;
868 // cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId "
869 // << _ThreadId << " " << _serviceName<< " _StartUsed "
870 // << _StartUsed << endl ;
873 // NOT implementet yet
880 void CallCancelThread()
882 if ( theEngines_Component )
883 theEngines_Component->CancelThread() ;
886 //=============================================================================
890 //=============================================================================
892 void Engines_Component_i::CancelThread()
894 _CanceledThread = true;
897 //=============================================================================
899 * C++ method: Send message to event channel
901 //=============================================================================
903 void Engines_Component_i::sendMessage(const char *event_type,
906 _notifSupplier->Send(_graphName.c_str(), _nodeName.c_str(), event_type, message);
909 //=============================================================================
911 * C++ method: return standard library name built on component name
913 //=============================================================================
915 string Engines_Component_i::GetDynLibraryName(const char *componentName)
923 //=============================================================================
925 * C++ method: DumpPython default implementation
927 //=============================================================================
929 Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Object_ptr theStudy,
930 CORBA::Boolean isPublished,
931 CORBA::Boolean& isValidScript)
933 const char* aScript = "def RebuildData(theStudy): pass";
934 char* aBuffer = new char[strlen(aScript)+1];
935 strcpy(aBuffer, aScript);
936 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
937 int aBufferSize = strlen(aBuffer)+1;
938 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
939 isValidScript = true;
940 return aStreamFile._retn();
943 Engines::Salome_file_ptr
944 Engines_Component_i::getInputFileToService(const char* service_name,
945 const char* Salome_file_name)
947 // Try to find the service, if it doesn't exist, we throw an exception.
948 _Service_file_map_it = _Input_Service_file_map.find(service_name);
949 if (_Service_file_map_it == _Input_Service_file_map.end()) {
950 SALOME::ExceptionStruct es;
951 es.type = SALOME::INTERNAL_ERROR;
952 es.text = "service doesn't have salome files";
953 throw SALOME::SALOME_Exception(es);
955 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
957 // Try to find the Salome_file ...
958 _Salome_file_map_it = _map->find(Salome_file_name);
959 if (_Salome_file_map_it == _map->end()) {
960 SALOME::ExceptionStruct es;
961 es.type = SALOME::INTERNAL_ERROR;
962 es.text = "service doesn't have this Salome_file";
963 throw SALOME::SALOME_Exception(es);
965 Salome_file_i * Sfile = (*_map)[Salome_file_name];
967 return Sfile->_this();
970 Engines::Salome_file_ptr
971 Engines_Component_i::setInputFileToService(const char* service_name,
972 const char* Salome_file_name)
974 // Try to find the service, if it doesn't exist, we add it.
975 _Service_file_map_it = _Input_Service_file_map.find(service_name);
976 if (_Service_file_map_it == _Input_Service_file_map.end()) {
977 _t_Salome_file_map * _map = new _t_Salome_file_map();
978 _Input_Service_file_map[service_name] = _map;
980 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
982 // Try to find the Salome_file ...
983 _Salome_file_map_it = _map->find(Salome_file_name);
984 if (_Salome_file_map_it == _map->end()) {
985 Salome_file_i * Sfile = new Salome_file_i();
986 Engines::Container_ptr container = this->GetContainerRef();
987 Sfile->setContainer(Engines::Container::_duplicate(container));
988 (*_map)[Salome_file_name] = Sfile;
991 Salome_file_i * Sfile = (*_map)[Salome_file_name];
992 return Sfile->_this();
996 Engines_Component_i::checkInputFilesToService(const char* service_name)
998 // Try to find the service, if it doesn't exist, nothing to do.
999 _Service_file_map_it = _Input_Service_file_map.find(service_name);
1000 if (_Service_file_map_it != _Input_Service_file_map.end()) {
1001 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
1002 _t_Salome_file_map::iterator begin = _map->begin();
1003 _t_Salome_file_map::iterator end = _map->end();
1005 for(;begin!=end;begin++) {
1006 Salome_file_i * file = begin->second;
1007 std::string file_port_name = begin->first;
1008 configureSalome_file(service_name, file_port_name, file);
1014 Engines::Salome_file_ptr
1015 Engines_Component_i::getOutputFileToService(const char* service_name,
1016 const char* Salome_file_name)
1018 // Try to find the service, if it doesn't exist, we throw an exception.
1019 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1020 if (_Service_file_map_it == _Output_Service_file_map.end()) {
1021 SALOME::ExceptionStruct es;
1022 es.type = SALOME::INTERNAL_ERROR;
1023 es.text = "service doesn't have salome files";
1024 throw SALOME::SALOME_Exception(es);
1026 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1028 // Try to find the Salome_file ...
1029 _Salome_file_map_it = _map->find(Salome_file_name);
1030 if (_Salome_file_map_it == _map->end()) {
1031 SALOME::ExceptionStruct es;
1032 es.type = SALOME::INTERNAL_ERROR;
1033 es.text = "service doesn't have this Salome_file";
1034 throw SALOME::SALOME_Exception(es);
1036 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1038 return Sfile->_this();
1041 Engines::Salome_file_ptr
1042 Engines_Component_i::setOutputFileToService(const char* service_name,
1043 const char* Salome_file_name)
1045 // Try to find the service, if it doesn't exist, we add it.
1046 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1047 if (_Service_file_map_it == _Output_Service_file_map.end()) {
1048 _t_Salome_file_map * _map = new _t_Salome_file_map();
1049 _Output_Service_file_map[service_name] = _map;
1051 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1053 // Try to find the Salome_file ...
1054 _Salome_file_map_it = _map->find(Salome_file_name);
1055 if (_Salome_file_map_it == _map->end()) {
1056 Salome_file_i * Sfile = new Salome_file_i();
1057 Engines::Container_ptr container = this->GetContainerRef();
1058 Sfile->setContainer(Engines::Container::_duplicate(container));
1059 (*_map)[Salome_file_name] = Sfile;
1062 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1063 return Sfile->_this();
1067 Engines_Component_i::checkOutputFilesToService(const char* service_name)
1069 // Try to find the service, if it doesn't exist, nothing to do.
1070 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1071 if (_Service_file_map_it != _Output_Service_file_map.end()) {
1072 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1073 _t_Salome_file_map::iterator begin = _map->begin();
1074 _t_Salome_file_map::iterator end = _map->end();
1076 for(;begin!=end;begin++) {
1077 Salome_file_i * file = begin->second;
1078 std::string file_port_name = begin->first;
1079 configureSalome_file(service_name, file_port_name, file);
1086 //=============================================================================
1088 * C++ method: used to configure the Salome_file into the runtime.
1089 * \param service_name name of the service that use this Salome_file
1090 * \param file_port_name name of the Salome_file
1091 * \param file Salome_file C++ object
1093 //=============================================================================
1095 Engines_Component_i::configureSalome_file(std::string service_name,
1096 std::string file_port_name,
1097 Salome_file_i * file)
1099 // By default this method does nothing