Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/shared_lib/src/util/loading/dynamic_loader.cc @ 7175

Last change on this file since 7175 was 7175, checked in by bensch, 19 years ago

orxonox/trunk: now the PKG-libdir should be eaten too

File size: 2.4 KB
Line 
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 "resource_manager.h"
20
21using namespace std;
22
23/**
24 * standard constructor
25 * @todo this constructor is not jet implemented - do it
26*/
27DynamicLoader::DynamicLoader (const std::string& libName)
28{
29  this->setClassID(CL_DYNAMIC_LOADER, "DynamicLoader");
30
31  this->handle = NULL;
32
33  if (loadDynamicLib(libName));
34  this->setName(&libName[0]);
35}
36
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}
51
52/**
53 * standard deconstructor
54*/
55DynamicLoader::~DynamicLoader ()
56{
57  // delete what has to be deleted here
58  if (this->handle != NULL)
59    lt_dlclose(this->handle);
60}
61
62
63bool DynamicLoader::loadDynamicLib(const std::string& libName)
64{
65  DynamicLoader::initialize();
66
67  this->handle = lt_dlopenext(&libName[0]);
68  if(this->handle == NULL)
69  {
70    return false;
71  }
72}
73
74bool DynamicLoader::loadDyLib(const char* libName)
75{
76  DynamicLoader::initialize();
77  void* handle;
78  handle = lt_dlopenext(libName);
79  if(handle == NULL)
80  {
81    PRINTF(1)("unable to load %s: %s\n", libName, lt_dlerror());
82
83    return false;
84  }
85
86}
87
88void DynamicLoader::addSearchDir(const char* searchDir)
89{
90  DynamicLoader::initialize();
91
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)
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  }
113}
114
115bool DynamicLoader::addSearchDirInLibDir(const char* relSearchDir)
116{
117
118}
119
120
121const char* DynamicLoader::getSearchDir()
122{
123  return lt_dlgetsearchpath();
124}
Note: See TracBrowser for help on using the repository browser.