From 247e2864c9545579fab5ad9028041409955dfab1 Mon Sep 17 00:00:00 2001 From: asv Date: Mon, 6 Mar 2006 12:38:15 +0000 Subject: [PATCH] merged with KERNEL from current dev version. --- src/SALOMEDS/SALOMEDS.cxx | 62 +++++++++- src/SALOMEDSClient/Makefile.in | 28 +++++ .../SALOMEDSClient_ClientFactory.cxx | 112 ++++++++++++++++++ .../SALOMEDSClient_ClientFactory.hxx | 71 +++++++++++ 4 files changed, 272 insertions(+), 1 deletion(-) create mode 100644 src/SALOMEDSClient/SALOMEDSClient_ClientFactory.cxx create mode 100644 src/SALOMEDSClient/SALOMEDSClient_ClientFactory.hxx diff --git a/src/SALOMEDS/SALOMEDS.cxx b/src/SALOMEDS/SALOMEDS.cxx index ae488ad0a..4a35577e1 100644 --- a/src/SALOMEDS/SALOMEDS.cxx +++ b/src/SALOMEDS/SALOMEDS.cxx @@ -26,13 +26,28 @@ // Module : SALOME // $Header$ - #ifndef WNT #include +#include +#include +#include +#include +#include +#include #else #include "SALOMEDS.hxx" +#include "SALOMEDS_StudyManager.hxx" +#include "SALOMEDS_Study.hxx" +#include "SALOMEDS_SObject.hxx" +#include "SALOMEDS_SComponent.hxx" +#include "SALOMEDSClient.hxx" +#include "SALOMEDS_StudyManager_i.hxx" #endif +// IDL headers +#include +#include CORBA_SERVER_HEADER(SALOMEDS) + using namespace SALOMEDS; // PAL8065: san -- Global recursive mutex for SALOMEDS methods @@ -55,3 +70,48 @@ void SALOMEDS::unlock() { Locker::MutexDS.unlock(); } + + + +// srn: Added new library methods that create basic SALOMEDS objects (StudyManager, Study, SComponent, SObject) + +//============================================================================= +/*! + * C factory, accessible with dlsym, after dlopen + */ +//============================================================================= + + +extern "C" +{ + +SALOMEDSClient_StudyManager* StudyManagerFactory() +{ + return new SALOMEDS_StudyManager(); +} + +SALOMEDSClient_Study* StudyFactory(SALOMEDS::Study_ptr theStudy) +{ + return new SALOMEDS_Study(theStudy); +} + +SALOMEDSClient_SObject* SObjectFactory(SALOMEDS::SObject_ptr theSObject) +{ + return new SALOMEDS_SObject(theSObject); +} + +SALOMEDSClient_SComponent* SComponentFactory(SALOMEDS::SComponent_ptr theSComponent) +{ + return new SALOMEDS_SComponent(theSComponent); +} + +SALOMEDSClient_StudyManager* CreateStudyManager(CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa) +{ + SALOMEDS_StudyManager_i * aStudyManager_i = new SALOMEDS_StudyManager_i(orb, root_poa); + // Activate the objects. This tells the POA that the objects are ready to accept requests. + PortableServer::ObjectId_var aStudyManager_iid = root_poa->activate_object(aStudyManager_i); + aStudyManager_i->register_name("/myStudyManager"); + return new SALOMEDS_StudyManager(); +} + +} diff --git a/src/SALOMEDSClient/Makefile.in b/src/SALOMEDSClient/Makefile.in index b29a1d0e3..c7cbfedae 100644 --- a/src/SALOMEDSClient/Makefile.in +++ b/src/SALOMEDSClient/Makefile.in @@ -50,7 +50,35 @@ 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_CLIENT_IDL = SALOMEDS.idl \ + SALOME_Exception.idl \ + SALOME_GenericObj.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..4b5e23b59 --- /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 | RTLD_GLOBAL); + 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 | RTLD_GLOBAL); + 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 | RTLD_GLOBAL); + 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 | RTLD_GLOBAL); + 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 | RTLD_GLOBAL); + 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..85929293d --- /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_CLIENT_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