1 #include "SALOMEDSClient_ClientFactory.hxx"
5 static HMODULE _libHandle = 0;
6 #define SALOMEDS_LIB_NAME "SalomeDS.dll"
9 static void* _libHandle = NULL;
10 #define SALOMEDS_LIB_NAME "libSalomeDS.so"
13 #define SOBJECT_FACTORY "SObjectFactory"
14 #define SCOMPONENT_FACTORY "SComponentFactory"
15 #define STUDY_FACTORY "StudyFactory"
16 #define STUDYMANAGER_FACTORY "StudyManagerFactory"
17 #define STUDYMANAGER_CREATE "CreateStudyManager"
19 typedef SALOMEDSClient_SObject* (*SOBJECT_FACTORY_FUNCTION) (SALOMEDS::SObject_ptr);
20 typedef SALOMEDSClient_SComponent* (*SCOMPONENT_FACTORY_FUNCTION) (SALOMEDS::SComponent_ptr);
21 typedef SALOMEDSClient_Study* (*STUDY_FACTORY_FUNCTION) (SALOMEDS::Study_ptr);
22 typedef SALOMEDSClient_StudyManager* (*STUDYMANAGER_FACTORY_FUNCTION) ();
23 typedef SALOMEDSClient_StudyManager* (*STUDYMANAGER_CREATE_FUNCTION) (CORBA::ORB_ptr, PortableServer::POA_ptr);
25 static SOBJECT_FACTORY_FUNCTION aSObjectFactory = NULL;
26 static SCOMPONENT_FACTORY_FUNCTION aSComponentFactory = NULL;
27 static STUDY_FACTORY_FUNCTION aStudyFactory = NULL;
28 static STUDYMANAGER_FACTORY_FUNCTION aManagerFactory = NULL;
29 static STUDYMANAGER_CREATE_FUNCTION aCreateFactory = NULL;
33 _PTR(SObject) ClientFactory::SObject(SALOMEDS::SObject_ptr theSObject)
35 SALOMEDSClient_SObject* so = NULL;
38 if(!_libHandle) _libHandle = ::LoadLibrary(SALOMEDS_LIB_NAME);
39 if(!aSObjectFactory) aSObjectFactory = (SOBJECT_FACTORY_FUNCTION)::GetProcAddress(_libHandle, SOBJECT_FACTORY);
41 if(!_libHandle) _libHandle = dlopen(SALOMEDS_LIB_NAME, RTLD_LAZY | RTLD_GLOBAL);
42 if(!aSObjectFactory) aSObjectFactory = (SOBJECT_FACTORY_FUNCTION) dlsym(_libHandle, SOBJECT_FACTORY);
45 if(aSObjectFactory) so = aSObjectFactory(theSObject);
46 return _PTR(SObject)(so);
49 _PTR(SComponent) ClientFactory::SComponent(SALOMEDS::SComponent_ptr theSComponent)
51 SALOMEDSClient_SComponent* sco = NULL;
54 if(!_libHandle) _libHandle = ::LoadLibrary(SALOMEDS_LIB_NAME);
55 if(!aSComponentFactory) aSComponentFactory = (SCOMPONENT_FACTORY_FUNCTION)::GetProcAddress(_libHandle, SCOMPONENT_FACTORY);
57 if(!_libHandle) _libHandle = dlopen(SALOMEDS_LIB_NAME, RTLD_LAZY | RTLD_GLOBAL);
58 if(!aSComponentFactory) aSComponentFactory = (SCOMPONENT_FACTORY_FUNCTION) dlsym(_libHandle, SCOMPONENT_FACTORY);
61 if(aSComponentFactory) sco = aSComponentFactory(theSComponent);
62 return _PTR(SComponent)(sco);
65 _PTR(Study) ClientFactory::Study(SALOMEDS::Study_ptr theStudy)
67 SALOMEDSClient_Study* study = NULL;
70 if(!_libHandle) _libHandle = ::LoadLibrary(SALOMEDS_LIB_NAME);
71 if(!aStudyFactory) aStudyFactory = (STUDY_FACTORY_FUNCTION)::GetProcAddress(_libHandle, STUDY_FACTORY);
73 if(!_libHandle) _libHandle = dlopen(SALOMEDS_LIB_NAME, RTLD_LAZY | RTLD_GLOBAL);
74 if(!aStudyFactory) aStudyFactory = (STUDY_FACTORY_FUNCTION) dlsym(_libHandle, STUDY_FACTORY);
77 if(aStudyFactory) study = aStudyFactory(theStudy);
78 return _PTR(Study)(study);
81 _PTR(StudyManager) ClientFactory::StudyManager()
83 SALOMEDSClient_StudyManager* manager = NULL;
86 if(!_libHandle) _libHandle = ::LoadLibrary(SALOMEDS_LIB_NAME);
87 if(!aManagerFactory) aManagerFactory = (STUDYMANAGER_FACTORY_FUNCTION)::GetProcAddress(_libHandle, STUDYMANAGER_FACTORY);
89 if(!_libHandle) _libHandle = dlopen(SALOMEDS_LIB_NAME, RTLD_LAZY | RTLD_GLOBAL);
90 if(!aManagerFactory) aManagerFactory = (STUDYMANAGER_FACTORY_FUNCTION) dlsym(_libHandle, STUDYMANAGER_FACTORY);
93 if(aManagerFactory) manager = aManagerFactory();
94 return _PTR(StudyManager)(manager);
97 _PTR(StudyManager) ClientFactory::createStudyManager(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
99 SALOMEDSClient_StudyManager* manager = NULL;
102 if(!_libHandle) _libHandle = ::LoadLibrary(SALOMEDS_LIB_NAME);
103 if(!aCreateFactory) aCreateFactory = (STUDYMANAGER_CREATE_FUNCTION)::GetProcAddress(_libHandle, STUDYMANAGER_CREATE);
105 if(!_libHandle) _libHandle = dlopen(SALOMEDS_LIB_NAME, RTLD_LAZY | RTLD_GLOBAL);
106 if(!aCreateFactory) aCreateFactory = (STUDYMANAGER_CREATE_FUNCTION) dlsym(_libHandle, STUDYMANAGER_CREATE);
109 if(aCreateFactory) manager = aCreateFactory(orb, poa);
110 return _PTR(StudyManager)(manager);