0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / Plugin / Plugin.cxx
CommitLineData
b311480e 1// Created on: 1997-03-06
2// Created by: Mister rmi
3// Copyright (c) 1997-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23#include <Plugin.ixx>
24#include <Plugin_MapOfFunctions.hxx>
25#include <OSD_SharedLibrary.hxx>
26#include <Resource_Manager.hxx>
27#include <Plugin_Failure.hxx>
28
29#include <TCollection_AsciiString.hxx>
30
31static Standard_Character tc[1000];
32static Standard_PCharacter thePluginId = tc;
33
34
35//=======================================================================
36//function : Load
37//purpose :
38//=======================================================================
39Handle(Standard_Transient) Plugin::Load(const Standard_GUID& aGUID)
40{
41
42 aGUID.ToCString(thePluginId);
43 TCollection_AsciiString pid(thePluginId);
44 static Plugin_MapOfFunctions theMapOfFunctions;
45 OSD_Function f;
46
47 if(!theMapOfFunctions.IsBound(pid)) {
48
49 Handle(Resource_Manager) PluginResource = new Resource_Manager("Plugin");
50 TCollection_AsciiString theResource(thePluginId);
51 theResource += ".Location";
52
53 if(!PluginResource->Find(theResource.ToCString())) {
54 Standard_SStream aMsg; aMsg << "could not find the resource:";
55 aMsg << theResource.ToCString()<< endl;
56 cout << "could not find the resource:"<<theResource.ToCString()<< endl;
57 Plugin_Failure::Raise(aMsg);
58 }
59
60 TCollection_AsciiString thePluginLibrary("");
61#ifndef WNT
62 thePluginLibrary += "lib";
63#endif
64 thePluginLibrary += PluginResource->Value(theResource.ToCString());
65#ifdef WNT
66 thePluginLibrary += ".dll";
67#elif defined(__APPLE__)
68 thePluginLibrary += ".dylib";
69#elif defined (HPUX) || defined(_hpux)
70 thePluginLibrary += ".sl";
71#else
72 thePluginLibrary += ".so";
73#endif
74 OSD_SharedLibrary theSharedLibrary(thePluginLibrary.ToCString());
75 if(!theSharedLibrary.DlOpen(OSD_RTLD_LAZY)) {
76 TCollection_AsciiString error(theSharedLibrary.DlError());
77 Standard_SStream aMsg; aMsg << "could not open:";
78 aMsg << PluginResource->Value(theResource.ToCString());
79 aMsg << "; reason:";
80 aMsg << error.ToCString();
81 cout << "could not open: " << PluginResource->Value(theResource.ToCString())<< " ; reason: "<< error.ToCString() << endl;
82 Plugin_Failure::Raise(aMsg);
83 }
84 f = theSharedLibrary.DlSymb("PLUGINFACTORY");
85 if( f == NULL ) {
86 TCollection_AsciiString error(theSharedLibrary.DlError());
87 Standard_SStream aMsg; aMsg << "could not find the factory in:";
88 aMsg << PluginResource->Value(theResource.ToCString());
89 aMsg << error.ToCString();
90 Plugin_Failure::Raise(aMsg);
91 }
92 theMapOfFunctions.Bind(pid,f);
93 }
94 else
95 f = theMapOfFunctions(pid);
96
97 Handle(Standard_Transient) (*fp) (const Standard_GUID&) = NULL;
98 fp = (Handle(Standard_Transient) (*)(const Standard_GUID&)) f;
99 Handle(Standard_Transient) theServiceFactory = (*fp) (aGUID);
100 return theServiceFactory;
101
102}
103