From ffc3ef3ff6175f5bd93b51f1cb0cf5ca9a523f6c Mon Sep 17 00:00:00 2001 From: srn Date: Mon, 20 Feb 2006 11:24:57 +0000 Subject: [PATCH] Added a new class ClientFactory, which has a set of static methods to create a SALOMEDSClient wrappers for the SALOMEDS CORBA objects. The libSalomeDS.so is dynamically loaded on requist for creation of the corresponing wrapper. --- src/SALOMEDSClient/Makefile.in | 26 ++++ .../SALOMEDSClient_ClientFactory.cxx | 112 ++++++++++++++++++ .../SALOMEDSClient_ClientFactory.hxx | 71 +++++++++++ 3 files changed, 209 insertions(+) create mode 100644 src/SALOMEDSClient/SALOMEDSClient_ClientFactory.cxx create mode 100644 src/SALOMEDSClient/SALOMEDSClient_ClientFactory.hxx diff --git a/src/SALOMEDSClient/Makefile.in b/src/SALOMEDSClient/Makefile.in index c3c92b5e2..b5d313ac4 100644 --- a/src/SALOMEDSClient/Makefile.in +++ b/src/SALOMEDSClient/Makefile.in @@ -49,7 +49,33 @@ EXPORT_HEADERS= SALOMEDSClient_definitions.hxx \ SALOMEDSClient_StudyManager.hxx \ SALOMEDSClient_UseCaseBuilder.hxx \ SALOMEDSClient_UseCaseIterator.hxx \ + SALOMEDSClient_ClientFactory.hxx \ SALOMEDSClient.hxx +# Libraries targets + +LIB = libSalomeDSClient.la +LIB_SRC = SALOMEDSClient_ClientFactory.cxx + +LIB_SERVER_IDL = SALOMEDS.idl + +CPPFLAGS+=$(BOOST_CPPFLAGS) +CXXFLAGS+=$(BOOST_CPPFLAGS) +#LDFLAGS+= -lSalomeNS + +# _CS_gbo_090604 Ajout Spécifique Calibre 3, pour l'utilisation de la version 5.12 de la bibliothèque OCC. +# La bibliothèque OCC5.12 a été compilée sur Calibre 3 avec l'extention Xmu (impossible de compiler sans). +# On est donc obligé ici, pour permettre l'édition de lien avec les bibliothèques OCC, de spécifier le +# chemin d'accès aux bibliothèques Xmu +# + +# _CS_gbo_090604 Ajout Sp.cifique Calibre 3, pour l'utilisation de la version 5.12 de la biblioth.que OCC. +# La biblioth.que OCC5.12 a .t. compil.e sur Calibre 3 avec l'extention Xmu (impossible de compiler sans). +# On est donc oblig. ici, pour permettre l'.dition de lien avec les biblioth.ques OCC, de sp.cifier le +# chemin d'acc.s aux biblioth.ques Xmu +# +LDXMUFLAGS= -L/usr/X11R6/lib -lXmu +LDFLAGS+=$(LDXMUFLAGS) + @CONCLUDE@ diff --git a/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.cxx b/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.cxx new file mode 100644 index 000000000..b675af16b --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.cxx @@ -0,0 +1,112 @@ +#include "SALOMEDSClient_ClientFactory.hxx" + +#ifdef WIN32 +#include +static HMODULE _libHandle = 0; +#define SALOMEDS_LIB_NAME "SalomeDS.dll" +#else +#include +static void* _libHandle = NULL; +#define SALOMEDS_LIB_NAME "libSalomeDS.so" +#endif + +#define SOBJECT_FACTORY "SObjectFactory" +#define SCOMPONENT_FACTORY "SComponentFactory" +#define STUDY_FACTORY "StudyFactory" +#define STUDYMANAGER_FACTORY "StudyManagerFactory" +#define STUDYMANAGER_CREATE "CreateStudyManager" + +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_StudyManager* (*STUDYMANAGER_CREATE_FUNCTION) (CORBA::ORB_ptr, PortableServer::POA_ptr); + +static SOBJECT_FACTORY_FUNCTION aSObjectFactory = NULL; +static SCOMPONENT_FACTORY_FUNCTION aSComponentFactory = NULL; +static STUDY_FACTORY_FUNCTION aStudyFactory = NULL; +static STUDYMANAGER_FACTORY_FUNCTION aManagerFactory = NULL; +static STUDYMANAGER_CREATE_FUNCTION aCreateFactory = NULL; + +using namespace std; + +_PTR(SObject) ClientFactory::SObject(SALOMEDS::SObject_ptr theSObject) +{ + SALOMEDSClient_SObject* so = NULL; + +#ifdef WIN32 + if(!_libHandle) _libHandle = ::LoadLibrary(SALOMEDS_LIB_NAME); + if(!aSObjectFactory) aSObjectFactory = (SOBJECT_FACTORY_FUNCTION)::GetProcAddress(_libHandle, SOBJECT_FACTORY); +#else + if(!_libHandle) _libHandle = dlopen(SALOMEDS_LIB_NAME, RTLD_LAZY); + if(!aSObjectFactory) aSObjectFactory = (SOBJECT_FACTORY_FUNCTION) dlsym(_libHandle, SOBJECT_FACTORY); +#endif + + if(aSObjectFactory) so = aSObjectFactory(theSObject); + return _PTR(SObject)(so); +} + +_PTR(SComponent) ClientFactory::SComponent(SALOMEDS::SComponent_ptr theSComponent) +{ + SALOMEDSClient_SComponent* sco = NULL; + +#ifdef WIN32 + if(!_libHandle) _libHandle = ::LoadLibrary(SALOMEDS_LIB_NAME); + if(!aSComponentFactory) aSComponentFactory = (SCOMPONENT_FACTORY_FUNCTION)::GetProcAddress(_libHandle, SCOMPONENT_FACTORY); +#else + if(!_libHandle) _libHandle = dlopen(SALOMEDS_LIB_NAME, RTLD_LAZY); + if(!aSComponentFactory) aSComponentFactory = (SCOMPONENT_FACTORY_FUNCTION) dlsym(_libHandle, SCOMPONENT_FACTORY); +#endif + + if(aSComponentFactory) sco = aSComponentFactory(theSComponent); + return _PTR(SComponent)(sco); +} + +_PTR(Study) ClientFactory::Study(SALOMEDS::Study_ptr theStudy) +{ + SALOMEDSClient_Study* study = NULL; + +#ifdef WIN32 + if(!_libHandle) _libHandle = ::LoadLibrary(SALOMEDS_LIB_NAME); + if(!aStudyFactory) aStudyFactory = (STUDY_FACTORY_FUNCTION)::GetProcAddress(_libHandle, STUDY_FACTORY); +#else + if(!_libHandle) _libHandle = dlopen(SALOMEDS_LIB_NAME, RTLD_LAZY); + if(!aStudyFactory) aStudyFactory = (STUDY_FACTORY_FUNCTION) dlsym(_libHandle, STUDY_FACTORY); +#endif + + if(aStudyFactory) study = aStudyFactory(theStudy); + return _PTR(Study)(study); +} + +_PTR(StudyManager) ClientFactory::StudyManager() +{ + SALOMEDSClient_StudyManager* manager = NULL; + +#ifdef WIN32 + if(!_libHandle) _libHandle = ::LoadLibrary(SALOMEDS_LIB_NAME); + if(!aManagerFactory) aManagerFactory = (STUDYMANAGER_FACTORY_FUNCTION)::GetProcAddress(_libHandle, STUDYMANAGER_FACTORY); +#else + if(!_libHandle) _libHandle = dlopen(SALOMEDS_LIB_NAME, RTLD_LAZY); + if(!aManagerFactory) aManagerFactory = (STUDYMANAGER_FACTORY_FUNCTION) dlsym(_libHandle, STUDYMANAGER_FACTORY); +#endif + + if(aManagerFactory) manager = aManagerFactory(); + return _PTR(StudyManager)(manager); +} + +_PTR(StudyManager) ClientFactory::createStudyManager(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa) +{ + SALOMEDSClient_StudyManager* manager = NULL; + +#ifdef WIN32 + if(!_libHandle) _libHandle = ::LoadLibrary(SALOMEDS_LIB_NAME); + if(!aCreateFactory) aCreateFactory = (STUDYMANAGER_CREATE_FUNCTION)::GetProcAddress(_libHandle, STUDYMANAGER_CREATE); +#else + if(!_libHandle) _libHandle = dlopen(SALOMEDS_LIB_NAME, RTLD_LAZY); + if(!aCreateFactory) aCreateFactory = (STUDYMANAGER_CREATE_FUNCTION) dlsym(_libHandle, STUDYMANAGER_CREATE); +#endif + + if(aCreateFactory) manager = aCreateFactory(orb, poa); + return _PTR(StudyManager)(manager); +} + diff --git a/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.hxx b/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.hxx new file mode 100644 index 000000000..091a26a75 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_ClientFactory.hxx @@ -0,0 +1,71 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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/ +// +// File : SALOMEDSClient_ClientFactory.hxx +// Author : Sergey RUIN +// Module : SALOME +// $Header: + +#ifndef SALOMEDSClient_ClientFactory_HeaderFile +#define SALOMEDSClient_ClientFactory_HeaderFile + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_SObject.hxx" +#include "SALOMEDSClient_SComponent.hxx" +#include "SALOMEDSClient_Study.hxx" +#include "SALOMEDSClient_StudyManager.hxx" + +#include + +// IDL headers +#include +#include CORBA_SERVER_HEADER(SALOMEDS) + +class ClientFactory { + +public: + /*! + * Returns a client SObject wrapper that corresponds %theSObject + */ + static _PTR(SObject) SObject(SALOMEDS::SObject_ptr theSObject); + + /*! + * Returns a client SComponent wrapper that corresponds %theSComponent + */ + static _PTR(SComponent) SComponent(SALOMEDS::SComponent_ptr theSComponent); + + /*! + * Returns a client Study wrapper that corresponds %theStudy + */ + static _PTR(Study) Study(SALOMEDS::Study_ptr theStudy); + + /*! + * Returns a client StudyManager wrapper + */ + static _PTR(StudyManager) StudyManager(); + + /*! + * Creates and returns a client StudyManager wrapper + */ + static _PTR(StudyManager) createStudyManager(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa); + + +}; + +#endif -- 2.39.2