X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FContainer%2FComponent_i.cxx;h=7e47c0d6195ca761bfd06f6efeef23446bfcc2a5;hb=7cbb0b15185107493896b24ddfc00766433b169d;hp=4b5272cc511632744da5b610b895afa1bcadf44c;hpb=a63265d524e8436588a7bb82147a69812c153b1b;p=modules%2Fkernel.git diff --git a/src/Container/Component_i.cxx b/src/Container/Component_i.cxx index 4b5272cc5..7e47c0d61 100644 --- a/src/Container/Component_i.cxx +++ b/src/Container/Component_i.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -31,7 +31,12 @@ #include "SALOME_Container_i.hxx" #include "RegistryConnexion.hxx" #include "Basics_Utils.hxx" -#include +#include "OpUtil.hxx" +#include "Utils_SINGLETON.hxx" +#include "SALOME_NamingService.hxx" +#include "Utils_CorbaException.hxx" + +#include #ifndef WIN32 #include #endif @@ -51,7 +56,6 @@ int SIGUSR11 = 1000; extern bool _Sleeping ; static Engines_Component_i * theEngines_Component ; -bool Engines_Component_i::_isMultiStudy = true; bool Engines_Component_i::_isMultiInstance = false; /*! \class Engines_Component_i @@ -60,12 +64,12 @@ bool Engines_Component_i::_isMultiInstance = false; */ //============================================================================= -/*! +/*! * Default constructor, not for use */ //============================================================================= -Engines_Component_i::Engines_Component_i():_myConnexionToRegistry(0), _notifSupplier(0), _id(0) +Engines_Component_i::Engines_Component_i(): _id(0), _myConnexionToRegistry(0), _notifSupplier(0) { //ASSERT(0); MESSAGE("Default Constructor, not for normal use..."); @@ -86,24 +90,23 @@ Engines_Component_i::Engines_Component_i():_myConnexionToRegistry(0), _notifSupp //============================================================================= Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, - PortableServer::POA_ptr poa, - PortableServer::ObjectId * contId, + PortableServer::POA_ptr poa, + PortableServer::ObjectId * contId, const char *instanceName, const char *interfaceName, bool notif, bool regist ) : _instanceName(instanceName), _interfaceName(interfaceName), + _id(0), + _contId(0), _myConnexionToRegistry(0), _notifSupplier(0), + _graphName("") , + _nodeName(""), _ThreadId(0) , _ThreadCpuUsed(0) , _Executed(false) , - _graphName("") , - _nodeName(""), - _studyId(-1), - _id(0), - _contId(0), _CanceledThread(false) { MESSAGE("Component constructor with instanceName "<< _instanceName); @@ -117,8 +120,8 @@ Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, if(regist) { const CORBA::String_var ior = _orb->object_to_string(o); - _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession", - _instanceName.c_str()); + _myConnexionToRegistry = new RegistryConnexion(ior,"theSession", + _instanceName.c_str(), getNS()); } if(notif) @@ -148,16 +151,15 @@ Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, bool regist) : _instanceName(instanceName), _interfaceName(interfaceName), + _id(0), + _contId(0), _myConnexionToRegistry(0), _notifSupplier(0), + _graphName("") , + _nodeName(""), _ThreadId(0) , _ThreadCpuUsed(0) , _Executed(false) , - _graphName("") , - _nodeName(""), - _studyId(-1), - _id(0), - _contId(0), _CanceledThread(false) { MESSAGE("Component constructor with instanceName "<< _instanceName); @@ -167,15 +169,39 @@ Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, setContainerName(); const CORBA::String_var ior = _orb->object_to_string(_container); if(regist) - _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession", _instanceName.c_str()); + { + _myConnexionToRegistry = new RegistryConnexion(ior,"theSession", _instanceName.c_str(),getNS()); + } if(notif) _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif); } +CORBA::Boolean Engines_Component_i::isSSLMode() +{ + PortableServer::ServantBase *serv(_poa->reference_to_servant(_container)); + if(!serv) + THROW_SALOME_CORBA_EXCEPTION("_container and component are not managed by the same POA ! Looks bad !", SALOME::INTERNAL_ERROR); + Abstract_Engines_Container_i *elt=dynamic_cast(serv); + if(!elt) + THROW_SALOME_CORBA_EXCEPTION("_container servant object if not a Abstract_Engines_Container_i ! It smells bad !", SALOME::INTERNAL_ERROR); + SALOME_NamingService_Container_Abstract *ns(elt->getNS()); + if(!ns) + THROW_SALOME_CORBA_EXCEPTION("_container servant object points to a nullptr NS ! It smells bad !", SALOME::INTERNAL_ERROR); + return elt->isSSLMode() && (!dynamic_cast(ns)); +} + +SALOME_NamingService_Abstract *Engines_Component_i::getNS() +{ + CORBA::ORB_var orb = KERNEL::GetRefToORB(); + + SALOME_NamingService *naming = SINGLETON_::Instance() ; + naming->init_orb( orb ) ; + return naming; +} //============================================================================= -/*! +/*! * Destructor: call Container for decrement of instances count. * When instances count falls to 0, the container tries to remove the * component library (dlclose) @@ -204,7 +230,7 @@ Engines_Component_i::~Engines_Component_i() } //============================================================================= -/*! +/*! * CORBA method: return name of the instance, unique in this Container */ //============================================================================= @@ -215,7 +241,7 @@ char* Engines_Component_i::instanceName() } //============================================================================= -/*! +/*! * CORBA method: return name of the component class */ //============================================================================= @@ -226,21 +252,7 @@ char* Engines_Component_i::interfaceName() } //============================================================================= -/*! - * CORBA method: Get study Id - * \return -1: not initialised (Internal Error) - * 0: multistudy component instance - * >0: study id associated to this instance - */ -//============================================================================= - -CORBA::Long Engines_Component_i::getStudyId() -{ - return _studyId; -} - -//============================================================================= -/*! +/*! * CORBA method: Test if instance is alive and responds */ //============================================================================= @@ -257,7 +269,7 @@ void Engines_Component_i::ping() } //============================================================================= -/*! +/*! * CORBA method: Deactivate this instance. CORBA object is deactivated (do not * respond any more to CORBA calls), the connection to Regsitry is removed * (Registry informed of deactivation), internal server reference counter on @@ -279,7 +291,7 @@ void Engines_Component_i::destroy() } //============================================================================= -/*! +/*! * CORBA method: return CORBA reference of the Container * */ @@ -291,12 +303,12 @@ Engines::Container_ptr Engines_Component_i::GetContainerRef() } //============================================================================= -/*! - * CORBA method: - * Gives a sequence of (key=string,value=any) to the component. +/*! + * CORBA method: + * Gives a sequence of (key=string,value=any) to the component. * Base class component stores the sequence in a map. * The map is cleared before. - * This map is for use by derived classes. + * This map is for use by derived classes. * \param dico sequence of (key=string,value=any) */ //============================================================================= @@ -312,8 +324,8 @@ void Engines_Component_i::setProperties(const Engines::FieldsDict& dico) } //============================================================================= -/*! - * CORBA method: +/*! + * CORBA method: * returns a previously stored map (key=string,value=any) as a sequence. * (see setProperties) */ @@ -322,7 +334,7 @@ void Engines_Component_i::setProperties(const Engines::FieldsDict& dico) Engines::FieldsDict* Engines_Component_i::getProperties() { Engines::FieldsDict_var copie = new Engines::FieldsDict; - copie->length(_fieldsDict.size()); + copie->length((CORBA::ULong)_fieldsDict.size()); std::map::iterator it; CORBA::ULong i = 0; for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++) @@ -335,8 +347,8 @@ Engines::FieldsDict* Engines_Component_i::getProperties() } //============================================================================= -/*! - * CORBA method: +/*! + * CORBA method: * This method is to set an option specific to a certain EngineComponent. */ //============================================================================= @@ -346,8 +358,8 @@ void Engines_Component_i::SetOption(const char*, const char*) } //============================================================================= -/*! - * CORBA method: +/*! + * CORBA method: * This method is to get value of an option specific to a certain EngineComponent. */ //============================================================================= @@ -358,7 +370,7 @@ char* Engines_Component_i::GetOption(const char*) } //============================================================================= -/*! +/*! * CORBA method: used by Supervision to give names to this instance */ //============================================================================= @@ -373,12 +385,12 @@ void Engines_Component_i::Names( const char * graphName , } //============================================================================= -/*! +/*! * CORBA method: used in Supervision */ //============================================================================= -bool Engines_Component_i::Kill_impl() +bool Engines_Component_i::Kill_impl() { // MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self() // << " pid " << getpid() << " instanceName " @@ -407,7 +419,7 @@ bool Engines_Component_i::Kill_impl() } //============================================================================= -/*! +/*! * CORBA method: used in Supervision */ //============================================================================= @@ -427,7 +439,7 @@ bool Engines_Component_i::Stop_impl() << " machineName " << Kernel_Utils::GetHostname().c_str()<< " _id " << std::hex << _id << std::dec << " _ThreadId " << _ThreadId ); #endif - + bool RetVal = false ; #ifndef WIN32 @@ -447,7 +459,7 @@ bool Engines_Component_i::Stop_impl() } //============================================================================= -/*! +/*! * CORBA method: used in Supervision */ //============================================================================= @@ -479,7 +491,7 @@ bool Engines_Component_i::Suspend_impl() { return false ; } - else + else { #ifndef WIN32 RetVal = Killer( _ThreadId ,SIGINT ) ; @@ -494,7 +506,7 @@ bool Engines_Component_i::Suspend_impl() } //============================================================================= -/*! +/*! * CORBA method: used in Supervision */ //============================================================================= @@ -521,7 +533,7 @@ bool Engines_Component_i::Resume_impl() if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p ) #endif { - if ( _Sleeping ) + if ( _Sleeping ) { _Sleeping = false ; RetVal = true ; @@ -535,8 +547,8 @@ bool Engines_Component_i::Resume_impl() } //============================================================================= -/*! - * CORBA method: +/*! + * CORBA method: */ //============================================================================= @@ -576,7 +588,7 @@ CORBA::Long Engines_Component_i::CpuUsed_impl() // << _serviceName << " " << cpu << endl ; } } - else + else { cpu = _ThreadCpuUsed ; // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl " @@ -593,7 +605,7 @@ CORBA::Long Engines_Component_i::CpuUsed_impl() //============================================================================= -/*! +/*! * C++ method: return Container Servant */ //============================================================================= @@ -605,32 +617,7 @@ Engines_Container_i *Engines_Component_i::GetContainerPtr() } //============================================================================= -/*! - * C++ method: set study Id - * \param studyId 0 if instance is not associated to a study, - * >0 otherwise (== study id) - * \return true if the set of study Id is OK - * must be set once by Container, at instance creation, - * and cannot be changed after. - */ -//============================================================================= - -CORBA::Boolean Engines_Component_i::setStudyId(CORBA::Long studyId) -{ - ASSERT( studyId >= 0); - CORBA::Boolean ret = false; - if (_studyId < 0) // --- not yet initialized - { - _studyId = studyId; - ret = true; - } - else - if ( _studyId == studyId) ret = true; - return ret; -} - -//============================================================================= -/*! +/*! * C++ method: return CORBA instance id, the id is set in derived class * constructor, when instance is activated. */ @@ -643,7 +630,7 @@ PortableServer::ObjectId * Engines_Component_i::getId() } //============================================================================= -/*! +/*! * C++ method: used by derived classes for supervision */ //============================================================================= @@ -695,7 +682,7 @@ void Engines_Component_i::beginService(const char *serviceName) } //============================================================================= -/*! +/*! * C++ method: used by derived classes for supervision */ //============================================================================= @@ -705,7 +692,7 @@ void Engines_Component_i::endService(const char *serviceName) if ( !_CanceledThread ) _ThreadCpuUsed = CpuUsed_impl() ; - float cpus=_ThreadCpuUsed/1000.; + float cpus=_ThreadCpuUsed/1000.f; std::cerr << "endService for " << serviceName << " Component instance : " << _instanceName ; std::cerr << " Cpu Used: " << cpus << " (s) " << std::endl; MESSAGE("Send EndService notification for " << serviceName @@ -715,7 +702,7 @@ void Engines_Component_i::endService(const char *serviceName) } //============================================================================= -/*! +/*! * C++ method: -- CHECK IF USED -- */ //============================================================================= @@ -726,7 +713,7 @@ char* Engines_Component_i::graphName() } //============================================================================= -/*! +/*! * C++ method: -- CHECK IF USED -- */ //============================================================================= @@ -737,7 +724,7 @@ char* Engines_Component_i::nodeName() } //============================================================================= -/*! +/*! * C++ method: used in Supervision (see kill_impl) */ //============================================================================= @@ -773,7 +760,7 @@ bool Engines_Component_i::Killer( pthread_t ThreadId , int signum ) perror("Killer pthread_kill error") ; return false ; } - else + else { #ifdef WIN32 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_killed(" << signum << ")") ; @@ -790,9 +777,9 @@ void SetCpuUsed(); void CallCancelThread(); //============================================================================= -/*! +/*! * C++ method: - */ + */ //============================================================================= void SetCpuUsed() @@ -802,7 +789,7 @@ void SetCpuUsed() } //============================================================================= -/*! +/*! * C++ method: */ //============================================================================= @@ -810,12 +797,12 @@ void SetCpuUsed() void Engines_Component_i::SetCurCpu() { _ThreadCpuUsed = CpuUsed() ; - // MESSAGE(pthread_self() << + // MESSAGE(pthread_self() << // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ; } //============================================================================= -/*! +/*! * C++ method: */ //============================================================================= @@ -843,11 +830,11 @@ long Engines_Component_i::CpuUsed() else { // std::cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId " - // << _ThreadId << " " << _serviceName<< " _StartUsed " + // << _ThreadId << " " << _serviceName<< " _StartUsed " // << _StartUsed << std::endl ; } -#else - // NOT implementet yet +#else + // NOT implemented yet #endif @@ -872,7 +859,7 @@ void Engines_Component_i::CancelThread() } //============================================================================= -/*! +/*! * C++ method: Send message to event channel */ //============================================================================= @@ -884,48 +871,51 @@ void Engines_Component_i::sendMessage(const char *event_type, } //============================================================================= -/*! +/*! * C++ method: return standard library name built on component name */ //============================================================================= std::string Engines_Component_i::GetDynLibraryName(const char *componentName) { -#ifndef WIN32 - std::string ret="lib"; - ret+=componentName; - ret+="Engine.so"; + std::string prefix, suffix; + std::string cname = componentName; +#if !defined(WIN32) + prefix = "lib"; +#endif +#if defined(WIN32) + suffix = "dll"; +#elif defined(__APPLE__) + suffix = "dylib"; #else - std::string ret=componentName; - ret+="Engine.dll"; -#endif + suffix = "so"; +#endif + std::string ret = prefix + cname + std::string("Engine.") + suffix; return ret; } //============================================================================= -/*! +/*! * C++ method: DumpPython default implementation */ //============================================================================= -Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Object_ptr theStudy, - CORBA::Boolean isPublished, - CORBA::Boolean isMultiFile, +Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Boolean /*isPublished*/, + CORBA::Boolean isMultiFile, CORBA::Boolean& isValidScript) { - const char* aScript = isMultiFile ? "def RebuildData(theStudy): pass" : ""; + const char* aScript = isMultiFile ? "def RebuildData(): pass" : ""; char* aBuffer = new char[strlen(aScript)+1]; strcpy(aBuffer, aScript); - CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer; - int aBufferSize = strlen(aBuffer)+1; - Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1); + size_t aBufferSize = strlen(aBuffer)+1; + Engines::TMPFile_var aStreamFile = new Engines::TMPFile((CORBA::ULong)aBufferSize, (CORBA::ULong)aBufferSize, (CORBA::Octet*)aBuffer, 1); isValidScript = true; - return aStreamFile._retn(); + return aStreamFile._retn(); } -Engines::Salome_file_ptr -Engines_Component_i::getInputFileToService(const char* service_name, - const char* Salome_file_name) +Engines::Salome_file_ptr +Engines_Component_i::getInputFileToService(const char* service_name, + const char* Salome_file_name) { // Try to find the service, if it doesn't exist, we throw an exception. _Service_file_map_it = _Input_Service_file_map.find(service_name); @@ -950,9 +940,9 @@ Engines_Component_i::getInputFileToService(const char* service_name, return Sfile->_this(); } -Engines::Salome_file_ptr -Engines_Component_i::setInputFileToService(const char* service_name, - const char* Salome_file_name) +Engines::Salome_file_ptr +Engines_Component_i::setInputFileToService(const char* service_name, + const char* Salome_file_name) { // Try to find the service, if it doesn't exist, we add it. _Service_file_map_it = _Input_Service_file_map.find(service_name); @@ -961,7 +951,7 @@ Engines_Component_i::setInputFileToService(const char* service_name, _Input_Service_file_map[service_name] = _map; } _t_Salome_file_map * _map = _Input_Service_file_map[service_name]; - + // Try to find the Salome_file ... _Salome_file_map_it = _map->find(Salome_file_name); if (_Salome_file_map_it == _map->end()) { @@ -975,8 +965,8 @@ Engines_Component_i::setInputFileToService(const char* service_name, return Sfile->_this(); } -void -Engines_Component_i::checkInputFilesToService(const char* service_name) +void +Engines_Component_i::checkInputFilesToService(const char* service_name) { // Try to find the service, if it doesn't exist, nothing to do. _Service_file_map_it = _Input_Service_file_map.find(service_name); @@ -994,9 +984,9 @@ Engines_Component_i::checkInputFilesToService(const char* service_name) } } -Engines::Salome_file_ptr -Engines_Component_i::getOutputFileToService(const char* service_name, - const char* Salome_file_name) +Engines::Salome_file_ptr +Engines_Component_i::getOutputFileToService(const char* service_name, + const char* Salome_file_name) { // Try to find the service, if it doesn't exist, we throw an exception. _Service_file_map_it = _Output_Service_file_map.find(service_name); @@ -1021,9 +1011,9 @@ Engines_Component_i::getOutputFileToService(const char* service_name, return Sfile->_this(); } -Engines::Salome_file_ptr -Engines_Component_i::setOutputFileToService(const char* service_name, - const char* Salome_file_name) +Engines::Salome_file_ptr +Engines_Component_i::setOutputFileToService(const char* service_name, + const char* Salome_file_name) { // Try to find the service, if it doesn't exist, we add it. _Service_file_map_it = _Output_Service_file_map.find(service_name); @@ -1032,7 +1022,7 @@ Engines_Component_i::setOutputFileToService(const char* service_name, _Output_Service_file_map[service_name] = _map; } _t_Salome_file_map * _map = _Output_Service_file_map[service_name]; - + // Try to find the Salome_file ... _Salome_file_map_it = _map->find(Salome_file_name); if (_Salome_file_map_it == _map->end()) { @@ -1046,8 +1036,8 @@ Engines_Component_i::setOutputFileToService(const char* service_name, return Sfile->_this(); } -void -Engines_Component_i::checkOutputFilesToService(const char* service_name) +void +Engines_Component_i::checkOutputFilesToService(const char* service_name) { // Try to find the service, if it doesn't exist, nothing to do. _Service_file_map_it = _Output_Service_file_map.find(service_name); @@ -1067,7 +1057,7 @@ Engines_Component_i::checkOutputFilesToService(const char* service_name) } //============================================================================= -/*! +/*! * C++ method: used to configure the Salome_file into the runtime. * \param service_name name of the service that use this Salome_file * \param file_port_name name of the Salome_file @@ -1075,47 +1065,15 @@ Engines_Component_i::checkOutputFilesToService(const char* service_name) */ //============================================================================= void -Engines_Component_i::configureSalome_file(std::string service_name, - std::string file_port_name, - Salome_file_i * file) -{ - // By default this method does nothing -} - -//============================================================================= -/*! - * C++ method: allows to import data file into the Component internal data - structure (like import operation of BRep file in GEOM module). - * \param studyId identifier of the working study - * \param data container of the file content - * \param options additional options for import (if needed) - */ -//============================================================================= -Engines::ListOfIdentifiers* Engines_Component_i::importData(CORBA::Long studyId, - Engines::DataContainer_ptr data, - const Engines::ListOfOptions& options) +Engines_Component_i::configureSalome_file(std::string /*service_name*/, + std::string /*file_port_name*/, + Salome_file_i* /*file*/) { // By default this method does nothing - Engines::ListOfIdentifiers_var aList = new Engines::ListOfIdentifiers; - return aList._retn(); } //============================================================================= -/*! - * C++ method: allows to export data files from the Component internal data - structure (like Export operation of Step file in GEOM module). - * \param studyId identifier of the working study - */ -//============================================================================= -Engines::ListOfData* Engines_Component_i::getModifiedData(CORBA::Long studyId) -{ - // By default this method does nothing - Engines::ListOfData_var aList = new Engines::ListOfData; - return aList._retn(); -} - -//============================================================================= -/*! +/*! * C++ method: return the name of the container associated with this component * This name does not contains the "/Containers" string and all "/" are replaced by "_" * \return the container name (reformatted) @@ -1126,7 +1084,7 @@ std::string Engines_Component_i::getContainerName() return _containerName; } //============================================================================= -/*! +/*! * C++ method: set the name of the container associated with this component (attribute _containerName) * This name does not contains the "/Containers" string and all "/" are replaced by "_" * \return the container name (reformatted) @@ -1145,16 +1103,37 @@ void Engines_Component_i::setContainerName() //============================================================================= /*! - \brief Get version of the component + * \brief Return \c true if component can provide creation information. + */ +//============================================================================= +bool Engines_Component_i::hasObjectInfo() +{ + return false; +} - This method is supposed to be implemented in all derived classes; default implementation - returns empty string that means that no version information about the component is available. +//============================================================================= +/*! + * \brief Get creation information for object addressed by given entry. + */ +//============================================================================= +char* Engines_Component_i::getObjectInfo(const char* /*entry*/) +{ + return CORBA::string_dup(""); +} - \note The version of the component is stored to the study, as a part of general persistence - mechanism; once stored, version information in the study cannot be changed. - - \return string containing component's version, e.g. "1.0" -*/ +//============================================================================= +/*! + * \brief Get version of the component + * + * This method is supposed to be implemented in all derived classes; default implementation + * returns empty string that means that no version information about the component is available. + * + * \note The version of the component is stored to the study, as a part of general persistence + * mechanism; once stored, version information in the study cannot be changed. + * + * \return string containing component's version, e.g. "1.0" + */ +//============================================================================= char* Engines_Component_i::getVersion() { return CORBA::string_dup( "" );