X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FContainer%2FComponent_i.cxx;h=4bf755f93f0b966b7571eaeb1c5373fe5cf1d30e;hb=910e1b8c12ac2978e64847e9694b080c8381bc60;hp=ae92c5b7e2f0a1abf0575c04a617e097b674aa67;hpb=9749fc1db72bd80e278405114b05ffc69b5031da;p=modules%2Fkernel.git diff --git a/src/Container/Component_i.cxx b/src/Container/Component_i.cxx index ae92c5b7e..4bf755f93 100644 --- a/src/Container/Component_i.cxx +++ b/src/Container/Component_i.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -6,7 +6,7 @@ // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -51,7 +51,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,7 +59,7 @@ bool Engines_Component_i::_isMultiInstance = false; */ //============================================================================= -/*! +/*! * Default constructor, not for use */ //============================================================================= @@ -86,8 +85,8 @@ 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, @@ -101,7 +100,6 @@ Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, _Executed(false) , _graphName("") , _nodeName(""), - _studyId(-1), _id(0), _contId(0), _CanceledThread(false) @@ -155,7 +153,6 @@ Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, _Executed(false) , _graphName("") , _nodeName(""), - _studyId(-1), _id(0), _contId(0), _CanceledThread(false) @@ -167,7 +164,9 @@ 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()); + } if(notif) _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif); @@ -175,7 +174,7 @@ Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, //============================================================================= -/*! +/*! * 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 +203,7 @@ Engines_Component_i::~Engines_Component_i() } //============================================================================= -/*! +/*! * CORBA method: return name of the instance, unique in this Container */ //============================================================================= @@ -215,7 +214,7 @@ char* Engines_Component_i::instanceName() } //============================================================================= -/*! +/*! * CORBA method: return name of the component class */ //============================================================================= @@ -226,21 +225,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 +242,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 +264,7 @@ void Engines_Component_i::destroy() } //============================================================================= -/*! +/*! * CORBA method: return CORBA reference of the Container * */ @@ -291,12 +276,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 +297,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) */ @@ -335,8 +320,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 +331,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 +343,7 @@ char* Engines_Component_i::GetOption(const char*) } //============================================================================= -/*! +/*! * CORBA method: used by Supervision to give names to this instance */ //============================================================================= @@ -373,12 +358,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 +392,7 @@ bool Engines_Component_i::Kill_impl() } //============================================================================= -/*! +/*! * CORBA method: used in Supervision */ //============================================================================= @@ -427,7 +412,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 +432,7 @@ bool Engines_Component_i::Stop_impl() } //============================================================================= -/*! +/*! * CORBA method: used in Supervision */ //============================================================================= @@ -479,7 +464,7 @@ bool Engines_Component_i::Suspend_impl() { return false ; } - else + else { #ifndef WIN32 RetVal = Killer( _ThreadId ,SIGINT ) ; @@ -494,7 +479,7 @@ bool Engines_Component_i::Suspend_impl() } //============================================================================= -/*! +/*! * CORBA method: used in Supervision */ //============================================================================= @@ -521,7 +506,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 +520,8 @@ bool Engines_Component_i::Resume_impl() } //============================================================================= -/*! - * CORBA method: +/*! + * CORBA method: */ //============================================================================= @@ -576,7 +561,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 +578,7 @@ CORBA::Long Engines_Component_i::CpuUsed_impl() //============================================================================= -/*! +/*! * C++ method: return Container Servant */ //============================================================================= @@ -605,32 +590,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 +603,7 @@ PortableServer::ObjectId * Engines_Component_i::getId() } //============================================================================= -/*! +/*! * C++ method: used by derived classes for supervision */ //============================================================================= @@ -695,7 +655,7 @@ void Engines_Component_i::beginService(const char *serviceName) } //============================================================================= -/*! +/*! * C++ method: used by derived classes for supervision */ //============================================================================= @@ -715,7 +675,7 @@ void Engines_Component_i::endService(const char *serviceName) } //============================================================================= -/*! +/*! * C++ method: -- CHECK IF USED -- */ //============================================================================= @@ -726,7 +686,7 @@ char* Engines_Component_i::graphName() } //============================================================================= -/*! +/*! * C++ method: -- CHECK IF USED -- */ //============================================================================= @@ -737,7 +697,7 @@ char* Engines_Component_i::nodeName() } //============================================================================= -/*! +/*! * C++ method: used in Supervision (see kill_impl) */ //============================================================================= @@ -759,7 +719,7 @@ bool Engines_Component_i::Killer( pthread_t ThreadId , int signum ) } else { -#ifdef WNT +#ifdef WIN32 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_canceled") ; #else MESSAGE("Killer : ThreadId " << ThreadId << " pthread_canceled") ; @@ -773,9 +733,9 @@ bool Engines_Component_i::Killer( pthread_t ThreadId , int signum ) perror("Killer pthread_kill error") ; return false ; } - else + else { -#ifdef WNT +#ifdef WIN32 MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_killed(" << signum << ")") ; #else MESSAGE("Killer : ThreadId " << ThreadId << " pthread_killed(" << signum << ")") ; @@ -790,9 +750,9 @@ void SetCpuUsed(); void CallCancelThread(); //============================================================================= -/*! +/*! * C++ method: - */ + */ //============================================================================= void SetCpuUsed() @@ -802,7 +762,7 @@ void SetCpuUsed() } //============================================================================= -/*! +/*! * C++ method: */ //============================================================================= @@ -810,12 +770,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,10 +803,10 @@ 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 +#else // NOT implementet yet #endif @@ -872,7 +832,7 @@ void Engines_Component_i::CancelThread() } //============================================================================= -/*! +/*! * C++ method: Send message to event channel */ //============================================================================= @@ -884,43 +844,52 @@ 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) { - 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 + 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); + Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 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); @@ -945,9 +914,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); @@ -956,7 +925,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()) { @@ -970,8 +939,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); @@ -989,9 +958,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); @@ -1016,9 +985,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); @@ -1027,7 +996,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()) { @@ -1041,8 +1010,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); @@ -1062,7 +1031,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 @@ -1072,13 +1041,13 @@ 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) + Salome_file_i * file) { // By default this method does nothing } //============================================================================= -/*! +/*! * 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) @@ -1089,7 +1058,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) @@ -1115,7 +1084,7 @@ void Engines_Component_i::setContainerName() \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()