7fd59977 |
1 | // File: Plugin.cxx |
2 | // Created: Thu Mar 6 15:49:00 1997 |
3 | // Author: Mister rmi |
4 | // <rmi@frilox.paris1.matra-dtv.fr> |
5 | |
6 | |
7 | #include <Plugin.ixx> |
8 | #include <Plugin_MapOfFunctions.hxx> |
9 | #include <OSD_SharedLibrary.hxx> |
10 | #include <Resource_Manager.hxx> |
11 | #include <Plugin_Failure.hxx> |
12 | |
13 | #include <TCollection_AsciiString.hxx> |
14 | |
15 | static Standard_Character tc[1000]; |
16 | static Standard_PCharacter thePluginId = tc; |
17 | |
18 | |
19 | //======================================================================= |
20 | //function : Load |
21 | //purpose : |
22 | //======================================================================= |
23 | Handle(Standard_Transient) Plugin::Load(const Standard_GUID& aGUID) |
24 | { |
25 | |
26 | aGUID.ToCString(thePluginId); |
27 | TCollection_AsciiString pid(thePluginId); |
28 | static Plugin_MapOfFunctions theMapOfFunctions; |
29 | OSD_Function f; |
30 | |
31 | if(!theMapOfFunctions.IsBound(pid)) { |
32 | |
33 | Handle(Resource_Manager) PluginResource = new Resource_Manager("Plugin"); |
34 | TCollection_AsciiString theResource(thePluginId); |
35 | theResource += ".Location"; |
36 | |
37 | if(!PluginResource->Find(theResource.ToCString())) { |
38 | Standard_SStream aMsg; aMsg << "could not find the resource:"; |
39 | aMsg << theResource.ToCString()<< endl; |
40 | cout << "could not find the resource:"<<theResource.ToCString()<< endl; |
41 | Plugin_Failure::Raise(aMsg); |
42 | } |
43 | |
44 | TCollection_AsciiString thePluginLibrary(""); |
45 | #ifndef WNT |
46 | thePluginLibrary += "lib"; |
47 | #endif |
48 | thePluginLibrary += PluginResource->Value(theResource.ToCString()); |
49 | #ifdef WNT |
50 | thePluginLibrary += ".dll"; |
51 | #elif defined(__APPLE__) |
52 | thePluginLibrary += ".dylib"; |
53 | #elif defined (HPUX) || defined(_hpux) |
54 | thePluginLibrary += ".sl"; |
55 | #else |
56 | thePluginLibrary += ".so"; |
57 | #endif |
58 | OSD_SharedLibrary theSharedLibrary(thePluginLibrary.ToCString()); |
59 | if(!theSharedLibrary.DlOpen(OSD_RTLD_LAZY)) { |
60 | TCollection_AsciiString error(theSharedLibrary.DlError()); |
61 | Standard_SStream aMsg; aMsg << "could not open:"; |
62 | aMsg << PluginResource->Value(theResource.ToCString()); |
63 | aMsg << "; reason:"; |
64 | aMsg << error.ToCString(); |
65 | cout << "could not open: " << PluginResource->Value(theResource.ToCString())<< " ; reason: "<< error.ToCString() << endl; |
66 | Plugin_Failure::Raise(aMsg); |
67 | } |
68 | f = theSharedLibrary.DlSymb("PLUGINFACTORY"); |
69 | if( f == NULL ) { |
70 | TCollection_AsciiString error(theSharedLibrary.DlError()); |
71 | Standard_SStream aMsg; aMsg << "could not find the factory in:"; |
72 | aMsg << PluginResource->Value(theResource.ToCString()); |
73 | aMsg << error.ToCString(); |
74 | Plugin_Failure::Raise(aMsg); |
75 | } |
76 | theMapOfFunctions.Bind(pid,f); |
77 | } |
78 | else |
79 | f = theMapOfFunctions(pid); |
80 | |
81 | Handle(Standard_Transient) (*fp) (const Standard_GUID&) = NULL; |
82 | fp = (Handle(Standard_Transient) (*)(const Standard_GUID&)) f; |
83 | Handle(Standard_Transient) theServiceFactory = (*fp) (aGUID); |
84 | return theServiceFactory; |
85 | |
86 | } |
87 | |