vrpn
07.33
Virtual Reality Peripheral Network
|
Go to the documentation of this file.
11 , d_logging_thread(NULL)
12 , d_imager_server_name(NULL)
17 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::vrpn_Imager_Stream_Buffer: "
29 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::vrpn_Imager_Stream_Buffer: "
30 "can't create logging thread\n");
39 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::vrpn_Imager_Stream_Buffer: "
40 "can't register got first connection type\n");
47 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::vrpn_Imager_Stream_Buffer: "
48 "can't register got first connection handler\n");
83 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::vrpn_Imager_Stream_Buffer: "
84 "can't register throttle handler\n");
105 const char *channelBuffer = NULL;
109 const char *bufptr = channelBuffer;
113 delete[]
const_cast<char *
>(channelBuffer);
126 for (i = 0; i < count; i++) {
130 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::mainloop(): Could "
131 "not retrieve message from queue\n");
148 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::mainloop(): Could "
149 "not pack message\n");
152 delete[]
const_cast<char *
>(p.
buffer);
181 "handle_got_first_connection: Thread running when it should not be",
200 "handle_got_first_connection: Failed to start logging thread", now,
206 struct timeval start, now;
209 const char *channelBuffer = NULL;
213 const char *bufptr = channelBuffer;
217 delete[]
const_cast<char *
>(channelBuffer);
236 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::handle_dropped_last_"
237 "connection(): Had to kill logging thread\n");
246 const char *bufptr = p.
buffer;
251 vrpn_int32 frames_to_send;
297 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::logging_thread_func(): "
298 "Cannot open connection\n");
302 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::logging_thread_func(): "
303 "Cannot set up handlers\n");
324 vrpn_int32 frames_to_send;
329 if (frames_to_send < 0) {
338 if (frames_to_send >= frames_in_queue) {
339 frames_to_send -= frames_in_queue;
358 char *lil, *lol, *ril, *rol;
445 char *msgbuf = (
char *)fbuf;
446 int buflen =
sizeof(fbuf);
451 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::handle_server_"
452 "messages: Can't pack count\n");
455 tp.
buffer =
static_cast<char *
>(
static_cast<void *
>(fbuf));
459 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::handle_server_"
460 "messages: Can't send discarded frames "
478 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::handle_server_messages:"
479 " Can't transcode and send\n");
504 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::handle_server_messages:"
505 " Can't transcode and send\n");
518 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::handle_server_messages:"
519 " Can't transcode and send\n");
547 sprintf(msg,
"Unknown message type from server: %d",
548 static_cast<int>(p.
type));
551 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::handle_server_messages:"
552 " Can't transcode text message\n");
572 if (newbuf == NULL) {
575 "vrpn_Imager_Stream_Buffer::transcode_and_send(): Out of memory\n");
588 if (newp.
type == -1) {
589 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::transcode_and_send(): "
590 "Unknown type (%d)\n",
591 static_cast<int>(p.
type));
598 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::transcode_and_send(): "
599 "Can't queue message\n");
650 const char *local_in_logfile_name,
const char *local_out_logfile_name,
651 const char *remote_in_logfile_name,
const char *remote_out_logfile_name)
658 const char *where_at;
659 if ((where_at = strrchr(cname,
'@')) != NULL) {
660 cname = where_at + 1;
666 where_at, local_in_logfile_name, local_out_logfile_name,
667 remote_in_logfile_name, remote_out_logfile_name, NULL,
true);
671 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::open_new_log_connection: "
672 "Could not create connection (files already exist?)");
691 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::setup_handlers_for_logging_"
692 "connection(): Cannot create vrpn_Imager_Remote\n");
736 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::teardown_handlers_for_"
737 "logging_connection(): No imager remote\n");
742 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::teardown_handlers_for_"
743 "logging_connection(): Cannot unregister handler\n");
758 const char *local_in_logfile_name,
const char *local_out_logfile_name,
759 const char *remote_in_logfile_name,
const char *remote_out_logfile_name)
766 local_in_logfile_name, local_out_logfile_name, remote_in_logfile_name,
767 remote_out_logfile_name);
768 if (new_log_connection == NULL) {
769 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::make_new_logging_"
770 "connection(): Cannot open connection\n");
777 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::make_new_logging_"
778 "connection(): Cannot teardown connection\n");
785 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::make_new_logging_"
786 "connection(): Cannot setup connection\n");
801 struct timeval start, now;
815 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::make_new_logging_"
816 "connection(): Could not connect new logging "
834 const char *local_in_logfile_name,
const char *local_out_logfile_name,
835 const char *remote_in_logfile_name,
const char *remote_out_logfile_name)
839 local_in_logfile_name, local_out_logfile_name, remote_in_logfile_name,
840 remote_out_logfile_name);
845 struct timeval start, now;
848 char *lil, *lol, *ril, *rol;
875 if (local_in)
delete[] local_in;
876 if (local_out)
delete[] local_out;
877 if (remote_in)
delete[] remote_in;
878 if (remote_out)
delete[] remote_out;
886 void *pvISB,
const struct timeval msg_time)
897 char *buffer =
static_cast<char *
>(
static_cast<void *
>(fbuf));
898 if (buffer == NULL) {
899 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::handle_image_description():"
905 char *bufptr = buffer;
907 sizeof(vrpn_float64);
931 struct timeval start, now;
static void VRPN_CALLBACK handle_image_description(void *pvISB, const struct timeval msg_time)
vrpn_int32 get_frames_in_queue(void)
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...
vrpn_int32 d_server_text_m_id
static int VRPN_CALLBACK static_handle_got_first_connection(void *userdata, vrpn_HANDLERPARAM p)
vrpn_int32 d_regionu16_m_id
vrpn_int32 d_regionu12in16_m_id
vrpn_Imager_Channel d_channels[vrpn_IMAGER_MAX_CHANNELS]
vrpn_int32 d_end_frame_m_id
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).
bool setup_handlers_for_logging_connection(vrpn_Connection *c)
virtual void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_int32 transcode_type(vrpn_int32 type)
bool stop_logging_thread(void)
virtual void handle_request_logging(const char *local_in_logfile_name, const char *local_out_logfile_name, const char *remote_in_logfile_name, const char *remote_out_logfile_name)
vrpn_Connection * open_new_log_connection(const char *local_in_logfile_name, const char *local_out_logfile_name, const char *remote_in_logfile_name, const char *remote_out_logfile_name)
static int VRPN_CALLBACK static_handle_server_messages(void *pvISB, vrpn_HANDLERPARAM p)
bool teardown_handlers_for_logging_connection(vrpn_Connection *c)
vrpn_Connection * d_log_connection
vrpn_int32 d_server_discarded_frames_m_id
virtual void handle_dropped_last_connection(void)
vrpn_int32 d_server_ping_m_id
bool make_new_logging_connection(const char *local_in_logfile_name, const char *local_out_logfile_name, const char *remote_in_logfile_name, const char *remote_out_logfile_name)
bool d_ready_to_drop_old_connection
bool get_logfile_result(char **lil, char **lol, char **ril, char **rol)
void set_logfile_result(const char *lil, const char *lol, const char *ril, const char *rol)
vrpn_int32 d_server_regionf32_m_id
const char * vrpn_got_first_connection
These are the strings that define the system-generated message types that tell when connections are r...
virtual int save_log_so_far()
Save any messages on any endpoints which have been logged so far.
vrpn_int32 d_regionu8_m_id
vrpn_uint16 d_server_dropped_due_to_throttle
vrpn_int32 d_server_regionu16_m_id
const int vrpn_CONNECTION_TCP_BUFLEN
const vrpn_Imager_Channel * channel(unsigned chanNum) const
Accessors for the member variables: can be queried in the handler for object changes.
vrpn_int32 got_first_connection_m_id
vrpn_int32 get_logger_to_client_queue_size(void)
vrpn_int32 d_text_message_id
ID for text messages.
virtual void handle_request_logging_status()
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 d_server_begin_frame_m_id
bool transcode_and_send(const vrpn_HANDLERPARAM &p)
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)
vrpn_int32 decrement_frames_in_queue(void)
virtual void handle_got_first_connection(void)
timeval vrpn_TimevalDiff(const timeval &tv1, const timeval &tv2)
const vrpn_uint32 vrpn_CONNECTION_RELIABLE
Classes of service for messages, specify multiple by ORing them together Priority of satisfying these...
vrpn_Imager_Stream_Buffer(const char *name, const char *imager_server_name, vrpn_Connection *c)
void vrpn_SleepMsecs(double dMsecs)
vrpn_int32 d_server_regionu12in16_m_id
vrpn_int32 d_discarded_frames_m_id
This structure is what is passed to a vrpn_Connection message callback.
void set_logfile_request(const char *lil, const char *lol, const char *ril, const char *rol)
bool get_logfile_request(char **lil, char **lol, char **ril, char **rol)
bool retrieve_logger_to_client_message(vrpn_HANDLERPARAM *p)
bool get_imager_description(vrpn_int32 &nRows, vrpn_int32 &nCols, vrpn_int32 &nDepth, vrpn_int32 &nChannels, const char **channelBuffer)
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_int32 d_server_pong_m_id
void logging_thread_func(void)
vrpn_int32 d_server_regionu8_m_id
vrpn_int32 d_server_end_frame_m_id
virtual int register_description_handler(void *userdata, vrpn_IMAGERDESCRIPTIONHANDLER handler)
Register a handler for when the object's description changes (if desired).
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...
bool send_description(void)
Sends a description of the imager so the remote can process the region messages.
Generic connection class not specific to the transport mechanism.
const int vrpn_ANY_TYPE
vrpn_ANY_TYPE can be used to register callbacks for any USER type of message from a given sender....
vrpn_Imager_Remote * d_imager_remote
vrpn_int32 nRows(void) const
vrpn_int32 d_server_frames_to_send
#define vrpn_gettimeofday
vrpn_Thread * d_logging_thread
vrpn_int32 d_regionf32_m_id
vrpn_Imager_Stream_Shared_State d_shared_state
const int vrpn_ANY_SENDER
vrpn_ANY_SENDER can be used to register callbacks on a given message type from any sender.
virtual void mainloop(void)
XXX It could be nice to let the user specify separate callbacks for.
vrpn_int32 nChannels(void) const
vrpn_int32 d_begin_frame_m_id
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...
vrpn_int32 d_server_description_m_id
vrpn_int32 d_throttle_frames_m_id
bool buffer(char **insertPt, vrpn_int32 *buflen) const
virtual int unregister_description_handler(void *userdata, vrpn_IMAGERDESCRIPTIONHANDLER handler)
virtual ~vrpn_Imager_Stream_Buffer()
vrpn_int32 d_description_m_id
vrpn_int32 nDepth(void) const
int handle_server_messages(const vrpn_HANDLERPARAM &p)
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 static_handle_throttle_message(void *userdata, vrpn_HANDLERPARAM p)
virtual vrpn_bool doing_okay(void) const
Returns vrpn_true if the connection is okay, vrpn_false if not.
static void static_logging_thread_func(vrpn_ThreadData &threadData)
bool unbuffer(const char **buffer)
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.
void set_throttle_request(vrpn_int32 throttle_count)
void get_logfile_names(char **local_in, char **local_out, char **remote_in, char **remote_out)
char * vrpn_copy_service_name(const char *fullname)
bool set_imager_description(vrpn_int32 nRows, vrpn_int32 nCols, vrpn_int32 nDepth, vrpn_int32 nChannels, const char *channelBuffer)
bool send_report_logging(const char *local_in_logfile_name, const char *local_out_logfile_name, const char *remote_in_logfile_name, const char *remote_out_logfile_name)
bool insert_logger_to_client_message(const vrpn_HANDLERPARAM &p)
This is the class users deal with: it tells the format and the region data when it arrives.
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_int32 nCols(void) const
bool get_throttle_request(vrpn_int32 *throttle_count)
vrpn_int32 increment_frames_in_queue(void)
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
char * d_imager_server_name