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"
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 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
197 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
198 CORBA::ORB_var &orb = init( 0 , 0 ) ;
200 SALOME_NamingService *naming = SINGLETON_<SALOME_NamingService>::Instance() ;
201 naming->init_orb( orb ) ;
205 //=============================================================================
207 * Destructor: call Container for decrement of instances count.
208 * When instances count falls to 0, the container tries to remove the
209 * component library (dlclose)
211 //=============================================================================
213 Engines_Component_i::~Engines_Component_i()
215 MESSAGE("Component destructor");
216 Engines_Container_i::decInstanceCnt(_interfaceName);
217 if(_myConnexionToRegistry)delete _myConnexionToRegistry;
218 _myConnexionToRegistry = 0 ;
225 SCRUTE(_notifSupplier->_refcount_value());
226 PortableServer::POA_var poa=_notifSupplier->_default_POA();
227 PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_notifSupplier);
228 poa->deactivate_object(anObjectId.in());
229 SCRUTE(_notifSupplier->_refcount_value());
230 _notifSupplier->_remove_ref();
234 //=============================================================================
236 * CORBA method: return name of the instance, unique in this Container
238 //=============================================================================
240 char* Engines_Component_i::instanceName()
242 return CORBA::string_dup(_instanceName.c_str()) ;
245 //=============================================================================
247 * CORBA method: return name of the component class
249 //=============================================================================
251 char* Engines_Component_i::interfaceName()
253 return CORBA::string_dup(_interfaceName.c_str()) ;
256 //=============================================================================
258 * CORBA method: Test if instance is alive and responds
260 //=============================================================================
262 void Engines_Component_i::ping()
265 MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid "
268 MESSAGE("Engines_Component_i::ping() pid "<< _getpid()<< " threadid "
269 << pthread_self().p );
273 //=============================================================================
275 * CORBA method: Deactivate this instance. CORBA object is deactivated (do not
276 * respond any more to CORBA calls), the connection to Regsitry is removed
277 * (Registry informed of deactivation), internal server reference counter on
278 * the derived servant class is decremented, to allow destruction of the class
279 * (delete) by POA, when there are no more references.
280 * -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
282 //=============================================================================
284 void Engines_Component_i::destroy()
286 MESSAGE("Engines_Component_i::destroy()");
287 //SCRUTE(_refcount_value());
288 _poa->deactivate_object(*_id);
289 //SCRUTE(_refcount_value());
291 //SCRUTE(_refcount_value());
292 MESSAGE("Engines_Component_i::destroyed") ;
295 //=============================================================================
297 * CORBA method: return CORBA reference of the Container
300 //=============================================================================
302 Engines::Container_ptr Engines_Component_i::GetContainerRef()
304 return Engines::Container::_duplicate(_container);
307 //=============================================================================
310 * Gives a sequence of (key=string,value=any) to the component.
311 * Base class component stores the sequence in a map.
312 * The map is cleared before.
313 * This map is for use by derived classes.
314 * \param dico sequence of (key=string,value=any)
316 //=============================================================================
318 void Engines_Component_i::setProperties(const Engines::FieldsDict& dico)
321 for (CORBA::ULong i=0; i<dico.length(); i++)
323 std::string cle(dico[i].key);
324 _fieldsDict[cle] = dico[i].value;
328 //=============================================================================
331 * returns a previously stored map (key=string,value=any) as a sequence.
332 * (see setProperties)
334 //=============================================================================
336 Engines::FieldsDict* Engines_Component_i::getProperties()
338 Engines::FieldsDict_var copie = new Engines::FieldsDict;
339 copie->length((CORBA::ULong)_fieldsDict.size());
340 std::map<std::string,CORBA::Any>::iterator it;
342 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++)
344 std::string cle((*it).first);
345 copie[i].key = CORBA::string_dup(cle.c_str());
346 copie[i].value = _fieldsDict[cle];
348 return copie._retn();
351 //=============================================================================
354 * This method is to set an option specific to a certain EngineComponent.
356 //=============================================================================
358 void Engines_Component_i::SetOption(const char*, const char*)
362 //=============================================================================
365 * This method is to get value of an option specific to a certain EngineComponent.
367 //=============================================================================
369 char* Engines_Component_i::GetOption(const char*)
371 return CORBA::string_dup("") ;
374 //=============================================================================
376 * CORBA method: used by Supervision to give names to this instance
378 //=============================================================================
380 void Engines_Component_i::Names( const char * graphName ,
381 const char * nodeName )
383 _graphName = graphName ;
384 _nodeName = nodeName ;
385 // MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
386 // << _nodeName << "' )");
389 //=============================================================================
391 * CORBA method: used in Supervision
393 //=============================================================================
395 bool Engines_Component_i::Kill_impl()
397 // MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
398 // << " pid " << getpid() << " instanceName "
399 // << _instanceName.c_str() << " interface " << _interfaceName.c_str()
400 // << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
401 // << dec << " _ThreadId " << _ThreadId << " this " << hex << this
404 bool RetVal = false ;
406 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
408 RetVal = Killer( _ThreadId , SIGUSR2 ) ;
409 _ThreadId = (pthread_t ) -1 ;
413 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
415 RetVal = Killer( *_ThreadId , 0 ) ;
416 _ThreadId = (pthread_t* ) 0 ;
423 //=============================================================================
425 * CORBA method: used in Supervision
427 //=============================================================================
429 bool Engines_Component_i::Stop_impl()
432 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self()
433 << " pid " << getpid() << " instanceName "
434 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
435 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
436 << std::dec << " _ThreadId " << _ThreadId );
438 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self().p
439 << " pid " << _getpid() << " instanceName "
440 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
441 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
442 << std::dec << " _ThreadId " << _ThreadId );
446 bool RetVal = false ;
448 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
450 RetVal = Killer( _ThreadId , 0 ) ;
451 _ThreadId = (pthread_t ) -1 ;
454 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
456 RetVal = Killer( *_ThreadId , 0 ) ;
457 _ThreadId = (pthread_t* ) 0 ;
463 //=============================================================================
465 * CORBA method: used in Supervision
467 //=============================================================================
469 bool Engines_Component_i::Suspend_impl()
472 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self()
473 << " pid " << getpid() << " instanceName "
474 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
475 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
476 << std::dec << " _ThreadId " << _ThreadId );
478 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self().p
479 << " pid " << _getpid() << " instanceName "
480 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
481 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
482 << std::dec << " _ThreadId " << _ThreadId );
485 bool RetVal = false ;
487 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
489 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
499 RetVal = Killer( _ThreadId ,SIGINT ) ;
501 RetVal = Killer( *_ThreadId ,SIGINT ) ;
503 //if ( RetVal ) _Sleeping = true;
510 //=============================================================================
512 * CORBA method: used in Supervision
514 //=============================================================================
516 bool Engines_Component_i::Resume_impl()
519 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self()
520 << " pid " << getpid() << " instanceName "
521 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
522 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
523 << std::dec << " _ThreadId " << _ThreadId );
525 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self().p
526 << " pid " << _getpid() << " instanceName "
527 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
528 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
529 << std::dec << " _ThreadId " << _ThreadId );
531 bool RetVal = false ;
533 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
535 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
551 //=============================================================================
555 //=============================================================================
557 CORBA::Long Engines_Component_i::CpuUsed_impl()
560 if ( _ThreadId || _Executed )
565 if ( pthread_self() != _ThreadId )
567 if ( pthread_self().p != _ThreadId->p )
575 // Get Cpu in the appropriate thread with that object !...
576 theEngines_Component = this ;
578 Killer( _ThreadId ,SIGUSR1 ) ;
580 Killer( *_ThreadId ,SIGUSR11 ) ;
583 cpu = _ThreadCpuUsed ;
587 _ThreadCpuUsed = CpuUsed() ;
588 cpu = _ThreadCpuUsed ;
589 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
590 // << _serviceName << " " << cpu << endl ;
595 cpu = _ThreadCpuUsed ;
596 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
597 // << _serviceName << " " << cpu<< endl ;
602 // cout<< pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId "
603 // <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<<endl;
609 //=============================================================================
611 * C++ method: return Container Servant
613 //=============================================================================
615 Engines_Container_i *Engines_Component_i::GetContainerPtr()
617 PortableServer::ObjectId_var contId=_poa->reference_to_id(_container);
618 return dynamic_cast<Engines_Container_i*>(_poa->id_to_servant(contId)) ;
621 //=============================================================================
623 * C++ method: return CORBA instance id, the id is set in derived class
624 * constructor, when instance is activated.
626 //=============================================================================
628 PortableServer::ObjectId * Engines_Component_i::getId()
630 // MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
634 //=============================================================================
636 * C++ method: used by derived classes for supervision
638 //=============================================================================
640 void Engines_Component_i::beginService(const char *serviceName)
642 std::cerr << "beginService for " << serviceName << " Component instance : " << _instanceName << std::endl;
645 _ThreadId = pthread_self() ;
647 _ThreadId = new pthread_t;
648 _ThreadId->p = pthread_self().p ;
649 _ThreadId->x = pthread_self().x ;
652 _StartUsed = CpuUsed_impl() ;
655 _serviceName = serviceName ;
656 theEngines_Component = this ;
657 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) )
659 perror("pthread_setcanceltype ") ;
662 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) )
664 perror("pthread_setcancelstate ") ;
668 // --- all strings given with setProperties are set in environment
669 std::map<std::string,CORBA::Any>::iterator it;
670 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
672 std::string cle((*it).first);
673 if ((*it).second.type()->kind() == CORBA::tk_string)
676 (*it).second >>= value;
680 putenv((char *)s.c_str());
681 MESSAGE("--- setenv: "<<cle<<" = "<< value);
686 //=============================================================================
688 * C++ method: used by derived classes for supervision
690 //=============================================================================
692 void Engines_Component_i::endService(const char *serviceName)
694 if ( !_CanceledThread )
695 _ThreadCpuUsed = CpuUsed_impl() ;
697 float cpus=_ThreadCpuUsed/1000.f;
698 std::cerr << "endService for " << serviceName << " Component instance : " << _instanceName ;
699 std::cerr << " Cpu Used: " << cpus << " (s) " << std::endl;
700 MESSAGE("Send EndService notification for " << serviceName
701 << std::endl << " Component instance : " << _instanceName << " StartUsed "
702 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << std::endl <<std::endl);
706 //=============================================================================
708 * C++ method: -- CHECK IF USED --
710 //=============================================================================
712 char* Engines_Component_i::graphName()
714 return CORBA::string_dup( _graphName.c_str() ) ;
717 //=============================================================================
719 * C++ method: -- CHECK IF USED --
721 //=============================================================================
723 char* Engines_Component_i::nodeName()
725 return CORBA::string_dup( _nodeName.c_str() ) ;
728 //=============================================================================
730 * C++ method: used in Supervision (see kill_impl)
732 //=============================================================================
734 bool Engines_Component_i::Killer( pthread_t ThreadId , int signum )
744 if ( pthread_cancel( ThreadId ) )
746 perror("Killer pthread_cancel error") ;
752 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_canceled") ;
754 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_canceled") ;
760 if ( pthread_kill( ThreadId , signum ) == -1 )
762 perror("Killer pthread_kill error") ;
768 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_killed(" << signum << ")") ;
770 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_killed(" << signum << ")") ;
779 void CallCancelThread();
781 //=============================================================================
785 //=============================================================================
789 if ( theEngines_Component )
790 theEngines_Component->SetCurCpu() ;
793 //=============================================================================
797 //=============================================================================
799 void Engines_Component_i::SetCurCpu()
801 _ThreadCpuUsed = CpuUsed() ;
802 // MESSAGE(pthread_self() <<
803 // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ;
806 //=============================================================================
810 //=============================================================================
812 long Engines_Component_i::CpuUsed()
816 struct rusage usage ;
817 if ( _ThreadId || _Executed )
819 if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
821 perror("Engines_Component_i::CpuUsed") ;
824 //cpu time is calculated in millisecond (user+system times)
825 cpu = usage.ru_utime.tv_sec*1000 +usage.ru_utime.tv_usec/1000;
826 cpu = cpu+ usage.ru_stime.tv_sec*1000 +usage.ru_stime.tv_usec/1000;
828 // std::cout << pthread_self() << " Engines_Component_i::CpuUsed " << " "
829 // << _serviceName << usage.ru_utime.tv_sec << " - " << _StartUsed
830 // << " = " << cpu << std::endl ;
834 // std::cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId "
835 // << _ThreadId << " " << _serviceName<< " _StartUsed "
836 // << _StartUsed << std::endl ;
839 // NOT implemented yet
846 void CallCancelThread()
848 if ( theEngines_Component )
849 theEngines_Component->CancelThread() ;
852 //=============================================================================
856 //=============================================================================
858 void Engines_Component_i::CancelThread()
860 _CanceledThread = true;
863 //=============================================================================
865 * C++ method: Send message to event channel
867 //=============================================================================
869 void Engines_Component_i::sendMessage(const char *event_type,
872 _notifSupplier->Send(_graphName.c_str(), _nodeName.c_str(), event_type, message);
875 //=============================================================================
877 * C++ method: return standard library name built on component name
879 //=============================================================================
881 std::string Engines_Component_i::GetDynLibraryName(const char *componentName)
883 std::string prefix, suffix;
884 std::string cname = componentName;
890 #elif defined(__APPLE__)
895 std::string ret = prefix + cname + std::string("Engine.") + suffix;
899 //=============================================================================
901 * C++ method: DumpPython default implementation
903 //=============================================================================
905 Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Boolean /*isPublished*/,
906 CORBA::Boolean isMultiFile,
907 CORBA::Boolean& isValidScript)
909 const char* aScript = isMultiFile ? "def RebuildData(): pass" : "";
910 char* aBuffer = new char[strlen(aScript)+1];
911 strcpy(aBuffer, aScript);
912 size_t aBufferSize = strlen(aBuffer)+1;
913 Engines::TMPFile_var aStreamFile = new Engines::TMPFile((CORBA::ULong)aBufferSize, (CORBA::ULong)aBufferSize, (CORBA::Octet*)aBuffer, 1);
914 isValidScript = true;
915 return aStreamFile._retn();
918 Engines::Salome_file_ptr
919 Engines_Component_i::getInputFileToService(const char* service_name,
920 const char* Salome_file_name)
922 // Try to find the service, if it doesn't exist, we throw an exception.
923 _Service_file_map_it = _Input_Service_file_map.find(service_name);
924 if (_Service_file_map_it == _Input_Service_file_map.end()) {
925 SALOME::ExceptionStruct es;
926 es.type = SALOME::INTERNAL_ERROR;
927 es.text = "service doesn't have salome files";
928 throw SALOME::SALOME_Exception(es);
930 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
932 // Try to find the Salome_file ...
933 _Salome_file_map_it = _map->find(Salome_file_name);
934 if (_Salome_file_map_it == _map->end()) {
935 SALOME::ExceptionStruct es;
936 es.type = SALOME::INTERNAL_ERROR;
937 es.text = "service doesn't have this Salome_file";
938 throw SALOME::SALOME_Exception(es);
940 Salome_file_i * Sfile = (*_map)[Salome_file_name];
942 return Sfile->_this();
945 Engines::Salome_file_ptr
946 Engines_Component_i::setInputFileToService(const char* service_name,
947 const char* Salome_file_name)
949 // Try to find the service, if it doesn't exist, we add it.
950 _Service_file_map_it = _Input_Service_file_map.find(service_name);
951 if (_Service_file_map_it == _Input_Service_file_map.end()) {
952 _t_Salome_file_map * _map = new _t_Salome_file_map();
953 _Input_Service_file_map[service_name] = _map;
955 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
957 // Try to find the Salome_file ...
958 _Salome_file_map_it = _map->find(Salome_file_name);
959 if (_Salome_file_map_it == _map->end()) {
960 Salome_file_i * Sfile = new Salome_file_i();
961 Engines::Container_ptr container = this->GetContainerRef();
962 Sfile->setContainer(Engines::Container::_duplicate(container));
963 (*_map)[Salome_file_name] = Sfile;
966 Salome_file_i * Sfile = (*_map)[Salome_file_name];
967 return Sfile->_this();
971 Engines_Component_i::checkInputFilesToService(const char* service_name)
973 // Try to find the service, if it doesn't exist, nothing to do.
974 _Service_file_map_it = _Input_Service_file_map.find(service_name);
975 if (_Service_file_map_it != _Input_Service_file_map.end()) {
976 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
977 _t_Salome_file_map::iterator begin = _map->begin();
978 _t_Salome_file_map::iterator end = _map->end();
980 for(;begin!=end;begin++) {
981 Salome_file_i * file = begin->second;
982 std::string file_port_name = begin->first;
983 configureSalome_file(service_name, file_port_name, file);
989 Engines::Salome_file_ptr
990 Engines_Component_i::getOutputFileToService(const char* service_name,
991 const char* Salome_file_name)
993 // Try to find the service, if it doesn't exist, we throw an exception.
994 _Service_file_map_it = _Output_Service_file_map.find(service_name);
995 if (_Service_file_map_it == _Output_Service_file_map.end()) {
996 SALOME::ExceptionStruct es;
997 es.type = SALOME::INTERNAL_ERROR;
998 es.text = "service doesn't have salome files";
999 throw SALOME::SALOME_Exception(es);
1001 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1003 // Try to find the Salome_file ...
1004 _Salome_file_map_it = _map->find(Salome_file_name);
1005 if (_Salome_file_map_it == _map->end()) {
1006 SALOME::ExceptionStruct es;
1007 es.type = SALOME::INTERNAL_ERROR;
1008 es.text = "service doesn't have this Salome_file";
1009 throw SALOME::SALOME_Exception(es);
1011 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1013 return Sfile->_this();
1016 Engines::Salome_file_ptr
1017 Engines_Component_i::setOutputFileToService(const char* service_name,
1018 const char* Salome_file_name)
1020 // Try to find the service, if it doesn't exist, we add it.
1021 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1022 if (_Service_file_map_it == _Output_Service_file_map.end()) {
1023 _t_Salome_file_map * _map = new _t_Salome_file_map();
1024 _Output_Service_file_map[service_name] = _map;
1026 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1028 // Try to find the Salome_file ...
1029 _Salome_file_map_it = _map->find(Salome_file_name);
1030 if (_Salome_file_map_it == _map->end()) {
1031 Salome_file_i * Sfile = new Salome_file_i();
1032 Engines::Container_ptr container = this->GetContainerRef();
1033 Sfile->setContainer(Engines::Container::_duplicate(container));
1034 (*_map)[Salome_file_name] = Sfile;
1037 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1038 return Sfile->_this();
1042 Engines_Component_i::checkOutputFilesToService(const char* service_name)
1044 // Try to find the service, if it doesn't exist, nothing to do.
1045 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1046 if (_Service_file_map_it != _Output_Service_file_map.end()) {
1047 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1048 _t_Salome_file_map::iterator begin = _map->begin();
1049 _t_Salome_file_map::iterator end = _map->end();
1051 for(;begin!=end;begin++) {
1052 Salome_file_i * file = begin->second;
1053 std::string file_port_name = begin->first;
1054 configureSalome_file(service_name, file_port_name, file);
1061 //=============================================================================
1063 * C++ method: used to configure the Salome_file into the runtime.
1064 * \param service_name name of the service that use this Salome_file
1065 * \param file_port_name name of the Salome_file
1066 * \param file Salome_file C++ object
1068 //=============================================================================
1070 Engines_Component_i::configureSalome_file(std::string /*service_name*/,
1071 std::string /*file_port_name*/,
1072 Salome_file_i* /*file*/)
1074 // By default this method does nothing
1077 //=============================================================================
1079 * C++ method: return the name of the container associated with this component
1080 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1081 * \return the container name (reformatted)
1083 //=============================================================================
1084 std::string Engines_Component_i::getContainerName()
1086 return _containerName;
1088 //=============================================================================
1090 * C++ method: set the name of the container associated with this component (attribute _containerName)
1091 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1092 * \return the container name (reformatted)
1094 //=============================================================================
1095 void Engines_Component_i::setContainerName()
1097 CORBA::String_var containerName=_container->name();
1098 std::string name(containerName);
1100 std::string::size_type slash =name.find_first_of('/');
1101 if(slash != std::string::npos)
1103 _containerName=name;
1106 //=============================================================================
1108 * \brief Return \c true if component can provide creation information.
1110 //=============================================================================
1111 bool Engines_Component_i::hasObjectInfo()
1116 //=============================================================================
1118 * \brief Get creation information for object addressed by given entry.
1120 //=============================================================================
1121 char* Engines_Component_i::getObjectInfo(const char* /*entry*/)
1123 return CORBA::string_dup("");
1126 //=============================================================================
1128 * \brief Get version of the component
1130 * This method is supposed to be implemented in all derived classes; default implementation
1131 * returns empty string that means that no version information about the component is available.
1133 * \note The version of the component is stored to the study, as a part of general persistence
1134 * mechanism; once stored, version information in the study cannot be changed.
1136 * \return string containing component's version, e.g. "1.0"
1138 //=============================================================================
1139 char* Engines_Component_i::getVersion()
1141 return CORBA::string_dup( "" );