|
Nemiver
0.3
|
This document describes the dynamic module framework used throughout nemiver to support modularity and extensibility.
We needed a way to separate programming interfaces from their implementation, so that a given programming interface could have several different implementations. Clients of a given interface must me able to load a particular implementation of that interfaces at runtime, without the need to recompile or statically re-linking to the involved binaries.
The nemiver common framework uses the concept of "Dynamic Module", also known as DynMod. A dynmod is a dynamic shared object (surprise!) that contains service objects. The aim of these service objects is to offer services to client code. The only way for client code to use a service object embedded in a dynmod is to acquire an abstract interface of that service object. Once the interface is acquired, using the service object is just as easy as calling methods of that interface.
object interface
Please find below a small code example to load the dynmod that contains the a service object that knows how to control GDB. The name of that dynmod is "gdbengine". gdbengine exposes the IDebugger interface (all public service object abstract interfaces name are prefixed by 'I'). Once the "gdbengine" dynmod is loaded, the code snippet queries it to get a pointer to the IDebugger interface embedded in it.
For the fearless readers around, before compiling the code snippet below, please make sure you have compiled nemiver and typed
in order to get the dynmod framework headers and binaries properly installed.
Okay, that code is a bit long, but it is made on purpose to make you see the different steps of the service object interface loading mechanism:
For real life usage, you can you a shorter code path, like the example below:
In this example, we use the default module manager (that is present during the lifetime of the main function) to load the "gdbengine" dynmod on which we query a pointer to the IDebugger interface. The function DynamicModuleManager::load_iface_with_default_manager() fails if no interface with the queried name and type exists.
to be continued ...
1.8.17