From bba51cdbc5da9ab68b9567860468b394e23f8690 Mon Sep 17 00:00:00 2001 From: srn Date: Mon, 20 Mar 2006 12:30:55 +0000 Subject: [PATCH] Implemented a possibility to dlopen SalomeDS libarary and create SObject, Study, StudyBuilder, StudyManager objects and IParameter interaface --- src/SALOMEDSClient/Makefile.am | 1 + .../SALOMEDSClient_ClientFactory.cxx | 102 ++++++++++++ .../SALOMEDSClient_ClientFactory.hxx | 28 +++- .../SALOMEDSClient_IParameters.hxx | 146 ++++++++++++++++++ 4 files changed, 276 insertions(+), 1 deletion(-) create mode 100644 src/SALOMEDSClient/SALOMEDSClient_IParameters.hxx diff --git a/src/SALOMEDSClient/Makefile.am b/src/SALOMEDSClient/Makefile.am index f74e21151..32578e10e 100644 --- a/src/SALOMEDSClient/Makefile.am +++ b/src/SALOMEDSClient/Makefile.am @@ -48,6 +48,7 @@ salomeinclude_HEADERS=\ SALOMEDSClient_UseCaseBuilder.hxx \ SALOMEDSClient_UseCaseIterator.hxx \ SALOMEDSClient_ClientFactory.hxx \ + SALOMEDSClient_IParameters.hxx \ SALOMEDSClient.hxx # diff --git a/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.cxx b/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.cxx index 4b5e23b59..4e29d1b5d 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.cxx +++ b/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.cxx @@ -13,20 +13,36 @@ static void* _libHandle = NULL; #define SOBJECT_FACTORY "SObjectFactory" #define SCOMPONENT_FACTORY "SComponentFactory" #define STUDY_FACTORY "StudyFactory" +#define BUILDER_FACTORY "BuilderFactory" #define STUDYMANAGER_FACTORY "StudyManagerFactory" #define STUDYMANAGER_CREATE "CreateStudyManager" +#define GET_PARAMETERS "GetIParameters" +#define CONVERT_SOBJECT "ConvertSObject" +#define CONVERT_STUDY "ConvertStudy" +#define CONVERT_BUILDER "ConvertBuilder" typedef SALOMEDSClient_SObject* (*SOBJECT_FACTORY_FUNCTION) (SALOMEDS::SObject_ptr); typedef SALOMEDSClient_SComponent* (*SCOMPONENT_FACTORY_FUNCTION) (SALOMEDS::SComponent_ptr); typedef SALOMEDSClient_Study* (*STUDY_FACTORY_FUNCTION) (SALOMEDS::Study_ptr); typedef SALOMEDSClient_StudyManager* (*STUDYMANAGER_FACTORY_FUNCTION) (); +typedef SALOMEDSClient_StudyBuilder* (*BUILDER_FACTORY_FUNCTION) (SALOMEDS::StudyBuilder_ptr); typedef SALOMEDSClient_StudyManager* (*STUDYMANAGER_CREATE_FUNCTION) (CORBA::ORB_ptr, PortableServer::POA_ptr); +typedef SALOMEDSClient_IParameters* (*GET_PARAMETERS_FACTORY) (const _PTR(AttributeParameter)&); +typedef SALOMEDS::SObject_ptr (*CONVERT_SOBJECT_FUNCTION) (const _PTR(SObject)&); +typedef SALOMEDS::Study_ptr (*CONVERT_STUDY_FUNCTION) (const _PTR(Study)&); +typedef SALOMEDS::StudyBuilder_ptr (*CONVERT_BUILDER_FUNCTION) (const _PTR(StudyBuilder)&); + static SOBJECT_FACTORY_FUNCTION aSObjectFactory = NULL; static SCOMPONENT_FACTORY_FUNCTION aSComponentFactory = NULL; static STUDY_FACTORY_FUNCTION aStudyFactory = NULL; +static BUILDER_FACTORY_FUNCTION aBuilderFactory = NULL; static STUDYMANAGER_FACTORY_FUNCTION aManagerFactory = NULL; static STUDYMANAGER_CREATE_FUNCTION aCreateFactory = NULL; +static GET_PARAMETERS_FACTORY aGetIParameters = NULL; +static CONVERT_SOBJECT_FUNCTION aConvertSObject = NULL; +static CONVERT_STUDY_FUNCTION aConvertStudy = NULL; +static CONVERT_BUILDER_FUNCTION aConvertBuilder = NULL; using namespace std; @@ -78,6 +94,22 @@ _PTR(Study) ClientFactory::Study(SALOMEDS::Study_ptr theStudy) return _PTR(Study)(study); } +_PTR(StudyBuilder) ClientFactory::StudyBuilder(SALOMEDS::StudyBuilder_ptr theStudyBuilder) +{ + SALOMEDSClient_StudyBuilder* studyBuilder = NULL; + +#ifdef WIN32 + if(!_libHandle) _libHandle = ::LoadLibrary(SALOMEDS_LIB_NAME); + if(!aBuilderFactory) aBuilderFactory = (BUILDER_FACTORY_FUNCTION)::GetProcAddress(_libHandle, BUILDER_FACTORY); +#else + if(!_libHandle) _libHandle = dlopen(SALOMEDS_LIB_NAME, RTLD_LAZY | RTLD_GLOBAL); + if(!aBuilderFactory) aBuilderFactory = (BUILDER_FACTORY_FUNCTION) dlsym(_libHandle, BUILDER_FACTORY); +#endif + + if(aBuilderFactory) studyBuilder = aBuilderFactory(theStudyBuilder); + return _PTR(StudyBuilder)(studyBuilder); +} + _PTR(StudyManager) ClientFactory::StudyManager() { SALOMEDSClient_StudyManager* manager = NULL; @@ -110,3 +142,73 @@ _PTR(StudyManager) ClientFactory::createStudyManager(CORBA::ORB_ptr orb, Portabl return _PTR(StudyManager)(manager); } +_PTR(IParameters) ClientFactory::getIParameters(const _PTR(AttributeParameter)& ap) +{ + SALOMEDSClient_IParameters* interface = NULL; + +#ifdef WIN32 + if(!_libHandle) _libHandle = ::LoadLibrary(SALOMEDS_LIB_NAME); + if(!aGetIParameters) aGetIParameters = (GET_PARAMETERS_FACTORY)::GetProcAddress(_libHandle, GET_PARAMETERS); +#else + if(!_libHandle) _libHandle = dlopen(SALOMEDS_LIB_NAME, RTLD_LAZY | RTLD_GLOBAL); + if(!aGetIParameters) aGetIParameters = (GET_PARAMETERS_FACTORY) dlsym(_libHandle, GET_PARAMETERS); +#endif + + if(aGetIParameters) interface = aGetIParameters(ap); + return _PTR(IParameters)(interface); +} + +SALOMEDS::SObject_ptr ClientFactory::crbSObject(const _PTR(SObject)& theSObject) +{ + SALOMEDS::SObject_var so; + +#ifdef WIN32 + if(!_libHandle) _libHandle = ::LoadLibrary(SALOMEDS_LIB_NAME); + if(!aConvertSObject) aConvertSObject = (CONVERT_SOBJECT_FUNCTION)::GetProcAddress(_libHandle, CONVERT_SOBJECT); +#else + if(!_libHandle) _libHandle = dlopen(SALOMEDS_LIB_NAME, RTLD_LAZY | RTLD_GLOBAL); + if(!aConvertSObject) aConvertSObject = (CONVERT_SOBJECT_FUNCTION) dlsym(_libHandle, CONVERT_SOBJECT); +#endif + + if(aConvertSObject) so = aConvertSObject(theSObject); + + if(CORBA::is_nil(so)) return SALOMEDS::SObject::_nil(); + return so._retn(); +} + + +SALOMEDS::Study_ptr ClientFactory::crbStudy(const _PTR(Study)& theStudy) +{ + SALOMEDS::Study_var study; + +#ifdef WIN32 + if(!_libHandle) _libHandle = ::LoadLibrary(SALOMEDS_LIB_NAME); + if(!aConvertStudy) aConvertStudy = (CONVERT_STUDY_FUNCTION)::GetProcAddress(_libHandle, CONVERT_STUDY); +#else + if(!_libHandle) _libHandle = dlopen(SALOMEDS_LIB_NAME, RTLD_LAZY | RTLD_GLOBAL); + if(!aConvertStudy) aConvertStudy = (CONVERT_STUDY_FUNCTION) dlsym(_libHandle, CONVERT_STUDY); +#endif + + if(aConvertStudy) study = aConvertStudy(theStudy); + + if(CORBA::is_nil(study)) return SALOMEDS::Study::_nil(); + return study._retn(); +} + +SALOMEDS::StudyBuilder_ptr ClientFactory::crbStudyBuilder(const _PTR(StudyBuilder)& theStudyBuilder) +{ + SALOMEDS::StudyBuilder_var studyBuilder; + +#ifdef WIN32 + if(!_libHandle) _libHandle = ::LoadLibrary(SALOMEDS_LIB_NAME); + if(!aConvertBuilder)aConvertBuilder = (CONVERT_BUILDER_FUNCTION)::GetProcAddress(_libHandle, CONVERT_BUILDER); +#else + if(!_libHandle) _libHandle = dlopen(SALOMEDS_LIB_NAME, RTLD_LAZY | RTLD_GLOBAL); + if(!aConvertBuilder) aConvertBuilder = (CONVERT_BUILDER_FUNCTION) dlsym(_libHandle, CONVERT_BUILDER); +#endif + + if(aConvertBuilder) studyBuilder = aConvertBuilder(theStudyBuilder); + + if(CORBA::is_nil(studyBuilder)) return SALOMEDS::StudyBuilder::_nil(); + return studyBuilder._retn(); +} diff --git a/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.hxx b/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.hxx index 85929293d..ae9ff5d5b 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.hxx +++ b/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.hxx @@ -30,6 +30,7 @@ #include "SALOMEDSClient_SComponent.hxx" #include "SALOMEDSClient_Study.hxx" #include "SALOMEDSClient_StudyManager.hxx" +#include "SALOMEDSClient_IParameters.hxx" #include @@ -55,6 +56,11 @@ public: */ static _PTR(Study) Study(SALOMEDS::Study_ptr theStudy); + /*! + * Returns a client StudyBuilder wrapper that corresponds %theStudy + */ + static _PTR(StudyBuilder) StudyBuilder(SALOMEDS::StudyBuilder_ptr theBuilder); + /*! * Returns a client StudyManager wrapper */ @@ -65,7 +71,27 @@ public: */ static _PTR(StudyManager) createStudyManager(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa); - + /*! + * Returns an IParameters interface + */ + static _PTR(IParameters) getIParameters(const _PTR(AttributeParameter)& ap); + + + /*! + * Returns a CORBA SObject that corresponds %theStudy + */ + static SALOMEDS::SObject_ptr crbSObject(const _PTR(SObject)& theSObject); + + /*! + * Returns a CORBA Study that corresponds %theStudy + */ + static SALOMEDS::Study_ptr crbStudy(const _PTR(Study)& theStudy); + + /*! + * Returns a CORBA StudyBuilder that corresponds %theStudyBuilder + */ + static SALOMEDS::StudyBuilder_ptr crbStudyBuilder(const _PTR(StudyBuilder)& theStudyBuilder); + }; #endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_IParameters.hxx b/src/SALOMEDSClient/SALOMEDSClient_IParameters.hxx new file mode 100644 index 000000000..66419ca82 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_IParameters.hxx @@ -0,0 +1,146 @@ +// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ +// +#ifndef SALOMEDSClient_IParameters_H +#define SALOMEDSClient_IParameters_H + +#include +#include +#include + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_AttributeParameter.hxx" + +/*! + Class which an interface to store the parameters of the objects +*/ +class SALOMEDSClient_IParameters +{ +public: + + virtual ~SALOMEDSClient_IParameters() {} + + /*! + Appends a string value to a named list. + Returns a number of the added value. + Note: the name of the list MUST be unique + */ + virtual int append(const std::string& listName, const std::string& value) = 0; + + /*! + Returns a number elements in the list + */ + virtual int nbValues(const std::string& listName) = 0; + + /*! + Returns a list of values in the list + */ + virtual std::vector getValues(const std::string& listName) = 0; + + /*! + Returns a value with given %index, where %index is in range [0:nbValues-1] + */ + virtual std::string getValue(const std::string& listName, int index) = 0; + + /*! + Returns a list all entries lists + */ + virtual std::vector getLists() = 0; + + /*! + Sets a new named parameter value for the given entry + */ + virtual void setParameter(const std::string& entry, const std::string& parameterName, const std::string& value) = 0; + + /*! + Gets a named parameter value for the given entry + */ + virtual std::string getParameter(const std::string& entry, const std::string& parameterName) = 0; + + /*! + Returns all parameter names of the given entry + */ + virtual std::vector getAllParameterNames(const std::string& entry) = 0; + + /*! + Returns all parameter values of the given entry + */ + virtual std::vector getAllParameterValues(const std::string& entry) = 0; + + /*! + Returns a number of parameters of the given entry + */ + virtual int getNbParameters(const std::string& entry) = 0; + + /*! + Returns a list all entries + */ + virtual std::vector getEntries() = 0; + + /*! + Sets a global named property value + */ + virtual void setProperty(const std::string& name, const std::string& value) = 0; + + /*! + Gets a value of global named property + */ + virtual std::string getProperty(const std::string& name) = 0; + + /*! + Returns a list all properties + */ + virtual std::vector getProperties() = 0; + + /*! + Breaks a value string in two parts which is divided by %separator. + If fromEnd is True the search of separator starts from the end of the string + */ + virtual std::vector parseValue(const std::string& value, const char separator, bool fromEnd = true) = 0; + + + /*! + Returns encoded entry that is a relative entry for the component + */ + virtual std::string encodeEntry(const std::string& entry, const std::string& compName) = 0; + + /*! + Returns decoded entry that is an absolute entry + */ + virtual std::string decodeEntry(const std::string& entry) = 0; + + /*! + Enables/Disables the dumping visual parameters, static implementation is supposed + */ + virtual void setDumpPython(_PTR(Study) study, const std::string& theID = "") = 0; + + /*! + Returns whether there is the dumping visual parameters, static implementation is supposed + */ + virtual bool isDumpPython(_PTR(Study) study, const std::string& theID = "") = 0; + + /*! + Returns a default name of the component where the visula parameters are stored. + Static implementation is supposed + */ + virtual std::string getDefaultVisualComponent() = 0; + +}; + + +#endif -- 2.39.2