11 , d_numMessagesQueued(0)
12 , d_numTransmissions(0)
13 , d_isEnabled(VRPN_FALSE)
83 delete[]qm -> p.buffer;
96 fprintf(stderr,
"vrpn_RedundantTransmission::mainloop(): "
97 "serious internal error.\n");
112 timeval transmissionInterval)
125 vrpn_uint32 len, timeval time, vrpn_uint32 type, vrpn_uint32 sender,
126 const char *buffer, vrpn_uint32 class_of_service,
127 vrpn_int32 numTransmissions, timeval *transmissionInterval)
134 fprintf(stderr,
"vrpn_RedundantTransmission::pack_message: "
135 "Connection not defined!\n");
150 if (numTransmissions < 0) {
153 if (!transmissionInterval) {
161 if (!numTransmissions) {
167 if (!transmissionInterval->tv_sec && !transmissionInterval->tv_usec) {
168 for (i = 0; i < numTransmissions; i++) {
181 "vrpn_RedundantTransmission::pack_message: "
182 "Out of memory; can't queue message for retransmission.\n");
190 try { qm->
p.
buffer =
new char[len]; }
193 "vrpn_RedundantTransmission::pack_message: "
194 "Out of memory; can't queue message for retransmission.\n");
197 memcpy(
const_cast<char *
>(qm->
p.
buffer), buffer, len);
224 buflen =
sizeof(vrpn_uint32) +
sizeof(timeval);
226 try { buffer =
new char[buflen]; }
228 fprintf(stderr,
"vrpn_RedundantController_Protocol::encode_set: "
254 buflen =
sizeof(vrpn_bool);
256 try { buffer =
new char[buflen]; }
258 fprintf(stderr,
"vrpn_RedundantController_Protocol::encode_enable: "
316 const char **bp = &p.
buffer;
331 const char **bp = &p.
buffer;
399 : nextTimestampToReplace(0)
401 , handlerIsRegistered(vrpn_FALSE)
436 pVMCB = pVMCB_Del->
next;
440 fprintf(stderr,
"vrpn_RedundantReceiver::~vrpn_RedundantReceiver(): delete failed\n");
450 pVMCB = pVMCB_Del->
next;
454 fprintf(stderr,
"vrpn_RedundantReceiver::~vrpn_RedundantReceiver(): delete failed\n");
467 void *userdata, vrpn_int32 sender)
472 fprintf(stderr,
"vrpn_RedundantReceiver::register_handler: "
484 }
else if (type < 0) {
485 fprintf(stderr,
"vrpn_RedundantReceiver::register_handler: "
486 "Negative type passed in.\n");
490 fprintf(stderr,
"vrpn_RedundantReceiver::register_handler(): delete failed\n");
499 if (!
d_records[type].handlerIsRegistered) {
526 while ((victim != NULL) &&
528 (victim->
sender != sender))) {
529 snitch = &((*snitch)->next);
530 victim = victim->
next;
534 if (victim == NULL) {
536 "vrpn_TypeDispatcher::removeHandler: No such handler\n");
541 *snitch = victim->
next;
545 fprintf(stderr,
"vrpn_RedundantReceiver::unregister_handler(): delete failed\n");
560 fprintf(stderr,
"vrpn_RedundantReceiver::writeMemory: "
561 "Memory is empty.\n");
571 fp = fopen(filename,
"wb");
573 fprintf(stderr,
"vrpn_RedundantReceiver::writeMemory: "
574 "Couldn't open %s for writing.\n",
580 fprintf(fp,
"%ld.%ld %d\n", mp->
timestamp.tv_sec,
596 fprintf(stderr,
"vrpn_RedundantReceiver::clearMemory(): delete failed\n");
644 "vrpn_RedundantReceiver::"
645 "handle_possiblyRedundantMessage: Out of memory.\n");
670 fprintf(stderr,
"vrpn_RedundantReceiver::"
671 "handle_possiblyRedundantMessage: "
672 "Nonzero user generic handler return.\n");
682 fprintf(stderr,
"vrpn_RedundantReceiver::"
683 "handle_possiblyRedundantMessage: "
684 "Nonzero user handler return.\n");
int register_autodeleted_handler(vrpn_int32 type, vrpn_MESSAGEHANDLER handler, void *userdata, vrpn_int32 sender=vrpn_ANY_SENDER)
Registers a handler with the connection, and remembers to delete at destruction.
vrpn_Connection * d_connection
Connection that this object talks to.
void client_mainloop(void)
Handles functions that all clients should provide in their mainloop() (warning of no server,...
vrpn_int32 d_sender_id
Sender ID registered with the connection.
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
Class from which all user-level (and other) classes that communicate with vrpn_Connections should der...
virtual int init(void)
Initialize things that the constructor can't. Returns 0 on success, -1 on failure.
Generic connection class not specific to the transport mechanism.
void addReference()
Counting references to this connection.
virtual vrpn_int32 register_message_type(const char *name)
virtual int send_pending_reports(void)=0
send pending report, clear the buffer. This function was protected, now is public,...
virtual int pack_message(vrpn_uint32 len, struct timeval time, vrpn_int32 type, vrpn_int32 sender, const char *buffer, vrpn_uint32 class_of_service)
Pack a message that will be sent the next time mainloop() is called. Turn off the RELIABLE flag if yo...
virtual int register_handler(vrpn_int32 type, vrpn_MESSAGEHANDLER handler, void *userdata, vrpn_int32 sender=vrpn_ANY_SENDER)
Set up (or remove) a handler for a message of a given type. Optionally, specify which sender to handl...
Accepts commands over a connection to control a local vrpn_RedundantTransmission's default parameters...
~vrpn_RedundantController(void)
virtual int register_types(void)
Register the types of messages this device sends/receives. Return 0 on success, -1 on fail.
void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
static int VRPN_CALLBACK handle_enable(void *, vrpn_HANDLERPARAM)
vrpn_RedundantController(vrpn_RedundantTransmission *, vrpn_Connection *)
vrpn_RedundantTransmission * d_object
vrpn_RedundantController_Protocol d_protocol
static int VRPN_CALLBACK handle_set(void *, vrpn_HANDLERPARAM)
Helper class that eliminates duplicates; only the first instance of a message is delivered....
vrpn_RedundantReceiver(vrpn_Connection *)
void clearMemory(void)
Throws away / resets statistics.
RRRecord d_records[vrpn_CONNECTION_MAX_TYPES]
virtual ~vrpn_RedundantReceiver(void)
void writeMemory(const char *filename)
Writes statistics to the named file: timestamp of every message received and number of copies of that...
virtual int unregister_handler(vrpn_int32 type, vrpn_MESSAGEHANDLER handler, void *userdata, vrpn_int32 sender=vrpn_ANY_SENDER)
void record(vrpn_bool)
Turns "memory" (tracking statistics of redundant reception) on and off.
virtual int register_handler(vrpn_int32 type, vrpn_MESSAGEHANDLER handler, void *userdata, vrpn_int32 sender=vrpn_ANY_SENDER)
static int VRPN_CALLBACK handle_possiblyRedundantMessage(void *, vrpn_HANDLERPARAM)
vrpn_Connection * d_connection
void set(int numRetransmissions, timeval transmissionInterval)
vrpn_RedundantController_Protocol d_protocol
int register_types(void)
Register the types of messages this device sends/receives. Return 0 on success, -1 on fail.
~vrpn_RedundantRemote(void)
void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_RedundantRemote(vrpn_Connection *)
Helper class for vrpn_Connection that automates redundant transmission for unreliable (low-latency) m...
vrpn_uint32 defaultRetransmissions(void) const
virtual ~vrpn_RedundantTransmission(void)
timeval defaultInterval(void) const
virtual int pack_message(vrpn_uint32 len, timeval time, vrpn_uint32 type, vrpn_uint32 sender, const char *buffer, vrpn_uint32 class_of_service, vrpn_int32 numRetransmissions=-1, timeval *transmissionInterval=NULL)
If !isEnabled(), does a normal pack_message(), but if isEnabled() ignores class_of_service and sends ...
virtual void mainloop(void)
Determines which messages need to be resent and queues them up on the connection for transmission.
vrpn_Connection * d_connection
vrpn_RedundantTransmission(vrpn_Connection *c)
timeval d_transmissionInterval
vrpn_uint32 d_numTransmissions
vrpn_bool isEnabled(void) const
queuedMessage * d_messageList
vrpn_uint32 d_numMessagesQueued
For debugging, mostly.
virtual void setDefaults(vrpn_uint32 numRetransmissions, timeval transmissionInterval)
Set default values for future calls to pack_message().
Description of a callback entry for a user type.
vrpnMsgCallbackEntry * next
Next handler.
void * userdata
Passed along.
vrpn_int32 sender
Only if from sender.
vrpn_MESSAGEHANDLER handler
Routine to call.
This structure is what is passed to a vrpn_Connection message callback.
char * encode_set(int *len, vrpn_uint32 num, timeval interval)
void register_types(vrpn_Connection *)
void decode_enable(const char **buf, vrpn_bool *)
char * encode_enable(int *len, vrpn_bool)
void decode_set(const char **buf, vrpn_uint32 *num, timeval *interval)
vrpnMsgCallbackEntry * cb
int numSeen[VRPN_RR_LENGTH]
vrpn_bool handlerIsRegistered
timeval timestampSeen[VRPN_RR_LENGTH]
int nextTimestampToReplace
timeval transmissionInterval
vrpn_uint32 remainingTransmissions
const vrpn_uint32 vrpn_CONNECTION_RELIABLE
Classes of service for messages, specify multiple by ORing them together Priority of satisfying these...
const int vrpn_ANY_SENDER
vrpn_ANY_SENDER can be used to register callbacks on a given message type from any sender.
const int vrpn_ANY_TYPE
vrpn_ANY_TYPE can be used to register callbacks for any USER type of message from a given sender....
int(VRPN_CALLBACK * vrpn_MESSAGEHANDLER)(void *userdata, vrpn_HANDLERPARAM p)
Type of a message handler for vrpn_Connection messages.
const int vrpn_CONNECTION_MAX_TYPES
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
VRPN_API int vrpn_unbuffer(const char **buffer, timeval *t)
Utility routine for taking a struct timeval from a buffer that was sent as a message.
bool vrpn_TimevalGreater(const timeval &tv1, const timeval &tv2)
VRPN_API int vrpn_buffer(char **insertPt, vrpn_int32 *buflen, const timeval t)
Utility routine for placing a timeval struct into a buffer that is to be sent as a message.
timeval vrpn_TimevalSum(const timeval &tv1, const timeval &tv2)
#define vrpn_gettimeofday