1 // Copyright (C) 2007-2016 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"
39 #include "utilities.h"
43 #include <sys/resource.h>
46 #include <sys/timeb.h>
51 extern bool _Sleeping ;
52 static Engines_Component_i * theEngines_Component ;
54 bool Engines_Component_i::_isMultiStudy = false;
55 bool Engines_Component_i::_isMultiInstance = false;
57 /*! \class Engines_Component_i
58 * \brief C++ implementation of Engines::Component interface
62 //=============================================================================
64 * Default constructor, not for use
66 //=============================================================================
68 Engines_Component_i::Engines_Component_i():_myConnexionToRegistry(0), _notifSupplier(0), _id(0)
71 MESSAGE("Default Constructor, not for normal use...");
74 //=============================================================================
75 /*! \brief Standard Constructor for generic Component, used in derived class
77 * Connection to Registry and Notification
78 * \param orb Object Request broker given by Container
79 * \param poa Portable Object Adapter from Container (normally root_poa)
80 * \param contId container CORBA id inside the server
81 * \param instanceName unique instance name for this object (see Container_i)
82 * \param interfaceName component class name
83 * \param notif use of notification
84 * \param regist (true or false) use of registry (default true)
86 //=============================================================================
88 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
89 PortableServer::POA_ptr poa,
90 PortableServer::ObjectId * contId,
91 const char *instanceName,
92 const char *interfaceName,
95 _instanceName(instanceName),
96 _interfaceName(interfaceName),
97 _myConnexionToRegistry(0),
106 _CanceledThread(false)
108 MESSAGE("Component constructor with instanceName "<< _instanceName);
109 _orb = CORBA::ORB::_duplicate(orb);
110 _poa = PortableServer::POA::_duplicate(poa);
112 CORBA::Object_var o = _poa->id_to_reference(*contId); // container ior...
113 _container=Engines::Container::_narrow(o);
118 const CORBA::String_var ior = _orb->object_to_string(o);
119 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession",
120 _instanceName.c_str());
124 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
127 //=============================================================================
128 /*! \brief Standard Constructor for standalone Component, used in derived class
130 * Connection to Registry and Notification
131 * \param orb Object Request broker given by Container
132 * \param poa Portable Object Adapter from Container (normally root_poa)
133 * \param container container CORBA reference
134 * \param instanceName unique instance name for this object (see Container_i)
135 * \param interfaceName component class name
136 * \param notif use of notification
137 * \param regist (true or false) use of registry (default true)
139 //=============================================================================
141 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
142 PortableServer::POA_ptr poa,
143 Engines::Container_ptr container,
144 const char *instanceName,
145 const char *interfaceName,
148 _instanceName(instanceName),
149 _interfaceName(interfaceName),
150 _myConnexionToRegistry(0),
159 _CanceledThread(false)
161 MESSAGE("Component constructor with instanceName "<< _instanceName);
162 _orb = CORBA::ORB::_duplicate(orb);
163 _poa = PortableServer::POA::_duplicate(poa);
164 _container=Engines::Container::_duplicate(container);
166 const CORBA::String_var ior = _orb->object_to_string(_container);
169 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession", _instanceName.c_str());
172 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
177 //=============================================================================
179 * Destructor: call Container for decrement of instances count.
180 * When instances count falls to 0, the container tries to remove the
181 * component library (dlclose)
183 //=============================================================================
185 Engines_Component_i::~Engines_Component_i()
187 MESSAGE("Component destructor");
188 Engines_Container_i::decInstanceCnt(_interfaceName);
189 if(_myConnexionToRegistry)delete _myConnexionToRegistry;
190 _myConnexionToRegistry = 0 ;
197 SCRUTE(_notifSupplier->_refcount_value());
198 PortableServer::POA_var poa=_notifSupplier->_default_POA();
199 PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_notifSupplier);
200 poa->deactivate_object(anObjectId.in());
201 SCRUTE(_notifSupplier->_refcount_value());
202 _notifSupplier->_remove_ref();
206 //=============================================================================
208 * CORBA method: return name of the instance, unique in this Container
210 //=============================================================================
212 char* Engines_Component_i::instanceName()
214 return CORBA::string_dup(_instanceName.c_str()) ;
217 //=============================================================================
219 * CORBA method: return name of the component class
221 //=============================================================================
223 char* Engines_Component_i::interfaceName()
225 return CORBA::string_dup(_interfaceName.c_str()) ;
228 //=============================================================================
230 * CORBA method: Test if instance is alive and responds
232 //=============================================================================
234 void Engines_Component_i::ping()
237 MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid "
240 MESSAGE("Engines_Component_i::ping() pid "<< _getpid()<< " threadid "
241 << pthread_self().p );
245 //=============================================================================
247 * CORBA method: Deactivate this instance. CORBA object is deactivated (do not
248 * respond any more to CORBA calls), the connection to Regsitry is removed
249 * (Registry informed of deactivation), internal server reference counter on
250 * the derived servant class is decremented, to allow destruction of the class
251 * (delete) by POA, when there are no more references.
252 * -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
254 //=============================================================================
256 void Engines_Component_i::destroy()
258 MESSAGE("Engines_Component_i::destroy()");
259 //SCRUTE(_refcount_value());
260 _poa->deactivate_object(*_id);
261 //SCRUTE(_refcount_value());
263 //SCRUTE(_refcount_value());
264 MESSAGE("Engines_Component_i::destroyed") ;
267 //=============================================================================
269 * CORBA method: return CORBA reference of the Container
272 //=============================================================================
274 Engines::Container_ptr Engines_Component_i::GetContainerRef()
276 return Engines::Container::_duplicate(_container);
279 //=============================================================================
282 * Gives a sequence of (key=string,value=any) to the component.
283 * Base class component stores the sequence in a map.
284 * The map is cleared before.
285 * This map is for use by derived classes.
286 * \param dico sequence of (key=string,value=any)
288 //=============================================================================
290 void Engines_Component_i::setProperties(const Engines::FieldsDict& dico)
293 for (CORBA::ULong i=0; i<dico.length(); i++)
295 std::string cle(dico[i].key);
296 _fieldsDict[cle] = dico[i].value;
300 //=============================================================================
303 * returns a previously stored map (key=string,value=any) as a sequence.
304 * (see setProperties)
306 //=============================================================================
308 Engines::FieldsDict* Engines_Component_i::getProperties()
310 Engines::FieldsDict_var copie = new Engines::FieldsDict;
311 copie->length(_fieldsDict.size());
312 std::map<std::string,CORBA::Any>::iterator it;
314 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++)
316 std::string cle((*it).first);
317 copie[i].key = CORBA::string_dup(cle.c_str());
318 copie[i].value = _fieldsDict[cle];
320 return copie._retn();
323 //=============================================================================
326 * This method is to set an option specific to a certain EngineComponent.
328 //=============================================================================
330 void Engines_Component_i::SetOption(const char*, const char*)
334 //=============================================================================
337 * This method is to get value of an option specific to a certain EngineComponent.
339 //=============================================================================
341 char* Engines_Component_i::GetOption(const char*)
343 return CORBA::string_dup("") ;
346 //=============================================================================
348 * CORBA method: used by Supervision to give names to this instance
350 //=============================================================================
352 void Engines_Component_i::Names( const char * graphName ,
353 const char * nodeName )
355 _graphName = graphName ;
356 _nodeName = nodeName ;
357 // MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
358 // << _nodeName << "' )");
361 //=============================================================================
363 * CORBA method: used in Supervision
365 //=============================================================================
367 bool Engines_Component_i::Kill_impl()
369 // MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
370 // << " pid " << getpid() << " instanceName "
371 // << _instanceName.c_str() << " interface " << _interfaceName.c_str()
372 // << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
373 // << dec << " _ThreadId " << _ThreadId << " this " << hex << this
376 bool RetVal = false ;
378 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
380 RetVal = Killer( _ThreadId , SIGUSR2 ) ;
381 _ThreadId = (pthread_t ) -1 ;
385 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
387 RetVal = Killer( *_ThreadId , 0 ) ;
388 _ThreadId = (pthread_t* ) 0 ;
395 //=============================================================================
397 * CORBA method: used in Supervision
399 //=============================================================================
401 bool Engines_Component_i::Stop_impl()
404 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self()
405 << " pid " << getpid() << " instanceName "
406 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
407 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
408 << std::dec << " _ThreadId " << _ThreadId );
410 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self().p
411 << " pid " << _getpid() << " instanceName "
412 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
413 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
414 << std::dec << " _ThreadId " << _ThreadId );
418 bool RetVal = false ;
420 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
422 RetVal = Killer( _ThreadId , 0 ) ;
423 _ThreadId = (pthread_t ) -1 ;
426 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
428 RetVal = Killer( *_ThreadId , 0 ) ;
429 _ThreadId = (pthread_t* ) 0 ;
435 //=============================================================================
437 * CORBA method: used in Supervision
439 //=============================================================================
441 bool Engines_Component_i::Suspend_impl()
444 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self()
445 << " pid " << getpid() << " instanceName "
446 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
447 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
448 << std::dec << " _ThreadId " << _ThreadId );
450 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self().p
451 << " pid " << _getpid() << " instanceName "
452 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
453 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
454 << std::dec << " _ThreadId " << _ThreadId );
457 bool RetVal = false ;
459 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
461 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
471 RetVal = Killer( _ThreadId ,SIGINT ) ;
473 RetVal = Killer( *_ThreadId ,SIGINT ) ;
475 //if ( RetVal ) _Sleeping = true;
482 //=============================================================================
484 * CORBA method: used in Supervision
486 //=============================================================================
488 bool Engines_Component_i::Resume_impl()
491 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self()
492 << " pid " << getpid() << " instanceName "
493 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
494 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
495 << std::dec << " _ThreadId " << _ThreadId );
497 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self().p
498 << " pid " << _getpid() << " instanceName "
499 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
500 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
501 << std::dec << " _ThreadId " << _ThreadId );
503 bool RetVal = false ;
505 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
507 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
523 //=============================================================================
527 //=============================================================================
529 CORBA::Long Engines_Component_i::CpuUsed_impl()
532 if ( _ThreadId || _Executed )
537 if ( pthread_self() != _ThreadId )
539 if ( pthread_self().p != _ThreadId->p )
547 // Get Cpu in the appropriate thread with that object !...
548 theEngines_Component = this ;
550 Killer( _ThreadId ,SIGUSR1 ) ;
552 Killer( *_ThreadId ,SIGUSR11 ) ;
555 cpu = _ThreadCpuUsed ;
559 _ThreadCpuUsed = CpuUsed() ;
560 cpu = _ThreadCpuUsed ;
561 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
562 // << _serviceName << " " << cpu << endl ;
567 cpu = _ThreadCpuUsed ;
568 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
569 // << _serviceName << " " << cpu<< endl ;
574 // cout<< pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId "
575 // <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<<endl;
581 //=============================================================================
583 * C++ method: return Container Servant
585 //=============================================================================
587 Engines_Container_i *Engines_Component_i::GetContainerPtr()
589 PortableServer::ObjectId_var contId=_poa->reference_to_id(_container);
590 return dynamic_cast<Engines_Container_i*>(_poa->id_to_servant(contId)) ;
593 //=============================================================================
595 * C++ method: return CORBA instance id, the id is set in derived class
596 * constructor, when instance is activated.
598 //=============================================================================
600 PortableServer::ObjectId * Engines_Component_i::getId()
602 // MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
606 //=============================================================================
608 * C++ method: used by derived classes for supervision
610 //=============================================================================
612 void Engines_Component_i::beginService(const char *serviceName)
614 std::cerr << "beginService for " << serviceName << " Component instance : " << _instanceName << std::endl;
617 _ThreadId = pthread_self() ;
619 _ThreadId = new pthread_t;
620 _ThreadId->p = pthread_self().p ;
621 _ThreadId->x = pthread_self().x ;
624 _StartUsed = CpuUsed_impl() ;
627 _serviceName = serviceName ;
628 theEngines_Component = this ;
629 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) )
631 perror("pthread_setcanceltype ") ;
634 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) )
636 perror("pthread_setcancelstate ") ;
640 // --- all strings given with setProperties are set in environment
641 std::map<std::string,CORBA::Any>::iterator it;
642 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
644 std::string cle((*it).first);
645 if ((*it).second.type()->kind() == CORBA::tk_string)
648 (*it).second >>= value;
652 putenv((char *)s.c_str());
653 MESSAGE("--- setenv: "<<cle<<" = "<< value);
658 //=============================================================================
660 * C++ method: used by derived classes for supervision
662 //=============================================================================
664 void Engines_Component_i::endService(const char *serviceName)
666 if ( !_CanceledThread )
667 _ThreadCpuUsed = CpuUsed_impl() ;
669 float cpus=_ThreadCpuUsed/1000.;
670 std::cerr << "endService for " << serviceName << " Component instance : " << _instanceName ;
671 std::cerr << " Cpu Used: " << cpus << " (s) " << std::endl;
672 MESSAGE("Send EndService notification for " << serviceName
673 << std::endl << " Component instance : " << _instanceName << " StartUsed "
674 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << std::endl <<std::endl);
678 //=============================================================================
680 * C++ method: -- CHECK IF USED --
682 //=============================================================================
684 char* Engines_Component_i::graphName()
686 return CORBA::string_dup( _graphName.c_str() ) ;
689 //=============================================================================
691 * C++ method: -- CHECK IF USED --
693 //=============================================================================
695 char* Engines_Component_i::nodeName()
697 return CORBA::string_dup( _nodeName.c_str() ) ;
700 //=============================================================================
702 * C++ method: used in Supervision (see kill_impl)
704 //=============================================================================
706 bool Engines_Component_i::Killer( pthread_t ThreadId , int signum )
716 if ( pthread_cancel( ThreadId ) )
718 perror("Killer pthread_cancel error") ;
724 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_canceled") ;
726 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_canceled") ;
732 if ( pthread_kill( ThreadId , signum ) == -1 )
734 perror("Killer pthread_kill error") ;
740 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_killed(" << signum << ")") ;
742 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_killed(" << signum << ")") ;
751 void CallCancelThread();
753 //=============================================================================
757 //=============================================================================
761 if ( theEngines_Component )
762 theEngines_Component->SetCurCpu() ;
765 //=============================================================================
769 //=============================================================================
771 void Engines_Component_i::SetCurCpu()
773 _ThreadCpuUsed = CpuUsed() ;
774 // MESSAGE(pthread_self() <<
775 // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ;
778 //=============================================================================
782 //=============================================================================
784 long Engines_Component_i::CpuUsed()
788 struct rusage usage ;
789 if ( _ThreadId || _Executed )
791 if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
793 perror("Engines_Component_i::CpuUsed") ;
796 //cpu time is calculated in millisecond (user+system times)
797 cpu = usage.ru_utime.tv_sec*1000 +usage.ru_utime.tv_usec/1000;
798 cpu = cpu+ usage.ru_stime.tv_sec*1000 +usage.ru_stime.tv_usec/1000;
800 // std::cout << pthread_self() << " Engines_Component_i::CpuUsed " << " "
801 // << _serviceName << usage.ru_utime.tv_sec << " - " << _StartUsed
802 // << " = " << cpu << std::endl ;
806 // std::cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId "
807 // << _ThreadId << " " << _serviceName<< " _StartUsed "
808 // << _StartUsed << std::endl ;
811 // NOT implementet yet
818 void CallCancelThread()
820 if ( theEngines_Component )
821 theEngines_Component->CancelThread() ;
824 //=============================================================================
828 //=============================================================================
830 void Engines_Component_i::CancelThread()
832 _CanceledThread = true;
835 //=============================================================================
837 * C++ method: Send message to event channel
839 //=============================================================================
841 void Engines_Component_i::sendMessage(const char *event_type,
844 _notifSupplier->Send(_graphName.c_str(), _nodeName.c_str(), event_type, message);
847 //=============================================================================
849 * C++ method: return standard library name built on component name
851 //=============================================================================
853 std::string Engines_Component_i::GetDynLibraryName(const char *componentName)
856 std::string ret="lib";
860 std::string ret=componentName;
866 //=============================================================================
868 * C++ method: DumpPython default implementation
870 //=============================================================================
872 Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Object_ptr theStudy,
873 CORBA::Boolean isPublished,
874 CORBA::Boolean isMultiFile,
875 CORBA::Boolean& isValidScript)
877 const char* aScript = isMultiFile ? "def RebuildData(theStudy): pass" : "";
878 char* aBuffer = new char[strlen(aScript)+1];
879 strcpy(aBuffer, aScript);
880 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
881 int aBufferSize = strlen(aBuffer)+1;
882 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
883 isValidScript = true;
884 return aStreamFile._retn();
887 Engines::Salome_file_ptr
888 Engines_Component_i::getInputFileToService(const char* service_name,
889 const char* Salome_file_name)
891 // Try to find the service, if it doesn't exist, we throw an exception.
892 _Service_file_map_it = _Input_Service_file_map.find(service_name);
893 if (_Service_file_map_it == _Input_Service_file_map.end()) {
894 SALOME::ExceptionStruct es;
895 es.type = SALOME::INTERNAL_ERROR;
896 es.text = "service doesn't have salome files";
897 throw SALOME::SALOME_Exception(es);
899 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
901 // Try to find the Salome_file ...
902 _Salome_file_map_it = _map->find(Salome_file_name);
903 if (_Salome_file_map_it == _map->end()) {
904 SALOME::ExceptionStruct es;
905 es.type = SALOME::INTERNAL_ERROR;
906 es.text = "service doesn't have this Salome_file";
907 throw SALOME::SALOME_Exception(es);
909 Salome_file_i * Sfile = (*_map)[Salome_file_name];
911 return Sfile->_this();
914 Engines::Salome_file_ptr
915 Engines_Component_i::setInputFileToService(const char* service_name,
916 const char* Salome_file_name)
918 // Try to find the service, if it doesn't exist, we add it.
919 _Service_file_map_it = _Input_Service_file_map.find(service_name);
920 if (_Service_file_map_it == _Input_Service_file_map.end()) {
921 _t_Salome_file_map * _map = new _t_Salome_file_map();
922 _Input_Service_file_map[service_name] = _map;
924 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
926 // Try to find the Salome_file ...
927 _Salome_file_map_it = _map->find(Salome_file_name);
928 if (_Salome_file_map_it == _map->end()) {
929 Salome_file_i * Sfile = new Salome_file_i();
930 Engines::Container_ptr container = this->GetContainerRef();
931 Sfile->setContainer(Engines::Container::_duplicate(container));
932 (*_map)[Salome_file_name] = Sfile;
935 Salome_file_i * Sfile = (*_map)[Salome_file_name];
936 return Sfile->_this();
940 Engines_Component_i::checkInputFilesToService(const char* service_name)
942 // Try to find the service, if it doesn't exist, nothing to do.
943 _Service_file_map_it = _Input_Service_file_map.find(service_name);
944 if (_Service_file_map_it != _Input_Service_file_map.end()) {
945 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
946 _t_Salome_file_map::iterator begin = _map->begin();
947 _t_Salome_file_map::iterator end = _map->end();
949 for(;begin!=end;begin++) {
950 Salome_file_i * file = begin->second;
951 std::string file_port_name = begin->first;
952 configureSalome_file(service_name, file_port_name, file);
958 Engines::Salome_file_ptr
959 Engines_Component_i::getOutputFileToService(const char* service_name,
960 const char* Salome_file_name)
962 // Try to find the service, if it doesn't exist, we throw an exception.
963 _Service_file_map_it = _Output_Service_file_map.find(service_name);
964 if (_Service_file_map_it == _Output_Service_file_map.end()) {
965 SALOME::ExceptionStruct es;
966 es.type = SALOME::INTERNAL_ERROR;
967 es.text = "service doesn't have salome files";
968 throw SALOME::SALOME_Exception(es);
970 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
972 // Try to find the Salome_file ...
973 _Salome_file_map_it = _map->find(Salome_file_name);
974 if (_Salome_file_map_it == _map->end()) {
975 SALOME::ExceptionStruct es;
976 es.type = SALOME::INTERNAL_ERROR;
977 es.text = "service doesn't have this Salome_file";
978 throw SALOME::SALOME_Exception(es);
980 Salome_file_i * Sfile = (*_map)[Salome_file_name];
982 return Sfile->_this();
985 Engines::Salome_file_ptr
986 Engines_Component_i::setOutputFileToService(const char* service_name,
987 const char* Salome_file_name)
989 // Try to find the service, if it doesn't exist, we add it.
990 _Service_file_map_it = _Output_Service_file_map.find(service_name);
991 if (_Service_file_map_it == _Output_Service_file_map.end()) {
992 _t_Salome_file_map * _map = new _t_Salome_file_map();
993 _Output_Service_file_map[service_name] = _map;
995 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
997 // Try to find the Salome_file ...
998 _Salome_file_map_it = _map->find(Salome_file_name);
999 if (_Salome_file_map_it == _map->end()) {
1000 Salome_file_i * Sfile = new Salome_file_i();
1001 Engines::Container_ptr container = this->GetContainerRef();
1002 Sfile->setContainer(Engines::Container::_duplicate(container));
1003 (*_map)[Salome_file_name] = Sfile;
1006 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1007 return Sfile->_this();
1011 Engines_Component_i::checkOutputFilesToService(const char* service_name)
1013 // Try to find the service, if it doesn't exist, nothing to do.
1014 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1015 if (_Service_file_map_it != _Output_Service_file_map.end()) {
1016 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1017 _t_Salome_file_map::iterator begin = _map->begin();
1018 _t_Salome_file_map::iterator end = _map->end();
1020 for(;begin!=end;begin++) {
1021 Salome_file_i * file = begin->second;
1022 std::string file_port_name = begin->first;
1023 configureSalome_file(service_name, file_port_name, file);
1030 //=============================================================================
1032 * C++ method: used to configure the Salome_file into the runtime.
1033 * \param service_name name of the service that use this Salome_file
1034 * \param file_port_name name of the Salome_file
1035 * \param file Salome_file C++ object
1037 //=============================================================================
1039 Engines_Component_i::configureSalome_file(std::string service_name,
1040 std::string file_port_name,
1041 Salome_file_i * file)
1043 // By default this method does nothing
1046 //=============================================================================
1048 * C++ method: return the name of the container associated with this component
1049 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1050 * \return the container name (reformatted)
1052 //=============================================================================
1053 std::string Engines_Component_i::getContainerName()
1055 return _containerName;
1057 //=============================================================================
1059 * C++ method: set the name of the container associated with this component (attribute _containerName)
1060 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1061 * \return the container name (reformatted)
1063 //=============================================================================
1064 void Engines_Component_i::setContainerName()
1066 CORBA::String_var containerName=_container->name();
1067 std::string name(containerName);
1069 std::string::size_type slash =name.find_first_of('/');
1070 if(slash != std::string::npos)
1072 _containerName=name;
1075 //=============================================================================
1077 \brief Get version of the component
1079 This method is supposed to be implemented in all derived classes; default implementation
1080 returns empty string that means that no version information about the component is available.
1082 \note The version of the component is stored to the study, as a part of general persistence
1083 mechanism; once stored, version information in the study cannot be changed.
1085 \return string containing component's version, e.g. "1.0"
1087 char* Engines_Component_i::getVersion()
1089 return CORBA::string_dup( "" );