1 // Created on: 1997-03-06
2 // Created by: Mister rmi
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Plugin_MapOfFunctions.hxx>
19 #include <OSD_SharedLibrary.hxx>
20 #include <Resource_Manager.hxx>
21 #include <Plugin_Failure.hxx>
23 #include <TCollection_AsciiString.hxx>
25 static Standard_Character tc[1000];
26 static Standard_PCharacter thePluginId = tc;
29 //=======================================================================
32 //=======================================================================
33 Handle(Standard_Transient) Plugin::Load(const Standard_GUID& aGUID)
36 aGUID.ToCString(thePluginId);
37 TCollection_AsciiString pid(thePluginId);
38 static Plugin_MapOfFunctions theMapOfFunctions;
41 if(!theMapOfFunctions.IsBound(pid)) {
43 Handle(Resource_Manager) PluginResource = new Resource_Manager("Plugin");
44 TCollection_AsciiString theResource(thePluginId);
45 theResource += ".Location";
47 if(!PluginResource->Find(theResource.ToCString())) {
48 Standard_SStream aMsg; aMsg << "could not find the resource:";
49 aMsg << theResource.ToCString()<< endl;
50 cout << "could not find the resource:"<<theResource.ToCString()<< endl;
51 Plugin_Failure::Raise(aMsg);
54 TCollection_AsciiString thePluginLibrary("");
56 thePluginLibrary += "lib";
58 thePluginLibrary += PluginResource->Value(theResource.ToCString());
60 thePluginLibrary += ".dll";
61 #elif defined(__APPLE__)
62 thePluginLibrary += ".dylib";
63 #elif defined (HPUX) || defined(_hpux)
64 thePluginLibrary += ".sl";
66 thePluginLibrary += ".so";
68 OSD_SharedLibrary theSharedLibrary(thePluginLibrary.ToCString());
69 if(!theSharedLibrary.DlOpen(OSD_RTLD_LAZY)) {
70 TCollection_AsciiString error(theSharedLibrary.DlError());
71 Standard_SStream aMsg; aMsg << "could not open:";
72 aMsg << PluginResource->Value(theResource.ToCString());
74 aMsg << error.ToCString();
75 cout << "could not open: " << PluginResource->Value(theResource.ToCString())<< " ; reason: "<< error.ToCString() << endl;
76 Plugin_Failure::Raise(aMsg);
78 f = theSharedLibrary.DlSymb("PLUGINFACTORY");
80 TCollection_AsciiString error(theSharedLibrary.DlError());
81 Standard_SStream aMsg; aMsg << "could not find the factory in:";
82 aMsg << PluginResource->Value(theResource.ToCString());
83 aMsg << error.ToCString();
84 Plugin_Failure::Raise(aMsg);
86 theMapOfFunctions.Bind(pid,f);
89 f = theMapOfFunctions(pid);
91 Handle(Standard_Transient) (*fp) (const Standard_GUID&) = NULL;
92 fp = (Handle(Standard_Transient) (*)(const Standard_GUID&)) f;
93 Handle(Standard_Transient) theServiceFactory = (*fp) (aGUID);
94 return theServiceFactory;