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 <OSD_SharedLibrary.hxx>
20 #include <Plugin_Failure.hxx>
21 #include <Plugin_MapOfFunctions.hxx>
22 #include <Resource_Manager.hxx>
23 #include <Standard_GUID.hxx>
24 #include <Standard_Transient.hxx>
25 #include <TCollection_AsciiString.hxx>
27 static Standard_Character tc[1000];
28 static Standard_PCharacter thePluginId = tc;
31 //=======================================================================
34 //=======================================================================
35 Handle(Standard_Transient) Plugin::Load (const Standard_GUID& aGUID,
36 const Standard_Boolean theVerbose)
39 aGUID.ToCString(thePluginId);
40 TCollection_AsciiString pid(thePluginId);
41 static Plugin_MapOfFunctions theMapOfFunctions;
44 if(!theMapOfFunctions.IsBound(pid)) {
46 Handle(Resource_Manager) PluginResource = new Resource_Manager("Plugin");
47 TCollection_AsciiString theResource(thePluginId);
48 theResource += ".Location";
50 if(!PluginResource->Find(theResource.ToCString())) {
51 Standard_SStream aMsg; aMsg << "could not find the resource:";
52 aMsg << theResource.ToCString() << endl;
54 cout << "could not find the resource:" << theResource.ToCString() << endl;
55 throw Plugin_Failure(aMsg.str().c_str());
58 TCollection_AsciiString thePluginLibrary("");
60 thePluginLibrary += "lib";
62 thePluginLibrary += PluginResource->Value(theResource.ToCString());
64 thePluginLibrary += ".dll";
65 #elif defined(__APPLE__)
66 thePluginLibrary += ".dylib";
67 #elif defined (HPUX) || defined(_hpux)
68 thePluginLibrary += ".sl";
70 thePluginLibrary += ".so";
72 OSD_SharedLibrary theSharedLibrary(thePluginLibrary.ToCString());
73 if(!theSharedLibrary.DlOpen(OSD_RTLD_LAZY)) {
74 TCollection_AsciiString error(theSharedLibrary.DlError());
75 Standard_SStream aMsg; aMsg << "could not open:";
76 aMsg << PluginResource->Value(theResource.ToCString());
78 aMsg << error.ToCString();
80 cout << "could not open: " << PluginResource->Value(theResource.ToCString())<< " ; reason: "<< error.ToCString() << endl;
81 throw Plugin_Failure(aMsg.str().c_str());
83 f = theSharedLibrary.DlSymb("PLUGINFACTORY");
85 TCollection_AsciiString error(theSharedLibrary.DlError());
86 Standard_SStream aMsg; aMsg << "could not find the factory in:";
87 aMsg << PluginResource->Value(theResource.ToCString());
88 aMsg << error.ToCString();
89 throw Plugin_Failure(aMsg.str().c_str());
91 theMapOfFunctions.Bind(pid,f);
94 f = theMapOfFunctions(pid);
96 Standard_Transient* (*fp) (const Standard_GUID&) = NULL;
97 fp = (Standard_Transient* (*)(const Standard_GUID&)) f;
98 Handle(Standard_Transient) theServiceFactory = (*fp) (aGUID);
99 return theServiceFactory;