26 "vrpn_Analog_Output Change_request");
28 "vrpn_Analog_Output Change_Channels_request");
30 "vrpn_Analog_Output Num_Channels_report");
44 printf(
"Analog_Output Report: ");
54 vrpn_int32 numChannels)
61 fprintf(stderr,
"vrpn_Analog_Output: Can't get connection!\n");
67 fprintf(stderr,
"vrpn_Analog_Output_Server: can't register change " 68 "channel request handler\n");
76 fprintf(stderr,
"vrpn_Analog_Output_Server: can't register change " 77 "channels request handler\n");
85 fprintf(stderr,
"vrpn_Analog_Output_Server: can't register new " 86 "connection handler\n");
96 if (sizeRequested < 0) sizeRequested = 0;
108 const char* bufptr = p.
buffer;
122 fprintf(stderr,
"vrpn_Analog_Output_Server::handle_request_message(): " 123 "Index out of bounds\n");
125 sprintf(msg,
"Error: (handle_request_message): channel %d is not " 126 "active. Squelching.",
141 const char* bufptr = p.
buffer;
151 sprintf(msg,
"Error: (handle_request_channels_message): channels " 152 "above %d not active; " 153 "bad request up to channel %d. Squelching.",
160 sprintf(msg,
"Error: (handle_request_channels_message): invalid " 161 "channel %d. Squelching.",
166 for (i = 0; i < num; i++) {
179 fprintf(stderr,
"Error: failed sending active channels to client.\n");
185 vrpn_uint32 class_of_service)
187 char msgbuf[
sizeof(vrpn_int32)];
188 vrpn_int32 len =
sizeof(vrpn_int32);
196 fprintf(stderr,
"vrpn_Analog_Output_Server (report_num_channels): " 197 "cannot write message: tossing\n");
207 int buflen =
sizeof(vrpn_int32);
210 return sizeof(vrpn_int32);
223 fprintf(stderr,
"vrpn_Analog_Output_Callback_Server: can't register " 224 "change channel request handler\n");
234 fprintf(stderr,
"vrpn_Analog_Output_Callback_Server: can't register " 235 "change channels request handler\n");
276 fprintf(stderr,
"vrpn_Analog_Output_Remote: can't register active " 277 "channel report handler\n");
297 const char* bufptr = p.
buffer;
310 "vrpn_Analog_Output_Remote::handle_report_num_channels_message: " 311 "Someone sent us a bogus number of channels: %d.\n",
318 unsigned int chan, vrpn_float64 val, vrpn_uint32 class_of_service)
321 vrpn_float64 fbuf[2];
322 char* msgbuf = (
char*)fbuf;
330 msgbuf, class_of_service)) {
332 "vrpn_Analog_Output_Remote: cannot write message: tossing\n");
340 int num, vrpn_float64* vals, vrpn_uint32 class_of_service)
343 fprintf(stderr,
"vrpn_Analog_Output_Remote: cannot change channels: " 344 "number of channels out of range\n");
349 char* msgbuf = (
char*)fbuf;
358 "vrpn_Analog_Output_Remote: cannot write message: tossing\n");
373 int buflen = 2 *
sizeof(vrpn_int32) +
sizeof(vrpn_float64);
379 return 2 *
sizeof(vrpn_int32) +
sizeof(vrpn_float64);
388 int buflen = 2 *
sizeof(vrpn_int32) + num *
sizeof(vrpn_float64);
392 for (i = 0; i < num; i++) {
396 return 2 *
sizeof(vrpn_int32) + num *
sizeof(vrpn_float64);
virtual int mainloop(const struct timeval *timeout=NULL)=0
Call each time through program main loop to handle receiving any incoming messages and sending any pa...
vrpn_Analog_Output_Server(const char *name, vrpn_Connection *c, vrpn_int32 numChannels=vrpn_CHANNEL_MAX)
struct timeval o_timestamp
virtual bool request_change_channels(int num, vrpn_float64 *vals, vrpn_uint32 class_of_service=vrpn_CONNECTION_RELIABLE)
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_int32 request_channels_m_id
virtual 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_report_num_channels(void *userdata, vrpn_HANDLERPARAM p)
vrpn_int32 setNumChannels(vrpn_int32 sizeRequested)
Sets the size of the array; returns the size actually set. (May be clamped to vrpn_CHANNEL_MAX) This ...
void client_mainloop(void)
Handles functions that all clients should provide in their mainloop() (warning of no server...
virtual ~vrpn_Analog_Output_Server(void)
vrpn_float64 o_channel[vrpn_CHANNEL_MAX]
static int VRPN_CALLBACK handle_got_connection(void *userdata, vrpn_HANDLERPARAM p)
Used to notify us when a new connection is requested, so that we can let the client know how many cha...
vrpn_Analog_Output_Remote(const char *name, vrpn_Connection *c=NULL)
virtual vrpn_int32 encode_change_channels_to(char *buf, vrpn_int32 num, vrpn_float64 *vals)
vrpn_Callback_List< vrpn_ANALOGOUTPUTCB > d_callback_list
List of user-level routines that need to be called back to let them know that the values have changed...
virtual bool report_num_channels(vrpn_uint32 class_of_service=vrpn_CONNECTION_RELIABLE)
Generic connection class not specific to the transport mechanism.
const vrpn_float64 * o_channels(void) const
Exposes an array of values for the user to read from.
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
virtual int init(void)
Initialize things that the constructor can't. Returns 0 on success, -1 on failure.
vrpn_int32 getNumChannels() const
virtual ~vrpn_Analog_Output_Remote(void)
static int VRPN_CALLBACK handle_request_channels_message(void *userdata, vrpn_HANDLERPARAM p)
Responds to a request to change a number of channels Derived class must either install handlers for t...
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.
const vrpn_float64 * channel
vrpn_Connection * d_connection
Connection that this object talks to.
This structure is what is passed to a vrpn_Connection message callback.
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...
vrpn_int32 got_connection_m_id
vrpn_int32 report_num_channels_m_id
const char * vrpn_got_connection
virtual bool request_change_channel_value(unsigned int chan, vrpn_float64 val, vrpn_uint32 class_of_service=vrpn_CONNECTION_RELIABLE)
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.
virtual vrpn_int32 encode_num_channels_to(char *buf, vrpn_int32 num)
#define vrpn_gettimeofday
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...
static int VRPN_CALLBACK handle_change_message(void *userdata, vrpn_HANDLERPARAM p)
Handles BOTH types of changes messages, and will be called after the vrpn_Analog_Output_Server class ...
Class from which all user-level (and other) classes that communicate with vrpn_Connections should der...
static int VRPN_CALLBACK handle_request_message(void *userdata, vrpn_HANDLERPARAM p)
Responds to a request to change one of the values by setting the channel to that value. Derived class must either install handlers for this routine or else make its own routines to handle the request message.
vrpn_int32 d_sender_id
Sender ID registered with the connection.
vrpn_Analog_Output_Callback_Server(const char *name, vrpn_Connection *c, vrpn_int32 numChannels=vrpn_CHANNEL_MAX)
virtual ~vrpn_Analog_Output_Callback_Server(void)
virtual vrpn_int32 encode_change_to(char *buf, vrpn_int32 chan, vrpn_float64 val)
vrpn_Analog_Output(const char *name, vrpn_Connection *c=NULL)
virtual vrpn_int32 register_message_type(const char *name)
void call_handlers(const CALLBACK_STRUCT &info)
This will pass the referenced parameter as a const to all the callbacks.