Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7174 in orxonox.OLD for branches/shared_lib/src


Ignore:
Timestamp:
Feb 21, 2006, 10:48:52 PM (19 years ago)
Author:
bensch
Message:

orxonox/dylib: now the dylibLoader should work

Location:
branches/shared_lib/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/shared_lib/src/Makefile.am

    r7170 r7174  
    1313
    1414orxonox_CPPFLAGS = -DIS_ORXONOX
    15 orxonox_LDFLAGS =
     15orxonox_LDFLAGS = -ldl -rdynamic
    1616
    1717orxonox_DEPENDENCIES = \
  • branches/shared_lib/src/orxonox.cc

    r7171 r7174  
    333333  delete[] imageDir;
    334334
    335 //   void* handle;
    336 //   handle = dlopen("./src/world_entities/.libs/libORXground_turret.so", RTLD_NOW);
    337 //   if(handle == NULL)
    338 //   {
    339 //     PRINTF(1)("unable to load %s\n", dlerror());
    340 //
    341 //     return false;
    342 //   }
    343   DynamicLoader::loadDyLib("src/world_entities/.libs/libORXground_turret.so");
     335  DynamicLoader::addSearchDirRelative("./world_entities");
     336  DynamicLoader::addSearchDirRelative("./src/world_entities");
     337
     338  DynamicLoader::loadDyLib("libORXground_turret");
    344339
    345340  // start the collision detection engine
  • branches/shared_lib/src/util/Makefile.am

    r7167 r7174  
    33
    44noinst_LIBRARIES = libORXutils.a
     5
    56
    67libORXutils_a_SOURCES = fast_factory.cc \
     
    2627                        track/track_node.cc
    2728
     29
    2830noinst_HEADERS =        fast_factory.h \
    2931                        object_manager.h \
  • branches/shared_lib/src/util/loading/dynamic_loader.cc

    r7171 r7174  
    1717
    1818#include "dynamic_loader.h"
    19 
     19#include "resource_manager.h"
    2020
    2121using namespace std;
    22 
    2322
    2423/**
     
    3635}
    3736
     37/**
     38 * @brief initializes the Dynamic Library loader
     39 * @returns true on succes, false otherwise
     40 */
     41bool 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}
    3851
    3952/**
     
    5063bool DynamicLoader::loadDynamicLib(const std::string& libName)
    5164{
    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]);
    5768  if(this->handle == NULL)
    5869  {
    5970    return false;
    6071  }
    61   //void *mkr = dlsym( this->handle, "maker");
    6272}
    6373
    6474bool DynamicLoader::loadDyLib(const char* libName)
    6575{
    66   if (lt_dlinit () != 0)
    67   {
    68     PRINTF(1)("Initializing LT_DL_LIB\n");
    69   }
    70 
     76  DynamicLoader::initialize();
    7177  void* handle;
    72   handle = lt_dlopen(libName);
     78  handle = lt_dlopenext(libName);
    7379  if(handle == NULL)
    7480  {
     
    7783    return false;
    7884  }
    79 //  void *mkr = dlsym("maker");
    8085
    8186}
    8287
     88void DynamicLoader::addSearchDir(const char* searchDir)
     89{
     90  DynamicLoader::initialize();
    8391
    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 */
     99bool DynamicLoader::addSearchDirRelative(const char* relSearchDir)
    85100{
     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  }
    86113}
     114
     115
     116const char* DynamicLoader::getSearchDir()
     117{
     118  return lt_dlgetsearchpath();
     119}
  • branches/shared_lib/src/util/loading/dynamic_loader.h

    r7171 r7174  
    2323
    2424  bool loadDynamicLib(const std::string& libName);
    25   virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const;
    2625
    2726  static bool loadDyLib(const char* libName);
    2827
     28  static void addSearchDir(const char* searchDir);
     29  static bool addSearchDirRelative(const char* relSearchDir);
     30  static const char* getSearchDir();
     31
     32  static void unload();
     33private:
     34  // will be done automatically when using the this Engine.
     35  static bool initialize();
    2936
    3037private:
  • branches/shared_lib/src/util/loading/resource_manager.cc

    r7059 r7174  
    6262  strcpy(this->dataDir, "./");
    6363  this->tryDataDir("./data");
     64
     65  this->_cwd = NULL;
    6466}
    6567
     
    8688
    8789  delete[] this->dataDir;
    88 
     90  if (this->_cwd)
     91    delete[] this->_cwd;
    8992  ResourceManager::singletonRef = NULL;
    9093}
     
    984987
    985988/**
     989 * @param name the relative name of the File/Directory.
     990 * @returns a new char* with the name in abs-dir-format
     991 */
     992char* 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/**
    9861015 * @param fileName the Name of the File to check
    9871016 * @returns The full name of the file, including the DataDir, and NULL if the file does not exist
     
    10031032    return NULL;
    10041033  }
     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 */
     1046const 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;
    10051059}
    10061060
  • branches/shared_lib/src/util/loading/resource_manager.h

    r6651 r7174  
    137137  static char* getFullName(const char* fileName);
    138138  static bool isInDataDir(const char* fileName);
     139  static char* getAbsDir(const char* fileName);
     140  static const char* cwd();
    139141
    140142  static const char* ResourceTypeToChar(ResourceType type);
     
    149151  static ResourceManager*  singletonRef;       //!< singleton Reference
    150152
     153  char*                    _cwd;               //!< The currend Working directory.
    151154  char*                    dataDir;            //!< The Data Directory, where all relevant Data is stored.
    152155  std::vector<char*>       imageDirs;          //!< A list of directories in which images are stored.
  • branches/shared_lib/src/world_entities/Makefile.am

    r7171 r7174  
    11MAINSRCDIR=..
    22include $(MAINSRCDIR)/defs/include_paths.am
    3 include WorldEntities.am
     3# include WorldEntities.am
    44
    55noinst_LIBRARIES = libORXwe.a
    6 lib_LTLIBRARIES = libORXground_turret.la
    7 libORXground_turret_la_SOURCES = npcs/ground_turret.cc
    86
    97## THESE ARE THE BASE CLASSES OF ALL WORLD_ENTITIES
  • branches/shared_lib/src/world_entities/WorldEntities.am

    r7169 r7174  
    11## THE SUBCLASSES. THESE MUST BE DYNAMICALLY LINKED OR COMPILED IN DIRECTLY
     2
     3pkglib_LTLIBRARIES = libORXground_turret.la
     4libORXground_turret_la_SOURCES = world_entities/npcs/ground_turret.cc
     5
     6
    27WorldEntities_SOURCES_ = \
    38                world_entities/npcs/npc_test1.cc \
Note: See TracChangeset for help on using the changeset viewer.