#include <glass.h>
Public Member Functions | |
Glass (Protocol *p) throw (Exception) | |
virtual | ~Glass () |
nodeId | getNodeId (void) const |
nodeRelation | getNodeRelation (nodeId id) const |
void | setCurrent (void) |
void | lockCurrent (void) |
void | unlockCurrent (void) |
virtual unsigned int | getTotalNodes (void) |
Protected Member Functions | |
void | clean (void) |
virtual bool | processPacket (Packet &p, bool rootOnly=false) |
virtual bool | sendPacket (Packet &p) |
virtual bool | rootPacket (Packet &p)=0 |
PluginBase * | getPlugin (PluginId id) const |
PluginManager * | getPluginManager (void) const |
virtual nodeFD | IdToFD (nodeId id) |
virtual nodeId | FDToId (nodeFD fd) |
virtual nodeId | registerNode (nodeFD fd)=0 |
virtual bool | setNode (nodeFD fd, nodeId id, nodeRelation r, bool force=false) |
virtual bool | setRelation (nodeId id, nodeRelation r) |
virtual bool | unregisterNode (nodeId id) |
virtual bool | unregisterNode (nodeFD fd) |
Protected Attributes | |
Protocol * | protocol |
nodeId | id |
PluginManager * | pm |
boost::thread::id | pt_id |
std::map< nodeFD, nodeId > | fdtoidmap |
std::map< nodeId, nodeFD > | idtofdmap |
std::map< nodeId, nodeRelation > | idtorelation |
Friends | |
class | GlassManager |
class | PluginInterface |
class | PluginManager |
class | Protocol |
Definition at line 47 of file glass.h.
virtual libglass::Glass::~Glass | ( | ) | [virtual] |
void libglass::Glass::clean | ( | void | ) | [protected] |
This is a virtual destructor.
It exists to circumvent a C++ behaviour. What happens is this: when a Glass-derived class (let's call it GD) calls a destructor, it in turn calls Glass' destructor. So far so good; the problem is that Glass' destructor accesses some virtual functions that may have been overriden by GD. But, by this time, GD has been destroyed (or, at least, is not "seen" by Glass' destructor). So we have to do this "virtual destructor idiom".
Clean does not delete the protocol, so you may still send messages on your destructor after calling clean. This is useful for a swan's song.
You MUST call clean() in your GD destructor.
Converts a nodeFD to a nodeId.
fd | The node fd. |
nodeId libglass::Glass::getNodeId | ( | void | ) | const |
Returns this node's Id.
nodeRelation libglass::Glass::getNodeRelation | ( | nodeId | id | ) | const |
Returns the relationship with a given node.
id | The other node's id. |
PluginBase* libglass::Glass::getPlugin | ( | PluginId | id | ) | const [protected] |
Returns a plugin given its id.
id | The plugin id. |
PluginManager* libglass::Glass::getPluginManager | ( | void | ) | const [protected] |
virtual unsigned int libglass::Glass::getTotalNodes | ( | void | ) | [virtual] |
Returns the number of nodes connected to the network.
This is a virtual function. The default implementation returns 0. Most derived class will override this function.
This function may be slow, requiring a network transmission. The number of nodes may change at any time.
Important: The actual implementation in the derived class may choose to return the number of nodes of a certain type. For example, the client/server architecture returns the number of CLIENTS, which makes sense, since the server is not doing any computation on the application. So, refer to the documentation of the derived class to know exactly what you are getting.
Reimplemented in libglass::GlassClient, and libglass::GlassServer.
Converts a nodeId to a nodeFD.
id | The node id. |
void libglass::Glass::lockCurrent | ( | void | ) |
virtual bool libglass::Glass::processPacket | ( | Packet & | p, | |
bool | rootOnly = false | |||
) | [protected, virtual] |
Forwards the packet to the pluginManager, guaranteeing protectedness.
p | The packet to send. | |
rootOnly | Only process root packets; other packets are ignored. |
true | If packet was correctly processed. | |
false | If an error occurred while processing packet or if a non-root packet was ignored. |
Registers a node.
fd | A valid node descriptor. |
Implemented in libglass::GlassClient, and libglass::GlassServer.
virtual bool libglass::Glass::rootPacket | ( | Packet & | p | ) | [protected, pure virtual] |
Responsible for processing
p | The packet to process. |
True | on success. | |
False | . |
Implemented in libglass::GlassClient, and libglass::GlassServer.
virtual bool libglass::Glass::sendPacket | ( | Packet & | p | ) | [protected, virtual] |
Forwards the packet to the Protocol, guaranteeing protectedness. It is also responsible for translating the Packet's nodeIds to nodeFDs.
p | The packet to send. |
True | on success. | |
False | if packet couldn't be sent for some reason. |
Reimplemented in libglass::GlassClient, and libglass::GlassServer.
void libglass::Glass::setCurrent | ( | void | ) |
Sets this Glass instance as the current one.
virtual bool libglass::Glass::setNode | ( | nodeFD | fd, | |
nodeId | id, | |||
nodeRelation | r, | |||
bool | force = false | |||
) | [protected, virtual] |
Associates a given fd and id to each other, and the relationship.
fd | The node fd. | |
id | The node id. | |
r | The node relationship. | |
force | If true, associates even if the id or fd were already associated to others. Does not change the previous association. |
true | if association was ok. | |
false | if an error ocurred. |
virtual bool libglass::Glass::setRelation | ( | nodeId | id, | |
nodeRelation | r | |||
) | [protected, virtual] |
Changes a node relationship.
id | The node id. | |
r | The relationship of the node. |
true | If successful. | |
false | If an error occurred (id or r invalid). |
void libglass::Glass::unlockCurrent | ( | void | ) |
virtual bool libglass::Glass::unregisterNode | ( | nodeFD | fd | ) | [protected, virtual] |
Reimplemented in libglass::GlassServer.
bool libglass::Glass::unregisterNode | ( | nodeId | id | ) | [protected, virtual] |
Unregisters a id/fd association.
Unregisters the relationship too.
id | The node id. |
True | if successful. | |
False | if not in list. |
fd | The node fd. |
Reimplemented in libglass::GlassServer.
friend class PluginInterface [friend] |
friend class PluginManager [friend] |
std::map<nodeFD, nodeId> libglass::Glass::fdtoidmap [protected] |
nodeId libglass::Glass::id [protected] |
std::map<nodeId, nodeFD> libglass::Glass::idtofdmap [protected] |
std::map<nodeId, nodeRelation> libglass::Glass::idtorelation [protected] |
PluginManager* libglass::Glass::pm [protected] |
Protocol* libglass::Glass::protocol [protected] |
boost::thread::id libglass::Glass::pt_id [protected] |