#include <plugin.h>
Public Member Functions | |
PluginBase (const PluginId id, bool *registered) | |
virtual | ~PluginBase ()=0 |
PluginId | getPluginId (void) const |
Protected Member Functions | |
virtual bool | processPacket (Packet &p)=0 |
virtual PluginBase * | instance (PluginManager *parent)=0 |
virtual void | unregisterNode (nodeId id)=0 |
virtual bool | sendPacket (Packet &p) |
nodeRelation | getNodeRelation (nodeId id) const |
Glass * | getGlass (void) const |
Protected Attributes | |
PluginManager * | pm_parent |
Friends | |
class | PluginManagerBase |
class | PluginManager |
Let me explain in the philosophy of PluginBase and derived classes. This is a singleton class (per PluginManager instance, that is) that should be unknown to the user. This is a good thing (TM), because the user doesn't have to use static methods to get a handle and all that kind of stuff. This class has a virtual method processPacket() that is called for every packet that arrives for this plugin.
To let the user interact with the plugin, you should provide classes derived from PluginInterface. These classes are not singletons, and they provide a method to talk to PluginBase. You can keep track of all these objects, calling the PluginBase class from the constructor, etc.
Since you're probably not following this lousy explanation, let's see an example. I'll use the Barrier plugin to illustrate this discussion. First, you have the PluginBase derived class, which is BarrierBase. This class is responsible for processing all barrier packets.
If the user wants to setup a barrier, he'll create a instance of another class, Barrier (which is derived from PluginInterface). To him, BarrierBase doesn't exist. When a Barrier is instanced, it calls BarrierBase, which keeps track of all Barrier objects. This way BarrierBase can release barriers when the appropriate packets arrive, etc.
Definition at line 235 of file plugin.h.
libglass::PluginBase::PluginBase | ( | const PluginId | id, | |
bool * | registered | |||
) |
Constructor.
virtual libglass::PluginBase::~PluginBase | ( | ) | [pure virtual] |
Destructor.
Glass* libglass::PluginBase::getGlass | ( | void | ) | const [protected] |
nodeRelation libglass::PluginBase::getNodeRelation | ( | nodeId | id | ) | const [protected] |
Get node type wrapper.
PluginId libglass::PluginBase::getPluginId | ( | void | ) | const |
Returns this plugin's id.
virtual PluginBase* libglass::PluginBase::instance | ( | PluginManager * | parent | ) | [protected, pure virtual] |
Virtual constructor, used by PluginManagerBase::createPluginManager.
This function is automatically created by PLUGIN(cl).
parent | Our parent PluginManager, to fill pm_parent. |
virtual bool libglass::PluginBase::processPacket | ( | Packet & | p | ) | [protected, pure virtual] |
Callback from PluginManager.
This prototype is automatically added by PLUGIN(cl).
p | The packet to process. |
true | If packet was correctly processed. | |
false | Otherwise. |
virtual bool libglass::PluginBase::sendPacket | ( | Packet & | p | ) | [protected, virtual] |
Wrapper to send a packet. You can override if desired.
p | The packet to send. |
true | If packet was correctly sent. | |
false | Otherwise. |
virtual void libglass::PluginBase::unregisterNode | ( | nodeId | id | ) | [protected, pure virtual] |
Clean up system.
Guarantees that a node quit event is properly handled by the plugin, avoiding potential deadlocks.
This prototype is automatically added by PLUGIN(cl).
id | The nodeId of the node. |
friend class PluginManager [friend] |
friend class PluginManagerBase [friend] |
PluginManager* libglass::PluginBase::pm_parent [protected] |