Introduction Manual Class Reference Header Reference

Extended Object Information

Introduction

When an object is announced to a client, it might be necessary to have more information available than just a class ID. For these cases, it is possible to attach extended announcement data to a server node, which will always get sent along everytime this node is announced to a client.

Attaching The Data

Two things need to be done.

First, the class needs to be registered with the ZCOM_CLASSFLAG_ANNOUNCEDATA flag.

control->ZCom_registerClass("Rock", ZCOM_CLASSFLAG_ANNOUNCEDATA);

This flag needs to be present in the server and in the client registration of the class.

Second, the data needs to be set with ZCom_Node::setAnnounceData(), on the server only!

node->registerNodeDynamic(control->ZCom_getClassID("Rock"), control);
ZCom_BitStream *adata = new ZCom_BitStream();
if (rock_is_black)
  adata->addString("black");
else
  adata->addString("grey");
node->setAnnounceData(adata);

Whenever the node gets announced to a client through either ZCom_Control::ZCom_cbNodeRequest_Dynamic() or ZCom_Control::ZCom_cbNodeRequest_Tag(), the data that was set through setAnnounceData() is available in the _announcedata parameter of the two callbacks.

class Client : public ZCom_Control {
  void 
    ZCom_cbNodeRequest_Dynamic( ZCom_ConnID _id, ZCom_ClassID _requested_class, ZCom_BitStream *_announcedata,
                                eZCom_NodeRole _role, ZCom_NodeID _net_id ) 
    {
      if (_requested_class == Rock::getClassID())
      {
        const char *color = _announcedata->getStringStatic();
        Rock* rock = new Rock(this);
        // assuming a method like this exists
        rock->setColor(color);
      }
    }

  // all other callback methods omitted here
};

Of course, sending a string to declare a color is a waste of bandwidth. In practice, the data should be compact as possible.

Attention:
When ZCOM_CLASSFLAG_ANNOUNCEDATA is used, all nodes of this class must have announcedata available. Also, the clients must always read the correct amount of bits from the _announcedata stream. If they read more or fewer bits than were provided by setAnnounceData(), Zoidcom will be unable to extract any more data from the currently processed packet and possibly close the connection.

This file is part of the documentation for Zoidcom. Documentation copyright © 2004-2008 by Jörg Rüppel. Generated on Sat Aug 16 15:26:51 2008 for Zoidcom by doxygen 1.4.6-NO