11 , d_numMessagesQueued(0)
12 , d_numTransmissions(0)
13 , d_isEnabled(VRPN_FALSE)
83 delete[](
char *)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");
193 "vrpn_RedundantTransmission::pack_message: " 194 "Out of memory; can't queue message for retransmission.\n");
197 memcpy((
char *)qm->
p.
buffer, buffer, len);
224 buflen =
sizeof(vrpn_uint32) +
sizeof(timeval);
226 buffer =
new char[buflen];
228 fprintf(stderr,
"vrpn_RedundantController_Protocol::encode_set: " 254 buflen =
sizeof(vrpn_bool);
256 buffer =
new char[buflen];
258 fprintf(stderr,
"vrpn_RedundantController_Protocol::encode_enable: " 316 const char **bp = &p.
buffer;
331 const char **bp = &p.
buffer;
398 : nextTimestampToReplace(0)
400 , handlerIsRegistered(vrpn_FALSE)
435 pVMCB = pVMCB_Del->
next;
444 pVMCB = pVMCB_Del->
next;
456 void *userdata, vrpn_int32 sender)
460 fprintf(stderr,
"vrpn_RedundantReceiver::register_handler: " 475 fprintf(stderr,
"vrpn_RedundantReceiver::register_handler: " 476 "Negative type passed in.\n");
484 if (!
d_records[type].handlerIsRegistered) {
511 while ((victim != NULL) &&
513 (victim->
sender != sender))) {
514 snitch = &((*snitch)->next);
515 victim = victim->
next;
519 if (victim == NULL) {
521 "vrpn_TypeDispatcher::removeHandler: No such handler\n");
526 *snitch = victim->
next;
540 fprintf(stderr,
"vrpn_RedundantReceiver::writeMemory: " 541 "Memory is empty.\n");
551 fp = fopen(filename,
"wb");
553 fprintf(stderr,
"vrpn_RedundantReceiver::writeMemory: " 554 "Couldn't open %s for writing.\n",
560 fprintf(fp,
"%ld.%ld %d\n", mp->
timestamp.tv_sec,
619 "vrpn_RedundantReceiver::" 620 "handle_possiblyRedundantMessage: Out of memory.\n");
645 fprintf(stderr,
"vrpn_RedundantReceiver::" 646 "handle_possiblyRedundantMessage: " 647 "Nonzero user generic handler return.\n");
657 fprintf(stderr,
"vrpn_RedundantReceiver::" 658 "handle_possiblyRedundantMessage: " 659 "Nonzero user handler return.\n");
void clearMemory(void)
Throws away / resets statistics.
timeval defaultInterval(void) const
vrpn_bool isEnabled(void) const
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
const int vrpn_ANY_TYPE
vrpn_ANY_TYPE can be used to register callbacks for any USER type of message from a given sender...
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
void register_types(vrpn_Connection *)
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.
static int VRPN_CALLBACK handle_enable(void *, vrpn_HANDLERPARAM)
void record(vrpn_bool)
Turns "memory" (tracking statistics of redundant reception) on and off.
vrpn_RedundantController_Protocol d_protocol
const vrpn_uint32 vrpn_CONNECTION_RELIABLE
Classes of service for messages, specify multiple by ORing them together Priority of satisfying these...
Description of a callback entry for a user type.
int nextTimestampToReplace
void client_mainloop(void)
Handles functions that all clients should provide in their mainloop() (warning of no server...
virtual int register_handler(vrpn_int32 type, vrpn_MESSAGEHANDLER handler, void *userdata, vrpn_int32 sender=vrpn_ANY_SENDER)
virtual int unregister_handler(vrpn_int32 type, vrpn_MESSAGEHANDLER handler, void *userdata, vrpn_int32 sender=vrpn_ANY_SENDER)
vrpn_Connection * d_connection
int register_types(void)
Register the types of messages this device sends/receives. Return 0 on success, -1 on fail...
static int VRPN_CALLBACK handle_set(void *, vrpn_HANDLERPARAM)
timeval transmissionInterval
virtual int send_pending_reports(void)=0
send pending report, clear the buffer. This function was protected, now is public, so we can use it to send out intermediate results without calling mainloop
queuedMessage * d_messageList
vrpn_uint32 remainingTransmissions
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 ...
~vrpn_RedundantController(void)
vrpn_bool handlerIsRegistered
Generic connection class not specific to the transport mechanism.
virtual int register_types(void)
Register the types of messages this device sends/receives. Return 0 on success, -1 on fail...
vrpn_MESSAGEHANDLER handler
Routine to call.
vrpn_RedundantTransmission(vrpn_Connection *c)
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...
char * encode_enable(int *len, vrpn_bool)
vrpn_uint32 d_numTransmissions
int(VRPN_CALLBACK * vrpn_MESSAGEHANDLER)(void *userdata, vrpn_HANDLERPARAM p)
Type of a message handler for vrpn_Connection messages.
Accepts commands over a connection to control a local vrpn_RedundantTransmission's default parameters...
void decode_enable(const char **buf, vrpn_bool *)
Helper class that eliminates duplicates; only the first instance of a message is delivered. Registers a callback on connection for any type it's told to monitor; when it gets a message back, checks its list of recently-seen-timestamps for that type; if it isn't on the list, it's dispatched and replaces the oldest item on the list. List length is limited, so if too many messages of the same type (more than VRPN_RR_LENGTH) are interleaved - if transmissionInterval * numRetransmissions > VRPN_RR_LENGTH * the normal rate of message generation - it will not detect the redundant messages.
RRRecord d_records[vrpn_CONNECTION_MAX_TYPES]
~vrpn_RedundantRemote(void)
virtual int init(void)
Initialize things that the constructor can't. Returns 0 on success, -1 on failure.
vrpn_Connection * d_connection
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.
void set(int numRetransmissions, timeval transmissionInterval)
static int VRPN_CALLBACK handle_possiblyRedundantMessage(void *, vrpn_HANDLERPARAM)
timeval d_transmissionInterval
vrpn_Connection * d_connection
Connection that this object talks to.
This structure is what is passed to a vrpn_Connection message callback.
vrpn_uint32 defaultRetransmissions(void) const
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...
void * userdata
Passed along.
vrpn_int32 sender
Only if from sender.
bool vrpn_TimevalGreater(const timeval &tv1, const timeval &tv2)
virtual void mainloop(void)
Determines which messages need to be resent and queues them up on the connection for transmission...
vrpn_RedundantController_Protocol d_protocol
void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_RedundantController(vrpn_RedundantTransmission *, vrpn_Connection *)
vrpn_RedundantRemote(vrpn_Connection *)
const int vrpn_CONNECTION_MAX_TYPES
~vrpn_RedundantTransmission(void)
virtual void setDefaults(vrpn_uint32 numRetransmissions, timeval transmissionInterval)
Set default values for future calls to pack_message().
#define vrpn_gettimeofday
int numSeen[VRPN_RR_LENGTH]
void decode_set(const char **buf, vrpn_uint32 *num, timeval *interval)
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...
vrpn_RedundantReceiver(vrpn_Connection *)
void writeMemory(const char *filename)
Writes statistics to the named file: timestamp of every message received and number of copies of that...
Class from which all user-level (and other) classes that communicate with vrpn_Connections should der...
~vrpn_RedundantReceiver(void)
vrpn_RedundantTransmission * d_object
vrpnMsgCallbackEntry * cb
vrpnMsgCallbackEntry * next
Next handler.
vrpn_int32 d_sender_id
Sender ID registered with the connection.
char * encode_set(int *len, vrpn_uint32 num, timeval interval)
void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
void addReference()
Counting references to this connection.
timeval vrpn_TimevalSum(const timeval &tv1, const timeval &tv2)
Helper class for vrpn_Connection that automates redundant transmission for unreliable (low-latency) m...
vrpn_uint32 d_numMessagesQueued
For debugging, mostly.
virtual vrpn_int32 register_message_type(const char *name)
const int vrpn_ANY_SENDER
vrpn_ANY_SENDER can be used to register callbacks on a given message type from any sender...
timeval timestampSeen[VRPN_RR_LENGTH]