Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7167 in orxonox.OLD for trunk/src/util/loading


Ignore:
Timestamp:
Feb 19, 2006, 3:18:08 PM (18 years ago)
Author:
bensch
Message:

trunk: dynamic library loading test

Location:
trunk/src/util/loading
Files:
1 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/util/loading/dynamic_loader.cc

    r7164 r7167  
    1010
    1111   ### File Specific:
    12    main-programmer: ...
     12   main-programmer: Benjamin Grauer
    1313   co-programmer: ...
    1414*/
    1515
    16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
     16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING
    1717
    18 #include "proto_class.h"
     18#include "dynamic_loader.h"
     19
     20
     21#include <dlfcn.h>
     22
    1923
    2024using namespace std;
     
    2529 * @todo this constructor is not jet implemented - do it
    2630*/
    27 ProtoClass::ProtoClass ()
     31DynamicLoader::DynamicLoader (const std::string& libName)
     32    : Factory(NULL, CL_NULL)
    2833{
    29    this->setClassID(CL_PROTO_ID, "ProtoClass");
     34  this->setClassID(CL_DYNAMIC_LOADER, "DynamicLoader");
    3035
    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;
    3537
    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]);
    4140}
    4241
     
    4544 * standard deconstructor
    4645*/
    47 ProtoClass::~ProtoClass ()
     46DynamicLoader::~DynamicLoader ()
    4847{
    4948  // delete what has to be deleted here
     49  if (this->handle != NULL)
     50    dlclose(this->handle);
    5051}
     52
     53
     54bool 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
     64bool 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
     78BaseObject* DynamicLoader::fabricateObject(const TiXmlElement* root) const
     79{
     80}
  • trunk/src/util/loading/dynamic_loader.h

    r7164 r7167  
    11/*!
    2  * @file proto_class.h
    3  * @brief Definition of ...
     2 * @file dynamic_loader.h
     3 * @brief Definition of The Dynamic Loader Factory.
    44*/
    55
    6 #ifndef _PROTO_CLASS_H
    7 #define _PROTO_CLASS_H
     6#ifndef _DYNAMIC_LOADER_H
     7#define _DYNAMIC_LOADER_H
    88
    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); };
    1015
    1116// FORWARD DECLARATION
    1217
     18//! A class for ...
     19class DynamicLoader : public Factory
     20{
     21
     22public:
     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);
    1330
    1431
    15 //! A class for ...
    16 class ProtoClass : public BaseObject {
    17 
    18  public:
    19   ProtoClass();
    20   virtual ~ProtoClass();
    21 
    22 
    23  private:
    24 
     32private:
     33  void*      handle;
    2534};
    2635
    27 #endif /* _PROTO_CLASS_H */
     36#endif /* _DYNAMIC_LOADER_H */
  • trunk/src/util/loading/factory.h

    r6341 r7167  
    3838    tFactory<CLASS_NAME>* global_##CLASS_NAME##_Factory = new tFactory<CLASS_NAME>(#CLASS_NAME, CLASS_ID)
    3939
     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
    4043//! The Factory is a loadable object handler
    4144class Factory : public BaseObject {
    4245
    4346 public:
    44   Factory (const char* factoryName, ClassID classID);
    4547  virtual ~Factory ();
    4648
     
    5658
    5759  protected:
     60    Factory (const char* factoryName, ClassID classID);
    5861    virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const = 0;
    5962
Note: See TracChangeset for help on using the changeset viewer.