Changeset 7174 in orxonox.OLD for branches/shared_lib/src/util/loading
- Timestamp:
- Feb 21, 2006, 10:48:52 PM (19 years ago)
- Location:
- branches/shared_lib/src/util/loading
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/shared_lib/src/util/loading/dynamic_loader.cc
r7171 r7174 17 17 18 18 #include "dynamic_loader.h" 19 19 #include "resource_manager.h" 20 20 21 21 using namespace std; 22 23 22 24 23 /** … … 36 35 } 37 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 } 38 51 39 52 /** … … 50 63 bool DynamicLoader::loadDynamicLib(const std::string& libName) 51 64 { 52 if (lt_dlinit () != 0) 53 { 54 PRINTF(1)("Initializing LT_DL_LIB\n"); 55 } 56 this->handle = lt_dlopen(&libName[0]); 65 DynamicLoader::initialize(); 66 67 this->handle = lt_dlopenext(&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 char* libName) 65 75 { 66 if (lt_dlinit () != 0) 67 { 68 PRINTF(1)("Initializing LT_DL_LIB\n"); 69 } 70 76 DynamicLoader::initialize(); 71 77 void* handle; 72 handle = lt_dlopen (libName);78 handle = lt_dlopenext(libName); 73 79 if(handle == NULL) 74 80 { … … 77 83 return false; 78 84 } 79 // void *mkr = dlsym("maker");80 85 81 86 } 82 87 88 void DynamicLoader::addSearchDir(const char* searchDir) 89 { 90 DynamicLoader::initialize(); 83 91 84 BaseObject* DynamicLoader::fabricateObject(const TiXmlElement* root) const 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) 85 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 } 86 113 } 114 115 116 const char* DynamicLoader::getSearchDir() 117 { 118 return lt_dlgetsearchpath(); 119 } -
branches/shared_lib/src/util/loading/dynamic_loader.h
r7171 r7174 23 23 24 24 bool loadDynamicLib(const std::string& libName); 25 virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const;26 25 27 26 static bool loadDyLib(const char* libName); 28 27 28 static void addSearchDir(const char* searchDir); 29 static bool addSearchDirRelative(const char* relSearchDir); 30 static const char* getSearchDir(); 31 32 static void unload(); 33 private: 34 // will be done automatically when using the this Engine. 35 static bool initialize(); 29 36 30 37 private: -
branches/shared_lib/src/util/loading/resource_manager.cc
r7059 r7174 62 62 strcpy(this->dataDir, "./"); 63 63 this->tryDataDir("./data"); 64 65 this->_cwd = NULL; 64 66 } 65 67 … … 86 88 87 89 delete[] this->dataDir; 88 90 if (this->_cwd) 91 delete[] this->_cwd; 89 92 ResourceManager::singletonRef = NULL; 90 93 } … … 984 987 985 988 /** 989 * @param name the relative name of the File/Directory. 990 * @returns a new char* with the name in abs-dir-format 991 */ 992 char* ResourceManager::getAbsDir(const char* name) 993 { 994 if (name == NULL) 995 return NULL; 996 char* retName; 997 if (strncmp(name, "/", 1)) 998 { 999 if (*name == '.' && *(name+1) != '.') 1000 name++; 1001 const char* absDir = ResourceManager::cwd(); 1002 retName = new char[strlen(absDir)+strlen(name)+1]; 1003 sprintf(retName, "%s%s", absDir, name); 1004 } 1005 else 1006 { 1007 retName = new char[strlen(name)+1]; 1008 strcpy(retName, name); 1009 } 1010 return retName; 1011 } 1012 1013 1014 /** 986 1015 * @param fileName the Name of the File to check 987 1016 * @returns The full name of the file, including the DataDir, and NULL if the file does not exist … … 1003 1032 return NULL; 1004 1033 } 1034 } 1035 1036 #ifdef __unix__ 1037 #include <unistd.h> 1038 #elif __WIN32__ || _MS_DOS_ 1039 #include <dir.h> 1040 #else 1041 #include <direct.h> /* Visual C++ */ 1042 #endif 1043 /** 1044 * @returns the Current Woring Directory 1045 */ 1046 const char* ResourceManager::cwd() 1047 { 1048 if (ResourceManager::getInstance()->_cwd == NULL) 1049 { 1050 char cwd[1024]; 1051 char* errno = getcwd(cwd, 1024); 1052 if (errno == 0) 1053 return NULL; 1054 1055 ResourceManager::getInstance()->_cwd = new char[strlen(cwd)+1]; 1056 strcpy(ResourceManager::getInstance()->_cwd, cwd); 1057 } 1058 return ResourceManager::getInstance()->_cwd; 1005 1059 } 1006 1060 -
branches/shared_lib/src/util/loading/resource_manager.h
r6651 r7174 137 137 static char* getFullName(const char* fileName); 138 138 static bool isInDataDir(const char* fileName); 139 static char* getAbsDir(const char* fileName); 140 static const char* cwd(); 139 141 140 142 static const char* ResourceTypeToChar(ResourceType type); … … 149 151 static ResourceManager* singletonRef; //!< singleton Reference 150 152 153 char* _cwd; //!< The currend Working directory. 151 154 char* dataDir; //!< The Data Directory, where all relevant Data is stored. 152 155 std::vector<char*> imageDirs; //!< A list of directories in which images are stored.
Note: See TracChangeset
for help on using the changeset viewer.