#include <ObjectBrokerClient.h>
Inheritance diagram for GNE::ObjectBrokerClient:
Public Member Functions | |
ObjectBrokerClient () | |
Default ctor. | |
~ObjectBrokerClient () | |
Default dtor. | |
NetworkObject * | usePacket (const Packet &packet, bool ignoreUpdateError) |
NetworkObject & | usePacket (const Packet &packet) |
Calls usePacket( const Packet&, bool ) with the second parameter as being false, thus this method always returns a valid NetworkObject reference, or throws an exception. | |
Static Public Member Functions | |
void | registerObject (guint8 id, ObjCreationFunc createFunc) |
Registers a new object type with the ObjectBrokerClient by relating a packet ID with a function that creates a NetworkObject. | |
Friends | |
bool | GNE::initGNE (NLenum, int(*)(void(*)(void)), int) |
|
Registers a new object type with the ObjectBrokerClient by relating a packet ID with a function that creates a NetworkObject. This is similar to PacketParser::registerPacket. While it is intended that a single creation function associated with a packet ID returns always the same type of object, this is by no means a requirement of the creation function -- it may return different subclasses of NetworkObjects different times it is called. This can be useful if the same packet type might describe a few very similar types of objects, or if there are more types of objects than there exist packet IDs.
|
|
If the passed packet is an ObjectCreationPacket, a new object is created with the registered create function and returned. If an object with the ID already exists, then an Error is thrown with code Error::DuplicateObjectID. If the packet type used to create the object has not been registered, then an Error with the ID Error::InvalidCreationPacketType is thrown. If the passed packet is an ObjectUpdatePacket, the specified object is given the packet to update itself with, and that object is returned. If no objects with the ID in the packet exist, an Error is thrown with code Error::UnknownObjectId. If ignoreUpdateError is set to true, then NULL instead is returned, and no action is taken on the packet. This particular flag is useful, because if updates are sent unreliably, then it is possible for an update for an object to arrive BEFORE its creation packet. If the passed packet is an ObjectDeathPacket, the specified object's incomingDeathPacket and onDeregistration events are called, and that object is returned. If no objects with the ID in the packet exist, an Error is thrown with code Error::UnknownObjectId. If the passed packet is not any one of these types, then an Error with code Error::InvalidObjectPacket is thrown. In all cases, either a valid NetworkObject is returned, or an Error is thrown. The single exception is that NULL can be returned if ignoreUpdateError is passed as true, and ObjectUpdatePacket processing failed because of an unknown packet ID, which should be the only typical error case. |