1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Benjamin Grauer |
---|
13 | co-programmer: ... |
---|
14 | */ |
---|
15 | |
---|
16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING |
---|
17 | |
---|
18 | #include "dynamic_loader.h" |
---|
19 | #include "resource_manager.h" |
---|
20 | |
---|
21 | using namespace std; |
---|
22 | |
---|
23 | /** |
---|
24 | * standard constructor |
---|
25 | * @todo this constructor is not jet implemented - do it |
---|
26 | */ |
---|
27 | DynamicLoader::DynamicLoader (const std::string& libName) |
---|
28 | { |
---|
29 | this->setClassID(CL_DYNAMIC_LOADER, "DynamicLoader"); |
---|
30 | |
---|
31 | this->handle = NULL; |
---|
32 | |
---|
33 | if (loadDynamicLib(libName)); |
---|
34 | this->setName(&libName[0]); |
---|
35 | } |
---|
36 | |
---|
37 | /** |
---|
38 | * @brief initializes the Dynamic Library loader |
---|
39 | * @returns true on succes, false otherwise |
---|
40 | */ |
---|
41 | bool DynamicLoader::initialize() |
---|
42 | { |
---|
43 | if (lt_dlinit () != 0) |
---|
44 | { |
---|
45 | PRINTF(1)("Initializing LT_DL_LIB: %s\n", lt_dlerror()); |
---|
46 | return false; |
---|
47 | } |
---|
48 | else |
---|
49 | return true; |
---|
50 | } |
---|
51 | |
---|
52 | /** |
---|
53 | * standard deconstructor |
---|
54 | */ |
---|
55 | DynamicLoader::~DynamicLoader () |
---|
56 | { |
---|
57 | // delete what has to be deleted here |
---|
58 | if (this->handle != NULL) |
---|
59 | lt_dlclose(this->handle); |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | bool DynamicLoader::loadDynamicLib(const std::string& libName) |
---|
64 | { |
---|
65 | DynamicLoader::initialize(); |
---|
66 | |
---|
67 | this->handle = lt_dlopenext(&libName[0]); |
---|
68 | if(this->handle == NULL) |
---|
69 | { |
---|
70 | return false; |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | bool DynamicLoader::loadDyLib(const char* libName) |
---|
75 | { |
---|
76 | DynamicLoader::initialize(); |
---|
77 | void* handle; |
---|
78 | handle = lt_dlopenext(libName); |
---|
79 | if(handle == NULL) |
---|
80 | { |
---|
81 | PRINTF(1)("unable to load %s: %s\n", libName, lt_dlerror()); |
---|
82 | |
---|
83 | return false; |
---|
84 | } |
---|
85 | |
---|
86 | } |
---|
87 | |
---|
88 | void DynamicLoader::addSearchDir(const char* searchDir) |
---|
89 | { |
---|
90 | DynamicLoader::initialize(); |
---|
91 | |
---|
92 | lt_dladdsearchdir(searchDir); |
---|
93 | } |
---|
94 | |
---|
95 | /** |
---|
96 | * @param relSearchDir: the Relative directory to add to searchPath of lt_dl |
---|
97 | * @returns true if the Path was Valid, false otherwise |
---|
98 | */ |
---|
99 | bool DynamicLoader::addSearchDirRelative(const char* relSearchDir) |
---|
100 | { |
---|
101 | char* absSearchDir = ResourceManager::getAbsDir(relSearchDir); |
---|
102 | if (ResourceManager::isDir(absSearchDir)) |
---|
103 | { |
---|
104 | DynamicLoader::addSearchDir(absSearchDir); |
---|
105 | delete[] absSearchDir; |
---|
106 | return true; |
---|
107 | } |
---|
108 | else |
---|
109 | { |
---|
110 | delete[] absSearchDir; |
---|
111 | return false; |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | bool DynamicLoader::addSearchDirInLibDir(const char* relSearchDir) |
---|
116 | { |
---|
117 | |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | const char* DynamicLoader::getSearchDir() |
---|
122 | { |
---|
123 | return lt_dlgetsearchpath(); |
---|
124 | } |
---|