16 "vrpn_Auxiliary_Logger Logging_request");
18 "vrpn_Auxiliary_Logger Logging_response");
20 "vrpn_Auxiliary_Logger Logging_status_request");
35 vrpn_int32 type,
const char *local_in_logfile_name,
36 const char *local_out_logfile_name,
const char *remote_in_logfile_name,
37 const char *remote_out_logfile_name)
45 if (local_in_logfile_name) {
46 lil = static_cast<vrpn_int32>(strlen(local_in_logfile_name));
49 if (local_out_logfile_name) {
50 lol = static_cast<vrpn_int32>(strlen(local_out_logfile_name));
53 if (remote_in_logfile_name) {
54 ril = static_cast<vrpn_int32>(strlen(remote_in_logfile_name));
57 if (remote_out_logfile_name) {
58 rol = static_cast<vrpn_int32>(strlen(remote_out_logfile_name));
63 static_cast<vrpn_int32>(4 *
sizeof(lil) + lil + lol + ril + rol);
64 char *buf =
new char[bufsize];
66 fprintf(stderr,
"vrpn_Auxiliary_Logger::pack_log_message_of_type(): " 78 vrpn_int32 bufleft = bufsize;
84 vrpn_buffer(bp, &bufleft, local_in_logfile_name, lil);
87 vrpn_buffer(bp, &bufleft, local_out_logfile_name, lol);
90 vrpn_buffer(bp, &bufleft, remote_in_logfile_name, ril);
93 vrpn_buffer(bp, &bufleft, remote_out_logfile_name, rol);
105 const char *buf, vrpn_int32 buflen,
char **local_in_logfile_name,
106 char **local_out_logfile_name,
char **remote_in_logfile_name,
107 char **remote_out_logfile_name)
109 const char *bufptr = buf;
114 vrpn_int32 localInNameLen, localOutNameLen, remoteInNameLen,
116 if (static_cast<size_t>(buflen) < 4 *
sizeof(localInNameLen)) {
117 fprintf(stderr,
"vrpn_Auxiliary_Logger::unpack_log_message_from_buffer:" 118 " Buffer too small for lengths.\n");
133 int size = 4 *
sizeof(localInNameLen) + localInNameLen + localOutNameLen +
134 remoteInNameLen + remoteOutNameLen;
135 if (buflen != size) {
136 fprintf(stderr,
"vrpn_Auxiliary_Logger::unpack_log_message_from_buffer:" 137 " Buffer size incorrect\n");
140 (*local_in_logfile_name) = NULL;
141 (*local_out_logfile_name) = NULL;
142 (*remote_in_logfile_name) = NULL;
143 (*remote_out_logfile_name) = NULL;
144 if (localInNameLen > 0) {
145 if (((*local_in_logfile_name) =
new char[localInNameLen + 1]) == NULL) {
146 fprintf(stderr,
"vrpn_Auxiliary_Logger::unpack_log_message_from_" 147 "buffer: Out of memory\n");
150 memcpy(*local_in_logfile_name, bufptr, localInNameLen);
151 (*local_in_logfile_name)[localInNameLen] =
'\0';
152 bufptr += localInNameLen;
155 if (((*local_in_logfile_name) =
new char[2]) == NULL) {
156 fprintf(stderr,
"vrpn_Auxiliary_Logger::unpack_log_message_from_" 157 "buffer: Out of memory\n");
160 (*local_in_logfile_name)[0] =
'\0';
162 if (localOutNameLen > 0) {
163 if (((*local_out_logfile_name) =
new char[localOutNameLen + 1]) ==
165 fprintf(stderr,
"vrpn_Auxiliary_Logger::unpack_log_message_from_" 166 "buffer: Out of memory\n");
169 memcpy(*local_out_logfile_name, bufptr, localOutNameLen);
170 (*local_out_logfile_name)[localOutNameLen] =
'\0';
171 bufptr += localOutNameLen;
174 if (((*local_out_logfile_name) =
new char[2]) == NULL) {
175 fprintf(stderr,
"vrpn_Auxiliary_Logger::unpack_log_message_from_" 176 "buffer: Out of memory\n");
179 (*local_out_logfile_name)[0] =
'\0';
181 if (remoteInNameLen > 0) {
182 if (((*remote_in_logfile_name) =
new char[remoteInNameLen + 1]) ==
184 fprintf(stderr,
"vrpn_Auxiliary_Logger::unpack_log_message_from_" 185 "buffer: Out of memory\n");
188 memcpy(*remote_in_logfile_name, bufptr, remoteInNameLen);
189 (*remote_in_logfile_name)[remoteInNameLen] =
'\0';
190 bufptr += remoteInNameLen;
193 if (((*remote_in_logfile_name) =
new char[2]) == NULL) {
194 fprintf(stderr,
"vrpn_Auxiliary_Logger::unpack_log_message_from_" 195 "buffer: Out of memory\n");
198 (*remote_in_logfile_name)[0] =
'\0';
200 if (remoteOutNameLen > 0) {
201 if (((*remote_out_logfile_name) =
new char[remoteOutNameLen + 1]) ==
203 fprintf(stderr,
"vrpn_Auxiliary_Logger::unpack_log_message_from_" 204 "buffer: Out of memory\n");
207 memcpy(*remote_out_logfile_name, bufptr, remoteOutNameLen);
208 (*remote_out_logfile_name)[remoteOutNameLen] =
'\0';
209 bufptr += remoteOutNameLen;
212 if (((*remote_out_logfile_name) =
new char[2]) == NULL) {
213 fprintf(stderr,
"vrpn_Auxiliary_Logger::unpack_log_message_from_" 214 "buffer: Out of memory\n");
217 (*remote_out_logfile_name)[0] =
'\0';
231 fprintf(stderr,
"vrpn_Auxiliary_Logger_Server::vrpn_Auxiliary_Logger_" 232 "Server: can't register dropped last connection " 240 fprintf(stderr,
"vrpn_Auxiliary_Logger_Server::vrpn_Auxiliary_Logger_" 241 "Server: can't register dropped last connection " 250 fprintf(stderr,
"vrpn_Auxiliary_Logger_Server::vrpn_Auxiliary_Logger_" 251 "Server: can't register logging request handler\n");
259 fprintf(stderr,
"vrpn_Auxiliary_Logger_Server::vrpn_Auxiliary_Logger_" 260 "Server: can't register logging-status request " 279 static_cast<vrpn_Auxiliary_Logger_Server *>(
userdata);
289 static_cast<vrpn_Auxiliary_Logger_Server *>(
userdata);
302 static_cast<vrpn_Auxiliary_Logger_Server *>(
userdata);
303 char *localInName = NULL, *localOutName = NULL, *remoteInName = NULL,
304 *remoteOutName = NULL;
308 &localInName, &localOutName,
309 &remoteInName, &remoteOutName)) {
310 fprintf(stderr,
"vrpn_Auxiliary_Logger_Server::static_handle_request_" 311 "logging: Could not unpack buffer\n");
320 delete[] localInName;
323 delete[] localOutName;
326 delete[] remoteInName;
329 delete[] remoteOutName;
335 const char *logger_name,
const char *connection_to_log,
vrpn_Connection *c)
337 , d_connection_name(NULL)
338 , d_logging_connection(NULL)
341 if ((connection_to_log == NULL) || (strlen(connection_to_log) == 0)) {
342 fprintf(stderr,
"vrpn_Auxiliary_Logger_Server_Generic::vrpn_Auxiliary_" 343 "Logger_Server_Generic: Empty logging name passed " 350 fprintf(stderr,
"vrpn_Auxiliary_Logger_Server_Generic::vrpn_Auxiliary_" 351 "Logger_Server_Generic: Out of memory\n");
378 const char *local_in_logfile_name,
const char *local_out_logfile_name,
379 const char *remote_in_logfile_name,
const char *remote_out_logfile_name)
395 const char *where_at;
396 if ((where_at = strrchr(cname,
'@')) != NULL) {
397 cname = where_at + 1;
403 where_at, local_in_logfile_name, local_out_logfile_name,
404 remote_in_logfile_name, remote_out_logfile_name, NULL,
true);
409 "(files already exist?)",
421 remote_in_logfile_name, remote_out_logfile_name);
433 if (local_in)
delete[] local_in;
434 if (local_out)
delete[] local_out;
435 if (remote_in)
delete[] remote_in;
436 if (remote_out)
delete[] remote_out;
458 "vrpn_Auxiliary_Logger_Remote: can't register handler\n");
464 "vrpn_Auxiliary_Logger_Remote: Can't get connection!\n");
474 static_cast<vrpn_Auxiliary_Logger_Remote *>(
userdata);
475 char *localInName = NULL, *localOutName = NULL, *remoteInName = NULL,
476 *remoteOutName = NULL;
480 &localInName, &localOutName,
481 &remoteInName, &remoteOutName)) {
482 fprintf(stderr,
"vrpn_Auxiliary_Logger_Remote::handle_report_message: " 483 "Could not unpack buffer\n");
501 delete[] localInName;
504 delete[] localOutName;
507 delete[] remoteInName;
510 delete[] remoteOutName;
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...
const char * local_out_logfile_name
vrpn_int32 request_logging_status_m_id
vrpn_Connection * d_logging_connection
virtual void handle_request_logging_status()
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)
virtual void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
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 dropped_last_connection_m_id
virtual void handle_request_logging_status()=0
const vrpn_uint32 vrpn_CONNECTION_RELIABLE
Classes of service for messages, specify multiple by ORing them together Priority of satisfying these...
vrpn_int32 report_logging_m_id
void client_mainloop(void)
Handles functions that all clients should provide in their mainloop() (warning of no server,...
virtual int register_types(void)
Register the types of messages this device sends/receives. Return 0 on success, -1 on fail.
const char * remote_out_logfile_name
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)=0
virtual vrpn_bool doing_okay(void) const
Returns vrpn_true if the connection is okay, vrpn_false if not.
bool unpack_log_message_from_buffer(const char *buf, vrpn_int32 buflen, char **local_in_logfile_name, char **local_out_logfile_name, char **remote_in_logfile_name, char **remote_out_logfile_name)
Generic connection class not specific to the transport mechanism.
vrpn_Auxiliary_Logger(const char *name, vrpn_Connection *c)
vrpn_int32 request_logging_m_id
bool pack_log_message_of_type(vrpn_int32 type, 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_Auxiliary_Logger_Server(const char *name, vrpn_Connection *c)
const char * vrpn_dropped_last_connection
virtual int init(void)
Initialize things that the constructor can't. Returns 0 on success, -1 on failure.
static int VRPN_CALLBACK static_handle_request_logging_status(void *userdata, vrpn_HANDLERPARAM p)
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_Callback_List< vrpn_AUXLOGGERCB > d_callback_list
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...
static int VRPN_CALLBACK static_handle_request_logging(void *userdata, vrpn_HANDLERPARAM p)
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_Auxiliary_Logger_Server_Generic()
const char * local_in_logfile_name
static int VRPN_CALLBACK handle_report_message(void *userdata, vrpn_HANDLERPARAM p)
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)
#define vrpn_gettimeofday
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).
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.
virtual void handle_dropped_last_connection(void)
Class from which all user-level (and other) classes that communicate with vrpn_Connections should der...
static int VRPN_CALLBACK static_handle_dropped_last_connection(void *userdata, vrpn_HANDLERPARAM p)
vrpn_int32 d_sender_id
Sender ID registered with the connection.
void get_log_names(char **local_in_logname, char **local_out_logname, char **remote_in_logname, char **remote_out_logname)
This function returns the logfile names of this connection in the parameters. It will allocate memory...
vrpn_Auxiliary_Logger_Remote(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.
vrpn_Auxiliary_Logger_Server_Generic(const char *logger_name, const char *connection_to_log, vrpn_Connection *c=NULL)
const int vrpn_ANY_SENDER
vrpn_ANY_SENDER can be used to register callbacks on a given message type from any sender.
const char * remote_in_logfile_name