Changeset 7264 in orxonox.OLD for branches/shared_lib/src/lib/util/loading
- Timestamp:
- Apr 2, 2006, 4:51:19 PM (19 years ago)
- Location:
- branches/shared_lib/src/lib/util/loading
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/shared_lib/src/lib/util/loading/dynamic_loader.cc
r7167 r7264 17 17 18 18 #include "dynamic_loader.h" 19 20 21 #include <dlfcn.h> 22 19 #include "resource_manager.h" 23 20 24 21 using namespace std; 25 26 22 27 23 /** … … 30 26 */ 31 27 DynamicLoader::DynamicLoader (const std::string& libName) 32 : Factory(NULL, CL_NULL)33 28 { 34 29 this->setClassID(CL_DYNAMIC_LOADER, "DynamicLoader"); … … 40 35 } 41 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 } 42 51 43 52 /** … … 48 57 // delete what has to be deleted here 49 58 if (this->handle != NULL) 50 dlclose(this->handle);59 lt_dlclose(this->handle); 51 60 } 52 61 … … 54 63 bool DynamicLoader::loadDynamicLib(const std::string& libName) 55 64 { 56 this->handle = dlopen(&libName[0], RTLD_NOW); 65 DynamicLoader::initialize(); 66 67 this->handle = lt_dlopen(&libName[0]); 57 68 if(this->handle == NULL) 58 69 { 59 70 return false; 60 71 } 61 void *mkr = dlsym( this->handle, "maker");62 72 } 63 73 64 74 bool DynamicLoader::loadDyLib(const std::string& libName) 65 75 { 76 DynamicLoader::initialize(); 77 66 78 void* handle; 67 handle = dlopen(&libName[0], RTLD_NOW);79 handle = lt_dlopen(libName.c_str()); 68 80 if(handle == NULL) 69 81 { 70 PRINTF(0)("unable to load %s\n", &libName[0]); 82 PRINTF(1)("unable to load %s: %s\n", libName.c_str(), lt_dlerror()); 83 71 84 return false; 72 85 } 73 // void *mkr = dlsym("maker"); 86 87 } 88 89 void DynamicLoader::addSearchDir(const std::string& searchDir) 90 { 91 DynamicLoader::initialize(); 92 93 lt_dladdsearchdir(searchDir.c_str()); 94 } 95 96 /** 97 * @param relSearchDir: the Relative directory to add to searchPath of lt_dl 98 * @returns true if the Path was Valid, false otherwise 99 */ 100 bool DynamicLoader::addSearchDirRelative(const std::string& relSearchDir) 101 { 102 std::string absSearchDir = ResourceManager::getAbsDir(relSearchDir); 103 if (ResourceManager::isDir(absSearchDir)) 104 { 105 DynamicLoader::addSearchDir(absSearchDir); 106 return true; 107 } 108 else 109 { 110 return false; 111 } 112 } 113 114 bool DynamicLoader::addSearchDirInLibDir(const std::string& relSearchDir) 115 { 74 116 75 117 } 76 118 77 119 78 BaseObject* DynamicLoader::fabricateObject(const TiXmlElement* root) const 120 const char* DynamicLoader::getSearchDir() 79 121 { 122 return lt_dlgetsearchpath(); 80 123 } -
branches/shared_lib/src/lib/util/loading/dynamic_loader.h
r7193 r7264 8 8 9 9 #include "util/loading/factory.h" 10 #include <ltdl.h> 10 11 11 12 #include <string> 12 13 #define DYNAMIC_LINKAGE_FACTORY(CLASS_NAME, CLASS_ID) \14 void* DynamicCreator(const TiXmlElement* root) { return new CLASS_NAME(root); };15 13 16 14 // FORWARD DECLARATION 17 15 18 16 //! A class for ... 19 class DynamicLoader : public Factory17 class DynamicLoader : public BaseObject 20 18 { 21 19 … … 25 23 26 24 bool loadDynamicLib(const std::string& libName); 27 virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const;28 25 29 26 static bool loadDyLib(const std::string& libName); 30 27 28 static void addSearchDir(const std::string& searchDir); 29 static bool addSearchDirRelative(const std::string& relSearchDir); 30 static bool addSearchDirInLibDir(const std::string& relSearchDir); 31 static const char* getSearchDir(); 32 33 static void unload(); 34 private: 35 // will be done automatically when using the this Engine. 36 static bool initialize(); 31 37 32 38 private: 33 void*handle;39 lt_dlhandle handle; 34 40 }; 35 41 -
branches/shared_lib/src/lib/util/loading/resource_manager.cc
r7225 r7264 881 881 882 882 883 884 883 885 /** 884 886 * @param fileName the Name of the File to check … … 921 923 return ResourceManager::getInstance()->_cwd; 922 924 } 923 924 925 925 926 /**
Note: See TracChangeset
for help on using the changeset viewer.