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");
100 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::~vrpn_Imager_Stream_Buffer(): delete failed\n");
114 const char *channelBuffer = NULL;
118 const char *bufptr = channelBuffer;
123 delete[]
const_cast<char *
>(channelBuffer);
125 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::mainloop(): delete failed\n");
140 for (i = 0; i < count; i++) {
144 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::mainloop(): Could "
145 "not retrieve message from queue\n");
162 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::mainloop(): Could "
163 "not pack message\n");
167 delete[]
const_cast<char *
>(p.
buffer);
169 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::mainloop(): delete failed\n");
200 "handle_got_first_connection: Thread running when it should not be",
219 "handle_got_first_connection: Failed to start logging thread", now,
224 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::handle_got_first_connection(): delete failed\n");
231 struct timeval start, now;
234 const char *channelBuffer = NULL;
238 const char *bufptr = channelBuffer;
243 delete[]
const_cast<char *
>(channelBuffer);
245 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::handle_got_first_connection(): delete failed\n");
266 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::handle_dropped_last_"
267 "connection(): Had to kill logging thread\n");
276 const char *bufptr = p.
buffer;
281 vrpn_int32 frames_to_send;
327 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::logging_thread_func(): "
328 "Cannot open connection\n");
332 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::logging_thread_func(): "
333 "Cannot set up handlers\n");
354 vrpn_int32 frames_to_send;
359 if (frames_to_send < 0) {
368 if (frames_to_send >= frames_in_queue) {
369 frames_to_send -= frames_in_queue;
388 char *lil, *lol, *ril, *rol;
403 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::logging_thread_func(): delete failed\n");
425 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::logging_thread_func(): delete failed\n");
485 char *msgbuf = (
char *)fbuf;
486 int buflen =
sizeof(fbuf);
491 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::handle_server_"
492 "messages: Can't pack count\n");
495 tp.
buffer =
static_cast<char *
>(
static_cast<void *
>(fbuf));
499 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::handle_server_"
500 "messages: Can't send discarded frames "
518 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::handle_server_messages:"
519 " Can't transcode and send\n");
544 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::handle_server_messages:"
545 " Can't transcode and send\n");
558 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::handle_server_messages:"
559 " Can't transcode and send\n");
587 sprintf(msg,
"Unknown message type from server: %d",
588 static_cast<int>(p.
type));
591 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::handle_server_messages:"
592 " Can't transcode text message\n");
616 "vrpn_Imager_Stream_Buffer::transcode_and_send(): Out of memory\n");
630 if (newp.
type == -1) {
631 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::transcode_and_send(): "
632 "Unknown type (%d)\n",
633 static_cast<int>(p.
type));
637 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::transcode_and_send(): delete failed\n");
645 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::transcode_and_send(): "
646 "Can't queue message\n");
697 const char *local_in_logfile_name,
const char *local_out_logfile_name,
698 const char *remote_in_logfile_name,
const char *remote_out_logfile_name)
705 const char *where_at;
706 if ((where_at = strrchr(cname,
'@')) != NULL) {
707 cname = where_at + 1;
713 where_at, local_in_logfile_name, local_out_logfile_name,
714 remote_in_logfile_name, remote_out_logfile_name, NULL,
true);
718 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::open_new_log_connection: "
719 "Could not create connection (files already exist?)");
724 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::open_new_log_connection(): delete failed\n");
743 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::setup_handlers_for_logging_"
744 "connection(): Cannot create vrpn_Imager_Remote\n");
788 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::teardown_handlers_for_"
789 "logging_connection(): No imager remote\n");
794 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::teardown_handlers_for_"
795 "logging_connection(): Cannot unregister handler\n");
807 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::teardown_handlers_for_logging_connection(): delete failed\n");
815 const char *local_in_logfile_name,
const char *local_out_logfile_name,
816 const char *remote_in_logfile_name,
const char *remote_out_logfile_name)
823 local_in_logfile_name, local_out_logfile_name, remote_in_logfile_name,
824 remote_out_logfile_name);
825 if (new_log_connection == NULL) {
826 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::make_new_logging_"
827 "connection(): Cannot open connection\n");
834 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::make_new_logging_"
835 "connection(): Cannot teardown connection\n");
842 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::make_new_logging_"
843 "connection(): Cannot setup connection\n");
858 struct timeval start, now;
872 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::make_new_logging_"
873 "connection(): Could not connect new logging "
891 const char *local_in_logfile_name,
const char *local_out_logfile_name,
892 const char *remote_in_logfile_name,
const char *remote_out_logfile_name)
896 local_in_logfile_name, local_out_logfile_name, remote_in_logfile_name,
897 remote_out_logfile_name);
902 struct timeval start, now;
905 char *lil, *lol, *ril, *rol;
914 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::handle_request_logging(): delete failed\n");
938 if (local_in)
delete[] local_in;
939 if (local_out)
delete[] local_out;
940 if (remote_in)
delete[] remote_in;
941 if (remote_out)
delete[] remote_out;
943 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::handle_request_logging_status(): delete failed\n");
953 void *pvISB,
const struct timeval)
965 fprintf(stderr,
"vrpn_Imager_Stream_Buffer::handle_image_description():"
971 char *buffer =
reinterpret_cast<char *
>(fbuf);
973 char *bufptr = buffer;
975 sizeof(vrpn_float64);
999 struct timeval start, now;
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)
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.
vrpn_int32 d_pong_message_id
Server telling that it is there.
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...
vrpn_int32 d_text_message_id
ID for text messages.
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.
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.
vrpn_int32 d_ping_message_id
Ask the server if they are there.
Generic connection class not specific to the transport mechanism.
virtual vrpn_int32 register_message_type(const char *name)
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 save_log_so_far()
Save any messages on any endpoints which have been logged so far.
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...
virtual vrpn_bool doing_okay(void) const
Returns vrpn_true if the connection is okay, vrpn_false if not.
virtual int unregister_handler(vrpn_int32 type, vrpn_MESSAGEHANDLER handler, void *userdata, vrpn_int32 sender=vrpn_ANY_SENDER)
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...
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...
bool buffer(char **insertPt, vrpn_int32 *buflen) const
bool unbuffer(const char **buffer)
This is the class users deal with: it tells the format and the region data when it arrives.
virtual int register_description_handler(void *userdata, vrpn_IMAGERDESCRIPTIONHANDLER handler)
Register a handler for when the object's description changes (if desired).
const vrpn_Imager_Channel * channel(unsigned chanNum) const
Accessors for the member variables: can be queried in the handler for object changes.
virtual void mainloop(void)
XXX It could be nice to let the user specify separate callbacks for.
virtual int unregister_description_handler(void *userdata, vrpn_IMAGERDESCRIPTIONHANDLER handler)
bool send_description(void)
Sends a description of the imager so the remote can process the region messages.
bool teardown_handlers_for_logging_connection(vrpn_Connection *c)
vrpn_int32 got_first_connection_m_id
vrpn_int32 d_server_regionu16_m_id
vrpn_Imager_Stream_Shared_State d_shared_state
vrpn_int32 d_server_begin_frame_m_id
bool setup_handlers_for_logging_connection(vrpn_Connection *c)
virtual ~vrpn_Imager_Stream_Buffer()
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)
void logging_thread_func(void)
vrpn_int32 d_server_regionu8_m_id
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)
vrpn_Thread * d_logging_thread
static void static_logging_thread_func(vrpn_ThreadData &threadData)
vrpn_int32 d_server_frames_to_send
bool d_ready_to_drop_old_connection
char * d_imager_server_name
virtual void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
bool transcode_and_send(const vrpn_HANDLERPARAM &p)
static int VRPN_CALLBACK static_handle_throttle_message(void *userdata, vrpn_HANDLERPARAM p)
vrpn_int32 d_server_end_frame_m_id
vrpn_Imager_Stream_Buffer(const char *name, const char *imager_server_name, vrpn_Connection *c)
static int VRPN_CALLBACK static_handle_server_messages(void *pvISB, vrpn_HANDLERPARAM p)
vrpn_int32 d_server_ping_m_id
vrpn_Imager_Remote * d_imager_remote
vrpn_int32 d_server_description_m_id
virtual void handle_dropped_last_connection(void)
vrpn_int32 d_server_text_m_id
virtual void handle_request_logging_status()
virtual void handle_got_first_connection(void)
vrpn_Connection * d_log_connection
vrpn_int32 transcode_type(vrpn_int32 type)
vrpn_int32 d_server_discarded_frames_m_id
static int VRPN_CALLBACK static_handle_got_first_connection(void *userdata, vrpn_HANDLERPARAM p)
vrpn_int32 d_server_pong_m_id
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_uint16 d_server_dropped_due_to_throttle
static void VRPN_CALLBACK handle_image_description(void *pvISB, const struct timeval msg_time)
int handle_server_messages(const vrpn_HANDLERPARAM &p)
vrpn_int32 d_server_regionu12in16_m_id
bool stop_logging_thread(void)
vrpn_int32 d_server_regionf32_m_id
bool insert_logger_to_client_message(const vrpn_HANDLERPARAM &p)
void set_logfile_result(const char *lil, const char *lol, const char *ril, const char *rol)
vrpn_int32 decrement_frames_in_queue(void)
vrpn_int32 get_logger_to_client_queue_size(void)
void set_logfile_request(const char *lil, const char *lol, const char *ril, const char *rol)
bool get_logfile_result(char **lil, char **lol, char **ril, char **rol)
bool get_logfile_request(char **lil, char **lol, char **ril, char **rol)
vrpn_int32 get_frames_in_queue(void)
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)
vrpn_int32 increment_frames_in_queue(void)
void set_throttle_request(vrpn_int32 throttle_count)
bool set_imager_description(vrpn_int32 nRows, vrpn_int32 nCols, vrpn_int32 nDepth, vrpn_int32 nChannels, const char *channelBuffer)
bool get_throttle_request(vrpn_int32 *throttle_count)
void get_logfile_names(char **local_in, char **local_out, char **remote_in, char **remote_out)
vrpn_int32 d_description_m_id
vrpn_int32 nDepth(void) const
vrpn_int32 nChannels(void) const
vrpn_int32 d_regionf32_m_id
vrpn_int32 nCols(void) const
vrpn_int32 d_throttle_frames_m_id
vrpn_int32 d_begin_frame_m_id
vrpn_int32 d_regionu8_m_id
vrpn_int32 d_end_frame_m_id
vrpn_int32 d_regionu12in16_m_id
vrpn_int32 nRows(void) const
vrpn_int32 d_regionu16_m_id
vrpn_int32 d_discarded_frames_m_id
vrpn_Imager_Channel d_channels[vrpn_IMAGER_MAX_CHANNELS]
This structure is what is passed to a vrpn_Connection message callback.
All types of client/server/peer objects in VRPN should be derived from the vrpn_BaseClass type descri...
const unsigned vrpn_MAX_TEXT_LEN
const char * vrpn_got_first_connection
These are the strings that define the system-generated message types that tell when connections are r...
char * vrpn_copy_service_name(const char *fullname)
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).
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....
const int vrpn_CONNECTION_TCP_BUFLEN
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_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_TimevalDiff(const timeval &tv1, const timeval &tv2)
void vrpn_SleepMsecs(double dMilliSecs)
#define vrpn_gettimeofday