1 // Copyright (C) 2007-2021 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, or (at your option) any later version.
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"
34 #include "Utils_SINGLETON.hxx"
35 #include "Utils_ORB_INIT.hxx"
36 #include "SALOME_NamingService.hxx"
43 #include "utilities.h"
47 #include <sys/resource.h>
50 #include <sys/timeb.h>
55 extern bool _Sleeping ;
56 static Engines_Component_i * theEngines_Component ;
58 bool Engines_Component_i::_isMultiInstance = false;
60 /*! \class Engines_Component_i
61 * \brief C++ implementation of Engines::Component interface
65 //=============================================================================
67 * Default constructor, not for use
69 //=============================================================================
71 Engines_Component_i::Engines_Component_i(): _id(0), _myConnexionToRegistry(0), _notifSupplier(0)
74 MESSAGE("Default Constructor, not for normal use...");
77 //=============================================================================
78 /*! \brief Standard Constructor for generic Component, used in derived class
80 * Connection to Registry and Notification
81 * \param orb Object Request broker given by Container
82 * \param poa Portable Object Adapter from Container (normally root_poa)
83 * \param contId container CORBA id inside the server
84 * \param instanceName unique instance name for this object (see Container_i)
85 * \param interfaceName component class name
86 * \param notif use of notification
87 * \param regist (true or false) use of registry (default true)
89 //=============================================================================
91 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
92 PortableServer::POA_ptr poa,
93 PortableServer::ObjectId * contId,
94 const char *instanceName,
95 const char *interfaceName,
98 _instanceName(instanceName),
99 _interfaceName(interfaceName),
102 _myConnexionToRegistry(0),
109 _CanceledThread(false)
111 MESSAGE("Component constructor with instanceName "<< _instanceName);
112 _orb = CORBA::ORB::_duplicate(orb);
113 _poa = PortableServer::POA::_duplicate(poa);
115 CORBA::Object_var o = _poa->id_to_reference(*contId); // container ior...
116 _container=Engines::Container::_narrow(o);
121 const CORBA::String_var ior = _orb->object_to_string(o);
122 _myConnexionToRegistry = new RegistryConnexion(ior,"theSession",
123 _instanceName.c_str(), getNS());
127 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
130 //=============================================================================
131 /*! \brief Standard Constructor for standalone Component, used in derived class
133 * Connection to Registry and Notification
134 * \param orb Object Request broker given by Container
135 * \param poa Portable Object Adapter from Container (normally root_poa)
136 * \param container container CORBA reference
137 * \param instanceName unique instance name for this object (see Container_i)
138 * \param interfaceName component class name
139 * \param notif use of notification
140 * \param regist (true or false) use of registry (default true)
142 //=============================================================================
144 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
145 PortableServer::POA_ptr poa,
146 Engines::Container_ptr container,
147 const char *instanceName,
148 const char *interfaceName,
151 _instanceName(instanceName),
152 _interfaceName(interfaceName),
155 _myConnexionToRegistry(0),
162 _CanceledThread(false)
164 MESSAGE("Component constructor with instanceName "<< _instanceName);
165 _orb = CORBA::ORB::_duplicate(orb);
166 _poa = PortableServer::POA::_duplicate(poa);
167 _container=Engines::Container::_duplicate(container);
169 const CORBA::String_var ior = _orb->object_to_string(_container);
172 _myConnexionToRegistry = new RegistryConnexion(ior,"theSession", _instanceName.c_str(),getNS());
175 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
179 SALOME_NamingService_Abstract *Engines_Component_i::getNS()
181 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
182 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
183 CORBA::ORB_var &orb = init( 0 , 0 ) ;
185 SALOME_NamingService *naming = SINGLETON_<SALOME_NamingService>::Instance() ;
186 naming->init_orb( orb ) ;
190 //=============================================================================
192 * Destructor: call Container for decrement of instances count.
193 * When instances count falls to 0, the container tries to remove the
194 * component library (dlclose)
196 //=============================================================================
198 Engines_Component_i::~Engines_Component_i()
200 MESSAGE("Component destructor");
201 Engines_Container_i::decInstanceCnt(_interfaceName);
202 if(_myConnexionToRegistry)delete _myConnexionToRegistry;
203 _myConnexionToRegistry = 0 ;
210 SCRUTE(_notifSupplier->_refcount_value());
211 PortableServer::POA_var poa=_notifSupplier->_default_POA();
212 PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_notifSupplier);
213 poa->deactivate_object(anObjectId.in());
214 SCRUTE(_notifSupplier->_refcount_value());
215 _notifSupplier->_remove_ref();
219 //=============================================================================
221 * CORBA method: return name of the instance, unique in this Container
223 //=============================================================================
225 char* Engines_Component_i::instanceName()
227 return CORBA::string_dup(_instanceName.c_str()) ;
230 //=============================================================================
232 * CORBA method: return name of the component class
234 //=============================================================================
236 char* Engines_Component_i::interfaceName()
238 return CORBA::string_dup(_interfaceName.c_str()) ;
241 //=============================================================================
243 * CORBA method: Test if instance is alive and responds
245 //=============================================================================
247 void Engines_Component_i::ping()
250 MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid "
253 MESSAGE("Engines_Component_i::ping() pid "<< _getpid()<< " threadid "
254 << pthread_self().p );
258 //=============================================================================
260 * CORBA method: Deactivate this instance. CORBA object is deactivated (do not
261 * respond any more to CORBA calls), the connection to Regsitry is removed
262 * (Registry informed of deactivation), internal server reference counter on
263 * the derived servant class is decremented, to allow destruction of the class
264 * (delete) by POA, when there are no more references.
265 * -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
267 //=============================================================================
269 void Engines_Component_i::destroy()
271 MESSAGE("Engines_Component_i::destroy()");
272 //SCRUTE(_refcount_value());
273 _poa->deactivate_object(*_id);
274 //SCRUTE(_refcount_value());
276 //SCRUTE(_refcount_value());
277 MESSAGE("Engines_Component_i::destroyed") ;
280 //=============================================================================
282 * CORBA method: return CORBA reference of the Container
285 //=============================================================================
287 Engines::Container_ptr Engines_Component_i::GetContainerRef()
289 return Engines::Container::_duplicate(_container);
292 //=============================================================================
295 * Gives a sequence of (key=string,value=any) to the component.
296 * Base class component stores the sequence in a map.
297 * The map is cleared before.
298 * This map is for use by derived classes.
299 * \param dico sequence of (key=string,value=any)
301 //=============================================================================
303 void Engines_Component_i::setProperties(const Engines::FieldsDict& dico)
306 for (CORBA::ULong i=0; i<dico.length(); i++)
308 std::string cle(dico[i].key);
309 _fieldsDict[cle] = dico[i].value;
313 //=============================================================================
316 * returns a previously stored map (key=string,value=any) as a sequence.
317 * (see setProperties)
319 //=============================================================================
321 Engines::FieldsDict* Engines_Component_i::getProperties()
323 Engines::FieldsDict_var copie = new Engines::FieldsDict;
324 copie->length((CORBA::ULong)_fieldsDict.size());
325 std::map<std::string,CORBA::Any>::iterator it;
327 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++)
329 std::string cle((*it).first);
330 copie[i].key = CORBA::string_dup(cle.c_str());
331 copie[i].value = _fieldsDict[cle];
333 return copie._retn();
336 //=============================================================================
339 * This method is to set an option specific to a certain EngineComponent.
341 //=============================================================================
343 void Engines_Component_i::SetOption(const char*, const char*)
347 //=============================================================================
350 * This method is to get value of an option specific to a certain EngineComponent.
352 //=============================================================================
354 char* Engines_Component_i::GetOption(const char*)
356 return CORBA::string_dup("") ;
359 //=============================================================================
361 * CORBA method: used by Supervision to give names to this instance
363 //=============================================================================
365 void Engines_Component_i::Names( const char * graphName ,
366 const char * nodeName )
368 _graphName = graphName ;
369 _nodeName = nodeName ;
370 // MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
371 // << _nodeName << "' )");
374 //=============================================================================
376 * CORBA method: used in Supervision
378 //=============================================================================
380 bool Engines_Component_i::Kill_impl()
382 // MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
383 // << " pid " << getpid() << " instanceName "
384 // << _instanceName.c_str() << " interface " << _interfaceName.c_str()
385 // << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
386 // << dec << " _ThreadId " << _ThreadId << " this " << hex << this
389 bool RetVal = false ;
391 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
393 RetVal = Killer( _ThreadId , SIGUSR2 ) ;
394 _ThreadId = (pthread_t ) -1 ;
398 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
400 RetVal = Killer( *_ThreadId , 0 ) ;
401 _ThreadId = (pthread_t* ) 0 ;
408 //=============================================================================
410 * CORBA method: used in Supervision
412 //=============================================================================
414 bool Engines_Component_i::Stop_impl()
417 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self()
418 << " pid " << getpid() << " instanceName "
419 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
420 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
421 << std::dec << " _ThreadId " << _ThreadId );
423 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self().p
424 << " pid " << _getpid() << " instanceName "
425 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
426 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
427 << std::dec << " _ThreadId " << _ThreadId );
431 bool RetVal = false ;
433 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
435 RetVal = Killer( _ThreadId , 0 ) ;
436 _ThreadId = (pthread_t ) -1 ;
439 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
441 RetVal = Killer( *_ThreadId , 0 ) ;
442 _ThreadId = (pthread_t* ) 0 ;
448 //=============================================================================
450 * CORBA method: used in Supervision
452 //=============================================================================
454 bool Engines_Component_i::Suspend_impl()
457 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self()
458 << " pid " << getpid() << " instanceName "
459 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
460 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
461 << std::dec << " _ThreadId " << _ThreadId );
463 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self().p
464 << " pid " << _getpid() << " instanceName "
465 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
466 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
467 << std::dec << " _ThreadId " << _ThreadId );
470 bool RetVal = false ;
472 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
474 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
484 RetVal = Killer( _ThreadId ,SIGINT ) ;
486 RetVal = Killer( *_ThreadId ,SIGINT ) ;
488 //if ( RetVal ) _Sleeping = true;
495 //=============================================================================
497 * CORBA method: used in Supervision
499 //=============================================================================
501 bool Engines_Component_i::Resume_impl()
504 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self()
505 << " pid " << getpid() << " instanceName "
506 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
507 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
508 << std::dec << " _ThreadId " << _ThreadId );
510 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self().p
511 << " pid " << _getpid() << " instanceName "
512 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
513 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
514 << std::dec << " _ThreadId " << _ThreadId );
516 bool RetVal = false ;
518 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
520 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
536 //=============================================================================
540 //=============================================================================
542 CORBA::Long Engines_Component_i::CpuUsed_impl()
545 if ( _ThreadId || _Executed )
550 if ( pthread_self() != _ThreadId )
552 if ( pthread_self().p != _ThreadId->p )
560 // Get Cpu in the appropriate thread with that object !...
561 theEngines_Component = this ;
563 Killer( _ThreadId ,SIGUSR1 ) ;
565 Killer( *_ThreadId ,SIGUSR11 ) ;
568 cpu = _ThreadCpuUsed ;
572 _ThreadCpuUsed = CpuUsed() ;
573 cpu = _ThreadCpuUsed ;
574 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
575 // << _serviceName << " " << cpu << endl ;
580 cpu = _ThreadCpuUsed ;
581 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
582 // << _serviceName << " " << cpu<< endl ;
587 // cout<< pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId "
588 // <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<<endl;
594 //=============================================================================
596 * C++ method: return Container Servant
598 //=============================================================================
600 Engines_Container_i *Engines_Component_i::GetContainerPtr()
602 PortableServer::ObjectId_var contId=_poa->reference_to_id(_container);
603 return dynamic_cast<Engines_Container_i*>(_poa->id_to_servant(contId)) ;
606 //=============================================================================
608 * C++ method: return CORBA instance id, the id is set in derived class
609 * constructor, when instance is activated.
611 //=============================================================================
613 PortableServer::ObjectId * Engines_Component_i::getId()
615 // MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
619 //=============================================================================
621 * C++ method: used by derived classes for supervision
623 //=============================================================================
625 void Engines_Component_i::beginService(const char *serviceName)
627 std::cerr << "beginService for " << serviceName << " Component instance : " << _instanceName << std::endl;
630 _ThreadId = pthread_self() ;
632 _ThreadId = new pthread_t;
633 _ThreadId->p = pthread_self().p ;
634 _ThreadId->x = pthread_self().x ;
637 _StartUsed = CpuUsed_impl() ;
640 _serviceName = serviceName ;
641 theEngines_Component = this ;
642 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) )
644 perror("pthread_setcanceltype ") ;
647 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) )
649 perror("pthread_setcancelstate ") ;
653 // --- all strings given with setProperties are set in environment
654 std::map<std::string,CORBA::Any>::iterator it;
655 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
657 std::string cle((*it).first);
658 if ((*it).second.type()->kind() == CORBA::tk_string)
661 (*it).second >>= value;
665 putenv((char *)s.c_str());
666 MESSAGE("--- setenv: "<<cle<<" = "<< value);
671 //=============================================================================
673 * C++ method: used by derived classes for supervision
675 //=============================================================================
677 void Engines_Component_i::endService(const char *serviceName)
679 if ( !_CanceledThread )
680 _ThreadCpuUsed = CpuUsed_impl() ;
682 float cpus=_ThreadCpuUsed/1000.f;
683 std::cerr << "endService for " << serviceName << " Component instance : " << _instanceName ;
684 std::cerr << " Cpu Used: " << cpus << " (s) " << std::endl;
685 MESSAGE("Send EndService notification for " << serviceName
686 << std::endl << " Component instance : " << _instanceName << " StartUsed "
687 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << std::endl <<std::endl);
691 //=============================================================================
693 * C++ method: -- CHECK IF USED --
695 //=============================================================================
697 char* Engines_Component_i::graphName()
699 return CORBA::string_dup( _graphName.c_str() ) ;
702 //=============================================================================
704 * C++ method: -- CHECK IF USED --
706 //=============================================================================
708 char* Engines_Component_i::nodeName()
710 return CORBA::string_dup( _nodeName.c_str() ) ;
713 //=============================================================================
715 * C++ method: used in Supervision (see kill_impl)
717 //=============================================================================
719 bool Engines_Component_i::Killer( pthread_t ThreadId , int signum )
729 if ( pthread_cancel( ThreadId ) )
731 perror("Killer pthread_cancel error") ;
737 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_canceled") ;
739 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_canceled") ;
745 if ( pthread_kill( ThreadId , signum ) == -1 )
747 perror("Killer pthread_kill error") ;
753 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_killed(" << signum << ")") ;
755 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_killed(" << signum << ")") ;
764 void CallCancelThread();
766 //=============================================================================
770 //=============================================================================
774 if ( theEngines_Component )
775 theEngines_Component->SetCurCpu() ;
778 //=============================================================================
782 //=============================================================================
784 void Engines_Component_i::SetCurCpu()
786 _ThreadCpuUsed = CpuUsed() ;
787 // MESSAGE(pthread_self() <<
788 // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ;
791 //=============================================================================
795 //=============================================================================
797 long Engines_Component_i::CpuUsed()
801 struct rusage usage ;
802 if ( _ThreadId || _Executed )
804 if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
806 perror("Engines_Component_i::CpuUsed") ;
809 //cpu time is calculated in millisecond (user+system times)
810 cpu = usage.ru_utime.tv_sec*1000 +usage.ru_utime.tv_usec/1000;
811 cpu = cpu+ usage.ru_stime.tv_sec*1000 +usage.ru_stime.tv_usec/1000;
813 // std::cout << pthread_self() << " Engines_Component_i::CpuUsed " << " "
814 // << _serviceName << usage.ru_utime.tv_sec << " - " << _StartUsed
815 // << " = " << cpu << std::endl ;
819 // std::cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId "
820 // << _ThreadId << " " << _serviceName<< " _StartUsed "
821 // << _StartUsed << std::endl ;
824 // NOT implemented yet
831 void CallCancelThread()
833 if ( theEngines_Component )
834 theEngines_Component->CancelThread() ;
837 //=============================================================================
841 //=============================================================================
843 void Engines_Component_i::CancelThread()
845 _CanceledThread = true;
848 //=============================================================================
850 * C++ method: Send message to event channel
852 //=============================================================================
854 void Engines_Component_i::sendMessage(const char *event_type,
857 _notifSupplier->Send(_graphName.c_str(), _nodeName.c_str(), event_type, message);
860 //=============================================================================
862 * C++ method: return standard library name built on component name
864 //=============================================================================
866 std::string Engines_Component_i::GetDynLibraryName(const char *componentName)
868 std::string prefix, suffix;
869 std::string cname = componentName;
875 #elif defined(__APPLE__)
880 std::string ret = prefix + cname + std::string("Engine.") + suffix;
884 //=============================================================================
886 * C++ method: DumpPython default implementation
888 //=============================================================================
890 Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Boolean /*isPublished*/,
891 CORBA::Boolean isMultiFile,
892 CORBA::Boolean& isValidScript)
894 const char* aScript = isMultiFile ? "def RebuildData(): pass" : "";
895 char* aBuffer = new char[strlen(aScript)+1];
896 strcpy(aBuffer, aScript);
897 size_t aBufferSize = strlen(aBuffer)+1;
898 Engines::TMPFile_var aStreamFile = new Engines::TMPFile((CORBA::ULong)aBufferSize, (CORBA::ULong)aBufferSize, (CORBA::Octet*)aBuffer, 1);
899 isValidScript = true;
900 return aStreamFile._retn();
903 Engines::Salome_file_ptr
904 Engines_Component_i::getInputFileToService(const char* service_name,
905 const char* Salome_file_name)
907 // Try to find the service, if it doesn't exist, we throw an exception.
908 _Service_file_map_it = _Input_Service_file_map.find(service_name);
909 if (_Service_file_map_it == _Input_Service_file_map.end()) {
910 SALOME::ExceptionStruct es;
911 es.type = SALOME::INTERNAL_ERROR;
912 es.text = "service doesn't have salome files";
913 throw SALOME::SALOME_Exception(es);
915 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
917 // Try to find the Salome_file ...
918 _Salome_file_map_it = _map->find(Salome_file_name);
919 if (_Salome_file_map_it == _map->end()) {
920 SALOME::ExceptionStruct es;
921 es.type = SALOME::INTERNAL_ERROR;
922 es.text = "service doesn't have this Salome_file";
923 throw SALOME::SALOME_Exception(es);
925 Salome_file_i * Sfile = (*_map)[Salome_file_name];
927 return Sfile->_this();
930 Engines::Salome_file_ptr
931 Engines_Component_i::setInputFileToService(const char* service_name,
932 const char* Salome_file_name)
934 // Try to find the service, if it doesn't exist, we add it.
935 _Service_file_map_it = _Input_Service_file_map.find(service_name);
936 if (_Service_file_map_it == _Input_Service_file_map.end()) {
937 _t_Salome_file_map * _map = new _t_Salome_file_map();
938 _Input_Service_file_map[service_name] = _map;
940 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
942 // Try to find the Salome_file ...
943 _Salome_file_map_it = _map->find(Salome_file_name);
944 if (_Salome_file_map_it == _map->end()) {
945 Salome_file_i * Sfile = new Salome_file_i();
946 Engines::Container_ptr container = this->GetContainerRef();
947 Sfile->setContainer(Engines::Container::_duplicate(container));
948 (*_map)[Salome_file_name] = Sfile;
951 Salome_file_i * Sfile = (*_map)[Salome_file_name];
952 return Sfile->_this();
956 Engines_Component_i::checkInputFilesToService(const char* service_name)
958 // Try to find the service, if it doesn't exist, nothing to do.
959 _Service_file_map_it = _Input_Service_file_map.find(service_name);
960 if (_Service_file_map_it != _Input_Service_file_map.end()) {
961 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
962 _t_Salome_file_map::iterator begin = _map->begin();
963 _t_Salome_file_map::iterator end = _map->end();
965 for(;begin!=end;begin++) {
966 Salome_file_i * file = begin->second;
967 std::string file_port_name = begin->first;
968 configureSalome_file(service_name, file_port_name, file);
974 Engines::Salome_file_ptr
975 Engines_Component_i::getOutputFileToService(const char* service_name,
976 const char* Salome_file_name)
978 // Try to find the service, if it doesn't exist, we throw an exception.
979 _Service_file_map_it = _Output_Service_file_map.find(service_name);
980 if (_Service_file_map_it == _Output_Service_file_map.end()) {
981 SALOME::ExceptionStruct es;
982 es.type = SALOME::INTERNAL_ERROR;
983 es.text = "service doesn't have salome files";
984 throw SALOME::SALOME_Exception(es);
986 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
988 // Try to find the Salome_file ...
989 _Salome_file_map_it = _map->find(Salome_file_name);
990 if (_Salome_file_map_it == _map->end()) {
991 SALOME::ExceptionStruct es;
992 es.type = SALOME::INTERNAL_ERROR;
993 es.text = "service doesn't have this Salome_file";
994 throw SALOME::SALOME_Exception(es);
996 Salome_file_i * Sfile = (*_map)[Salome_file_name];
998 return Sfile->_this();
1001 Engines::Salome_file_ptr
1002 Engines_Component_i::setOutputFileToService(const char* service_name,
1003 const char* Salome_file_name)
1005 // Try to find the service, if it doesn't exist, we add it.
1006 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1007 if (_Service_file_map_it == _Output_Service_file_map.end()) {
1008 _t_Salome_file_map * _map = new _t_Salome_file_map();
1009 _Output_Service_file_map[service_name] = _map;
1011 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1013 // Try to find the Salome_file ...
1014 _Salome_file_map_it = _map->find(Salome_file_name);
1015 if (_Salome_file_map_it == _map->end()) {
1016 Salome_file_i * Sfile = new Salome_file_i();
1017 Engines::Container_ptr container = this->GetContainerRef();
1018 Sfile->setContainer(Engines::Container::_duplicate(container));
1019 (*_map)[Salome_file_name] = Sfile;
1022 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1023 return Sfile->_this();
1027 Engines_Component_i::checkOutputFilesToService(const char* service_name)
1029 // Try to find the service, if it doesn't exist, nothing to do.
1030 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1031 if (_Service_file_map_it != _Output_Service_file_map.end()) {
1032 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1033 _t_Salome_file_map::iterator begin = _map->begin();
1034 _t_Salome_file_map::iterator end = _map->end();
1036 for(;begin!=end;begin++) {
1037 Salome_file_i * file = begin->second;
1038 std::string file_port_name = begin->first;
1039 configureSalome_file(service_name, file_port_name, file);
1046 //=============================================================================
1048 * C++ method: used to configure the Salome_file into the runtime.
1049 * \param service_name name of the service that use this Salome_file
1050 * \param file_port_name name of the Salome_file
1051 * \param file Salome_file C++ object
1053 //=============================================================================
1055 Engines_Component_i::configureSalome_file(std::string /*service_name*/,
1056 std::string /*file_port_name*/,
1057 Salome_file_i* /*file*/)
1059 // By default this method does nothing
1062 //=============================================================================
1064 * C++ method: return the name of the container associated with this component
1065 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1066 * \return the container name (reformatted)
1068 //=============================================================================
1069 std::string Engines_Component_i::getContainerName()
1071 return _containerName;
1073 //=============================================================================
1075 * C++ method: set the name of the container associated with this component (attribute _containerName)
1076 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1077 * \return the container name (reformatted)
1079 //=============================================================================
1080 void Engines_Component_i::setContainerName()
1082 CORBA::String_var containerName=_container->name();
1083 std::string name(containerName);
1085 std::string::size_type slash =name.find_first_of('/');
1086 if(slash != std::string::npos)
1088 _containerName=name;
1091 //=============================================================================
1093 * \brief Return \c true if component can provide creation information.
1095 //=============================================================================
1096 bool Engines_Component_i::hasObjectInfo()
1101 //=============================================================================
1103 * \brief Get creation information for object addressed by given entry.
1105 //=============================================================================
1106 char* Engines_Component_i::getObjectInfo(const char* /*entry*/)
1108 return CORBA::string_dup("");
1111 //=============================================================================
1113 * \brief Get version of the component
1115 * This method is supposed to be implemented in all derived classes; default implementation
1116 * returns empty string that means that no version information about the component is available.
1118 * \note The version of the component is stored to the study, as a part of general persistence
1119 * mechanism; once stored, version information in the study cannot be changed.
1121 * \return string containing component's version, e.g. "1.0"
1123 //=============================================================================
1124 char* Engines_Component_i::getVersion()
1126 return CORBA::string_dup( "" );