1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SALOME Container : implementation of container and engine for Kernel
23 // File : Component_i.cxx
24 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
27 //#define private protected // for pd_refCount trace
29 #include "SALOME_Component_i.hxx"
30 #include "SALOME_Container_i.hxx"
31 #include "RegistryConnexion.hxx"
32 #include "Basics_Utils.hxx"
38 #include "utilities.h"
42 #include <sys/resource.h>
45 #include <sys/timeb.h>
53 extern bool _Sleeping ;
54 static Engines_Component_i * theEngines_Component ;
56 bool Engines_Component_i::_isMultiStudy = true;
57 bool Engines_Component_i::_isMultiInstance = false;
59 /*! \class Engines_Component_i
60 * \brief C++ implementation of Engines::Component interface
64 //=============================================================================
66 * Default constructor, not for use
68 //=============================================================================
70 Engines_Component_i::Engines_Component_i():_myConnexionToRegistry(0), _notifSupplier(0)
73 MESSAGE("Default Constructor, not for normal use...");
76 //=============================================================================
77 /*! \brief Standard Constructor for generic Component, used in derived class
79 * Connection to Registry and Notification
80 * \param orb Object Request broker given by Container
81 * \param poa Portable Object Adapter from Container (normally root_poa)
82 * \param contId container CORBA id inside the server
83 * \param instanceName unique instance name for this object (see Container_i)
84 * \param interfaceName component class name
85 * \param notif use of notification
86 * \param regist (true or false) use of registry (default true)
88 //=============================================================================
90 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
91 PortableServer::POA_ptr poa,
92 PortableServer::ObjectId * contId,
93 const char *instanceName,
94 const char *interfaceName,
97 _instanceName(instanceName),
98 _interfaceName(interfaceName),
99 _myConnexionToRegistry(0),
107 _CanceledThread(false)
109 MESSAGE("Component constructor with instanceName "<< _instanceName);
110 _orb = CORBA::ORB::_duplicate(orb);
111 _poa = PortableServer::POA::_duplicate(poa);
113 CORBA::Object_var o = _poa->id_to_reference(*contId); // container ior...
114 _container=Engines::Container::_narrow(o);
118 const CORBA::String_var ior = _orb->object_to_string(o);
119 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession",
120 _instanceName.c_str());
123 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
126 //=============================================================================
127 /*! \brief Standard Constructor for standalone Component, used in derived class
129 * Connection to Registry and Notification
130 * \param orb Object Request broker given by Container
131 * \param poa Portable Object Adapter from Container (normally root_poa)
132 * \param container container CORBA reference
133 * \param instanceName unique instance name for this object (see Container_i)
134 * \param interfaceName component class name
135 * \param notif use of notification
136 * \param regist (true or false) use of registry (default true)
138 //=============================================================================
140 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
141 PortableServer::POA_ptr poa,
142 Engines::Container_ptr container,
143 const char *instanceName,
144 const char *interfaceName,
147 _instanceName(instanceName),
148 _interfaceName(interfaceName),
149 _myConnexionToRegistry(0),
157 _CanceledThread(false)
159 MESSAGE("Component constructor with instanceName "<< _instanceName);
160 _orb = CORBA::ORB::_duplicate(orb);
161 _poa = PortableServer::POA::_duplicate(poa);
162 _container=Engines::Container::_duplicate(container);
165 _contId=_poa->reference_to_id(container);
167 catch(PortableServer::POA::WrongAdapter)
169 //not created by this poa
172 const CORBA::String_var ior = _orb->object_to_string(_container);
174 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession", _instanceName.c_str());
175 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
179 //=============================================================================
181 * Destructor: call Container for decrement of instances count.
182 * When instances count falls to 0, the container tries to remove the
183 * component library (dlclose)
185 //=============================================================================
187 Engines_Component_i::~Engines_Component_i()
189 MESSAGE("Component destructor");
190 Engines_Container_i::decInstanceCnt(_interfaceName);
191 if(_myConnexionToRegistry)delete _myConnexionToRegistry;
192 if(_notifSupplier)delete _notifSupplier;
195 //=============================================================================
197 * CORBA method: return name of the instance, unique in this Container
199 //=============================================================================
201 char* Engines_Component_i::instanceName()
203 return CORBA::string_dup(_instanceName.c_str()) ;
206 //=============================================================================
208 * CORBA method: return name of the component class
210 //=============================================================================
212 char* Engines_Component_i::interfaceName()
214 return CORBA::string_dup(_interfaceName.c_str()) ;
217 //=============================================================================
219 * CORBA method: Get study Id
220 * \return -1: not initialised (Internal Error)
221 * 0: multistudy component instance
222 * >0: study id associated to this instance
224 //=============================================================================
226 CORBA::Long Engines_Component_i::getStudyId()
231 //=============================================================================
233 * CORBA method: Test if instance is alive and responds
235 //=============================================================================
237 void Engines_Component_i::ping()
240 MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid "
243 MESSAGE("Engines_Component_i::ping() pid "<< _getpid()<< " threadid "
244 << pthread_self().p );
248 //=============================================================================
250 * CORBA method: Deactivate this instance. CORBA object is deactivated (do not
251 * respond any more to CORBA calls), the connection to Regsitry is removed
252 * (Registry informed of deactivation), internal server reference counter on
253 * the derived servant class is decremented, to allow destruction of the class
254 * (delete) by POA, when there are no more references.
255 * -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
257 //=============================================================================
259 void Engines_Component_i::destroy()
261 MESSAGE("Engines_Component_i::destroy()");
262 //SCRUTE(_refcount_value());
264 if(_myConnexionToRegistry)delete _myConnexionToRegistry;
265 _myConnexionToRegistry = 0 ;
266 if(_notifSupplier)delete _notifSupplier;
268 _poa->deactivate_object(*_id);
271 //SCRUTE(_refcount_value());
273 //SCRUTE(_refcount_value());
274 MESSAGE("Engines_Component_i::destroyed") ;
277 //=============================================================================
279 * CORBA method: return CORBA reference of the Container
282 //=============================================================================
284 Engines::Container_ptr Engines_Component_i::GetContainerRef()
286 return Engines::Container::_duplicate(_container);
289 //=============================================================================
292 * Gives a sequence of (key=string,value=any) to the component.
293 * Base class component stores the sequence in a map.
294 * The map is cleared before.
295 * This map is for use by derived classes.
296 * \param dico sequence of (key=string,value=any)
298 //=============================================================================
300 void Engines_Component_i::setProperties(const Engines::FieldsDict& dico)
303 for (CORBA::ULong i=0; i<dico.length(); i++)
305 std::string cle(dico[i].key);
306 _fieldsDict[cle] = dico[i].value;
310 //=============================================================================
313 * returns a previously stored map (key=string,value=any) as a sequence.
314 * (see setProperties)
316 //=============================================================================
318 Engines::FieldsDict* Engines_Component_i::getProperties()
320 Engines::FieldsDict_var copie = new Engines::FieldsDict;
321 copie->length(_fieldsDict.size());
322 map<std::string,CORBA::Any>::iterator it;
324 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++)
326 std::string cle((*it).first);
327 copie[i].key = CORBA::string_dup(cle.c_str());
328 copie[i].value = _fieldsDict[cle];
330 return copie._retn();
333 //=============================================================================
335 * CORBA method: used by Supervision to give names to this instance
337 //=============================================================================
339 void Engines_Component_i::Names( const char * graphName ,
340 const char * nodeName )
342 _graphName = graphName ;
343 _nodeName = nodeName ;
344 // MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
345 // << _nodeName << "' )");
348 //=============================================================================
350 * CORBA method: used in Supervision
352 //=============================================================================
354 bool Engines_Component_i::Kill_impl()
356 // MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
357 // << " pid " << getpid() << " instanceName "
358 // << _instanceName.c_str() << " interface " << _interfaceName.c_str()
359 // << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
360 // << dec << " _ThreadId " << _ThreadId << " this " << hex << this
363 bool RetVal = false ;
365 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
367 RetVal = Killer( _ThreadId , SIGUSR2 ) ;
368 _ThreadId = (pthread_t ) -1 ;
372 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
374 RetVal = Killer( *_ThreadId , 0 ) ;
375 _ThreadId = (pthread_t* ) 0 ;
382 //=============================================================================
384 * CORBA method: used in Supervision
386 //=============================================================================
388 bool Engines_Component_i::Stop_impl()
391 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self()
392 << " pid " << getpid() << " instanceName "
393 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
394 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
395 << dec << " _ThreadId " << _ThreadId );
397 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self().p
398 << " pid " << _getpid() << " instanceName "
399 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
400 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
401 << dec << " _ThreadId " << _ThreadId );
405 bool RetVal = false ;
407 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
409 RetVal = Killer( _ThreadId , 0 ) ;
410 _ThreadId = (pthread_t ) -1 ;
413 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
415 RetVal = Killer( *_ThreadId , 0 ) ;
416 _ThreadId = (pthread_t* ) 0 ;
422 //=============================================================================
424 * CORBA method: used in Supervision
426 //=============================================================================
428 bool Engines_Component_i::Suspend_impl()
431 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self()
432 << " pid " << getpid() << " instanceName "
433 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
434 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
435 << dec << " _ThreadId " << _ThreadId );
437 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self().p
438 << " pid " << _getpid() << " instanceName "
439 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
440 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
441 << dec << " _ThreadId " << _ThreadId );
444 bool RetVal = false ;
446 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
448 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
458 RetVal = Killer( _ThreadId ,SIGINT ) ;
460 RetVal = Killer( *_ThreadId ,SIGINT ) ;
462 //if ( RetVal ) _Sleeping = true;
469 //=============================================================================
471 * CORBA method: used in Supervision
473 //=============================================================================
475 bool Engines_Component_i::Resume_impl()
478 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self()
479 << " pid " << getpid() << " instanceName "
480 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
481 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
482 << dec << " _ThreadId " << _ThreadId );
484 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self().p
485 << " pid " << _getpid() << " instanceName "
486 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
487 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
488 << dec << " _ThreadId " << _ThreadId );
490 bool RetVal = false ;
492 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
494 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
510 //=============================================================================
514 //=============================================================================
516 CORBA::Long Engines_Component_i::CpuUsed_impl()
519 if ( _ThreadId || _Executed )
524 if ( pthread_self() != _ThreadId )
526 if ( pthread_self().p != _ThreadId->p )
534 // Get Cpu in the appropriate thread with that object !...
535 theEngines_Component = this ;
537 Killer( _ThreadId ,SIGUSR1 ) ;
539 Killer( *_ThreadId ,SIGUSR11 ) ;
542 cpu = _ThreadCpuUsed ;
546 _ThreadCpuUsed = CpuUsed() ;
547 cpu = _ThreadCpuUsed ;
548 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
549 // << _serviceName << " " << cpu << endl ;
554 cpu = _ThreadCpuUsed ;
555 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
556 // << _serviceName << " " << cpu<< endl ;
561 // cout<< pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId "
562 // <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<<endl;
568 //=============================================================================
570 * C++ method: return Container Servant
572 //=============================================================================
574 Engines_Container_i *Engines_Component_i::GetContainerPtr()
576 return dynamic_cast<Engines_Container_i*>(_poa->id_to_servant(*_contId)) ;
579 //=============================================================================
581 * C++ method: set study Id
582 * \param studyId 0 if instance is not associated to a study,
583 * >0 otherwise (== study id)
584 * \return true if the set of study Id is OK
585 * must be set once by Container, at instance creation,
586 * and cannot be changed after.
588 //=============================================================================
590 CORBA::Boolean Engines_Component_i::setStudyId(CORBA::Long studyId)
592 ASSERT( studyId >= 0);
593 CORBA::Boolean ret = false;
594 if (_studyId < 0) // --- not yet initialized
600 if ( _studyId == studyId) ret = true;
604 //=============================================================================
606 * C++ method: return CORBA instance id, the id is set in derived class
607 * constructor, when instance is activated.
609 //=============================================================================
611 PortableServer::ObjectId * Engines_Component_i::getId()
613 // MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
617 //=============================================================================
619 * C++ method: used by derived classes for supervision
621 //=============================================================================
623 void Engines_Component_i::beginService(const char *serviceName)
626 MESSAGE(pthread_self() << "Send BeginService notification for " <<serviceName
627 << endl << "Component instance : " << _instanceName << endl << endl);
629 MESSAGE(pthread_self().p << "Send BeginService notification for " <<serviceName
630 << endl << "Component instance : " << _instanceName << endl << endl);
632 std::cerr << "beginService for " << serviceName << " Component instance : " << _instanceName << std::endl;
634 _ThreadId = pthread_self() ;
636 _ThreadId = new pthread_t;
637 _ThreadId->p = pthread_self().p ;
638 _ThreadId->x = pthread_self().x ;
641 _StartUsed = CpuUsed_impl() ;
644 _serviceName = serviceName ;
645 theEngines_Component = this ;
646 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) )
648 perror("pthread_setcanceltype ") ;
651 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) )
653 perror("pthread_setcancelstate ") ;
656 // MESSAGE(pthread_self() << " Return from BeginService for " << serviceName
657 // << " ThreadId " << _ThreadId << " StartUsed " << _StartUsed
658 // << " _graphName " << _graphName << " _nodeName " << _nodeName );
660 // --- for supervisor : all strings given with setProperties
661 // are set in environment
662 bool overwrite = true;
663 map<std::string,CORBA::Any>::iterator it;
664 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
666 std::string cle((*it).first);
667 if ((*it).second.type()->kind() == CORBA::tk_string)
670 (*it).second >>= value;
671 // ---todo: replace __GNUC__ test by an autoconf macro AC_CHECK_FUNC.
673 // int ret = setenv(cle.c_str(), value, overwrite);
674 setenv(cle.c_str(), value, overwrite);
676 //CCRT porting : setenv not defined in stdlib.h
680 // char* cast because 1st arg of linux putenv function
681 // is not a const char* !
682 // int ret=putenv((char *)s.c_str());
683 putenv((char *)s.c_str());
684 //End of CCRT porting
686 MESSAGE("--- setenv: "<<cle<<" = "<< value);
691 //=============================================================================
693 * C++ method: used by derived classes for supervision
695 //=============================================================================
697 void Engines_Component_i::endService(const char *serviceName)
699 if ( !_CanceledThread )
700 _ThreadCpuUsed = CpuUsed_impl() ;
702 float cpus=_ThreadCpuUsed/1000.;
703 std::cerr << "endService for " << serviceName << " Component instance : " << _instanceName ;
704 std::cerr << " Cpu Used: " << cpus << " (s) " << std::endl;
706 MESSAGE(pthread_self() << " Send EndService notification for " << serviceName
707 << endl << " Component instance : " << _instanceName << " StartUsed "
708 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << endl <<endl);
710 MESSAGE(pthread_self().p << " Send EndService notification for " << serviceName
711 << endl << " Component instance : " << _instanceName << " StartUsed "
712 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << endl <<endl);
717 //=============================================================================
719 * C++ method: -- CHECK IF USED --
721 //=============================================================================
723 char* Engines_Component_i::graphName()
725 return CORBA::string_dup( _graphName.c_str() ) ;
728 //=============================================================================
730 * C++ method: -- CHECK IF USED --
732 //=============================================================================
734 char* Engines_Component_i::nodeName()
736 return CORBA::string_dup( _nodeName.c_str() ) ;
739 //=============================================================================
741 * C++ method: used in Supervision (see kill_impl)
743 //=============================================================================
745 bool Engines_Component_i::Killer( pthread_t ThreadId , int signum )
755 if ( pthread_cancel( ThreadId ) )
757 perror("Killer pthread_cancel error") ;
763 MESSAGE(pthread_self() << "Killer : ThreadId " << ThreadId
764 << " pthread_canceled") ;
766 MESSAGE(pthread_self().p << "Killer : ThreadId " << ThreadId.p
767 << " pthread_canceled") ;
773 if ( pthread_kill( ThreadId , signum ) == -1 )
775 perror("Killer pthread_kill error") ;
781 MESSAGE(pthread_self() << "Killer : ThreadId " << ThreadId
782 << " pthread_killed(" << signum << ")") ;
784 MESSAGE(pthread_self().p << "Killer : ThreadId " << ThreadId.p
785 << " pthread_killed(" << signum << ")") ;
793 //=============================================================================
797 //=============================================================================
801 if ( theEngines_Component )
802 theEngines_Component->SetCurCpu() ;
805 //=============================================================================
809 //=============================================================================
811 void Engines_Component_i::SetCurCpu()
813 _ThreadCpuUsed = CpuUsed() ;
814 // MESSAGE(pthread_self() <<
815 // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ;
818 //=============================================================================
822 //=============================================================================
824 long Engines_Component_i::CpuUsed()
828 struct rusage usage ;
829 if ( _ThreadId || _Executed )
831 if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
833 perror("Engines_Component_i::CpuUsed") ;
836 //cpu time is calculated in millisecond (user+system times)
837 cpu = usage.ru_utime.tv_sec*1000 +usage.ru_utime.tv_usec/1000;
838 cpu = cpu+ usage.ru_stime.tv_sec*1000 +usage.ru_stime.tv_usec/1000;
840 // cout << pthread_self() << " Engines_Component_i::CpuUsed " << " "
841 // << _serviceName << usage.ru_utime.tv_sec << " - " << _StartUsed
842 // << " = " << cpu << endl ;
846 // cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId "
847 // << _ThreadId << " " << _serviceName<< " _StartUsed "
848 // << _StartUsed << endl ;
851 // NOT implementet yet
858 void CallCancelThread()
860 if ( theEngines_Component )
861 theEngines_Component->CancelThread() ;
864 //=============================================================================
868 //=============================================================================
870 void Engines_Component_i::CancelThread()
872 _CanceledThread = true;
875 //=============================================================================
877 * C++ method: Send message to event channel
879 //=============================================================================
881 void Engines_Component_i::sendMessage(const char *event_type,
884 _notifSupplier->Send(_graphName.c_str(), _nodeName.c_str(), event_type, message);
887 //=============================================================================
889 * C++ method: return standard library name built on component name
891 //=============================================================================
893 string Engines_Component_i::GetDynLibraryName(const char *componentName)
901 //=============================================================================
903 * C++ method: DumpPython default implementation
905 //=============================================================================
907 Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Object_ptr theStudy,
908 CORBA::Boolean isPublished,
909 CORBA::Boolean& isValidScript)
911 const char* aScript = "def RebuildData(theStudy): pass";
912 char* aBuffer = new char[strlen(aScript)+1];
913 strcpy(aBuffer, aScript);
914 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
915 int aBufferSize = strlen(aBuffer)+1;
916 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
917 isValidScript = true;
918 return aStreamFile._retn();
921 Engines::Salome_file_ptr
922 Engines_Component_i::getInputFileToService(const char* service_name,
923 const char* Salome_file_name)
925 // Try to find the service, if it doesn't exist, we throw an exception.
926 _Service_file_map_it = _Input_Service_file_map.find(service_name);
927 if (_Service_file_map_it == _Input_Service_file_map.end()) {
928 SALOME::ExceptionStruct es;
929 es.type = SALOME::INTERNAL_ERROR;
930 es.text = "service doesn't have salome files";
931 throw SALOME::SALOME_Exception(es);
933 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
935 // Try to find the Salome_file ...
936 _Salome_file_map_it = _map->find(Salome_file_name);
937 if (_Salome_file_map_it == _map->end()) {
938 SALOME::ExceptionStruct es;
939 es.type = SALOME::INTERNAL_ERROR;
940 es.text = "service doesn't have this Salome_file";
941 throw SALOME::SALOME_Exception(es);
943 Salome_file_i * Sfile = (*_map)[Salome_file_name];
945 return Sfile->_this();
948 Engines::Salome_file_ptr
949 Engines_Component_i::setInputFileToService(const char* service_name,
950 const char* Salome_file_name)
952 // Try to find the service, if it doesn't exist, we add it.
953 _Service_file_map_it = _Input_Service_file_map.find(service_name);
954 if (_Service_file_map_it == _Input_Service_file_map.end()) {
955 _t_Salome_file_map * _map = new _t_Salome_file_map();
956 _Input_Service_file_map[service_name] = _map;
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_file_i * Sfile = new Salome_file_i();
964 Engines::Container_ptr container = this->GetContainerRef();
965 Sfile->setContainer(Engines::Container::_duplicate(container));
966 (*_map)[Salome_file_name] = Sfile;
969 Salome_file_i * Sfile = (*_map)[Salome_file_name];
970 return Sfile->_this();
974 Engines_Component_i::checkInputFilesToService(const char* service_name)
976 // Try to find the service, if it doesn't exist, nothing to do.
977 _Service_file_map_it = _Input_Service_file_map.find(service_name);
978 if (_Service_file_map_it != _Input_Service_file_map.end()) {
979 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
980 _t_Salome_file_map::iterator begin = _map->begin();
981 _t_Salome_file_map::iterator end = _map->end();
983 for(;begin!=end;begin++) {
984 Salome_file_i * file = begin->second;
985 std::string file_port_name = begin->first;
986 configureSalome_file(service_name, file_port_name, file);
992 Engines::Salome_file_ptr
993 Engines_Component_i::getOutputFileToService(const char* service_name,
994 const char* Salome_file_name)
996 // Try to find the service, if it doesn't exist, we throw an exception.
997 _Service_file_map_it = _Output_Service_file_map.find(service_name);
998 if (_Service_file_map_it == _Output_Service_file_map.end()) {
999 SALOME::ExceptionStruct es;
1000 es.type = SALOME::INTERNAL_ERROR;
1001 es.text = "service doesn't have salome files";
1002 throw SALOME::SALOME_Exception(es);
1004 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1006 // Try to find the Salome_file ...
1007 _Salome_file_map_it = _map->find(Salome_file_name);
1008 if (_Salome_file_map_it == _map->end()) {
1009 SALOME::ExceptionStruct es;
1010 es.type = SALOME::INTERNAL_ERROR;
1011 es.text = "service doesn't have this Salome_file";
1012 throw SALOME::SALOME_Exception(es);
1014 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1016 return Sfile->_this();
1019 Engines::Salome_file_ptr
1020 Engines_Component_i::setOutputFileToService(const char* service_name,
1021 const char* Salome_file_name)
1023 // Try to find the service, if it doesn't exist, we add it.
1024 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1025 if (_Service_file_map_it == _Output_Service_file_map.end()) {
1026 _t_Salome_file_map * _map = new _t_Salome_file_map();
1027 _Output_Service_file_map[service_name] = _map;
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_file_i * Sfile = new Salome_file_i();
1035 Engines::Container_ptr container = this->GetContainerRef();
1036 Sfile->setContainer(Engines::Container::_duplicate(container));
1037 (*_map)[Salome_file_name] = Sfile;
1040 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1041 return Sfile->_this();
1045 Engines_Component_i::checkOutputFilesToService(const char* service_name)
1047 // Try to find the service, if it doesn't exist, nothing to do.
1048 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1049 if (_Service_file_map_it != _Output_Service_file_map.end()) {
1050 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1051 _t_Salome_file_map::iterator begin = _map->begin();
1052 _t_Salome_file_map::iterator end = _map->end();
1054 for(;begin!=end;begin++) {
1055 Salome_file_i * file = begin->second;
1056 std::string file_port_name = begin->first;
1057 configureSalome_file(service_name, file_port_name, file);
1064 //=============================================================================
1066 * C++ method: used to configure the Salome_file into the runtime.
1067 * \param service_name name of the service that use this Salome_file
1068 * \param file_port_name name of the Salome_file
1069 * \param file Salome_file C++ object
1071 //=============================================================================
1073 Engines_Component_i::configureSalome_file(std::string service_name,
1074 std::string file_port_name,
1075 Salome_file_i * file)
1077 // By default this method does nothing
1080 //=============================================================================
1082 * C++ method: return the name of the container associated with this component
1083 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1084 * \return the container name (reformatted)
1086 //=============================================================================
1087 std::string Engines_Component_i::getContainerName()
1089 CORBA::String_var containerName=_container->name();
1090 std::string name(containerName);
1092 string::size_type slash =name.find_first_of('/');
1093 if(slash != std::string::npos)