0024624: Lost word in license statement in source files
[occt.git] / src / Plugin / Plugin.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <Plugin.ixx>
18 #include <Plugin_MapOfFunctions.hxx>
19 #include <OSD_SharedLibrary.hxx>
20 #include <Resource_Manager.hxx>
21 #include <Plugin_Failure.hxx>
22
23 #include <TCollection_AsciiString.hxx>
24
25 static Standard_Character tc[1000];
26 static Standard_PCharacter thePluginId = tc;
27
28
29 //=======================================================================
30 //function : Load
31 //purpose  : 
32 //=======================================================================
33 Handle(Standard_Transient) Plugin::Load(const Standard_GUID& aGUID) 
34 {
35   
36   aGUID.ToCString(thePluginId);
37   TCollection_AsciiString pid(thePluginId);
38   static Plugin_MapOfFunctions theMapOfFunctions;
39   OSD_Function f;
40
41   if(!theMapOfFunctions.IsBound(pid)) {
42    
43     Handle(Resource_Manager) PluginResource = new Resource_Manager("Plugin");
44     TCollection_AsciiString theResource(thePluginId);
45     theResource += ".Location";
46
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);
52     }
53     
54     TCollection_AsciiString thePluginLibrary("");
55 #ifndef WNT
56     thePluginLibrary += "lib";
57 #endif
58     thePluginLibrary +=  PluginResource->Value(theResource.ToCString());
59 #ifdef WNT
60     thePluginLibrary += ".dll";
61 #elif defined(__APPLE__)
62     thePluginLibrary += ".dylib";
63 #elif defined (HPUX) || defined(_hpux)
64     thePluginLibrary += ".sl";
65 #else
66     thePluginLibrary += ".so";
67 #endif  
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());
73       aMsg << "; reason:";
74       aMsg << error.ToCString();
75       cout << "could not open: "  << PluginResource->Value(theResource.ToCString())<< " ; reason: "<< error.ToCString() << endl;
76       Plugin_Failure::Raise(aMsg);
77     }
78     f = theSharedLibrary.DlSymb("PLUGINFACTORY");
79     if( f == NULL ) {
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);
85     }
86     theMapOfFunctions.Bind(pid,f);
87   }
88   else
89     f = theMapOfFunctions(pid);
90   
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;
95   
96 }
97