plugin.h File Reference

#include "exception.h"
#include "types.h"
#include <vector>
#include <map>
#include <string>

Go to the source code of this file.

Classes

class  libglass::PluginManagerBase
class  libglass::PluginManager
class  libglass::PluginBase
class  libglass::PluginInterface

Namespaces

namespace  libglass

Defines

#define PLUGIN(cl)
#define PLUGIN_CONSTRUCTOR(cl)


Define Documentation

#define PLUGIN ( cl   ) 

Value:

private:                                                \
        cl();                                           \
        void operator=(cl &);                           \
        static bool registered; /* avoid duplicate id */\
        static cl singleton; /* for auto-registering */ \
protected:                                              \
        /* prototypes for virtual functions */          \
        bool processPacket(Packet &p);                  \
        void unregisterNode(nodeId id);                 \
        /* the virtual constructor */                   \
        PluginBase *instance(PluginManager *parent) {   \
                cl *inst = new cl();                    \
                inst->pm_parent = parent;               \
                return inst;                            \
        }                                               \
        friend class PluginManagerBase;                 \
public:                                                 \
        static cl & getHandle(void) {                   \
                return singleton;                       \
        }
This define does everything you need to create a plugin. Just run it with your plugin class name inside the plugin class. If you need special behaviour, you may want to manually copy the define and change as it suits you.

Definition at line 331 of file plugin.h.

#define PLUGIN_CONSTRUCTOR ( cl   ) 

Value:

bool cl::registered = false;                            \
  cl cl::singleton;                                     \
  cl::cl() : PluginBase(#cl, &registered)
This is the static declaration of your plugin AND the constructor. It will ensure that the plugin registers itself automatically. Use it as you'd normally use the declaration of the constructor, except that if you use initialization lists, you should start with a comma ',' instead of a double colon ':'. Here's an example:

        PLUGIN_CONSTRUCTOR(MyClass), init1(), init2() {
                some code;
        }

Consider a concrete example that uses the PLUGIN_CONSTRUCTOR macro: In alias.cpp we have...

   PLUGIN_CONSTRUCTOR(AliasBase) { // add your constructor code here }

This gets expanded to (note additional comments added in expanded code)...

   // Initialisation of class static member
   // Note: This is performed during runtime initialisation before calling main()
   bool AliasBase::registered = false;

   // Initialisation of class static member object
   // Note: This is performed during runtime initialisation before calling main()
   // Will call default constructor for the class (see below), which calls
   // the PluginBase constructor during initialisation as...
   // PluginBase(const PluginId id, bool *registered)
   AliasBase AliasBase::singleton;

   // Define the default constructor
   AliasBase::AliasBase() : PluginBase("AliasBase", &registered) { // add your constructor code here }

You can't have any parameters in the constructors. If you desperatedly need parameters, let us developers know, because I can't think of any reason. Remember that the user will *not* call this constructor, *ever*, so it's impossible to pass a parameter! If you wish to get/set parameters after the constructor returns, it's suggested to use an objected derived from PluginInterface, so the user will have access to those functions.

Note that the PLUGIN_CONSTRUCTOR macro uses the gnu c-preprocessor syntax for _stringification_ (or stringization as Microsoft call it) of the argument. That is to say c1 gets expanded (once) to a constant string. For example,

    #define FOO(bar) format(#bar) 
    FOO(hello)

would produce

    format("hello")

See also:
PluginBase.

Definition at line 416 of file plugin.h.


Generated on Fri May 28 13:19:01 2010 for libGlass by  doxygen 1.5.8