|
Boost : |
From: Martin Reinecke (martin_at_[hidden])
Date: 2001-07-18 08:10:13
Hello,
I'd like to find out if there is any interest to include the
DLC library for dynamically loadable classes into Boost.
This library allows loading and unloading of different implementations
for abstract classes at runtime in an easy and type-safe way.
Portability:
------------
The code does not use any nonstandard language extensions. Exceptions
and RTTI are used, as well as several STL classes (map, string, etc.).
Additionally, the functions dlopen() and dlclose() from <dlfcn.h> are needed.
For DLC to work properly, the operating system must have good support for
shared libraries. Static global objects in shared libraries must be
automatically constructed at load time and destroyed at unload time.
Furthermore, unresolved symbols in the loaded library must be linked against
the loading application at load time.
Not all of these requirements are adressed in the C++ standard, so in this
respect it is implementation-dependent if DLC actually works.
The library has been compiled and tested with gcc 2.95.2 and gcc 3.0
on a Linux platform and with gcc 2.95.2 on IRIX 6.4.
Earlier versions were successfully compiled with DEC cxx under Digital Unix.
Unfortunately I do not have the resources to try a port to Windows.
Availability:
-------------
The current version can be downloaded from
http://www.mpa-garching.mpg.de/~martin/dlc/dlc-180701.tar.gz
Updates are available from
http://www.mpa-garching.mpg.de/~martin/dlc/
License:
--------
Currently, DLC is covered by the LGPL. If this is too restrictive
for distribution with Boost I am prepared to change the licensing terms
accordingly.
Coding style:
-------------
The current version does not follow the Boost coding guidelines. If DLC
is considered suitable for the includion into Boost, I will rewrite the
code to fit into the Boost framework.
Usage example:
--------------
Suppose an application (file Application.cpp) knows the abstract interface
of a class (defined in AbstractParent.hpp), but when Application.cpp
is compiled, no concrete implementations of that interface have been written yet.
Using DLC, the application can dynamically load any class derived from
AbstractParent (e.g. as defined in file Child.cpp) from a shared library.
The syntax for using DLC in that context is shown below.
File AbstractParent.hpp:
--------------------------------------------------------------------
#include "dlc_client.h"
class AbstractParent: public DLC::BASE
{
// defines an abstract interface
};
File Child.cpp:
--------------------------------------------------------------------
#include "AbstractParent.hpp"
class Child: public AbstractParent
{
// implements the abstract interface defined by AbstractParent
};
// Now register this class with the DLC server
DLC_Register_Macro (Child)
File Application.cpp:
--------------------------------------------------------------------
#include "dlc_server.h"
#include "AbstractParent.hpp"
int main()
{
DLC::Server.load ("Child.so");
AbstractParent *obj = DLC::New<AbstractParent> ("Child");
// use obj
delete obj;
DLC::Server.unload ("Child.so");
}
Please contact me if you need any further information.
Regards,
Martin Reinecke
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk