Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ModulePool Class Reference

Does loading and unloading of modules. Kindof "manager". More...

#include <pool.h>

Collaboration diagram for ModulePool:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ~ModulePool ()

Static Public Member Functions

int init ()
 Initialize the module pool (manger).

void cleanup ()
 Cleanup module pool (manager).

SharedObject load (const char *name, int flags=0)
 Load a module / shared object / DLL.

int unload (const char *name)
 Force unloading of a module / shared object / DLL; DO NOT USE.

void unregister (_ISharedObject *iso)
 Internal unregistration functions of shared objects called by their destructor.


Private Member Functions

SharedObject _load (const char *name, int flags)
 Internally used method to load a shared object.

int _unload (const char *name)
 Internally used method for forced unloading of a shared object.

void _unregister (_ISharedObject *iso)
 Internally used method for shared object de-registration.

_ISharedObject_FindObjectByName (const char *name, bool requeue)
 Find module with passed name in list of loaded modules.

 ModulePool (const ModulePool &)
 Do use this class directly; just its static members.

void operator= (const ModulePool &)
 ModulePool ()
 Do use this class directly; just its static members.


Private Attributes

LinkedList< _ISharedObjectso_list
 List of all shared objects currently loaded.

RecursiveMutex pool_mutex
 Mutex to protect the module pool:.


Static Private Attributes

ModulePoolpool = NULL
 Static module pool manager; created by init().


Detailed Description

Does loading and unloading of modules. Kindof "manager".

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
This class is the main module loader class; you need to ask this class to get a module loaded. The class is designed to exist exactly once; normally generated from within the main thread during startup.

Note:
All user interface methods are actually static; never create an object of this type in your application (constructors are private).

Definition at line 136 of file pool.h.


Constructor & Destructor Documentation

ModulePool::ModulePool const ModulePool  )  [private]
 

Do use this class directly; just its static members.

ModulePool::ModulePool  )  [private]
 

Do use this class directly; just its static members.

Definition at line 144 of file pool.cc.

References Assert, and pool.

Referenced by init().

ModulePool::~ModulePool  ) 
 

Definition at line 153 of file pool.cc.

References _unregister(), Assert, LinkedList< _ISharedObject >::first(), LinkedList< _ISharedObject >::IsEmpty(), RecursiveMutex::lock(), pool, pool_mutex, so_list, and RecursiveMutex::unlock().


Member Function Documentation

_ISharedObject * ModulePool::_FindObjectByName const char *  name,
bool  requeue
[private]
 

Find module with passed name in list of loaded modules.

Definition at line 26 of file pool.cc.

References LinkedList< _ISharedObject >::dequeue(), LinkedList< _ISharedObject >::first(), LinkedList< _ISharedObject >::insert(), RecursiveMutex::lock(), _ISharedObject::mname, LinkedListBase< _ISharedObject >::next, pool_mutex, so_list, and RecursiveMutex::unlock().

Referenced by _load(), and _unload().

SharedObject ModulePool::_load const char *  name,
int  flags
[private]
 

Internally used method to load a shared object.

Definition at line 51 of file pool.cc.

References _FindObjectByName(), LinkedList< _ISharedObject >::insert(), RecursiveMutex::lock(), pool_mutex, SharedObject, so_list, and RecursiveMutex::unlock().

Referenced by load().

int ModulePool::_unload const char *  name  )  [private]
 

Internally used method for forced unloading of a shared object.

Definition at line 85 of file pool.cc.

References _FindObjectByName(), and _unregister().

Referenced by unload().

void ModulePool::_unregister _ISharedObject iso  )  [private]
 

Internally used method for shared object de-registration.

Definition at line 99 of file pool.cc.

References LinkedList< _ISharedObject >::dequeue(), RecursiveMutex::lock(), _ISharedObject::module, _ISharedObject::name(), pool_mutex, so_list, and RecursiveMutex::unlock().

Referenced by _unload(), unregister(), and ~ModulePool().

void ModulePool::cleanup  )  [static]
 

Cleanup module pool (manager).

The opposite of init().

Definition at line 136 of file pool.cc.

References pool.

int ModulePool::init  )  [static]
 

Initialize the module pool (manger).

In order to use the shared objects, you must first initialize the shared object pool using ModulePool::init(), normally from the main thread.

Note:
Make sure this function is called exactly once.
Returns:
: 0 -> OK, 1 -> error (module loading not supported)

Definition at line 122 of file pool.cc.

References ModulePool().

SharedObject ModulePool::load const char *  name,
int  flags = 0
[inline, static]
 

Load a module / shared object / DLL.

This function will load a shared object. It can be safely called (e.g. by different threads but also by the same thread) several times with the same module file as argument; in this case, always the same reference will be returned.

The flags is a bitwise OR of the _ISharedObject_Namespace::Flags, i.e.:

  • SharedObject::BindLazy
  • SharedObject::BindLocal
You need to test the returned shared object for error code to check for failures; use the error() function of the returned SharedObject which returns an error string in case of failure or a NULL ref in case of success.

The returned SharedObject is "C++-safe" and used ref couning.

Definition at line 214 of file pool.h.

References _load(), pool, and SharedObject.

void ModulePool::operator= const ModulePool  )  [private]
 

int ModulePool::unload const char *  name  )  [inline, static]
 

Force unloading of a module / shared object / DLL; DO NOT USE.

This function will unload the specified shared object no matter if it is still used or not.

DO NOT USE. IT WILL MOST LIKELY CRASH YOUR APPLICATION.

Shared objects are automatically unloaded if they are no longer in use, i.e. once all SharedObject and ModuleFunction instances referring to that shared object got destroyed.

Returns:
0 -> OK, unloaded, 1 -> module with that name not loaded.

Definition at line 232 of file pool.h.

References _unload(), and pool.

void ModulePool::unregister _ISharedObject iso  )  [inline, static]
 

Internal unregistration functions of shared objects called by their destructor.

For internal use only.

Definition at line 239 of file pool.h.

References _unregister(), and pool.

Referenced by _ISharedObject::~_ISharedObject().


Member Data Documentation

ModulePool * ModulePool::pool = NULL [static, private]
 

Static module pool manager; created by init().

Todo:
fixme (stdio.h)

Definition at line 23 of file pool.cc.

Referenced by cleanup(), load(), ModulePool(), unload(), unregister(), and ~ModulePool().

RecursiveMutex ModulePool::pool_mutex [private]
 

Mutex to protect the module pool:.

Definition at line 152 of file pool.h.

Referenced by _FindObjectByName(), _load(), _unregister(), and ~ModulePool().

LinkedList<_ISharedObject> ModulePool::so_list [private]
 

List of all shared objects currently loaded.

We can use a list here since we will normally deal with few shared objects and the elemets are LRU-requeued as some sort of caching. May be replaced by a balanced tree if needed.

Definition at line 150 of file pool.h.

Referenced by _FindObjectByName(), _load(), _unregister(), and ~ModulePool().


The documentation for this class was generated from the following files:
Generated on Sat Feb 19 22:35:31 2005 for Ray by doxygen 1.3.5