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 = true;
55 bool Engines_Component_i::_isMultiInstance = false;
57 /*! \class Engines_Component_i
58 * \brief C++ implementation of Engines::Component interface
62 //=============================================================================
64 * Default constructor, not for use
66 //=============================================================================
68 Engines_Component_i::Engines_Component_i():_myConnexionToRegistry(0), _notifSupplier(0), _id(0)
71 MESSAGE("Default Constructor, not for normal use...");
74 //=============================================================================
75 /*! \brief Standard Constructor for generic Component, used in derived class
77 * Connection to Registry and Notification
78 * \param orb Object Request broker given by Container
79 * \param poa Portable Object Adapter from Container (normally root_poa)
80 * \param contId container CORBA id inside the server
81 * \param instanceName unique instance name for this object (see Container_i)
82 * \param interfaceName component class name
83 * \param notif use of notification
84 * \param regist (true or false) use of registry (default true)
86 //=============================================================================
88 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
89 PortableServer::POA_ptr poa,
90 PortableServer::ObjectId * contId,
91 const char *instanceName,
92 const char *interfaceName,
95 _instanceName(instanceName),
96 _interfaceName(interfaceName),
97 _myConnexionToRegistry(0),
107 _CanceledThread(false)
109 MESSAGE("Component constructor with instanceName "<< _instanceName);
110 _orb = CORBA::ORB::_duplicate(orb);
111 _poa = PortableServer::POA::_duplicate(poa);
113 CORBA::Object_var o = _poa->id_to_reference(*contId); // container ior...
114 _container=Engines::Container::_narrow(o);
119 const CORBA::String_var ior = _orb->object_to_string(o);
120 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession",
121 _instanceName.c_str());
125 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
128 //=============================================================================
129 /*! \brief Standard Constructor for standalone Component, used in derived class
131 * Connection to Registry and Notification
132 * \param orb Object Request broker given by Container
133 * \param poa Portable Object Adapter from Container (normally root_poa)
134 * \param container container CORBA reference
135 * \param instanceName unique instance name for this object (see Container_i)
136 * \param interfaceName component class name
137 * \param notif use of notification
138 * \param regist (true or false) use of registry (default true)
140 //=============================================================================
142 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
143 PortableServer::POA_ptr poa,
144 Engines::Container_ptr container,
145 const char *instanceName,
146 const char *interfaceName,
149 _instanceName(instanceName),
150 _interfaceName(interfaceName),
151 _myConnexionToRegistry(0),
161 _CanceledThread(false)
163 MESSAGE("Component constructor with instanceName "<< _instanceName);
164 _orb = CORBA::ORB::_duplicate(orb);
165 _poa = PortableServer::POA::_duplicate(poa);
166 _container=Engines::Container::_duplicate(container);
168 const CORBA::String_var ior = _orb->object_to_string(_container);
171 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession", _instanceName.c_str());
174 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
179 //=============================================================================
181 * Destructor: call Container for decrement of instances count.
182 * When instances count falls to 0, the container tries to remove the
183 * component library (dlclose)
185 //=============================================================================
187 Engines_Component_i::~Engines_Component_i()
189 MESSAGE("Component destructor");
190 Engines_Container_i::decInstanceCnt(_interfaceName);
191 if(_myConnexionToRegistry)delete _myConnexionToRegistry;
192 _myConnexionToRegistry = 0 ;
199 SCRUTE(_notifSupplier->_refcount_value());
200 PortableServer::POA_var poa=_notifSupplier->_default_POA();
201 PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_notifSupplier);
202 poa->deactivate_object(anObjectId.in());
203 SCRUTE(_notifSupplier->_refcount_value());
204 _notifSupplier->_remove_ref();
208 //=============================================================================
210 * CORBA method: return name of the instance, unique in this Container
212 //=============================================================================
214 char* Engines_Component_i::instanceName()
216 return CORBA::string_dup(_instanceName.c_str()) ;
219 //=============================================================================
221 * CORBA method: return name of the component class
223 //=============================================================================
225 char* Engines_Component_i::interfaceName()
227 return CORBA::string_dup(_interfaceName.c_str()) ;
230 //=============================================================================
232 * CORBA method: Get study Id
233 * \return -1: not initialised (Internal Error)
234 * 0: multistudy component instance
235 * >0: study id associated to this instance
237 //=============================================================================
239 CORBA::Long Engines_Component_i::getStudyId()
244 //=============================================================================
246 * CORBA method: Test if instance is alive and responds
248 //=============================================================================
250 void Engines_Component_i::ping()
253 MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid "
256 MESSAGE("Engines_Component_i::ping() pid "<< _getpid()<< " threadid "
257 << pthread_self().p );
261 //=============================================================================
263 * CORBA method: Deactivate this instance. CORBA object is deactivated (do not
264 * respond any more to CORBA calls), the connection to Regsitry is removed
265 * (Registry informed of deactivation), internal server reference counter on
266 * the derived servant class is decremented, to allow destruction of the class
267 * (delete) by POA, when there are no more references.
268 * -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
270 //=============================================================================
272 void Engines_Component_i::destroy()
274 MESSAGE("Engines_Component_i::destroy()");
275 //SCRUTE(_refcount_value());
276 _poa->deactivate_object(*_id);
277 //SCRUTE(_refcount_value());
279 //SCRUTE(_refcount_value());
280 MESSAGE("Engines_Component_i::destroyed") ;
283 //=============================================================================
285 * CORBA method: return CORBA reference of the Container
288 //=============================================================================
290 Engines::Container_ptr Engines_Component_i::GetContainerRef()
292 return Engines::Container::_duplicate(_container);
295 //=============================================================================
298 * Gives a sequence of (key=string,value=any) to the component.
299 * Base class component stores the sequence in a map.
300 * The map is cleared before.
301 * This map is for use by derived classes.
302 * \param dico sequence of (key=string,value=any)
304 //=============================================================================
306 void Engines_Component_i::setProperties(const Engines::FieldsDict& dico)
309 for (CORBA::ULong i=0; i<dico.length(); i++)
311 std::string cle(dico[i].key);
312 _fieldsDict[cle] = dico[i].value;
316 //=============================================================================
319 * returns a previously stored map (key=string,value=any) as a sequence.
320 * (see setProperties)
322 //=============================================================================
324 Engines::FieldsDict* Engines_Component_i::getProperties()
326 Engines::FieldsDict_var copie = new Engines::FieldsDict;
327 copie->length(_fieldsDict.size());
328 std::map<std::string,CORBA::Any>::iterator it;
330 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++)
332 std::string cle((*it).first);
333 copie[i].key = CORBA::string_dup(cle.c_str());
334 copie[i].value = _fieldsDict[cle];
336 return copie._retn();
339 //=============================================================================
342 * This method is to set an option specific to a certain EngineComponent.
344 //=============================================================================
346 void Engines_Component_i::SetOption(const char*, const char*)
350 //=============================================================================
353 * This method is to get value of an option specific to a certain EngineComponent.
355 //=============================================================================
357 char* Engines_Component_i::GetOption(const char*)
359 return CORBA::string_dup("") ;
362 //=============================================================================
364 * CORBA method: used by Supervision to give names to this instance
366 //=============================================================================
368 void Engines_Component_i::Names( const char * graphName ,
369 const char * nodeName )
371 _graphName = graphName ;
372 _nodeName = nodeName ;
373 // MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
374 // << _nodeName << "' )");
377 //=============================================================================
379 * CORBA method: used in Supervision
381 //=============================================================================
383 bool Engines_Component_i::Kill_impl()
385 // MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
386 // << " pid " << getpid() << " instanceName "
387 // << _instanceName.c_str() << " interface " << _interfaceName.c_str()
388 // << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
389 // << dec << " _ThreadId " << _ThreadId << " this " << hex << this
392 bool RetVal = false ;
394 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
396 RetVal = Killer( _ThreadId , SIGUSR2 ) ;
397 _ThreadId = (pthread_t ) -1 ;
401 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
403 RetVal = Killer( *_ThreadId , 0 ) ;
404 _ThreadId = (pthread_t* ) 0 ;
411 //=============================================================================
413 * CORBA method: used in Supervision
415 //=============================================================================
417 bool Engines_Component_i::Stop_impl()
420 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self()
421 << " pid " << getpid() << " instanceName "
422 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
423 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
424 << std::dec << " _ThreadId " << _ThreadId );
426 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self().p
427 << " pid " << _getpid() << " instanceName "
428 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
429 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
430 << std::dec << " _ThreadId " << _ThreadId );
434 bool RetVal = false ;
436 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
438 RetVal = Killer( _ThreadId , 0 ) ;
439 _ThreadId = (pthread_t ) -1 ;
442 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
444 RetVal = Killer( *_ThreadId , 0 ) ;
445 _ThreadId = (pthread_t* ) 0 ;
451 //=============================================================================
453 * CORBA method: used in Supervision
455 //=============================================================================
457 bool Engines_Component_i::Suspend_impl()
460 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self()
461 << " pid " << getpid() << " instanceName "
462 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
463 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
464 << std::dec << " _ThreadId " << _ThreadId );
466 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self().p
467 << " pid " << _getpid() << " instanceName "
468 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
469 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
470 << std::dec << " _ThreadId " << _ThreadId );
473 bool RetVal = false ;
475 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
477 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
487 RetVal = Killer( _ThreadId ,SIGINT ) ;
489 RetVal = Killer( *_ThreadId ,SIGINT ) ;
491 //if ( RetVal ) _Sleeping = true;
498 //=============================================================================
500 * CORBA method: used in Supervision
502 //=============================================================================
504 bool Engines_Component_i::Resume_impl()
507 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self()
508 << " pid " << getpid() << " instanceName "
509 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
510 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
511 << std::dec << " _ThreadId " << _ThreadId );
513 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self().p
514 << " pid " << _getpid() << " instanceName "
515 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
516 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
517 << std::dec << " _ThreadId " << _ThreadId );
519 bool RetVal = false ;
521 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
523 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
539 //=============================================================================
543 //=============================================================================
545 CORBA::Long Engines_Component_i::CpuUsed_impl()
548 if ( _ThreadId || _Executed )
553 if ( pthread_self() != _ThreadId )
555 if ( pthread_self().p != _ThreadId->p )
563 // Get Cpu in the appropriate thread with that object !...
564 theEngines_Component = this ;
566 Killer( _ThreadId ,SIGUSR1 ) ;
568 Killer( *_ThreadId ,SIGUSR11 ) ;
571 cpu = _ThreadCpuUsed ;
575 _ThreadCpuUsed = CpuUsed() ;
576 cpu = _ThreadCpuUsed ;
577 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
578 // << _serviceName << " " << cpu << endl ;
583 cpu = _ThreadCpuUsed ;
584 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
585 // << _serviceName << " " << cpu<< endl ;
590 // cout<< pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId "
591 // <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<<endl;
597 //=============================================================================
599 * C++ method: return Container Servant
601 //=============================================================================
603 Engines_Container_i *Engines_Component_i::GetContainerPtr()
605 PortableServer::ObjectId_var contId=_poa->reference_to_id(_container);
606 return dynamic_cast<Engines_Container_i*>(_poa->id_to_servant(contId)) ;
609 //=============================================================================
611 * C++ method: set study Id
612 * \param studyId 0 if instance is not associated to a study,
613 * >0 otherwise (== study id)
614 * \return true if the set of study Id is OK
615 * must be set once by Container, at instance creation,
616 * and cannot be changed after.
618 //=============================================================================
620 CORBA::Boolean Engines_Component_i::setStudyId(CORBA::Long studyId)
622 ASSERT( studyId >= 0);
623 CORBA::Boolean ret = false;
624 if (_studyId < 0) // --- not yet initialized
630 if ( _studyId == studyId) ret = true;
634 //=============================================================================
636 * C++ method: return CORBA instance id, the id is set in derived class
637 * constructor, when instance is activated.
639 //=============================================================================
641 PortableServer::ObjectId * Engines_Component_i::getId()
643 // MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
647 //=============================================================================
649 * C++ method: used by derived classes for supervision
651 //=============================================================================
653 void Engines_Component_i::beginService(const char *serviceName)
655 std::cerr << "beginService for " << serviceName << " Component instance : " << _instanceName << std::endl;
658 _ThreadId = pthread_self() ;
660 _ThreadId = new pthread_t;
661 _ThreadId->p = pthread_self().p ;
662 _ThreadId->x = pthread_self().x ;
665 _StartUsed = CpuUsed_impl() ;
668 _serviceName = serviceName ;
669 theEngines_Component = this ;
670 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) )
672 perror("pthread_setcanceltype ") ;
675 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) )
677 perror("pthread_setcancelstate ") ;
681 // --- all strings given with setProperties are set in environment
682 std::map<std::string,CORBA::Any>::iterator it;
683 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
685 std::string cle((*it).first);
686 if ((*it).second.type()->kind() == CORBA::tk_string)
689 (*it).second >>= value;
693 putenv((char *)s.c_str());
694 MESSAGE("--- setenv: "<<cle<<" = "<< value);
699 //=============================================================================
701 * C++ method: used by derived classes for supervision
703 //=============================================================================
705 void Engines_Component_i::endService(const char *serviceName)
707 if ( !_CanceledThread )
708 _ThreadCpuUsed = CpuUsed_impl() ;
710 float cpus=_ThreadCpuUsed/1000.;
711 std::cerr << "endService for " << serviceName << " Component instance : " << _instanceName ;
712 std::cerr << " Cpu Used: " << cpus << " (s) " << std::endl;
713 MESSAGE("Send EndService notification for " << serviceName
714 << std::endl << " Component instance : " << _instanceName << " StartUsed "
715 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << std::endl <<std::endl);
719 //=============================================================================
721 * C++ method: -- CHECK IF USED --
723 //=============================================================================
725 char* Engines_Component_i::graphName()
727 return CORBA::string_dup( _graphName.c_str() ) ;
730 //=============================================================================
732 * C++ method: -- CHECK IF USED --
734 //=============================================================================
736 char* Engines_Component_i::nodeName()
738 return CORBA::string_dup( _nodeName.c_str() ) ;
741 //=============================================================================
743 * C++ method: used in Supervision (see kill_impl)
745 //=============================================================================
747 bool Engines_Component_i::Killer( pthread_t ThreadId , int signum )
757 if ( pthread_cancel( ThreadId ) )
759 perror("Killer pthread_cancel error") ;
765 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_canceled") ;
767 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_canceled") ;
773 if ( pthread_kill( ThreadId , signum ) == -1 )
775 perror("Killer pthread_kill error") ;
781 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_killed(" << signum << ")") ;
783 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_killed(" << signum << ")") ;
792 void CallCancelThread();
794 //=============================================================================
798 //=============================================================================
802 if ( theEngines_Component )
803 theEngines_Component->SetCurCpu() ;
806 //=============================================================================
810 //=============================================================================
812 void Engines_Component_i::SetCurCpu()
814 _ThreadCpuUsed = CpuUsed() ;
815 // MESSAGE(pthread_self() <<
816 // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ;
819 //=============================================================================
823 //=============================================================================
825 long Engines_Component_i::CpuUsed()
829 struct rusage usage ;
830 if ( _ThreadId || _Executed )
832 if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
834 perror("Engines_Component_i::CpuUsed") ;
837 //cpu time is calculated in millisecond (user+system times)
838 cpu = usage.ru_utime.tv_sec*1000 +usage.ru_utime.tv_usec/1000;
839 cpu = cpu+ usage.ru_stime.tv_sec*1000 +usage.ru_stime.tv_usec/1000;
841 // std::cout << pthread_self() << " Engines_Component_i::CpuUsed " << " "
842 // << _serviceName << usage.ru_utime.tv_sec << " - " << _StartUsed
843 // << " = " << cpu << std::endl ;
847 // std::cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId "
848 // << _ThreadId << " " << _serviceName<< " _StartUsed "
849 // << _StartUsed << std::endl ;
852 // NOT implemented yet
859 void CallCancelThread()
861 if ( theEngines_Component )
862 theEngines_Component->CancelThread() ;
865 //=============================================================================
869 //=============================================================================
871 void Engines_Component_i::CancelThread()
873 _CanceledThread = true;
876 //=============================================================================
878 * C++ method: Send message to event channel
880 //=============================================================================
882 void Engines_Component_i::sendMessage(const char *event_type,
885 _notifSupplier->Send(_graphName.c_str(), _nodeName.c_str(), event_type, message);
888 //=============================================================================
890 * C++ method: return standard library name built on component name
892 //=============================================================================
894 std::string Engines_Component_i::GetDynLibraryName(const char *componentName)
896 std::string prefix, suffix;
897 std::string cname = componentName;
903 #elif defined(__APPLE__)
908 std::string ret = prefix + cname + std::string("Engine.") + suffix;
912 //=============================================================================
914 * C++ method: DumpPython default implementation
916 //=============================================================================
918 Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Object_ptr theStudy,
919 CORBA::Boolean isPublished,
920 CORBA::Boolean isMultiFile,
921 CORBA::Boolean& isValidScript)
923 const char* aScript = isMultiFile ? "def RebuildData(theStudy): pass" : "";
924 char* aBuffer = new char[strlen(aScript)+1];
925 strcpy(aBuffer, aScript);
926 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
927 int aBufferSize = strlen(aBuffer)+1;
928 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
929 isValidScript = true;
930 return aStreamFile._retn();
933 Engines::Salome_file_ptr
934 Engines_Component_i::getInputFileToService(const char* service_name,
935 const char* Salome_file_name)
937 // Try to find the service, if it doesn't exist, we throw an exception.
938 _Service_file_map_it = _Input_Service_file_map.find(service_name);
939 if (_Service_file_map_it == _Input_Service_file_map.end()) {
940 SALOME::ExceptionStruct es;
941 es.type = SALOME::INTERNAL_ERROR;
942 es.text = "service doesn't have salome files";
943 throw SALOME::SALOME_Exception(es);
945 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
947 // Try to find the Salome_file ...
948 _Salome_file_map_it = _map->find(Salome_file_name);
949 if (_Salome_file_map_it == _map->end()) {
950 SALOME::ExceptionStruct es;
951 es.type = SALOME::INTERNAL_ERROR;
952 es.text = "service doesn't have this Salome_file";
953 throw SALOME::SALOME_Exception(es);
955 Salome_file_i * Sfile = (*_map)[Salome_file_name];
957 return Sfile->_this();
960 Engines::Salome_file_ptr
961 Engines_Component_i::setInputFileToService(const char* service_name,
962 const char* Salome_file_name)
964 // Try to find the service, if it doesn't exist, we add it.
965 _Service_file_map_it = _Input_Service_file_map.find(service_name);
966 if (_Service_file_map_it == _Input_Service_file_map.end()) {
967 _t_Salome_file_map * _map = new _t_Salome_file_map();
968 _Input_Service_file_map[service_name] = _map;
970 _t_Salome_file_map * _map = _Input_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_file_i * Sfile = new Salome_file_i();
976 Engines::Container_ptr container = this->GetContainerRef();
977 Sfile->setContainer(Engines::Container::_duplicate(container));
978 (*_map)[Salome_file_name] = Sfile;
981 Salome_file_i * Sfile = (*_map)[Salome_file_name];
982 return Sfile->_this();
986 Engines_Component_i::checkInputFilesToService(const char* service_name)
988 // Try to find the service, if it doesn't exist, nothing to do.
989 _Service_file_map_it = _Input_Service_file_map.find(service_name);
990 if (_Service_file_map_it != _Input_Service_file_map.end()) {
991 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
992 _t_Salome_file_map::iterator begin = _map->begin();
993 _t_Salome_file_map::iterator end = _map->end();
995 for(;begin!=end;begin++) {
996 Salome_file_i * file = begin->second;
997 std::string file_port_name = begin->first;
998 configureSalome_file(service_name, file_port_name, file);
1004 Engines::Salome_file_ptr
1005 Engines_Component_i::getOutputFileToService(const char* service_name,
1006 const char* Salome_file_name)
1008 // Try to find the service, if it doesn't exist, we throw an exception.
1009 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1010 if (_Service_file_map_it == _Output_Service_file_map.end()) {
1011 SALOME::ExceptionStruct es;
1012 es.type = SALOME::INTERNAL_ERROR;
1013 es.text = "service doesn't have salome files";
1014 throw SALOME::SALOME_Exception(es);
1016 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1018 // Try to find the Salome_file ...
1019 _Salome_file_map_it = _map->find(Salome_file_name);
1020 if (_Salome_file_map_it == _map->end()) {
1021 SALOME::ExceptionStruct es;
1022 es.type = SALOME::INTERNAL_ERROR;
1023 es.text = "service doesn't have this Salome_file";
1024 throw SALOME::SALOME_Exception(es);
1026 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1028 return Sfile->_this();
1031 Engines::Salome_file_ptr
1032 Engines_Component_i::setOutputFileToService(const char* service_name,
1033 const char* Salome_file_name)
1035 // Try to find the service, if it doesn't exist, we add it.
1036 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1037 if (_Service_file_map_it == _Output_Service_file_map.end()) {
1038 _t_Salome_file_map * _map = new _t_Salome_file_map();
1039 _Output_Service_file_map[service_name] = _map;
1041 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1043 // Try to find the Salome_file ...
1044 _Salome_file_map_it = _map->find(Salome_file_name);
1045 if (_Salome_file_map_it == _map->end()) {
1046 Salome_file_i * Sfile = new Salome_file_i();
1047 Engines::Container_ptr container = this->GetContainerRef();
1048 Sfile->setContainer(Engines::Container::_duplicate(container));
1049 (*_map)[Salome_file_name] = Sfile;
1052 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1053 return Sfile->_this();
1057 Engines_Component_i::checkOutputFilesToService(const char* service_name)
1059 // Try to find the service, if it doesn't exist, nothing to do.
1060 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1061 if (_Service_file_map_it != _Output_Service_file_map.end()) {
1062 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1063 _t_Salome_file_map::iterator begin = _map->begin();
1064 _t_Salome_file_map::iterator end = _map->end();
1066 for(;begin!=end;begin++) {
1067 Salome_file_i * file = begin->second;
1068 std::string file_port_name = begin->first;
1069 configureSalome_file(service_name, file_port_name, file);
1076 //=============================================================================
1078 * C++ method: used to configure the Salome_file into the runtime.
1079 * \param service_name name of the service that use this Salome_file
1080 * \param file_port_name name of the Salome_file
1081 * \param file Salome_file C++ object
1083 //=============================================================================
1085 Engines_Component_i::configureSalome_file(std::string service_name,
1086 std::string file_port_name,
1087 Salome_file_i * file)
1089 // By default this method does nothing
1092 //=============================================================================
1094 * C++ method: return the name of the container associated with this component
1095 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1096 * \return the container name (reformatted)
1098 //=============================================================================
1099 std::string Engines_Component_i::getContainerName()
1101 return _containerName;
1103 //=============================================================================
1105 * C++ method: set the name of the container associated with this component (attribute _containerName)
1106 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1107 * \return the container name (reformatted)
1109 //=============================================================================
1110 void Engines_Component_i::setContainerName()
1112 CORBA::String_var containerName=_container->name();
1113 std::string name(containerName);
1115 std::string::size_type slash =name.find_first_of('/');
1116 if(slash != std::string::npos)
1118 _containerName=name;
1121 //=============================================================================
1123 \brief Get version of the component
1125 This method is supposed to be implemented in all derived classes; default implementation
1126 returns empty string that means that no version information about the component is available.
1128 \note The version of the component is stored to the study, as a part of general persistence
1129 mechanism; once stored, version information in the study cannot be changed.
1131 \return string containing component's version, e.g. "1.0"
1133 char* Engines_Component_i::getVersion()
1135 return CORBA::string_dup( "" );