Main Page   Modules   Namespace List   Class Hierarchy   Compound List   Namespace Members   Compound Members   Related Pages  

GNE::NetworkObject Class Reference
[High-Level API]

#include <NetworkObject.h>

List of all members.

Public Member Functions

 NetworkObject ()
 Initializes this NetworkObject to have an invalid (unassigned) ID.

 NetworkObject (int objectId)
 Initializes this NetworkObject to have the given object ID.

 NetworkObject (const NetworkObject &o)
 Copies from the given NetworkObject, but does NOT copy the object ID! Instead, an invalid object ID is assigned to this object.

NetworkObject & operator= (const NetworkObject &rhs)
 Care must be taken with this operator, because an object must be unregistered with the ObjectBroker.

int getObjectId () const
 Returns the objectID for this object.

bool hasValidId () const
 Returns true if this NetworkObject has a valid ID, which implies that is currently under the management of an ObjectBroker.

virtual PacketcreateCreationPacket ()=0
 This method will be called when the remote side has not seen this object before, and a Packet needs to be created that will completely express this object so that it can be created on the remote side.

virtual PacketcreateUpdatePacket (const void *param)=0
 The remote side has already seen this object before, and has created it already, but a Packet is desired to send to the remote object so that it may update its copy with new information.

virtual PacketcreateDeathPacket ()=0
 When this object is released from the ObjectBroker system, it may want to send a death packet if the remote end needs to know when an object dies.

virtual void onDeregistration (int oldId)
 An optional event called when the object has been deregistered, and has lost its ID.

virtual void incomingUpdatePacket (const Packet &packet)=0
 This method is called by the ObjectBroker when it receives an ObjectUpdatePacket for this object.

virtual void incomingDeathPacket (const Packet *packet)=0
 This method is called by the ObjectBroker when it receives an ObjectDeathPacket, and it is releasing the object from its control.


Friends

class ObjectBroker


Detailed Description

Represents an object which can be replicated through the ObjectBroker. All of these methods should be called through the ObjectBroker, but it is acceptable to call createCreationPacket, createUpdatePacket, incomingUpdatePacket, and createDeathPacket once ObjectBroker has called createCreationPacket for the first time (and therefore assigned this object an ID).


Constructor & Destructor Documentation

GNE::NetworkObject::NetworkObject const NetworkObject &  o  ) 
 

Copies from the given NetworkObject, but does NOT copy the object ID! Instead, an invalid object ID is assigned to this object.

This must be done because two objects cannot share an object ID.


Member Function Documentation

virtual Packet* GNE::NetworkObject::createCreationPacket  )  [pure virtual]
 

This method will be called when the remote side has not seen this object before, and a Packet needs to be created that will completely express this object so that it can be created on the remote side.

The type of packet used to create an object must always be the same, because the ObjectBroker looks up the object creation method based on the packet type ID.

The object ID for this object will be set, and available for viewing with the getObjectID method when this method is called. It must be called through the ObjectBroker.

The object returned should be a new Packet, for which GNE will become responsible for deallocating the object.

virtual Packet* GNE::NetworkObject::createDeathPacket  )  [pure virtual]
 

When this object is released from the ObjectBroker system, it may want to send a death packet if the remote end needs to know when an object dies.

Sometimes creating a death packet is optional if the server and client both agree that the object will die at a certain time (for example if an object has a finite lifetime). Even if a death packet is needed, it may not need any associated data, so this method may return NULL if no additional information is needed with the DeathPacket.

This method may be called zero or more times before getting deregistered from the ObjectBroker system, depending on the need for ObjectDeathPackets for this NetworkObject.

The object returned should be a new Packet, or a NULL pointer, for which GNE will become responsible for deallocating the object.

virtual Packet* GNE::NetworkObject::createUpdatePacket const void *  param  )  [pure virtual]
 

The remote side has already seen this object before, and has created it already, but a Packet is desired to send to the remote object so that it may update its copy with new information.

Unlike the createCreationPacket method, the Packet returned by this method may be of any type, and the type of Packet returned need not be consistant, since object updates are routed by object ID rather than by packet ID.

The parameter given to this function exists to give the update function a context if desired. For example an update packet for only a certain part of the data may be desired.

The object returned should be a new Packet, for which GNE will become responsible for deallocating the object.

int GNE::NetworkObject::getObjectId  )  const
 

Returns the objectID for this object.

IDs are always positive. A negative value is an invalid ID, and means that this object has not yet been given an ID by the ObjectBroker.

virtual void GNE::NetworkObject::incomingDeathPacket const Packet packet  )  [pure virtual]
 

This method is called by the ObjectBroker when it receives an ObjectDeathPacket, and it is releasing the object from its control.

An ObjectDeathPacket may or may not have a Packet of associated data with it, so the passed pointer may be NULL.

After the incomingDeathPacket event, an onDeregistration event is immediately generated.

void GNE::NetworkObject::onDeregistration int  oldId  )  [virtual]
 

An optional event called when the object has been deregistered, and has lost its ID.

This event is triggered on both the "server" and the "client" sides. This will be the last event called on this object from the ObjectBroker.

On the "server" side, this event is called after any possible createDeathPacket calls. On the "client" side, this event always immedately follows incomingDeathPacket.

The objectID for this object has been set to an invalid ID, indicating it has been released from the ObjectBroker. The ID that this object used to have is passed in the parameter oldId.

Once this method is called by the ObjectBroker, it will never access this object again, and any references to this object are dropped, so after this method, you may feel free to delete this object at any time.

The default behavior for this event is to do nothing.

Parameters:
oldId the ID this object used to have.

NetworkObject & GNE::NetworkObject::operator= const NetworkObject &  rhs  ) 
 

Care must be taken with this operator, because an object must be unregistered with the ObjectBroker.

Therefore, this object retains its old object ID.


The documentation for this class was generated from the following files:
Generated on Fri Aug 22 13:40:06 2003 for GNE by doxygen1.3