Salome HOME
This commit was generated by cvs2git to create branch 'IMPORT'.
[modules/smesh.git] / src / Driver / Driver_dl.cxx
1 using namespace std;
2 #include "Driver.h"
3
4 #include <dlfcn.h>
5 #include <stdio.h>
6 #include <utilities.h>
7
8 #include "DriverDAT_R_SMESHDS_Document.h"
9 #include "Test.h"
10
11 /*!  extern "C"
12 {
13   void test() {
14
15                   void *handle;
16                   double (*cosine)(double);
17                   char *error;
18
19                   handle = dlopen ("/usr/lib/libm.so", RTLD_LAZY);
20                   if (!handle) {
21                       fputs (dlerror(), stderr);
22                       exit(1);
23                   }
24
25                   cosine = dlsym(handle, "cos");
26                   if ((error = dlerror()) != NULL)  {
27                       fprintf (stderr, "%s\n", error);
28                       exit(1);
29                   }
30
31                   printf ("%f\n", (*cosine)(2.0));
32                   dlclose(handle);
33
34   char* error;
35   string Extension=string("DAT");
36   string Class=string("SMESHDS_Document");
37   string myLibrary = string("/home/barberou/barberou/SALOME_3105/build/lib/libMeshDriver")+Extension+string(".so");
38   SCRUTE(myLibrary);
39   //Document_Reader* myDriver;//a caster ???
40   DriverDAT_R_SMESHDS_Document* myDriver;
41
42   string myClass = string("Driver")+Extension+string("_R_")+Class;
43   SCRUTE(myClass);
44   
45   void* handle = dlopen (myLibrary.c_str(), RTLD_LAZY);
46   if (!handle) {
47     fputs (dlerror(), stderr);
48     exit(1);
49   }
50   MESSAGE("Open ok");
51
52   //int* res = (int*)dlsym(handle, "getOne");
53   //SCRUTE(res);
54   SCRUTE(dlsym(handle, "getOne"));
55   //int res2= (*res)();
56   myDriver = (DriverDAT_R_SMESHDS_Document*) dlsym(handle, myClass.c_str());
57   MESSAGE("Reading 1");
58   SCRUTE(myDriver);
59   if ((error = dlerror()) != NULL)  {
60     fprintf (stderr, "%s\n", error);
61     exit(1);
62   }
63   MESSAGE("Reading 2");
64     
65   dlclose(handle);
66   MESSAGE("after close");
67                   
68   }
69   }*/
70
71 Document_Reader* Driver::GetDocumentReader(string Extension, string Class) {
72   test();
73   //p-e extern C ?
74   /*!
75   char* error;
76   string myLibrary = string("/home/barberou/barberou/SALOME_3105/build/lib/libMeshDriver")+Extension+string(".so");
77   SCRUTE(myLibrary);
78   //Document_Reader* myDriver;//a caster ???
79   DriverDAT_R_SMESHDS_Document* myDriver;
80
81   string myClass = string("Driver")+Extension+string("_R_")+Class;
82   SCRUTE(myClass);
83   
84   void* handle = dlopen (myLibrary.c_str(), RTLD_LAZY);
85   if (!handle) {
86     fputs (dlerror(), stderr);
87     exit(1);
88   }
89   MESSAGE("Open ok");
90   //myDriver = (Document_Reader*) dlsym(handle, myClass.c_str());
91   int* res = (int*) dlsym(handle, "getOne");
92   SCRUTE(res);
93   myDriver = (DriverDAT_R_SMESHDS_Document*) dlsym(handle, myClass.c_str());
94   MESSAGE("Reading 1");
95   SCRUTE(myDriver);
96   if ((error = dlerror()) != NULL)  {
97     fprintf (stderr, "%s\n", error);
98     exit(1);
99   }
100   MESSAGE("Reading 2");
101     
102   dlclose(handle);
103   MESSAGE("after close");
104   return (myDriver);
105   */
106
107 }
108
109 Document_Writer* Driver::GetDocumentWriter(string Extension, string Class) {
110
111   char* error;
112   string myLibrary = string("libMeshDriver")+Extension+string(".so");
113   Document_Writer* myDriver;//a caster ???
114   string myClass = string("Driver")+Extension+string("_W_")+Class;
115   
116   void* handle = dlopen (myLibrary.c_str(), RTLD_LAZY);
117   if (!handle) {
118     fputs (dlerror(), stderr);
119     exit(1);
120   }
121
122   myDriver = (Document_Writer*) dlsym(handle, myClass.c_str());
123   if ((error = dlerror()) != NULL)  {
124     fprintf (stderr, "%s\n", error);
125     exit(1);
126   }
127     
128   dlclose(handle);
129   
130   return (myDriver);
131
132 }
133
134 Mesh_Reader* Driver::GetMeshReader(string Extension, string Class) {
135
136   char* error;
137   string myLibrary = string("libMeshDriver")+Extension+string(".so");
138   Mesh_Reader* myDriver;//a caster ???
139   string myClass = string("Driver")+Extension+string("_R_")+Class;
140   
141   void* handle = dlopen (myLibrary.c_str(), RTLD_LAZY);
142   if (!handle) {
143     fputs (dlerror(), stderr);
144     exit(1);
145   }
146
147   myDriver = (Mesh_Reader*) dlsym(handle, myClass.c_str());
148   if ((error = dlerror()) != NULL)  {
149     fprintf (stderr, "%s\n", error);
150     exit(1);
151   }
152     
153   dlclose(handle);
154   
155   return (myDriver);
156
157 }
158
159 Mesh_Writer* Driver::GetMeshWriter(string Extension, string Class) {
160
161   char* error;
162   string myLibrary = string("libMeshDriver")+Extension+string(".so");
163   Mesh_Writer* myDriver;//a caster ???
164   string myClass = string("Driver")+Extension+string("_W_")+Class;
165   
166   void* handle = dlopen (myLibrary.c_str(), RTLD_LAZY);
167   if (!handle) {
168     fputs (dlerror(), stderr);
169     exit(1);
170   }
171
172   myDriver = (Mesh_Writer*) dlsym(handle, myClass.c_str());
173   if ((error = dlerror()) != NULL)  {
174     fprintf (stderr, "%s\n", error);
175     exit(1);
176   }
177     
178   dlclose(handle);
179   
180   return (myDriver);
181
182 }
183