1 // Copyright (C) 2007-2012 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
23 // SALOME Container : implementation of container and engine for Kernel
24 // File : Component_i.cxx
25 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
28 //#define private protected // for pd_refCount trace
30 #include "SALOME_Component_i.hxx"
31 #include "SALOME_Container_i.hxx"
32 #include "RegistryConnexion.hxx"
33 #include "Basics_Utils.hxx"
39 #include "utilities.h"
43 #include <sys/resource.h>
46 #include <sys/timeb.h>
51 extern bool _Sleeping ;
52 static Engines_Component_i * theEngines_Component ;
54 bool Engines_Component_i::_isMultiStudy = true;
55 bool Engines_Component_i::_isMultiInstance = false;
57 /*! \class Engines_Component_i
58 * \brief C++ implementation of Engines::Component interface
62 //=============================================================================
64 * Default constructor, not for use
66 //=============================================================================
68 Engines_Component_i::Engines_Component_i():_myConnexionToRegistry(0), _notifSupplier(0), _id(0)
71 MESSAGE("Default Constructor, not for normal use...");
74 //=============================================================================
75 /*! \brief Standard Constructor for generic Component, used in derived class
77 * Connection to Registry and Notification
78 * \param orb Object Request broker given by Container
79 * \param poa Portable Object Adapter from Container (normally root_poa)
80 * \param contId container CORBA id inside the server
81 * \param instanceName unique instance name for this object (see Container_i)
82 * \param interfaceName component class name
83 * \param notif use of notification
84 * \param regist (true or false) use of registry (default true)
86 //=============================================================================
88 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
89 PortableServer::POA_ptr poa,
90 PortableServer::ObjectId * contId,
91 const char *instanceName,
92 const char *interfaceName,
95 _instanceName(instanceName),
96 _interfaceName(interfaceName),
97 _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);
119 const CORBA::String_var ior = _orb->object_to_string(o);
120 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession",
121 _instanceName.c_str());
125 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
128 //=============================================================================
129 /*! \brief Standard Constructor for standalone Component, used in derived class
131 * Connection to Registry and Notification
132 * \param orb Object Request broker given by Container
133 * \param poa Portable Object Adapter from Container (normally root_poa)
134 * \param container container CORBA reference
135 * \param instanceName unique instance name for this object (see Container_i)
136 * \param interfaceName component class name
137 * \param notif use of notification
138 * \param regist (true or false) use of registry (default true)
140 //=============================================================================
142 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
143 PortableServer::POA_ptr poa,
144 Engines::Container_ptr container,
145 const char *instanceName,
146 const char *interfaceName,
149 _instanceName(instanceName),
150 _interfaceName(interfaceName),
151 _myConnexionToRegistry(0),
161 _CanceledThread(false)
163 MESSAGE("Component constructor with instanceName "<< _instanceName);
164 _orb = CORBA::ORB::_duplicate(orb);
165 _poa = PortableServer::POA::_duplicate(poa);
166 _container=Engines::Container::_duplicate(container);
168 const CORBA::String_var ior = _orb->object_to_string(_container);
170 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession", _instanceName.c_str());
172 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
177 //=============================================================================
179 * Destructor: call Container for decrement of instances count.
180 * When instances count falls to 0, the container tries to remove the
181 * component library (dlclose)
183 //=============================================================================
185 Engines_Component_i::~Engines_Component_i()
187 MESSAGE("Component destructor");
188 Engines_Container_i::decInstanceCnt(_interfaceName);
189 if(_myConnexionToRegistry)delete _myConnexionToRegistry;
190 _myConnexionToRegistry = 0 ;
197 SCRUTE(_notifSupplier->_refcount_value());
198 PortableServer::POA_var poa=_notifSupplier->_default_POA();
199 PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_notifSupplier);
200 poa->deactivate_object(anObjectId.in());
201 SCRUTE(_notifSupplier->_refcount_value());
202 _notifSupplier->_remove_ref();
206 //=============================================================================
208 * CORBA method: return name of the instance, unique in this Container
210 //=============================================================================
212 char* Engines_Component_i::instanceName()
214 return CORBA::string_dup(_instanceName.c_str()) ;
217 //=============================================================================
219 * CORBA method: return name of the component class
221 //=============================================================================
223 char* Engines_Component_i::interfaceName()
225 return CORBA::string_dup(_interfaceName.c_str()) ;
228 //=============================================================================
230 * CORBA method: Get study Id
231 * \return -1: not initialised (Internal Error)
232 * 0: multistudy component instance
233 * >0: study id associated to this instance
235 //=============================================================================
237 CORBA::Long Engines_Component_i::getStudyId()
242 //=============================================================================
244 * CORBA method: Test if instance is alive and responds
246 //=============================================================================
248 void Engines_Component_i::ping()
251 MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid "
254 MESSAGE("Engines_Component_i::ping() pid "<< _getpid()<< " threadid "
255 << pthread_self().p );
259 //=============================================================================
261 * CORBA method: Deactivate this instance. CORBA object is deactivated (do not
262 * respond any more to CORBA calls), the connection to Regsitry is removed
263 * (Registry informed of deactivation), internal server reference counter on
264 * the derived servant class is decremented, to allow destruction of the class
265 * (delete) by POA, when there are no more references.
266 * -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
268 //=============================================================================
270 void Engines_Component_i::destroy()
272 MESSAGE("Engines_Component_i::destroy()");
273 //SCRUTE(_refcount_value());
274 _poa->deactivate_object(*_id);
275 //SCRUTE(_refcount_value());
277 //SCRUTE(_refcount_value());
278 MESSAGE("Engines_Component_i::destroyed") ;
281 //=============================================================================
283 * CORBA method: return CORBA reference of the Container
286 //=============================================================================
288 Engines::Container_ptr Engines_Component_i::GetContainerRef()
290 return Engines::Container::_duplicate(_container);
293 //=============================================================================
296 * Gives a sequence of (key=string,value=any) to the component.
297 * Base class component stores the sequence in a map.
298 * The map is cleared before.
299 * This map is for use by derived classes.
300 * \param dico sequence of (key=string,value=any)
302 //=============================================================================
304 void Engines_Component_i::setProperties(const Engines::FieldsDict& dico)
307 for (CORBA::ULong i=0; i<dico.length(); i++)
309 std::string cle(dico[i].key);
310 _fieldsDict[cle] = dico[i].value;
314 //=============================================================================
317 * returns a previously stored map (key=string,value=any) as a sequence.
318 * (see setProperties)
320 //=============================================================================
322 Engines::FieldsDict* Engines_Component_i::getProperties()
324 Engines::FieldsDict_var copie = new Engines::FieldsDict;
325 copie->length(_fieldsDict.size());
326 std::map<std::string,CORBA::Any>::iterator it;
328 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++)
330 std::string cle((*it).first);
331 copie[i].key = CORBA::string_dup(cle.c_str());
332 copie[i].value = _fieldsDict[cle];
334 return copie._retn();
337 //=============================================================================
340 * This method is to set an option specific to a certain EngineComponent.
342 //=============================================================================
344 void Engines_Component_i::SetOption(const char*, const char*)
348 //=============================================================================
351 * This method is to get value of an option specific to a certain EngineComponent.
353 //=============================================================================
355 char* Engines_Component_i::GetOption(const char*)
357 return CORBA::string_dup("") ;
360 //=============================================================================
362 * CORBA method: used by Supervision to give names to this instance
364 //=============================================================================
366 void Engines_Component_i::Names( const char * graphName ,
367 const char * nodeName )
369 _graphName = graphName ;
370 _nodeName = nodeName ;
371 // MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
372 // << _nodeName << "' )");
375 //=============================================================================
377 * CORBA method: used in Supervision
379 //=============================================================================
381 bool Engines_Component_i::Kill_impl()
383 // MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
384 // << " pid " << getpid() << " instanceName "
385 // << _instanceName.c_str() << " interface " << _interfaceName.c_str()
386 // << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
387 // << dec << " _ThreadId " << _ThreadId << " this " << hex << this
390 bool RetVal = false ;
392 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
394 RetVal = Killer( _ThreadId , SIGUSR2 ) ;
395 _ThreadId = (pthread_t ) -1 ;
399 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
401 RetVal = Killer( *_ThreadId , 0 ) ;
402 _ThreadId = (pthread_t* ) 0 ;
409 //=============================================================================
411 * CORBA method: used in Supervision
413 //=============================================================================
415 bool Engines_Component_i::Stop_impl()
418 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self()
419 << " pid " << getpid() << " instanceName "
420 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
421 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
422 << std::dec << " _ThreadId " << _ThreadId );
424 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self().p
425 << " pid " << _getpid() << " instanceName "
426 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
427 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
428 << std::dec << " _ThreadId " << _ThreadId );
432 bool RetVal = false ;
434 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
436 RetVal = Killer( _ThreadId , 0 ) ;
437 _ThreadId = (pthread_t ) -1 ;
440 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
442 RetVal = Killer( *_ThreadId , 0 ) ;
443 _ThreadId = (pthread_t* ) 0 ;
449 //=============================================================================
451 * CORBA method: used in Supervision
453 //=============================================================================
455 bool Engines_Component_i::Suspend_impl()
458 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self()
459 << " pid " << getpid() << " instanceName "
460 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
461 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
462 << std::dec << " _ThreadId " << _ThreadId );
464 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self().p
465 << " pid " << _getpid() << " instanceName "
466 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
467 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
468 << std::dec << " _ThreadId " << _ThreadId );
471 bool RetVal = false ;
473 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
475 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
485 RetVal = Killer( _ThreadId ,SIGINT ) ;
487 RetVal = Killer( *_ThreadId ,SIGINT ) ;
489 //if ( RetVal ) _Sleeping = true;
496 //=============================================================================
498 * CORBA method: used in Supervision
500 //=============================================================================
502 bool Engines_Component_i::Resume_impl()
505 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self()
506 << " pid " << getpid() << " instanceName "
507 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
508 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
509 << std::dec << " _ThreadId " << _ThreadId );
511 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self().p
512 << " pid " << _getpid() << " instanceName "
513 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
514 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
515 << std::dec << " _ThreadId " << _ThreadId );
517 bool RetVal = false ;
519 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
521 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
537 //=============================================================================
541 //=============================================================================
543 CORBA::Long Engines_Component_i::CpuUsed_impl()
546 if ( _ThreadId || _Executed )
551 if ( pthread_self() != _ThreadId )
553 if ( pthread_self().p != _ThreadId->p )
561 // Get Cpu in the appropriate thread with that object !...
562 theEngines_Component = this ;
564 Killer( _ThreadId ,SIGUSR1 ) ;
566 Killer( *_ThreadId ,SIGUSR11 ) ;
569 cpu = _ThreadCpuUsed ;
573 _ThreadCpuUsed = CpuUsed() ;
574 cpu = _ThreadCpuUsed ;
575 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
576 // << _serviceName << " " << cpu << endl ;
581 cpu = _ThreadCpuUsed ;
582 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
583 // << _serviceName << " " << cpu<< endl ;
588 // cout<< pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId "
589 // <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<<endl;
595 //=============================================================================
597 * C++ method: return Container Servant
599 //=============================================================================
601 Engines_Container_i *Engines_Component_i::GetContainerPtr()
603 PortableServer::ObjectId_var contId=_poa->reference_to_id(_container);
604 return dynamic_cast<Engines_Container_i*>(_poa->id_to_servant(contId)) ;
607 //=============================================================================
609 * C++ method: set study Id
610 * \param studyId 0 if instance is not associated to a study,
611 * >0 otherwise (== study id)
612 * \return true if the set of study Id is OK
613 * must be set once by Container, at instance creation,
614 * and cannot be changed after.
616 //=============================================================================
618 CORBA::Boolean Engines_Component_i::setStudyId(CORBA::Long studyId)
620 ASSERT( studyId >= 0);
621 CORBA::Boolean ret = false;
622 if (_studyId < 0) // --- not yet initialized
628 if ( _studyId == studyId) ret = true;
632 //=============================================================================
634 * C++ method: return CORBA instance id, the id is set in derived class
635 * constructor, when instance is activated.
637 //=============================================================================
639 PortableServer::ObjectId * Engines_Component_i::getId()
641 // MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
645 //=============================================================================
647 * C++ method: used by derived classes for supervision
649 //=============================================================================
651 void Engines_Component_i::beginService(const char *serviceName)
653 std::cerr << "beginService for " << serviceName << " Component instance : " << _instanceName << std::endl;
656 _ThreadId = pthread_self() ;
658 _ThreadId = new pthread_t;
659 _ThreadId->p = pthread_self().p ;
660 _ThreadId->x = pthread_self().x ;
663 _StartUsed = CpuUsed_impl() ;
666 _serviceName = serviceName ;
667 theEngines_Component = this ;
668 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) )
670 perror("pthread_setcanceltype ") ;
673 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) )
675 perror("pthread_setcancelstate ") ;
679 // --- all strings given with setProperties are set in environment
680 std::map<std::string,CORBA::Any>::iterator it;
681 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
683 std::string cle((*it).first);
684 if ((*it).second.type()->kind() == CORBA::tk_string)
687 (*it).second >>= value;
691 putenv((char *)s.c_str());
692 MESSAGE("--- setenv: "<<cle<<" = "<< value);
697 //=============================================================================
699 * C++ method: used by derived classes for supervision
701 //=============================================================================
703 void Engines_Component_i::endService(const char *serviceName)
705 if ( !_CanceledThread )
706 _ThreadCpuUsed = CpuUsed_impl() ;
708 float cpus=_ThreadCpuUsed/1000.;
709 std::cerr << "endService for " << serviceName << " Component instance : " << _instanceName ;
710 std::cerr << " Cpu Used: " << cpus << " (s) " << std::endl;
711 MESSAGE("Send EndService notification for " << serviceName
712 << std::endl << " Component instance : " << _instanceName << " StartUsed "
713 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << std::endl <<std::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("Killer : ThreadId " << ThreadId.p << " pthread_canceled") ;
765 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_canceled") ;
771 if ( pthread_kill( ThreadId , signum ) == -1 )
773 perror("Killer pthread_kill error") ;
779 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_killed(" << signum << ")") ;
781 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_killed(" << signum << ")") ;
790 void CallCancelThread();
792 //=============================================================================
796 //=============================================================================
800 if ( theEngines_Component )
801 theEngines_Component->SetCurCpu() ;
804 //=============================================================================
808 //=============================================================================
810 void Engines_Component_i::SetCurCpu()
812 _ThreadCpuUsed = CpuUsed() ;
813 // MESSAGE(pthread_self() <<
814 // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ;
817 //=============================================================================
821 //=============================================================================
823 long Engines_Component_i::CpuUsed()
827 struct rusage usage ;
828 if ( _ThreadId || _Executed )
830 if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
832 perror("Engines_Component_i::CpuUsed") ;
835 //cpu time is calculated in millisecond (user+system times)
836 cpu = usage.ru_utime.tv_sec*1000 +usage.ru_utime.tv_usec/1000;
837 cpu = cpu+ usage.ru_stime.tv_sec*1000 +usage.ru_stime.tv_usec/1000;
839 // std::cout << pthread_self() << " Engines_Component_i::CpuUsed " << " "
840 // << _serviceName << usage.ru_utime.tv_sec << " - " << _StartUsed
841 // << " = " << cpu << std::endl ;
845 // std::cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId "
846 // << _ThreadId << " " << _serviceName<< " _StartUsed "
847 // << _StartUsed << std::endl ;
850 // NOT implementet yet
857 void CallCancelThread()
859 if ( theEngines_Component )
860 theEngines_Component->CancelThread() ;
863 //=============================================================================
867 //=============================================================================
869 void Engines_Component_i::CancelThread()
871 _CanceledThread = true;
874 //=============================================================================
876 * C++ method: Send message to event channel
878 //=============================================================================
880 void Engines_Component_i::sendMessage(const char *event_type,
883 _notifSupplier->Send(_graphName.c_str(), _nodeName.c_str(), event_type, message);
886 //=============================================================================
888 * C++ method: return standard library name built on component name
890 //=============================================================================
892 std::string Engines_Component_i::GetDynLibraryName(const char *componentName)
894 std::string ret="lib";
900 //=============================================================================
902 * C++ method: DumpPython default implementation
904 //=============================================================================
906 Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Object_ptr theStudy,
907 CORBA::Boolean isPublished,
908 CORBA::Boolean isMultiFile,
909 CORBA::Boolean& isValidScript)
911 const char* aScript = isMultiFile ? "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 return _containerName;
1091 //=============================================================================
1093 * C++ method: set the name of the container associated with this component (attribute _containerName)
1094 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1095 * \return the container name (reformatted)
1097 //=============================================================================
1098 void Engines_Component_i::setContainerName()
1100 CORBA::String_var containerName=_container->name();
1101 std::string name(containerName);
1103 std::string::size_type slash =name.find_first_of('/');
1104 if(slash != std::string::npos)
1106 _containerName=name;
1109 //=============================================================================
1111 \brief Get version of the component
1113 This method is supposed to be implemented in all derived classes; default implementation
1114 returns empty string that means that no version information about the component is available.
1116 \note The version of the component is stored to the study, as a part of general persistence
1117 mechanism; once stored, version information in the study cannot be changed.
1119 \return string containing component's version, e.g. "1.0"
1121 char* Engines_Component_i::getVersion()
1123 return CORBA::string_dup( "" );