| 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 "debug.h" | 
|---|
| 20 |  | 
|---|
| 21 | #ifndef __WIN32__ | 
|---|
| 22 | #include <dlfcn.h> | 
|---|
| 23 |  | 
|---|
| 24 |  | 
|---|
| 25 |  | 
|---|
| 26 |  | 
|---|
| 27 |  | 
|---|
| 28 | /** | 
|---|
| 29 |  * standard constructor | 
|---|
| 30 |  * @todo this constructor is not jet implemented - do it | 
|---|
| 31 | */ | 
|---|
| 32 | DynamicLoader::DynamicLoader (const std::string& libName) | 
|---|
| 33 |     : Factory(NULL, CL_NULL) | 
|---|
| 34 | { | 
|---|
| 35 |   this->setClassID(CL_DYNAMIC_LOADER, "DynamicLoader"); | 
|---|
| 36 |  | 
|---|
| 37 |   this->handle = NULL; | 
|---|
| 38 |  | 
|---|
| 39 |   if (loadDynamicLib(libName)); | 
|---|
| 40 |   this->setName(&libName[0]); | 
|---|
| 41 | } | 
|---|
| 42 |  | 
|---|
| 43 |  | 
|---|
| 44 | /** | 
|---|
| 45 |  * standard deconstructor | 
|---|
| 46 | */ | 
|---|
| 47 | DynamicLoader::~DynamicLoader () | 
|---|
| 48 | { | 
|---|
| 49 |   // delete what has to be deleted here | 
|---|
| 50 |   if (this->handle != NULL) | 
|---|
| 51 |     dlclose(this->handle); | 
|---|
| 52 | } | 
|---|
| 53 |  | 
|---|
| 54 |  | 
|---|
| 55 | bool DynamicLoader::loadDynamicLib(const std::string& libName) | 
|---|
| 56 | { | 
|---|
| 57 |   this->handle = dlopen(&libName[0], RTLD_NOW); | 
|---|
| 58 |   if(this->handle == NULL) | 
|---|
| 59 |   { | 
|---|
| 60 |     return false; | 
|---|
| 61 |   } | 
|---|
| 62 |   void *mkr = dlsym( this->handle, "maker"); | 
|---|
| 63 |   return (mkr != NULL); | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 66 | bool DynamicLoader::loadDyLib(const std::string& libName) | 
|---|
| 67 | { | 
|---|
| 68 |   void* handle; | 
|---|
| 69 |   handle = dlopen(&libName[0], RTLD_NOW); | 
|---|
| 70 |   if(handle == NULL) | 
|---|
| 71 |   { | 
|---|
| 72 |     PRINTF(0)("unable to load %s\n", &libName[0]); | 
|---|
| 73 |     return false; | 
|---|
| 74 |   } | 
|---|
| 75 | //  void *mkr = dlsym("maker"); | 
|---|
| 76 |   return true; | 
|---|
| 77 | } | 
|---|
| 78 |  | 
|---|
| 79 |  | 
|---|
| 80 | BaseObject* DynamicLoader::fabricateObject(const TiXmlElement* root) const | 
|---|
| 81 | { | 
|---|
| 82 |   /// FIXME | 
|---|
| 83 |   return NULL; | 
|---|
| 84 | } | 
|---|
| 85 | #endif | 
|---|