GNE  0.75.0
GNE::ObjectBrokerServer Class Reference

The ObjectBrokerServer assigns IDs to NetworkObject objects, and aids in the creation of ObjectBrokerPacket packets. More...

#include <ObjectBrokerServer.h>

Inheritance diagram for GNE::ObjectBrokerServer:
GNE::ObjectBroker

Public Member Functions

 ObjectBrokerServer ()
 Creates a new ObjectBrokerServer Object with no taken IDs.
 ~ObjectBrokerServer ()
 Dtor.
ObjectCreationPacket::sptr getCreationPacket (NetworkObject &obj)
 Method for registering a new object, or getting a creation packet from an already registered object.
ObjectUpdatePacket::sptr getUpdatePacket (NetworkObject &obj, const void *param)
 Returns an ObjectUpdatePacket for the given object.
ObjectUpdatePacket::sptr getUpdatePacket (NetworkObject &obj)
 Same as ObjectBrokerServer::getUpdatePacket( NetworkObject&, const void* ), but passes in NULL as the const void* parameter.
ObjectDeathPacket::sptr getDeathPacket (NetworkObject &obj)
 Creates an ObjectDeathPacket for the given object, but does NOT unregister the object, in case additional death packets need to be created (to send to other, multiple clients).
- Public Member Functions inherited from GNE::ObjectBroker
int numObjects () const
 Returns the number of objects currently being managed by this ObjectBroker.
NetworkObjectgetObjectById (int objId)
 Returns the NetworkObject currently registered with the given object ID.
void deregisterObject (NetworkObject &obj)
 Deregisters the given object entirely from the ObjectBroker.

Additional Inherited Members

- Protected Types inherited from GNE::ObjectBroker
typedef std::map< int,
NetworkObject * > 
ObjectsMap
typedef std::map< int,
NetworkObject * >::iterator 
ObjectsIter
- Protected Member Functions inherited from GNE::ObjectBroker
bool exists (int objId)
 Returns true if the object ID given exists.
void assignId (NetworkObject &o, int newId)
 Assigns the given ID to the object.
- Protected Attributes inherited from GNE::ObjectBroker
Mutex sync
ObjectsMap objects
 Associates an integer object ID to a NetworkObject.

Detailed Description

The ObjectBrokerServer assigns IDs to NetworkObject objects, and aids in the creation of ObjectBrokerPacket packets.

When a new object is registered with the broker, a new, unique, ID is assigned to that NetworkObject and that ID is marked as a taken ID until it is unregistered.

The packets that the ObjectBrokerServer returns about a particular object must be sent to the clients in the same order that ObjectBrokerServer gives them to you based on the API calls. This is fairly self-evident, but this means that the ObjectCreationPacket must be sent before ObjectUpdatePacket packets and those before ObjectDeathPacket packets. In order to guarantee this, the creation and death packets must be sent reliably. Update packets may be sent unreliably, but you must be prepared for the scenario that the update packet arrives before the creation packet, and will probably need to be ignored. This is possible because the reliable and unreliable packet streams in GNE may be unrelated, and have no guaranteed order in relation to each other.

There are 65535 available object IDs, so you cannot have more objects than that.

Almost all methods return a smart pointer to a packet, which means you do not need worry about memory allocation.

Member Function Documentation

ObjectCreationPacket::sptr GNE::ObjectBrokerServer::getCreationPacket ( NetworkObject obj)

Method for registering a new object, or getting a creation packet from an already registered object.

If the given object has an ID, a new ObjectCreationPacket is generated. A new ID is assigned automatically if the given object does not have an ID.

If no IDs remain because there are too many objects, then a NULL pointer is returned.

ObjectDeathPacket::sptr GNE::ObjectBrokerServer::getDeathPacket ( NetworkObject obj)

Creates an ObjectDeathPacket for the given object, but does NOT unregister the object, in case additional death packets need to be created (to send to other, multiple clients).

Parameters
obja valid NetworkObject (one that has been assigned a valid ID through getCreationPacket).
ObjectUpdatePacket::sptr GNE::ObjectBrokerServer::getUpdatePacket ( NetworkObject obj,
const void *  param 
)

Returns an ObjectUpdatePacket for the given object.

The passed parameter, param, is passed directly into the NetworkObject's createUpdatePacket method.

See Also
NetworkObject::createUpdatePacket
ObjectUpdatePacket::sptr GNE::ObjectBrokerServer::getUpdatePacket ( NetworkObject obj)

Same as ObjectBrokerServer::getUpdatePacket( NetworkObject&, const void* ), but passes in NULL as the const void* parameter.

Parameters
obja valid NetworkObject (one that has been assigned a valid ID through getCreationPacket).

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