vrpn
07.33
Virtual Reality Peripheral Network
|
Go to the documentation of this file.
18 : d_first_watched_object(NULL)
41 while (victim != NULL) {
75 "vrpn_TextPrinter::add_object(): NULL pointer passed\n");
81 printf(
"vrpn_TextPrinter: adding object %s\n", o->
d_servicename);
88 while (victim != NULL) {
94 victim = victim->
next;
99 fprintf(stderr,
"vrpn_TextPrinter::add_object(): out of memory\n");
113 "vrpn_TextPrinter::add_object(): Can't register callback\n");
138 printf(
"vrpn_TextPrinter: removing object %s\n", o->
d_servicename);
144 "vrpn_TextPrinter::remove_object(): NULL pointer passed\n");
155 while ((victim != NULL) &&
159 snitch = &((*snitch)->next);
160 victim = victim->
next;
164 if (victim != NULL) {
173 fprintf(stderr,
"vrpn_TextPrinter::remove_object(): Can't "
174 "unregister callback\n");
179 *snitch = victim->
next;
212 printf(
"vrpn_TextPrinter: text handler called\n");
222 message, &severity, &level, p.
buffer) != 0) {
225 "vrpn_TextPrinter::text_message_handler(): Can't decode message\n");
253 fprintf(me->
d_ostream,
"UNKNOWN SEVERITY\n");
257 fprintf(me->
d_ostream,
" (%d) from %s: %s\n", level,
319 if (firstTimeCalled) {
375 fprintf(stderr,
"vrpn_BaseClassUnique: Can't register IDs\n");
386 "vrpn_BaseClassUnique: Can't register Text type ID\n");
394 "vrpn_BaseClassUnique: Can't register ping type ID\n");
402 "vrpn_BaseClassUnique: Can't register pong type ID\n");
445 , d_servicename(NULL)
446 , d_num_autodeletions(0)
447 , d_first_mainloop(1)
448 , d_unanswered_ping(0)
452 d_time_first_ping.tv_sec = d_time_first_ping.tv_usec = 0;
466 for (i = 0; i < d_num_autodeletions; i++) {
468 d_handler_autodeletion_record[i].
type,
469 d_handler_autodeletion_record[i].
handler,
470 d_handler_autodeletion_record[i].
userdata,
471 d_handler_autodeletion_record[i].
sender);
473 d_num_autodeletions = 0;
509 fprintf(stderr,
"vrpn_BaseClassUnique::register_autodeleted_handler: "
510 "No vrpn_Connection.\n");
517 "vrpn_BaseClassUnique::register_autodeleted_handler: "
518 "Too many handlers registered. Increase vrpn_MAX_BCADRS "
519 "and recompile VRPN. Please report to vrpn@cs.unc.edu.\n");
524 d_handler_autodeletion_record[d_num_autodeletions].handler =
handler;
525 d_handler_autodeletion_record[d_num_autodeletions].sender =
sender;
526 d_handler_autodeletion_record[d_num_autodeletions].type =
type;
527 d_handler_autodeletion_record[d_num_autodeletions].userdata =
userdata;
528 d_num_autodeletions++;
539 vrpn_uint32 severity_as_uint = severity;
553 const char *bufptr = buf;
554 vrpn_uint32 severity_as_uint;
569 struct timeval timestamp,
574 size_t len = strlen(msg) + 1;
577 fprintf(stderr,
"vrpn_BaseClassUnique::send_message: Attempt to encode "
578 "string that is too long\n");
611 d_first_mainloop = 0;
658 handle_connection_dropped,
this);
661 initiate_ping_cycle();
664 d_first_mainloop = 0;
675 if (d_unanswered_ping) {
681 if (diff.tv_sec >= 1) {
689 d_time_last_warned = now;
693 if (diff.tv_sec >= 10) {
695 "No response from server for >= 10 seconds", now,
699 else if (diff.tv_sec >= 3) {
701 "No response from server for >= 3 seconds", now,
709 void vrpn_BaseClassUnique::initiate_ping_cycle(
void)
715 d_unanswered_ping = 1;
718 d_time_last_warned.tv_sec = d_time_last_warned.tv_usec = 0;
732 me->d_unanswered_ping = 0;
735 if (me->d_flatline) {
773 int vrpn_BaseClassUnique::handle_connection_dropped(
void *userdata,
779 if (me->d_unanswered_ping != 0) {
785 me->initiate_ping_cycle();
static int decode_text_message_from_buffer(char *msg, vrpn_TEXT_SEVERITY *severity, vrpn_uint32 *level, const char *buf)
Decodes the body of the text message from a buffer from the connection.
timeval vrpn_TimevalNormalize(const timeval &in_tv)
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.
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 client_mainloop(void)
Handles functions that all clients should provide in their mainloop() (warning of no server,...
vrpn_int32 d_ping_message_id
Ask the server if they are there.
const unsigned vrpn_MAX_TEXT_LEN
vrpn_Connection * vrpn_get_connection_by_name(const char *cname, const char *local_in_logfile_name, const char *local_out_logfile_name, const char *remote_in_logfile_name, const char *remote_out_logfile_name, const char *NIC_IPaddress, bool force_connection)
Create a client connection of arbitrary type (VRPN UDP/TCP, TCP, File, Loopback, MPI).
virtual const char * sender_name(vrpn_int32 sender)
Returns the name of the specified sender/type, or NULL if the parameter is invalid....
vrpn_TextPrinter vrpn_System_TextPrinter
Definition of the system TextPrinter object that prints messages for all created objects.
vrpn_uint32 d_level_to_print
Minimum level to print.
static int VRPN_CALLBACK text_message_handler(void *userdata, vrpn_HANDLERPARAM p)
Handles the text messages that come from the connections for objects we are watching.
vrpn_int32 d_text_message_id
ID for text messages.
virtual int register_senders(void)
Register the sender for this device (by default, the name of the device). Return 0 on success,...
void addReference()
Counting references to this 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.
vrpn_TEXT_SEVERITY d_severity_to_print
Minimum severity to print.
vrpn_Connection * d_connection
Connection that this object talks to.
static int encode_text_message_to_buffer(char *buf, vrpn_TEXT_SEVERITY severity, vrpn_uint32 level, const char *msg)
Encodes the body of the text message into a buffer, preparing for sending.
virtual vrpn_int32 register_message_type(const char *name)
timeval vrpn_TimevalDiff(const timeval &tv1, const timeval &tv2)
const char * vrpn_dropped_connection
const vrpn_uint32 vrpn_CONNECTION_RELIABLE
Classes of service for messages, specify multiple by ORing them together Priority of satisfying these...
This structure is what is passed to a vrpn_Connection message callback.
INTERNAL class to hold members that there should only be one copy of even when a class inherits from ...
virtual int unregister_handler(vrpn_int32 type, vrpn_MESSAGEHANDLER handler, void *userdata, vrpn_int32 sender=vrpn_ANY_SENDER)
vrpn_int32 d_sender_id
Sender ID registered with the connection.
~vrpn_TextPrinter()
Deletes any callbacks that are still registered.
vrpn_Semaphore d_semaphore
Mutex to ensure thread safety;.
virtual ~vrpn_BaseClass()
vrpn_TextPrinter * me
Pointer to this, because used in a static function.
void set_min_level_to_print(vrpn_TEXT_SEVERITY severity, vrpn_uint32 level=0)
Change the level of printing for the object (sets the minimum level to print). Default is Warnings an...
Generic connection class not specific to the transport mechanism.
vrpn_Connection * connectionPtr()
Returns a pointer to the connection this object is using.
void set_ostream_to_use(FILE *o)
Change the ostream that will be used to print messages. Setting a NULL ostream results in no printing...
vrpn_BaseClass * obj
Object being watched.
#define vrpn_gettimeofday
int add_object(vrpn_BaseClass *o)
Adds an object to the list of watched objects (multiple registration of the same object will result i...
virtual int register_types(void)=0
Register the types of messages this device sends/receives. Return 0 on success, -1 on fail.
FILE * d_ostream
Output stream to use.
int(VRPN_CALLBACK * vrpn_MESSAGEHANDLER)(void *userdata, vrpn_HANDLERPARAM p)
Type of a message handler for vrpn_Connection messages.
virtual vrpn_int32 register_sender(const char *name)
Get a token to use for the string name of the sender or type. Remember to check for -1 meaning failur...
void remove_object(vrpn_BaseClass *o)
Remove an object from the list of watched objects (multiple deletions of the object will not cause an...
Structure to hold the objects that are being watched.
virtual int init(void)
Initialize things that the constructor can't. Returns 0 on success, -1 on failure.
vrpn_TEXT_SEVERITY
Since the sending of text messages has been pulled into the base class (so that every object can send...
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.
int send_text_message(const char *msg, struct timeval timestamp, vrpn_TEXT_SEVERITY type=vrpn_TEXT_NORMAL, vrpn_uint32 level=0)
Sends a NULL-terminated text message from the device d_sender_id.
vrpn_BaseClass(const char *name, vrpn_Connection *c=NULL)
Names the device and assigns or opens connection, calls registration methods.
char * d_servicename
Name of this device, not including the connection part.
Class that handles text/warning/error printing for all objects in the system.
char * vrpn_copy_service_name(const char *fullname)
vrpn_int32 d_pong_message_id
Server telling that it is there.
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...
vrpn_TextPrinter_Watch_Entry * next
Pointer to the next one in the list.
virtual ~vrpn_BaseClassUnique()
Unregister all of the message handlers that were to be autodeleted.
vrpn_TextPrinter_Watch_Entry * d_first_watched_object
Head of list of objects being watched.
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...
const int vrpn_MAX_BCADRS
Internal value for number of BaseClass addresses.
vrpn_MESSAGEHANDLER handler