1 // Copyright (C) 2007-2022 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"
35 #include "Utils_SINGLETON.hxx"
36 #include "SALOME_NamingService.hxx"
37 #include "Utils_CorbaException.hxx"
44 #include "utilities.h"
48 #include <sys/resource.h>
51 #include <sys/timeb.h>
56 extern bool _Sleeping ;
57 static Engines_Component_i * theEngines_Component ;
59 bool Engines_Component_i::_isMultiInstance = false;
61 /*! \class Engines_Component_i
62 * \brief C++ implementation of Engines::Component interface
66 //=============================================================================
68 * Default constructor, not for use
70 //=============================================================================
72 Engines_Component_i::Engines_Component_i(): _id(0), _myConnexionToRegistry(0), _notifSupplier(0)
75 MESSAGE("Default Constructor, not for normal use...");
78 //=============================================================================
79 /*! \brief Standard Constructor for generic Component, used in derived class
81 * Connection to Registry and Notification
82 * \param orb Object Request broker given by Container
83 * \param poa Portable Object Adapter from Container (normally root_poa)
84 * \param contId container CORBA id inside the server
85 * \param instanceName unique instance name for this object (see Container_i)
86 * \param interfaceName component class name
87 * \param notif use of notification
88 * \param regist (true or false) use of registry (default true)
90 //=============================================================================
92 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
93 PortableServer::POA_ptr poa,
94 PortableServer::ObjectId * contId,
95 const char *instanceName,
96 const char *interfaceName,
99 _instanceName(instanceName),
100 _interfaceName(interfaceName),
103 _myConnexionToRegistry(0),
110 _CanceledThread(false)
112 MESSAGE("Component constructor with instanceName "<< _instanceName);
113 _orb = CORBA::ORB::_duplicate(orb);
114 _poa = PortableServer::POA::_duplicate(poa);
116 CORBA::Object_var o = _poa->id_to_reference(*contId); // container ior...
117 _container=Engines::Container::_narrow(o);
122 const CORBA::String_var ior = _orb->object_to_string(o);
123 _myConnexionToRegistry = new RegistryConnexion(ior,"theSession",
124 _instanceName.c_str(), getNS());
128 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
131 //=============================================================================
132 /*! \brief Standard Constructor for standalone Component, used in derived class
134 * Connection to Registry and Notification
135 * \param orb Object Request broker given by Container
136 * \param poa Portable Object Adapter from Container (normally root_poa)
137 * \param container container CORBA reference
138 * \param instanceName unique instance name for this object (see Container_i)
139 * \param interfaceName component class name
140 * \param notif use of notification
141 * \param regist (true or false) use of registry (default true)
143 //=============================================================================
145 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
146 PortableServer::POA_ptr poa,
147 Engines::Container_ptr container,
148 const char *instanceName,
149 const char *interfaceName,
152 _instanceName(instanceName),
153 _interfaceName(interfaceName),
156 _myConnexionToRegistry(0),
163 _CanceledThread(false)
165 MESSAGE("Component constructor with instanceName "<< _instanceName);
166 _orb = CORBA::ORB::_duplicate(orb);
167 _poa = PortableServer::POA::_duplicate(poa);
168 _container=Engines::Container::_duplicate(container);
170 const CORBA::String_var ior = _orb->object_to_string(_container);
173 _myConnexionToRegistry = new RegistryConnexion(ior,"theSession", _instanceName.c_str(),getNS());
176 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
180 CORBA::Boolean Engines_Component_i::isSSLMode()
182 PortableServer::ServantBase *serv(_poa->reference_to_servant(_container));
184 THROW_SALOME_CORBA_EXCEPTION("_container and component are not managed by the same POA ! Looks bad !", SALOME::INTERNAL_ERROR);
185 Abstract_Engines_Container_i *elt=dynamic_cast<Abstract_Engines_Container_i *>(serv);
187 THROW_SALOME_CORBA_EXCEPTION("_container servant object if not a Abstract_Engines_Container_i ! It smells bad !", SALOME::INTERNAL_ERROR);
188 SALOME_NamingService_Container_Abstract *ns(elt->getNS());
190 THROW_SALOME_CORBA_EXCEPTION("_container servant object points to a nullptr NS ! It smells bad !", SALOME::INTERNAL_ERROR);
191 return elt->isSSLMode() && (!dynamic_cast<SALOME_NamingService *>(ns));
194 SALOME_NamingService_Abstract *Engines_Component_i::getNS()
196 CORBA::ORB_var orb = KERNEL::GetRefToORB();
198 SALOME_NamingService *naming = SINGLETON_<SALOME_NamingService>::Instance() ;
199 naming->init_orb( orb ) ;
203 //=============================================================================
205 * Destructor: call Container for decrement of instances count.
206 * When instances count falls to 0, the container tries to remove the
207 * component library (dlclose)
209 //=============================================================================
211 Engines_Component_i::~Engines_Component_i()
213 MESSAGE("Component destructor");
214 Engines_Container_i::decInstanceCnt(_interfaceName);
215 if(_myConnexionToRegistry)delete _myConnexionToRegistry;
216 _myConnexionToRegistry = 0 ;
223 SCRUTE(_notifSupplier->_refcount_value());
224 PortableServer::POA_var poa=_notifSupplier->_default_POA();
225 PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_notifSupplier);
226 poa->deactivate_object(anObjectId.in());
227 SCRUTE(_notifSupplier->_refcount_value());
228 _notifSupplier->_remove_ref();
232 //=============================================================================
234 * CORBA method: return name of the instance, unique in this Container
236 //=============================================================================
238 char* Engines_Component_i::instanceName()
240 return CORBA::string_dup(_instanceName.c_str()) ;
243 //=============================================================================
245 * CORBA method: return name of the component class
247 //=============================================================================
249 char* Engines_Component_i::interfaceName()
251 return CORBA::string_dup(_interfaceName.c_str()) ;
254 //=============================================================================
256 * CORBA method: Test if instance is alive and responds
258 //=============================================================================
260 void Engines_Component_i::ping()
263 MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid "
266 MESSAGE("Engines_Component_i::ping() pid "<< _getpid()<< " threadid "
267 << pthread_self().p );
271 //=============================================================================
273 * CORBA method: Deactivate this instance. CORBA object is deactivated (do not
274 * respond any more to CORBA calls), the connection to Regsitry is removed
275 * (Registry informed of deactivation), internal server reference counter on
276 * the derived servant class is decremented, to allow destruction of the class
277 * (delete) by POA, when there are no more references.
278 * -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
280 //=============================================================================
282 void Engines_Component_i::destroy()
284 MESSAGE("Engines_Component_i::destroy()");
285 //SCRUTE(_refcount_value());
286 _poa->deactivate_object(*_id);
287 //SCRUTE(_refcount_value());
289 //SCRUTE(_refcount_value());
290 MESSAGE("Engines_Component_i::destroyed") ;
293 //=============================================================================
295 * CORBA method: return CORBA reference of the Container
298 //=============================================================================
300 Engines::Container_ptr Engines_Component_i::GetContainerRef()
302 return Engines::Container::_duplicate(_container);
305 //=============================================================================
308 * Gives a sequence of (key=string,value=any) to the component.
309 * Base class component stores the sequence in a map.
310 * The map is cleared before.
311 * This map is for use by derived classes.
312 * \param dico sequence of (key=string,value=any)
314 //=============================================================================
316 void Engines_Component_i::setProperties(const Engines::FieldsDict& dico)
319 for (CORBA::ULong i=0; i<dico.length(); i++)
321 std::string cle(dico[i].key);
322 _fieldsDict[cle] = dico[i].value;
326 //=============================================================================
329 * returns a previously stored map (key=string,value=any) as a sequence.
330 * (see setProperties)
332 //=============================================================================
334 Engines::FieldsDict* Engines_Component_i::getProperties()
336 Engines::FieldsDict_var copie = new Engines::FieldsDict;
337 copie->length((CORBA::ULong)_fieldsDict.size());
338 std::map<std::string,CORBA::Any>::iterator it;
340 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++)
342 std::string cle((*it).first);
343 copie[i].key = CORBA::string_dup(cle.c_str());
344 copie[i].value = _fieldsDict[cle];
346 return copie._retn();
349 //=============================================================================
352 * This method is to set an option specific to a certain EngineComponent.
354 //=============================================================================
356 void Engines_Component_i::SetOption(const char*, const char*)
360 //=============================================================================
363 * This method is to get value of an option specific to a certain EngineComponent.
365 //=============================================================================
367 char* Engines_Component_i::GetOption(const char*)
369 return CORBA::string_dup("") ;
372 //=============================================================================
374 * CORBA method: used by Supervision to give names to this instance
376 //=============================================================================
378 void Engines_Component_i::Names( const char * graphName ,
379 const char * nodeName )
381 _graphName = graphName ;
382 _nodeName = nodeName ;
383 // MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
384 // << _nodeName << "' )");
387 //=============================================================================
389 * CORBA method: used in Supervision
391 //=============================================================================
393 bool Engines_Component_i::Kill_impl()
395 // MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
396 // << " pid " << getpid() << " instanceName "
397 // << _instanceName.c_str() << " interface " << _interfaceName.c_str()
398 // << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
399 // << dec << " _ThreadId " << _ThreadId << " this " << hex << this
402 bool RetVal = false ;
404 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
406 RetVal = Killer( _ThreadId , SIGUSR2 ) ;
407 _ThreadId = (pthread_t ) -1 ;
411 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
413 RetVal = Killer( *_ThreadId , 0 ) ;
414 _ThreadId = (pthread_t* ) 0 ;
421 //=============================================================================
423 * CORBA method: used in Supervision
425 //=============================================================================
427 bool Engines_Component_i::Stop_impl()
430 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self()
431 << " pid " << getpid() << " instanceName "
432 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
433 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
434 << std::dec << " _ThreadId " << _ThreadId );
436 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self().p
437 << " pid " << _getpid() << " instanceName "
438 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
439 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
440 << std::dec << " _ThreadId " << _ThreadId );
444 bool RetVal = false ;
446 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
448 RetVal = Killer( _ThreadId , 0 ) ;
449 _ThreadId = (pthread_t ) -1 ;
452 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
454 RetVal = Killer( *_ThreadId , 0 ) ;
455 _ThreadId = (pthread_t* ) 0 ;
461 //=============================================================================
463 * CORBA method: used in Supervision
465 //=============================================================================
467 bool Engines_Component_i::Suspend_impl()
470 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self()
471 << " pid " << getpid() << " instanceName "
472 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
473 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
474 << std::dec << " _ThreadId " << _ThreadId );
476 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self().p
477 << " pid " << _getpid() << " instanceName "
478 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
479 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
480 << std::dec << " _ThreadId " << _ThreadId );
483 bool RetVal = false ;
485 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
487 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
497 RetVal = Killer( _ThreadId ,SIGINT ) ;
499 RetVal = Killer( *_ThreadId ,SIGINT ) ;
501 //if ( RetVal ) _Sleeping = true;
508 //=============================================================================
510 * CORBA method: used in Supervision
512 //=============================================================================
514 bool Engines_Component_i::Resume_impl()
517 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self()
518 << " pid " << getpid() << " instanceName "
519 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
520 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
521 << std::dec << " _ThreadId " << _ThreadId );
523 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self().p
524 << " pid " << _getpid() << " instanceName "
525 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
526 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
527 << std::dec << " _ThreadId " << _ThreadId );
529 bool RetVal = false ;
531 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
533 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
549 //=============================================================================
553 //=============================================================================
555 CORBA::Long Engines_Component_i::CpuUsed_impl()
558 if ( _ThreadId || _Executed )
563 if ( pthread_self() != _ThreadId )
565 if ( pthread_self().p != _ThreadId->p )
573 // Get Cpu in the appropriate thread with that object !...
574 theEngines_Component = this ;
576 Killer( _ThreadId ,SIGUSR1 ) ;
578 Killer( *_ThreadId ,SIGUSR11 ) ;
581 cpu = _ThreadCpuUsed ;
585 _ThreadCpuUsed = CpuUsed() ;
586 cpu = _ThreadCpuUsed ;
587 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
588 // << _serviceName << " " << cpu << endl ;
593 cpu = _ThreadCpuUsed ;
594 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
595 // << _serviceName << " " << cpu<< endl ;
600 // cout<< pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId "
601 // <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<<endl;
607 //=============================================================================
609 * C++ method: return Container Servant
611 //=============================================================================
613 Engines_Container_i *Engines_Component_i::GetContainerPtr()
615 PortableServer::ObjectId_var contId=_poa->reference_to_id(_container);
616 return dynamic_cast<Engines_Container_i*>(_poa->id_to_servant(contId)) ;
619 //=============================================================================
621 * C++ method: return CORBA instance id, the id is set in derived class
622 * constructor, when instance is activated.
624 //=============================================================================
626 PortableServer::ObjectId * Engines_Component_i::getId()
628 // MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
632 //=============================================================================
634 * C++ method: used by derived classes for supervision
636 //=============================================================================
638 void Engines_Component_i::beginService(const char *serviceName)
640 std::cerr << "beginService for " << serviceName << " Component instance : " << _instanceName << std::endl;
643 _ThreadId = pthread_self() ;
645 _ThreadId = new pthread_t;
646 _ThreadId->p = pthread_self().p ;
647 _ThreadId->x = pthread_self().x ;
650 _StartUsed = CpuUsed_impl() ;
653 _serviceName = serviceName ;
654 theEngines_Component = this ;
655 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) )
657 perror("pthread_setcanceltype ") ;
660 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) )
662 perror("pthread_setcancelstate ") ;
666 // --- all strings given with setProperties are set in environment
667 std::map<std::string,CORBA::Any>::iterator it;
668 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
670 std::string cle((*it).first);
671 if ((*it).second.type()->kind() == CORBA::tk_string)
674 (*it).second >>= value;
678 putenv((char *)s.c_str());
679 MESSAGE("--- setenv: "<<cle<<" = "<< value);
684 //=============================================================================
686 * C++ method: used by derived classes for supervision
688 //=============================================================================
690 void Engines_Component_i::endService(const char *serviceName)
692 if ( !_CanceledThread )
693 _ThreadCpuUsed = CpuUsed_impl() ;
695 float cpus=_ThreadCpuUsed/1000.f;
696 std::cerr << "endService for " << serviceName << " Component instance : " << _instanceName ;
697 std::cerr << " Cpu Used: " << cpus << " (s) " << std::endl;
698 MESSAGE("Send EndService notification for " << serviceName
699 << std::endl << " Component instance : " << _instanceName << " StartUsed "
700 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << std::endl <<std::endl);
704 //=============================================================================
706 * C++ method: -- CHECK IF USED --
708 //=============================================================================
710 char* Engines_Component_i::graphName()
712 return CORBA::string_dup( _graphName.c_str() ) ;
715 //=============================================================================
717 * C++ method: -- CHECK IF USED --
719 //=============================================================================
721 char* Engines_Component_i::nodeName()
723 return CORBA::string_dup( _nodeName.c_str() ) ;
726 //=============================================================================
728 * C++ method: used in Supervision (see kill_impl)
730 //=============================================================================
732 bool Engines_Component_i::Killer( pthread_t ThreadId , int signum )
742 if ( pthread_cancel( ThreadId ) )
744 perror("Killer pthread_cancel error") ;
750 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_canceled") ;
752 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_canceled") ;
758 if ( pthread_kill( ThreadId , signum ) == -1 )
760 perror("Killer pthread_kill error") ;
766 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_killed(" << signum << ")") ;
768 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_killed(" << signum << ")") ;
777 void CallCancelThread();
779 //=============================================================================
783 //=============================================================================
787 if ( theEngines_Component )
788 theEngines_Component->SetCurCpu() ;
791 //=============================================================================
795 //=============================================================================
797 void Engines_Component_i::SetCurCpu()
799 _ThreadCpuUsed = CpuUsed() ;
800 // MESSAGE(pthread_self() <<
801 // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ;
804 //=============================================================================
808 //=============================================================================
810 long Engines_Component_i::CpuUsed()
814 struct rusage usage ;
815 if ( _ThreadId || _Executed )
817 if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
819 perror("Engines_Component_i::CpuUsed") ;
822 //cpu time is calculated in millisecond (user+system times)
823 cpu = usage.ru_utime.tv_sec*1000 +usage.ru_utime.tv_usec/1000;
824 cpu = cpu+ usage.ru_stime.tv_sec*1000 +usage.ru_stime.tv_usec/1000;
826 // std::cout << pthread_self() << " Engines_Component_i::CpuUsed " << " "
827 // << _serviceName << usage.ru_utime.tv_sec << " - " << _StartUsed
828 // << " = " << cpu << std::endl ;
832 // std::cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId "
833 // << _ThreadId << " " << _serviceName<< " _StartUsed "
834 // << _StartUsed << std::endl ;
837 // NOT implemented yet
844 void CallCancelThread()
846 if ( theEngines_Component )
847 theEngines_Component->CancelThread() ;
850 //=============================================================================
854 //=============================================================================
856 void Engines_Component_i::CancelThread()
858 _CanceledThread = true;
861 //=============================================================================
863 * C++ method: Send message to event channel
865 //=============================================================================
867 void Engines_Component_i::sendMessage(const char *event_type,
870 _notifSupplier->Send(_graphName.c_str(), _nodeName.c_str(), event_type, message);
873 //=============================================================================
875 * C++ method: return standard library name built on component name
877 //=============================================================================
879 std::string Engines_Component_i::GetDynLibraryName(const char *componentName)
881 std::string prefix, suffix;
882 std::string cname = componentName;
888 #elif defined(__APPLE__)
893 std::string ret = prefix + cname + std::string("Engine.") + suffix;
897 //=============================================================================
899 * C++ method: DumpPython default implementation
901 //=============================================================================
903 Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Boolean /*isPublished*/,
904 CORBA::Boolean isMultiFile,
905 CORBA::Boolean& isValidScript)
907 const char* aScript = isMultiFile ? "def RebuildData(): pass" : "";
908 char* aBuffer = new char[strlen(aScript)+1];
909 strcpy(aBuffer, aScript);
910 size_t aBufferSize = strlen(aBuffer)+1;
911 Engines::TMPFile_var aStreamFile = new Engines::TMPFile((CORBA::ULong)aBufferSize, (CORBA::ULong)aBufferSize, (CORBA::Octet*)aBuffer, 1);
912 isValidScript = true;
913 return aStreamFile._retn();
916 Engines::Salome_file_ptr
917 Engines_Component_i::getInputFileToService(const char* service_name,
918 const char* Salome_file_name)
920 // Try to find the service, if it doesn't exist, we throw an exception.
921 _Service_file_map_it = _Input_Service_file_map.find(service_name);
922 if (_Service_file_map_it == _Input_Service_file_map.end()) {
923 SALOME::ExceptionStruct es;
924 es.type = SALOME::INTERNAL_ERROR;
925 es.text = "service doesn't have salome files";
926 throw SALOME::SALOME_Exception(es);
928 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
930 // Try to find the Salome_file ...
931 _Salome_file_map_it = _map->find(Salome_file_name);
932 if (_Salome_file_map_it == _map->end()) {
933 SALOME::ExceptionStruct es;
934 es.type = SALOME::INTERNAL_ERROR;
935 es.text = "service doesn't have this Salome_file";
936 throw SALOME::SALOME_Exception(es);
938 Salome_file_i * Sfile = (*_map)[Salome_file_name];
940 return Sfile->_this();
943 Engines::Salome_file_ptr
944 Engines_Component_i::setInputFileToService(const char* service_name,
945 const char* Salome_file_name)
947 // Try to find the service, if it doesn't exist, we add it.
948 _Service_file_map_it = _Input_Service_file_map.find(service_name);
949 if (_Service_file_map_it == _Input_Service_file_map.end()) {
950 _t_Salome_file_map * _map = new _t_Salome_file_map();
951 _Input_Service_file_map[service_name] = _map;
953 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
955 // Try to find the Salome_file ...
956 _Salome_file_map_it = _map->find(Salome_file_name);
957 if (_Salome_file_map_it == _map->end()) {
958 Salome_file_i * Sfile = new Salome_file_i();
959 Engines::Container_ptr container = this->GetContainerRef();
960 Sfile->setContainer(Engines::Container::_duplicate(container));
961 (*_map)[Salome_file_name] = Sfile;
964 Salome_file_i * Sfile = (*_map)[Salome_file_name];
965 return Sfile->_this();
969 Engines_Component_i::checkInputFilesToService(const char* service_name)
971 // Try to find the service, if it doesn't exist, nothing to do.
972 _Service_file_map_it = _Input_Service_file_map.find(service_name);
973 if (_Service_file_map_it != _Input_Service_file_map.end()) {
974 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
975 _t_Salome_file_map::iterator begin = _map->begin();
976 _t_Salome_file_map::iterator end = _map->end();
978 for(;begin!=end;begin++) {
979 Salome_file_i * file = begin->second;
980 std::string file_port_name = begin->first;
981 configureSalome_file(service_name, file_port_name, file);
987 Engines::Salome_file_ptr
988 Engines_Component_i::getOutputFileToService(const char* service_name,
989 const char* Salome_file_name)
991 // Try to find the service, if it doesn't exist, we throw an exception.
992 _Service_file_map_it = _Output_Service_file_map.find(service_name);
993 if (_Service_file_map_it == _Output_Service_file_map.end()) {
994 SALOME::ExceptionStruct es;
995 es.type = SALOME::INTERNAL_ERROR;
996 es.text = "service doesn't have salome files";
997 throw SALOME::SALOME_Exception(es);
999 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1001 // Try to find the Salome_file ...
1002 _Salome_file_map_it = _map->find(Salome_file_name);
1003 if (_Salome_file_map_it == _map->end()) {
1004 SALOME::ExceptionStruct es;
1005 es.type = SALOME::INTERNAL_ERROR;
1006 es.text = "service doesn't have this Salome_file";
1007 throw SALOME::SALOME_Exception(es);
1009 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1011 return Sfile->_this();
1014 Engines::Salome_file_ptr
1015 Engines_Component_i::setOutputFileToService(const char* service_name,
1016 const char* Salome_file_name)
1018 // Try to find the service, if it doesn't exist, we add it.
1019 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1020 if (_Service_file_map_it == _Output_Service_file_map.end()) {
1021 _t_Salome_file_map * _map = new _t_Salome_file_map();
1022 _Output_Service_file_map[service_name] = _map;
1024 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1026 // Try to find the Salome_file ...
1027 _Salome_file_map_it = _map->find(Salome_file_name);
1028 if (_Salome_file_map_it == _map->end()) {
1029 Salome_file_i * Sfile = new Salome_file_i();
1030 Engines::Container_ptr container = this->GetContainerRef();
1031 Sfile->setContainer(Engines::Container::_duplicate(container));
1032 (*_map)[Salome_file_name] = Sfile;
1035 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1036 return Sfile->_this();
1040 Engines_Component_i::checkOutputFilesToService(const char* service_name)
1042 // Try to find the service, if it doesn't exist, nothing to do.
1043 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1044 if (_Service_file_map_it != _Output_Service_file_map.end()) {
1045 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1046 _t_Salome_file_map::iterator begin = _map->begin();
1047 _t_Salome_file_map::iterator end = _map->end();
1049 for(;begin!=end;begin++) {
1050 Salome_file_i * file = begin->second;
1051 std::string file_port_name = begin->first;
1052 configureSalome_file(service_name, file_port_name, file);
1059 //=============================================================================
1061 * C++ method: used to configure the Salome_file into the runtime.
1062 * \param service_name name of the service that use this Salome_file
1063 * \param file_port_name name of the Salome_file
1064 * \param file Salome_file C++ object
1066 //=============================================================================
1068 Engines_Component_i::configureSalome_file(std::string /*service_name*/,
1069 std::string /*file_port_name*/,
1070 Salome_file_i* /*file*/)
1072 // By default this method does nothing
1075 //=============================================================================
1077 * C++ method: return the name of the container associated with this component
1078 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1079 * \return the container name (reformatted)
1081 //=============================================================================
1082 std::string Engines_Component_i::getContainerName()
1084 return _containerName;
1086 //=============================================================================
1088 * C++ method: set the name of the container associated with this component (attribute _containerName)
1089 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1090 * \return the container name (reformatted)
1092 //=============================================================================
1093 void Engines_Component_i::setContainerName()
1095 CORBA::String_var containerName=_container->name();
1096 std::string name(containerName);
1098 std::string::size_type slash =name.find_first_of('/');
1099 if(slash != std::string::npos)
1101 _containerName=name;
1104 //=============================================================================
1106 * \brief Return \c true if component can provide creation information.
1108 //=============================================================================
1109 bool Engines_Component_i::hasObjectInfo()
1114 //=============================================================================
1116 * \brief Get creation information for object addressed by given entry.
1118 //=============================================================================
1119 char* Engines_Component_i::getObjectInfo(const char* /*entry*/)
1121 return CORBA::string_dup("");
1124 //=============================================================================
1126 * \brief Get version of the component
1128 * This method is supposed to be implemented in all derived classes; default implementation
1129 * returns empty string that means that no version information about the component is available.
1131 * \note The version of the component is stored to the study, as a part of general persistence
1132 * mechanism; once stored, version information in the study cannot be changed.
1134 * \return string containing component's version, e.g. "1.0"
1136 //=============================================================================
1137 char* Engines_Component_i::getVersion()
1139 return CORBA::string_dup( "" );