The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download | Blog | Stats
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

DLLManager Class Reference

The DLLManager class is able to load a module file by filename, and locate its init_module symbol. More...

#include <dynamic.h>

Inheritance diagram for DLLManager:

Inheritance graph
[legend]
Collaboration diagram for DLLManager:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 DLLManager (InspIRCd *ServerInstance, const char *fname)
 This constructor loads the module using dlopen().
virtual ~DLLManager ()
bool GetSymbol (void **v, const char *sym_name)
 Get a symbol using dynamic linking.
char * LastError ()
 Get the last error from dlopen() or dlsym().

Public Attributes

void * h
 The module handle.

Protected Attributes

char * err
 The last error string, or NULL.

Detailed Description

The DLLManager class is able to load a module file by filename, and locate its init_module symbol.

Definition at line 30 of file dynamic.h.


Constructor & Destructor Documentation

DLLManager::DLLManager InspIRCd ServerInstance,
const char *  fname
 

This constructor loads the module using dlopen().

Parameters:
ServerInstance The creator class of this object
fname The filename to load. This should be within the modules dir.

Definition at line 21 of file dynamic.cpp.

References err, and h.

00022 {
00023         err = NULL;
00024 
00025         if (!strstr(fname,".so"))
00026         {
00027                 err = "This doesn't look like a module file to me...";
00028                 return;
00029         }
00030 
00031         h = dlopen(fname, RTLD_NOW|RTLD_LOCAL);
00032         if (!h)
00033         {
00034                 err = (char*)dlerror();
00035                 return;
00036         }
00037 }

DLLManager::~DLLManager  )  [virtual]
 

Definition at line 39 of file dynamic.cpp.

References h.

00040 {
00041         /* close the library */
00042         if (h)
00043                 dlclose(h);
00044 }


Member Function Documentation

bool DLLManager::GetSymbol void **  v,
const char *  sym_name
 

Get a symbol using dynamic linking.

Parameters:
v A function pointer, pointing at an init_module function
sym_name The symbol name to find, usually "init_module"
Returns:
true if the symbol can be found, also the symbol will be put into v.

Definition at line 48 of file dynamic.cpp.

References err, and h.

Referenced by DLLFactoryBase::DLLFactoryBase().

00049 {
00050         /*
00051          * try extract a symbol from the library
00052          * get any error message is there is any
00053          */
00054         
00055         if (h)
00056         {
00057                 dlerror(); // clear value
00058                 *v = dlsym(h, sym_name);
00059                 err = (char*)dlerror();
00060                 if (!*v || err)
00061                         return false;
00062         }
00063         
00064         /* succeeded :) */
00065         return true;
00066 }

char* DLLManager::LastError  )  [inline]
 

Get the last error from dlopen() or dlsym().

Returns:
The last error string, or NULL if no error has occured.

Definition at line 51 of file dynamic.h.

Referenced by DLLFactoryBase::DLLFactoryBase().

00052         {
00053                  return err;
00054         }


Member Data Documentation

char* DLLManager::err [protected]
 

The last error string, or NULL.

Definition at line 66 of file dynamic.h.

Referenced by DLLManager(), and GetSymbol().

void* DLLManager::h
 

The module handle.

This is OS dependent, on POSIX platforms it is a pointer to a function pointer (yes, really!) and on windows it is a library handle.

Definition at line 60 of file dynamic.h.

Referenced by DLLManager(), GetSymbol(), and ~DLLManager().


The documentation for this class was generated from the following files: