libglass::Glass Class Reference

#include <glass.h>

Inheritance diagram for libglass::Glass:

libglass::GlassClient libglass::GlassServer libglass::GlassServerPeer

List of all members.

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
PluginBasegetPlugin (PluginId id) const
PluginManagergetPluginManager (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

Protocolprotocol
nodeId id
PluginManagerpm
boost::thread::id pt_id
std::map< nodeFD, nodeIdfdtoidmap
std::map< nodeId, nodeFDidtofdmap
std::map< nodeId, nodeRelationidtorelation

Friends

class GlassManager
class PluginInterface
class PluginManager
class Protocol


Detailed Description

Definition at line 47 of file glass.h.


Constructor & Destructor Documentation

libglass::Glass::Glass ( Protocol p  )  throw (Exception)

virtual libglass::Glass::~Glass (  )  [virtual]


Member Function Documentation

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.

virtual nodeId libglass::Glass::FDToId ( nodeFD  fd  )  [protected, virtual]

Converts a nodeFD to a nodeId.

Parameters:
fd The node fd.
Returns:
The associated nodeId, or nobodyId if none found.
See also:
IdToFD.

nodeId libglass::Glass::getNodeId ( void   )  const

Returns this node's Id.

Returns:
This node's Id.

nodeRelation libglass::Glass::getNodeRelation ( nodeId  id  )  const

Returns the relationship with a given node.

Parameters:
id The other node's id.
Returns:
The relationship of the node id with this one. That is, if this node is the Server and id is the Client, returns Client.

PluginBase* libglass::Glass::getPlugin ( PluginId  id  )  const [protected]

Returns a plugin given its id.

Parameters:
id The plugin id.
Returns:
The plugin, or NULL if not found.
See also:
getPluginManager().

PluginManager* libglass::Glass::getPluginManager ( void   )  const [protected]

Returns our plugin manager.

Returns:
Our plugin manager.
See also:
getPlugin().

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.

Returns:
The number of nodes connected to the network, or zero if could not get it. See the derived class documentation for a more complete description.

Reimplemented in libglass::GlassClient, and libglass::GlassServer.

virtual nodeFD libglass::Glass::IdToFD ( nodeId  id  )  [protected, virtual]

Converts a nodeId to a nodeFD.

Parameters:
id The node id.
Returns:
The associated nodeFD.
See also:
FDToId.

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.

Parameters:
p The packet to send.
rootOnly Only process root packets; other packets are ignored.
Return values:
true If packet was correctly processed.
false If an error occurred while processing packet or if a non-root packet was ignored.

virtual nodeId libglass::Glass::registerNode ( nodeFD  fd  )  [protected, pure virtual]

Registers a node.

Parameters:
fd A valid node descriptor.
Returns:
A new node Id, or nobodyId if an error occurred.
See also:
unregisterNode().

Implemented in libglass::GlassClient, and libglass::GlassServer.

virtual bool libglass::Glass::rootPacket ( Packet p  )  [protected, pure virtual]

Responsible for processing

Parameters:
p The packet to process.
Return values:
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.

Parameters:
p The packet to send.
Return values:
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.

See also:
lockCurrent(), unlockCurrent().

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.

Parameters:
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.
Return values:
true if association was ok.
false if an error ocurred.
See also:
registerNode(), setRelation().

virtual bool libglass::Glass::setRelation ( nodeId  id,
nodeRelation  r 
) [protected, virtual]

Changes a node relationship.

Parameters:
id The node id.
r The relationship of the node.
Return values:
true If successful.
false If an error occurred (id or r invalid).
See also:
registerNode(), unregisterNode(), setNode().

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.

Parameters:
id The node id.
Return values:
True if successful.
False if not in list.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
fd The node fd.

Reimplemented in libglass::GlassServer.


Friends And Related Function Documentation

friend class GlassManager [friend]

Definition at line 51 of file glass.h.

friend class PluginInterface [friend]

Definition at line 52 of file glass.h.

friend class PluginManager [friend]

Definition at line 53 of file glass.h.

friend class Protocol [friend]

Definition at line 54 of file glass.h.


Member Data Documentation

std::map<nodeFD, nodeId> libglass::Glass::fdtoidmap [protected]

a nodeFD to nodeId hash map

Definition at line 60 of file glass.h.

node id.

Definition at line 57 of file glass.h.

std::map<nodeId, nodeFD> libglass::Glass::idtofdmap [protected]

a nodeId to nodeFD hash map

Definition at line 61 of file glass.h.

Definition at line 62 of file glass.h.

our internal plugin manager

Definition at line 58 of file glass.h.

the protocol to use

Definition at line 56 of file glass.h.

boost::thread::id libglass::Glass::pt_id [protected]

thread id (used in multi-threaded programs)

Definition at line 59 of file glass.h.


The documentation for this class was generated from the following file:

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