Changeset 7167 in orxonox.OLD for trunk/src/util/loading
- Timestamp:
- Feb 19, 2006, 3:18:08 PM (19 years ago)
- Location:
- trunk/src/util/loading
- Files:
-
- 1 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/util/loading/dynamic_loader.cc
r7164 r7167 10 10 11 11 ### File Specific: 12 main-programmer: ...12 main-programmer: Benjamin Grauer 13 13 co-programmer: ... 14 14 */ 15 15 16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING 17 17 18 #include "proto_class.h" 18 #include "dynamic_loader.h" 19 20 21 #include <dlfcn.h> 22 19 23 20 24 using namespace std; … … 25 29 * @todo this constructor is not jet implemented - do it 26 30 */ 27 ProtoClass::ProtoClass () 31 DynamicLoader::DynamicLoader (const std::string& libName) 32 : Factory(NULL, CL_NULL) 28 33 { 29 this->setClassID(CL_PROTO_ID, "ProtoClass");34 this->setClassID(CL_DYNAMIC_LOADER, "DynamicLoader"); 30 35 31 /* If you make a new class, what is most probably the case when you write this file 32 don't forget to: 33 1. Add the new file new_class.cc to the ./src/Makefile.am 34 2. Add the class identifier to ./src/class_id.h eg. CL_NEW_CLASS 36 this->handle = NULL; 35 37 36 Advanced Topics: 37 - if you want to let your object be managed via the ObjectManager make sure to read 38 the object_manager.h header comments. You will use this most certanly only if you 39 make many objects of your class, like a weapon bullet. 40 */ 38 if (loadDynamicLib(libName)); 39 this->setName(&libName[0]); 41 40 } 42 41 … … 45 44 * standard deconstructor 46 45 */ 47 ProtoClass::~ProtoClass()46 DynamicLoader::~DynamicLoader () 48 47 { 49 48 // delete what has to be deleted here 49 if (this->handle != NULL) 50 dlclose(this->handle); 50 51 } 52 53 54 bool DynamicLoader::loadDynamicLib(const std::string& libName) 55 { 56 this->handle = dlopen(&libName[0], RTLD_NOW); 57 if(this->handle == NULL) 58 { 59 return false; 60 } 61 void *mkr = dlsym( this->handle, "maker"); 62 } 63 64 bool DynamicLoader::loadDyLib(const std::string& libName) 65 { 66 void* handle; 67 handle = dlopen(&libName[0], RTLD_NOW); 68 if(handle == NULL) 69 { 70 PRINTF(0)("unable to load %s\n", &libName[0]); 71 return false; 72 } 73 // void *mkr = dlsym("maker"); 74 75 } 76 77 78 BaseObject* DynamicLoader::fabricateObject(const TiXmlElement* root) const 79 { 80 } -
trunk/src/util/loading/dynamic_loader.h
r7164 r7167 1 1 /*! 2 * @file proto_class.h3 * @brief Definition of ...2 * @file dynamic_loader.h 3 * @brief Definition of The Dynamic Loader Factory. 4 4 */ 5 5 6 #ifndef _ PROTO_CLASS_H7 #define _ PROTO_CLASS_H6 #ifndef _DYNAMIC_LOADER_H 7 #define _DYNAMIC_LOADER_H 8 8 9 #include "base_object.h" 9 #include "factory.h" 10 11 #include <string> 12 13 #define DYNAMIC_LINKAGE_FACTORY(CLASS_NAME, CLASS_ID) \ 14 void* DynamicCreator(const TiXmlElement* root) { return new CLASS_NAME(root); }; 10 15 11 16 // FORWARD DECLARATION 12 17 18 //! A class for ... 19 class DynamicLoader : public Factory 20 { 21 22 public: 23 DynamicLoader(const std::string& libName); 24 virtual ~DynamicLoader(); 25 26 bool loadDynamicLib(const std::string& libName); 27 virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const; 28 29 static bool loadDyLib(const std::string& libName); 13 30 14 31 15 //! A class for ... 16 class ProtoClass : public BaseObject { 17 18 public: 19 ProtoClass(); 20 virtual ~ProtoClass(); 21 22 23 private: 24 32 private: 33 void* handle; 25 34 }; 26 35 27 #endif /* _ PROTO_CLASS_H */36 #endif /* _DYNAMIC_LOADER_H */ -
trunk/src/util/loading/factory.h
r6341 r7167 38 38 tFactory<CLASS_NAME>* global_##CLASS_NAME##_Factory = new tFactory<CLASS_NAME>(#CLASS_NAME, CLASS_ID) 39 39 40 // #define CREATE_DYNAMIC_FACTORY(CLASS_NAME, CLASS_ID) \ 41 // tFactory<CLASS_NAME>* global_##CLASS_NAME##_Dynamic_Factory = new DynamicLoader<CLASS_NAME>(#CLASS_NAME, CLASS_ID) 42 40 43 //! The Factory is a loadable object handler 41 44 class Factory : public BaseObject { 42 45 43 46 public: 44 Factory (const char* factoryName, ClassID classID);45 47 virtual ~Factory (); 46 48 … … 56 58 57 59 protected: 60 Factory (const char* factoryName, ClassID classID); 58 61 virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const = 0; 59 62
Note: See TracChangeset
for help on using the changeset viewer.