]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Added a new class ClientFactory, which has a set of static methods to create a SALOME...
authorsrn <srn@opencascade.com>
Mon, 20 Feb 2006 11:24:57 +0000 (11:24 +0000)
committersrn <srn@opencascade.com>
Mon, 20 Feb 2006 11:24:57 +0000 (11:24 +0000)
src/SALOMEDSClient/Makefile.in
src/SALOMEDSClient/SALOMEDSClient_ClientFactory.cxx [new file with mode: 0644]
src/SALOMEDSClient/SALOMEDSClient_ClientFactory.hxx [new file with mode: 0644]

index c3c92b5e2c413e9938b75b2de2c0bfeb6d243768..b5d313ac4f2ae0fa212177f3a6905e9a6352e30b 100644 (file)
@@ -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 (file)
index 0000000..b675af1
--- /dev/null
@@ -0,0 +1,112 @@
+#include "SALOMEDSClient_ClientFactory.hxx"
+
+#ifdef WIN32
+#include <windows.h>
+static HMODULE _libHandle = 0;
+#define SALOMEDS_LIB_NAME "SalomeDS.dll"
+#else
+#include <dlfcn.h>
+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 (file)
index 0000000..091a26a
--- /dev/null
@@ -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 <string>
+
+// IDL headers
+#include <SALOMEconfig.h>
+#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