1 // Copyright (C) 2007-2014 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);
170 _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: Get study Id
231 * \return -1: not initialised (Internal Error)
232 * 0: multistudy component instance
233 * >0: study id associated to this instance
235 //=============================================================================
237 CORBA::Long Engines_Component_i::getStudyId()
242 //=============================================================================
244 * CORBA method: Test if instance is alive and responds
246 //=============================================================================
248 void Engines_Component_i::ping()
251 MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid "
254 MESSAGE("Engines_Component_i::ping() pid "<< _getpid()<< " threadid "
255 << pthread_self().p );
259 //=============================================================================
261 * CORBA method: Deactivate this instance. CORBA object is deactivated (do not
262 * respond any more to CORBA calls), the connection to Regsitry is removed
263 * (Registry informed of deactivation), internal server reference counter on
264 * the derived servant class is decremented, to allow destruction of the class
265 * (delete) by POA, when there are no more references.
266 * -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
268 //=============================================================================
270 void Engines_Component_i::destroy()
272 MESSAGE("Engines_Component_i::destroy()");
273 //SCRUTE(_refcount_value());
274 _poa->deactivate_object(*_id);
275 //SCRUTE(_refcount_value());
277 //SCRUTE(_refcount_value());
278 MESSAGE("Engines_Component_i::destroyed") ;
281 //=============================================================================
283 * CORBA method: return CORBA reference of the Container
286 //=============================================================================
288 Engines::Container_ptr Engines_Component_i::GetContainerRef()
290 return Engines::Container::_duplicate(_container);
293 //=============================================================================
296 * Gives a sequence of (key=string,value=any) to the component.
297 * Base class component stores the sequence in a map.
298 * The map is cleared before.
299 * This map is for use by derived classes.
300 * \param dico sequence of (key=string,value=any)
302 //=============================================================================
304 void Engines_Component_i::setProperties(const Engines::FieldsDict& dico)
307 for (CORBA::ULong i=0; i<dico.length(); i++)
309 std::string cle(dico[i].key);
310 _fieldsDict[cle] = dico[i].value;
314 //=============================================================================
317 * returns a previously stored map (key=string,value=any) as a sequence.
318 * (see setProperties)
320 //=============================================================================
322 Engines::FieldsDict* Engines_Component_i::getProperties()
324 Engines::FieldsDict_var copie = new Engines::FieldsDict;
325 copie->length(_fieldsDict.size());
326 std::map<std::string,CORBA::Any>::iterator it;
328 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++)
330 std::string cle((*it).first);
331 copie[i].key = CORBA::string_dup(cle.c_str());
332 copie[i].value = _fieldsDict[cle];
334 return copie._retn();
337 //=============================================================================
340 * This method is to set an option specific to a certain EngineComponent.
342 //=============================================================================
344 void Engines_Component_i::SetOption(const char*, const char*)
348 //=============================================================================
351 * This method is to get value of an option specific to a certain EngineComponent.
353 //=============================================================================
355 char* Engines_Component_i::GetOption(const char*)
357 return CORBA::string_dup("") ;
360 //=============================================================================
362 * CORBA method: used by Supervision to give names to this instance
364 //=============================================================================
366 void Engines_Component_i::Names( const char * graphName ,
367 const char * nodeName )
369 _graphName = graphName ;
370 _nodeName = nodeName ;
371 // MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
372 // << _nodeName << "' )");
375 //=============================================================================
377 * CORBA method: used in Supervision
379 //=============================================================================
381 bool Engines_Component_i::Kill_impl()
383 // MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
384 // << " pid " << getpid() << " instanceName "
385 // << _instanceName.c_str() << " interface " << _interfaceName.c_str()
386 // << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << hex << _id
387 // << dec << " _ThreadId " << _ThreadId << " this " << hex << this
390 bool RetVal = false ;
392 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
394 RetVal = Killer( _ThreadId , SIGUSR2 ) ;
395 _ThreadId = (pthread_t ) -1 ;
399 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
401 RetVal = Killer( *_ThreadId , 0 ) ;
402 _ThreadId = (pthread_t* ) 0 ;
409 //=============================================================================
411 * CORBA method: used in Supervision
413 //=============================================================================
415 bool Engines_Component_i::Stop_impl()
418 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self()
419 << " pid " << getpid() << " instanceName "
420 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
421 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
422 << std::dec << " _ThreadId " << _ThreadId );
424 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self().p
425 << " pid " << _getpid() << " instanceName "
426 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
427 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
428 << std::dec << " _ThreadId " << _ThreadId );
432 bool RetVal = false ;
434 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
436 RetVal = Killer( _ThreadId , 0 ) ;
437 _ThreadId = (pthread_t ) -1 ;
440 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
442 RetVal = Killer( *_ThreadId , 0 ) ;
443 _ThreadId = (pthread_t* ) 0 ;
449 //=============================================================================
451 * CORBA method: used in Supervision
453 //=============================================================================
455 bool Engines_Component_i::Suspend_impl()
458 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self()
459 << " pid " << getpid() << " instanceName "
460 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
461 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
462 << std::dec << " _ThreadId " << _ThreadId );
464 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self().p
465 << " pid " << _getpid() << " instanceName "
466 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
467 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
468 << std::dec << " _ThreadId " << _ThreadId );
471 bool RetVal = false ;
473 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
475 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
485 RetVal = Killer( _ThreadId ,SIGINT ) ;
487 RetVal = Killer( *_ThreadId ,SIGINT ) ;
489 //if ( RetVal ) _Sleeping = true;
496 //=============================================================================
498 * CORBA method: used in Supervision
500 //=============================================================================
502 bool Engines_Component_i::Resume_impl()
505 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self()
506 << " pid " << getpid() << " instanceName "
507 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
508 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
509 << std::dec << " _ThreadId " << _ThreadId );
511 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self().p
512 << " pid " << _getpid() << " instanceName "
513 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
514 << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id
515 << std::dec << " _ThreadId " << _ThreadId );
517 bool RetVal = false ;
519 if ( _ThreadId > 0 && pthread_self() != _ThreadId )
521 if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
537 //=============================================================================
541 //=============================================================================
543 CORBA::Long Engines_Component_i::CpuUsed_impl()
546 if ( _ThreadId || _Executed )
551 if ( pthread_self() != _ThreadId )
553 if ( pthread_self().p != _ThreadId->p )
561 // Get Cpu in the appropriate thread with that object !...
562 theEngines_Component = this ;
564 Killer( _ThreadId ,SIGUSR1 ) ;
566 Killer( *_ThreadId ,SIGUSR11 ) ;
569 cpu = _ThreadCpuUsed ;
573 _ThreadCpuUsed = CpuUsed() ;
574 cpu = _ThreadCpuUsed ;
575 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
576 // << _serviceName << " " << cpu << endl ;
581 cpu = _ThreadCpuUsed ;
582 // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
583 // << _serviceName << " " << cpu<< endl ;
588 // cout<< pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId "
589 // <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<<endl;
595 //=============================================================================
597 * C++ method: return Container Servant
599 //=============================================================================
601 Engines_Container_i *Engines_Component_i::GetContainerPtr()
603 PortableServer::ObjectId_var contId=_poa->reference_to_id(_container);
604 return dynamic_cast<Engines_Container_i*>(_poa->id_to_servant(contId)) ;
607 //=============================================================================
609 * C++ method: set study Id
610 * \param studyId 0 if instance is not associated to a study,
611 * >0 otherwise (== study id)
612 * \return true if the set of study Id is OK
613 * must be set once by Container, at instance creation,
614 * and cannot be changed after.
616 //=============================================================================
618 CORBA::Boolean Engines_Component_i::setStudyId(CORBA::Long studyId)
620 ASSERT( studyId >= 0);
621 CORBA::Boolean ret = false;
622 if (_studyId < 0) // --- not yet initialized
628 if ( _studyId == studyId) ret = true;
632 //=============================================================================
634 * C++ method: return CORBA instance id, the id is set in derived class
635 * constructor, when instance is activated.
637 //=============================================================================
639 PortableServer::ObjectId * Engines_Component_i::getId()
641 // MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
645 //=============================================================================
647 * C++ method: used by derived classes for supervision
649 //=============================================================================
651 void Engines_Component_i::beginService(const char *serviceName)
653 std::cerr << "beginService for " << serviceName << " Component instance : " << _instanceName << std::endl;
656 _ThreadId = pthread_self() ;
658 _ThreadId = new pthread_t;
659 _ThreadId->p = pthread_self().p ;
660 _ThreadId->x = pthread_self().x ;
663 _StartUsed = CpuUsed_impl() ;
666 _serviceName = serviceName ;
667 theEngines_Component = this ;
668 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) )
670 perror("pthread_setcanceltype ") ;
673 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) )
675 perror("pthread_setcancelstate ") ;
679 // --- all strings given with setProperties are set in environment
680 std::map<std::string,CORBA::Any>::iterator it;
681 for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
683 std::string cle((*it).first);
684 if ((*it).second.type()->kind() == CORBA::tk_string)
687 (*it).second >>= value;
691 putenv((char *)s.c_str());
692 MESSAGE("--- setenv: "<<cle<<" = "<< value);
697 //=============================================================================
699 * C++ method: used by derived classes for supervision
701 //=============================================================================
703 void Engines_Component_i::endService(const char *serviceName)
705 if ( !_CanceledThread )
706 _ThreadCpuUsed = CpuUsed_impl() ;
708 float cpus=_ThreadCpuUsed/1000.;
709 std::cerr << "endService for " << serviceName << " Component instance : " << _instanceName ;
710 std::cerr << " Cpu Used: " << cpus << " (s) " << std::endl;
711 MESSAGE("Send EndService notification for " << serviceName
712 << std::endl << " Component instance : " << _instanceName << " StartUsed "
713 << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << std::endl <<std::endl);
717 //=============================================================================
719 * C++ method: -- CHECK IF USED --
721 //=============================================================================
723 char* Engines_Component_i::graphName()
725 return CORBA::string_dup( _graphName.c_str() ) ;
728 //=============================================================================
730 * C++ method: -- CHECK IF USED --
732 //=============================================================================
734 char* Engines_Component_i::nodeName()
736 return CORBA::string_dup( _nodeName.c_str() ) ;
739 //=============================================================================
741 * C++ method: used in Supervision (see kill_impl)
743 //=============================================================================
745 bool Engines_Component_i::Killer( pthread_t ThreadId , int signum )
755 if ( pthread_cancel( ThreadId ) )
757 perror("Killer pthread_cancel error") ;
763 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_canceled") ;
765 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_canceled") ;
771 if ( pthread_kill( ThreadId , signum ) == -1 )
773 perror("Killer pthread_kill error") ;
779 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_killed(" << signum << ")") ;
781 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_killed(" << signum << ")") ;
790 void CallCancelThread();
792 //=============================================================================
796 //=============================================================================
800 if ( theEngines_Component )
801 theEngines_Component->SetCurCpu() ;
804 //=============================================================================
808 //=============================================================================
810 void Engines_Component_i::SetCurCpu()
812 _ThreadCpuUsed = CpuUsed() ;
813 // MESSAGE(pthread_self() <<
814 // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ;
817 //=============================================================================
821 //=============================================================================
823 long Engines_Component_i::CpuUsed()
827 struct rusage usage ;
828 if ( _ThreadId || _Executed )
830 if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
832 perror("Engines_Component_i::CpuUsed") ;
835 //cpu time is calculated in millisecond (user+system times)
836 cpu = usage.ru_utime.tv_sec*1000 +usage.ru_utime.tv_usec/1000;
837 cpu = cpu+ usage.ru_stime.tv_sec*1000 +usage.ru_stime.tv_usec/1000;
839 // std::cout << pthread_self() << " Engines_Component_i::CpuUsed " << " "
840 // << _serviceName << usage.ru_utime.tv_sec << " - " << _StartUsed
841 // << " = " << cpu << std::endl ;
845 // std::cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId "
846 // << _ThreadId << " " << _serviceName<< " _StartUsed "
847 // << _StartUsed << std::endl ;
850 // NOT implementet yet
857 void CallCancelThread()
859 if ( theEngines_Component )
860 theEngines_Component->CancelThread() ;
863 //=============================================================================
867 //=============================================================================
869 void Engines_Component_i::CancelThread()
871 _CanceledThread = true;
874 //=============================================================================
876 * C++ method: Send message to event channel
878 //=============================================================================
880 void Engines_Component_i::sendMessage(const char *event_type,
883 _notifSupplier->Send(_graphName.c_str(), _nodeName.c_str(), event_type, message);
886 //=============================================================================
888 * C++ method: return standard library name built on component name
890 //=============================================================================
892 std::string Engines_Component_i::GetDynLibraryName(const char *componentName)
895 std::string ret="lib";
899 std::string ret=componentName;
905 //=============================================================================
907 * C++ method: DumpPython default implementation
909 //=============================================================================
911 Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Object_ptr theStudy,
912 CORBA::Boolean isPublished,
913 CORBA::Boolean isMultiFile,
914 CORBA::Boolean& isValidScript)
916 const char* aScript = isMultiFile ? "def RebuildData(theStudy): pass" : "";
917 char* aBuffer = new char[strlen(aScript)+1];
918 strcpy(aBuffer, aScript);
919 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
920 int aBufferSize = strlen(aBuffer)+1;
921 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
922 isValidScript = true;
923 return aStreamFile._retn();
926 Engines::Salome_file_ptr
927 Engines_Component_i::getInputFileToService(const char* service_name,
928 const char* Salome_file_name)
930 // Try to find the service, if it doesn't exist, we throw an exception.
931 _Service_file_map_it = _Input_Service_file_map.find(service_name);
932 if (_Service_file_map_it == _Input_Service_file_map.end()) {
933 SALOME::ExceptionStruct es;
934 es.type = SALOME::INTERNAL_ERROR;
935 es.text = "service doesn't have salome files";
936 throw SALOME::SALOME_Exception(es);
938 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
940 // Try to find the Salome_file ...
941 _Salome_file_map_it = _map->find(Salome_file_name);
942 if (_Salome_file_map_it == _map->end()) {
943 SALOME::ExceptionStruct es;
944 es.type = SALOME::INTERNAL_ERROR;
945 es.text = "service doesn't have this Salome_file";
946 throw SALOME::SALOME_Exception(es);
948 Salome_file_i * Sfile = (*_map)[Salome_file_name];
950 return Sfile->_this();
953 Engines::Salome_file_ptr
954 Engines_Component_i::setInputFileToService(const char* service_name,
955 const char* Salome_file_name)
957 // Try to find the service, if it doesn't exist, we add it.
958 _Service_file_map_it = _Input_Service_file_map.find(service_name);
959 if (_Service_file_map_it == _Input_Service_file_map.end()) {
960 _t_Salome_file_map * _map = new _t_Salome_file_map();
961 _Input_Service_file_map[service_name] = _map;
963 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
965 // Try to find the Salome_file ...
966 _Salome_file_map_it = _map->find(Salome_file_name);
967 if (_Salome_file_map_it == _map->end()) {
968 Salome_file_i * Sfile = new Salome_file_i();
969 Engines::Container_ptr container = this->GetContainerRef();
970 Sfile->setContainer(Engines::Container::_duplicate(container));
971 (*_map)[Salome_file_name] = Sfile;
974 Salome_file_i * Sfile = (*_map)[Salome_file_name];
975 return Sfile->_this();
979 Engines_Component_i::checkInputFilesToService(const char* service_name)
981 // Try to find the service, if it doesn't exist, nothing to do.
982 _Service_file_map_it = _Input_Service_file_map.find(service_name);
983 if (_Service_file_map_it != _Input_Service_file_map.end()) {
984 _t_Salome_file_map * _map = _Input_Service_file_map[service_name];
985 _t_Salome_file_map::iterator begin = _map->begin();
986 _t_Salome_file_map::iterator end = _map->end();
988 for(;begin!=end;begin++) {
989 Salome_file_i * file = begin->second;
990 std::string file_port_name = begin->first;
991 configureSalome_file(service_name, file_port_name, file);
997 Engines::Salome_file_ptr
998 Engines_Component_i::getOutputFileToService(const char* service_name,
999 const char* Salome_file_name)
1001 // Try to find the service, if it doesn't exist, we throw an exception.
1002 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1003 if (_Service_file_map_it == _Output_Service_file_map.end()) {
1004 SALOME::ExceptionStruct es;
1005 es.type = SALOME::INTERNAL_ERROR;
1006 es.text = "service doesn't have salome files";
1007 throw SALOME::SALOME_Exception(es);
1009 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1011 // Try to find the Salome_file ...
1012 _Salome_file_map_it = _map->find(Salome_file_name);
1013 if (_Salome_file_map_it == _map->end()) {
1014 SALOME::ExceptionStruct es;
1015 es.type = SALOME::INTERNAL_ERROR;
1016 es.text = "service doesn't have this Salome_file";
1017 throw SALOME::SALOME_Exception(es);
1019 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1021 return Sfile->_this();
1024 Engines::Salome_file_ptr
1025 Engines_Component_i::setOutputFileToService(const char* service_name,
1026 const char* Salome_file_name)
1028 // Try to find the service, if it doesn't exist, we add it.
1029 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1030 if (_Service_file_map_it == _Output_Service_file_map.end()) {
1031 _t_Salome_file_map * _map = new _t_Salome_file_map();
1032 _Output_Service_file_map[service_name] = _map;
1034 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1036 // Try to find the Salome_file ...
1037 _Salome_file_map_it = _map->find(Salome_file_name);
1038 if (_Salome_file_map_it == _map->end()) {
1039 Salome_file_i * Sfile = new Salome_file_i();
1040 Engines::Container_ptr container = this->GetContainerRef();
1041 Sfile->setContainer(Engines::Container::_duplicate(container));
1042 (*_map)[Salome_file_name] = Sfile;
1045 Salome_file_i * Sfile = (*_map)[Salome_file_name];
1046 return Sfile->_this();
1050 Engines_Component_i::checkOutputFilesToService(const char* service_name)
1052 // Try to find the service, if it doesn't exist, nothing to do.
1053 _Service_file_map_it = _Output_Service_file_map.find(service_name);
1054 if (_Service_file_map_it != _Output_Service_file_map.end()) {
1055 _t_Salome_file_map * _map = _Output_Service_file_map[service_name];
1056 _t_Salome_file_map::iterator begin = _map->begin();
1057 _t_Salome_file_map::iterator end = _map->end();
1059 for(;begin!=end;begin++) {
1060 Salome_file_i * file = begin->second;
1061 std::string file_port_name = begin->first;
1062 configureSalome_file(service_name, file_port_name, file);
1069 //=============================================================================
1071 * C++ method: used to configure the Salome_file into the runtime.
1072 * \param service_name name of the service that use this Salome_file
1073 * \param file_port_name name of the Salome_file
1074 * \param file Salome_file C++ object
1076 //=============================================================================
1078 Engines_Component_i::configureSalome_file(std::string service_name,
1079 std::string file_port_name,
1080 Salome_file_i * file)
1082 // By default this method does nothing
1085 //=============================================================================
1087 * C++ method: allows to import data file into the Component internal data
1088 structure (like import operation of BRep file in GEOM module).
1089 * \param studyId identifier of the working study
1090 * \param data container of the file content
1091 * \param options additional options for import (if needed)
1093 //=============================================================================
1094 Engines::ListOfIdentifiers* Engines_Component_i::importData(CORBA::Long studyId,
1095 Engines::DataContainer_ptr data,
1096 const Engines::ListOfOptions& options)
1098 // By default this method does nothing
1099 Engines::ListOfIdentifiers_var aList = new Engines::ListOfIdentifiers;
1100 return aList._retn();
1103 //=============================================================================
1105 * C++ method: allows to export data files from the Component internal data
1106 structure (like Export operation of Step file in GEOM module).
1107 * \param studyId identifier of the working study
1109 //=============================================================================
1110 Engines::ListOfData* Engines_Component_i::getModifiedData(CORBA::Long studyId)
1112 // By default this method does nothing
1113 Engines::ListOfData_var aList = new Engines::ListOfData;
1114 return aList._retn();
1117 //=============================================================================
1119 * C++ method: return the name of the container associated with this component
1120 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1121 * \return the container name (reformatted)
1123 //=============================================================================
1124 std::string Engines_Component_i::getContainerName()
1126 return _containerName;
1128 //=============================================================================
1130 * C++ method: set the name of the container associated with this component (attribute _containerName)
1131 * This name does not contains the "/Containers" string and all "/" are replaced by "_"
1132 * \return the container name (reformatted)
1134 //=============================================================================
1135 void Engines_Component_i::setContainerName()
1137 CORBA::String_var containerName=_container->name();
1138 std::string name(containerName);
1140 std::string::size_type slash =name.find_first_of('/');
1141 if(slash != std::string::npos)
1143 _containerName=name;
1146 //=============================================================================
1148 \brief Get version of the component
1150 This method is supposed to be implemented in all derived classes; default implementation
1151 returns empty string that means that no version information about the component is available.
1153 \note The version of the component is stored to the study, as a part of general persistence
1154 mechanism; once stored, version information in the study cannot be changed.
1156 \return string containing component's version, e.g. "1.0"
1158 char* Engines_Component_i::getVersion()
1160 return CORBA::string_dup( "" );