VRPN 06.04

VRPN main page

Obtaining VRPN

VRPN Support

Installing and Testing

Compiling and Modifying

Client code

Server code

Troubleshooting

Connections

Logging and Playback

Shared Objects

Sound

Clock Synchronization

Text Messages

Doxygen documentation

VRPN on PDAs

Coming attractions & suggestions

UNC-specific information

Registering a type

The type field in a message specifies the kind of message being sent. Like the sender field, this can be thought of as a channel descriptor. Types are defined to a vrpn_Connection by a string name; the connection reports a token (a long integer) that is to be used to refer to that type when sending and receiving messages. Examples of types are, "Button Toggle" and "Tracker Pos/Quat". A device can get a token for a given type by calling:

long vrpn_Connection::register_message_type(char *name);

For example, a program could open a listening connection and then describe a new type called "Test_type" by doing the following:

	vrpn_Connection *connection = new vrpn_Connection();
	long my_type = connection->register_message_type("Test_type");

The identifier my_type could then be used as the type field to send a message or to register a message handler.

Each vrpn_Connection object maintains a list of types that have been registered with it. When a link is established between two connections, each describes its mapping from strings to tokens to the other. Each vrpn_Connection maintains a table that it uses to translate the type field coming across the link into its local value before delivering the message. This allows each connection object to allocate its own list of type-to-token mappings independently.

This string-to-token mapping is done for two efficiency reasons. Firstly, it allows the connection to avoid doing string-matching to determine what to do with a given message. Second, it reduces the bandwidth sent over the link between connections (for names longer than 4 characters). Strings are used to give the device classes and user code flexibility in defining type names.