17 #if !(defined(_WIN32) && defined(VRPN_USE_WINSOCK_SOCKETS)) 18 #include <netinet/in.h> 54 if (x == -1) return -1 64 const char *local_in_logfile_name,
65 const char *local_out_logfile_name)
66 :
vrpn_Connection(local_in_logfile_name, local_out_logfile_name, NULL, NULL)
67 , d_controllerId(register_sender(
"vrpn File Controller"))
68 , d_set_replay_rate_type(register_message_type(
"vrpn_File set_replay_rate"))
69 , d_reset_type(register_message_type(
"vrpn_File reset"))
70 , d_play_to_time_type(register_message_type(
"vrpn_File play_to_time"))
75 , d_currentLogEntry(NULL)
86 fprintf(stderr,
"vrpn_File_Connection::vrpn_File_Connection(): NULL " 87 "zeroeth endpoint\n");
112 fprintf(stderr,
"vrpn_File_Connection: Out of memory!\n");
119 fprintf(stderr,
"vrpn_File_Connection: " 120 "Could not open file \"%s\".\n",
158 fprintf(stderr,
"vrpn_File_Connection: Can't read first message\n");
221 delete[](
char *)
d_logHead -> data.buffer;
289 d_filetime_accum_since_last_playback.tv_sec = 0;
290 d_filetime_accum_since_last_playback.tv_usec = 0;
292 d_time_of_last_accum.tv_sec = 0;
293 d_time_of_last_accum.tv_usec = 0;
297 const timeval &now_time)
299 timeval &accum = d_filetime_accum_since_last_playback;
300 timeval &last_accum = d_time_of_last_accum;
307 now_time, d_time_of_last_accum),
309 last_accum = now_time;
313 vrpn_float32 new_rate)
317 accumulate_to(now_time);
319 d_replay_rate = new_rate;
324 const timeval &now_time)
328 d_filetime_accum_since_last_playback.tv_sec = 0;
329 d_filetime_accum_since_last_playback.tv_usec = 0;
330 d_time_of_last_accum = now_time;
425 const timeval end_time =
447 if (need_to_play_retval > 0) {
453 else if (need_to_play_retval == 0) {
574 vrpn_uint32 playback_this_iteration = 0;
590 playback_this_iteration++;
635 static const timeval tvMAX = {LONG_MAX, 999999L};
682 fprintf(stderr,
"Couldn't log \"incoming\" message during replay!\n");
690 if (header.
type >= 0) {
692 printf(
"vrpn_FC: Msg Sender (%s), Type (%s), at (%ld:%ld)\n",
693 endpoint->other_senders[header.
sender].name,
694 endpoint->other_types[header.
type].name, header.
msg_time.tv_sec,
710 fprintf(stderr,
"vrpn_File_Connection::playone_to_filename: " 711 "Nonzero system return.\n");
751 timeval len = {0, 0};
776 timeval high = {0, 0};
777 timeval low = {LONG_MAX, 999999L};
781 if (retval ==
false) {
783 printf(
"vrpn_File_Connection::find_superlative_user_times: didn't " 784 "successfully save bookmark.\n");
807 if (retval ==
false) {
809 fprintf(stderr,
"vrpn_File_Connection::find_superlative_user_times " 810 "messed up the location in the file stream.\n");
815 if (high.tv_sec != LONG_MIN)
822 fprintf( stderr,
"vrpn_File_Connection::find_superlative_user_times: did not find a highest-time user message\n" 826 if (low.tv_sec != LONG_MAX)
828 d_earliest_user_time = low;
829 d_earliest_user_time_valid = true;
833 fprintf( stderr,
"vrpn_File_Connection::find_superlative_user_times: did not find an earliest user message\n" 845 oldCurrentLogEntryPtr = NULL;
846 oldCurrentLogEntryCopy = NULL;
851 if (oldCurrentLogEntryCopy == NULL)
return;
852 if (oldCurrentLogEntryCopy->data.buffer != NULL)
853 delete[](
char *)(oldCurrentLogEntryCopy->data.buffer);
854 delete oldCurrentLogEntryCopy;
889 fprintf(stderr,
"Out of memory error: " 890 "vrpn_File_Connection::store_stream_" 952 if (newBuffer == NULL) {
978 if (temp)
delete[] temp;
982 return (retval == 0);
1024 fprintf(stderr,
"vrpn_File_Connection::read_cookie: " 1025 "No cookie. If you're sure this is a logfile, " 1026 "run add_vrpn_cookie on it and try again.\n");
1037 fprintf(stderr,
"vrpn_File_Connection::read_cookie: " 1038 "No endpoints[0]. Internal failure.\n");
1054 fprintf(stderr,
"vrpn_File_Connection::read_entry: Out of memory.\n");
1063 fprintf(stderr,
"vrpn_File_Connection::read_entry: no open file\n");
1079 vrpn_int32 values[6];
1080 retval = fread(values,
sizeof(vrpn_int32), 6,
d_file);
1090 header.
type = ntohl(values[0]);
1091 header.
sender = ntohl(values[1]);
1092 header.
msg_time.tv_sec = ntohl(values[2]);
1093 header.
msg_time.tv_usec = ntohl(values[3]);
1103 fprintf(stderr,
"vrpn_File_Connection::read_entry: " 1104 "Out of memory.\n");
1126 newEntry->
next = NULL;
1146 delete[](
char *)
d_logTail -> data.buffer;
1156 newEntry->
next = NULL;
1157 newEntry->
prev = NULL;
1214 const char *bufPtr = p.
buffer;
1237 newtime.tv_sec = ((vrpn_int32 *)(p.
buffer))[0];
1238 newtime.tv_usec = ((vrpn_int32 *)(p.
buffer))[1];
vrpn_uint32 get_Jane_value(void)
int jump_to_filetime(timeval absolute_time)
virtual int mainloop(const timeval *timeout=NULL)
virtual int time_since_connection_open(timeval *elapsed_time)
Returns the time since the connection opened. Some subclasses may redefine time.
vrpn_LOGLIST * oldCurrentLogEntryPtr
virtual ~vrpn_File_Connection(void)
void set_replay_rate(vrpn_float32 rate)
size_t vrpn_cookie_size(void)
Returns the size of the magic cookie buffer, plus any alignment overhead.
bool vrpn_FILE_CONNECTIONS_SHOULD_SKIP_TO_USER_MESSAGES
timeval get_lowest_user_timestamp()
int logIncomingMessage(size_t payloadLen, struct timeval time, vrpn_int32 type, vrpn_int32 sender, const char *buffer)
Should be called with the timeval adjusted by the clock offset on the receiving Endpoint.
const vrpn_int32 vrpn_CONNECTION_UDP_DESCRIPTION
virtual int send_pending_reports(void)
send pending report, clear the buffer. This function was protected, now is public,...
static int VRPN_CALLBACK handle_set_replay_rate(void *, vrpn_HANDLERPARAM)
int play_to_time(vrpn_float64 end_time)
timeval vrpn_TimevalDiff(const timeval &tv1, const timeval &tv2)
void drop_connection(void)
Should only be called by vrpn_Connection::drop_connection(), since there's more housecleaning to do a...
void accumulate_to(const timeval &now_time)
char * vrpn_copy_file_name(const char *filespecifier)
Utility routines to parse file specifiers FROM service locations.
void find_superlative_user_times()
static int VRPN_CALLBACK handle_reset(void *, vrpn_HANDLERPARAM)
const char * get_filename()
Generic connection class not specific to the transport mechanism.
vrpn_bool d_highest_user_time_valid
bool vrpn_FILE_CONNECTIONS_SHOULD_PRELOAD
int play_to_filetime(const timeval end_filetime)
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 vrpn_FILE_CONNECTIONS_SHOULD_ACCUMULATE
FileTime_Accumulator d_filetime_accum
vrpn_int32 d_play_to_time_type
vrpn_int32 d_controllerId
vrpn_FileBookmark d_bookmark
int check_vrpn_file_cookie(const char *buffer)
virtual int read_cookie(void)
timeval vrpn_TimevalScale(const timeval &tv, double scale)
void reset_at_time(const timeval &now_time)
void addConnection(vrpn_Connection *, const char *name)
NB implementation is not particularly efficient; we expect to have O(10) connections,...
virtual int read_entry(void)
int setCookie(const char *cookieBuffer)
The magic cookie is set to the default value of the version of VRPN compiled, but a more correct valu...
void deleteConnection(vrpn_Connection *)
vrpn_bool d_earliest_user_time_valid
double vrpn_TimevalMsecs(const timeval &tv)
timeval vrpn_MsecsTimeval(const double dMsecs)
void set_replay_rate(vrpn_float32 new_rate)
This structure is what is passed to a vrpn_Connection message callback.
vrpn_File_Connection(const char *station_name, const char *local_in_logfile_name=NULL, const char *local_out_logfile_name=NULL)
timeval d_earliest_user_time
int connectionStatus
Status of the connection.
static vrpn_ConnectionManager & instance(void)
The only way to get access to an instance of this class. Guarantees that there is only one,...
virtual int advance_currentLogEntry(void)
bool vrpn_TimevalGreater(const timeval &tv1, const timeval &tv2)
Encapsulation of the data and methods for a single generic connection to take care of one part of man...
int local_type_id(vrpn_int32 remote_type) const
Returns the local mapping for the remote type (-1 if none).
bool store_stream_bookmark()
int doSystemCallbacksFor(vrpn_HANDLERPARAM, void *)
int need_to_play(timeval filetime)
#define vrpn_gettimeofday
vrpn_Endpoint_IP * d_endpoints[vrpn_MAX_ENDPOINTS]
Sockets used to talk to remote Connection(s) and other information needed on a per-connection basis.
const timeval & accumulated(void)
static int VRPN_CALLBACK handle_play_to_time(void *, vrpn_HANDLERPARAM)
vrpn_int32 d_set_replay_rate_type
bool return_to_bookmark()
virtual int close_file(void)
int jump_to_time(vrpn_float64 newtime)
timeval d_highest_user_time
void play_to_user_message()
void clearBuffers(void)
Empties out the TCP and UDP send buffers. Needed by vrpn_FileConnection to get at {udp,...
int playone_to_filetime(timeval end_filetime)
timeval get_highest_user_timestamp()
vrpn_LOGLIST * d_currentLogEntry
timeval vrpn_TimevalSum(const timeval &tv1, const timeval &tv2)
vrpn_LOGLIST * oldCurrentLogEntryCopy
vrpn_LOGLIST * d_startEntry
virtual vrpn_File_Connection * get_File_Connection(void)
vrpn_File_Connection implements this as "return this" so it can be used to detect a File_Connection a...
int local_sender_id(vrpn_int32 remote_sender) const
Returns the local mapping for the remote sender (-1 if none).
Placed here so vrpn_FileConnection can use it too.
virtual int do_callbacks_for(vrpn_int32 type, vrpn_int32 sender, struct timeval time, vrpn_uint32 len, const char *buffer)