BLLoad Class Reference

#include <BLLoad.hh>

List of all members.


Detailed Description

class BLLoad will load a shared object.

All static object constructors in the shared object are executed while loading, and they can register the resources implemented. The corresponding destructors are probably not executed -- use atexit() or register an appropriate callback with BLManager..

NOTE: the release 2 build architecture makes this unnecessary (user shared objects are not used). Several .cc files have residual calls to this class, surrounded by ifdef USE_SHARED_OBJECTS. That may be removed when it's clear this is no longer needed.

Public Member Functions

G4String getName ()
 getName() returns the library name of this DLLoad object.
void * getDataSymbol (G4String sym)
 getDataSymbol() returns a pointer to a DATA symbol in the shared object. Returns null if not found. The caller must cast the return value to the appropriate type.
VoidFunctionPointer getFunctionSymbol (G4String sym)
 getFunctionSymbol() returns a pointer to a FUNCTION symbol in the shared object. Returns null if not found. The caller must cast the return value to the appropriate type.
 ~BLLoad ()

Static Public Member Functions

static BLLoadload (const G4String &name)
 load() is a static function to load a shared object. It returns a pointer to a BLLoad object, null if error. If no '/' or '\' is present in the name, it will be searched for in the usual way. Normally no extension is used (.so, .dylib, or .dll); this function then appends those extensions in order until a file is found. Loading an already loaded shared object does nothing (no error), returning a new BLLoad object with the same handle.
static const char * errorString ()
 errorString() returns a string describing the previous error. Static.
static std::vector< BLLoad * > getList ()
 getList() returns the list of BLLoad pointers. Static.

Private Member Functions

 BLLoad (G4String name, void *p)

Static Private Member Functions

static void * load1 (G4String n)
 load1() is used internally by load()

Private Attributes

G4String libname
void * handle

Static Private Attributes

static std::vector< BLLoad * > list


Constructor & Destructor Documentation

BLLoad::BLLoad ( G4String  name,
void *  p 
) [private]

Referenced by load().

BLLoad::~BLLoad (  )  [inline]

References handle.

00115 { if(handle != 0) dlclose(handle); handle=0; }


Member Function Documentation

static BLLoad* BLLoad::load ( const G4String &  name  )  [inline, static]

load() is a static function to load a shared object. It returns a pointer to a BLLoad object, null if error. If no '/' or '\' is present in the name, it will be searched for in the usual way. Normally no extension is used (.so, .dylib, or .dll); this function then appends those extensions in order until a file is found. Loading an already loaded shared object does nothing (no error), returning a new BLLoad object with the same handle.

References BLLoad(), and load1().

00061                                                   {
00062                 G4String n = name;
00063                 void *p = load1(n);
00064                 if(p) return new BLLoad(n,p);
00065                 n = name + ".so";
00066                 p = load1(n);
00067                 if(p) return new BLLoad(n,p);
00068                 n = name + ".dylib";
00069                 p = load1(n);
00070                 if(p) return new BLLoad(n,p);
00071                 n = name + ".dll";
00072                 p = load1(n);
00073                 if(p) return new BLLoad(n,p);
00074 
00075                 return 0;
00076         }

static const char* BLLoad::errorString (  )  [inline, static]

errorString() returns a string describing the previous error. Static.

00080                                          {
00081 #ifdef WIN32
00082                 return "Unsupported OS";
00083 #endif
00084 #ifdef __CYGWIN__
00085                 return "Unsupported OS";
00086 #endif
00087 #if defined(__linux) || defined(__APPLE__)
00088                 return dlerror(); 
00089 #endif
00090         }

static std::vector<BLLoad*> BLLoad::getList (  )  [inline, static]

getList() returns the list of BLLoad pointers. Static.

References list.

00093 { return list; }

G4String BLLoad::getName (  )  [inline]

getName() returns the library name of this DLLoad object.

References libname.

00096 { return libname; }

void* BLLoad::getDataSymbol ( G4String  sym  )  [inline]

getDataSymbol() returns a pointer to a DATA symbol in the shared object. Returns null if not found. The caller must cast the return value to the appropriate type.

References handle.

00103                 { return dlsym(handle,sym.c_str()); }

VoidFunctionPointer BLLoad::getFunctionSymbol ( G4String  sym  )  [inline]

getFunctionSymbol() returns a pointer to a FUNCTION symbol in the shared object. Returns null if not found. The caller must cast the return value to the appropriate type.

References handle.

00108                                                             {
00109                 union { void *a; VoidFunctionPointer b; };
00110                 a = dlsym(handle,sym.c_str());
00111                 return b;
00112         }

static void* BLLoad::load1 ( G4String  n  )  [inline, static, private]

load1() is used internally by load()

Referenced by load().

00118                                        {
00119 
00120 #ifdef WIN32
00121                 return 0;
00122 #endif
00123 #ifdef __CYGWIN__
00124                 return 0;
00125 #endif
00126 #if defined(__linux) || defined(__APPLE__)
00127                 return dlopen(n.c_str(),RTLD_NOW);
00128 #endif
00129         }


Member Data Documentation

G4String BLLoad::libname [private]

Referenced by getName().

void* BLLoad::handle [private]

std::vector<BLLoad*> BLLoad::list [static, private]

Referenced by getList().


The documentation for this class was generated from the following file:
g4beamline