7#if !(defined(_WIN32) && defined(VRPN_USE_WINSOCK_SOCKETS))
40 vrpn_int32 remote_port)
46 *length =
sizeof(vrpn_int32);
47 try { outbuf =
new char[*length]; }
53 nPort = htonl(remote_port);
54 memcpy(outbuf, &nPort,
sizeof(vrpn_int32));
61 const char *buffer, vrpn_int32 *remote_port)
65 if (!buffer || !remote_port)
return;
67 memcpy(&port, buffer,
sizeof(vrpn_int32));
68 *remote_port = ntohl(port);
73 vrpn_int32 *length, vrpn_int32 remote_port,
const char *service_name,
74 const char *message_type)
82 if (!service_name || !message_type) { *length = 0;
return NULL; }
83 *length =
static_cast<int>(3 *
sizeof(vrpn_int32) + strlen(service_name) +
84 strlen(message_type));
85 try { outbuf =
new char[*length]; }
97 nPort = htonl(remote_port);
98 nSLen = htonl(
static_cast<vrpn_int32
>(strlen(service_name)));
99 nTLen = htonl(
static_cast<vrpn_int32
>(strlen(message_type)));
100 memcpy(outbuf, &nPort,
sizeof(vrpn_int32));
101 memcpy(outbuf +
sizeof(vrpn_int32), &nSLen,
sizeof(vrpn_int32));
102 memcpy(outbuf + 2 *
sizeof(vrpn_int32), &nTLen,
sizeof(vrpn_int32));
103 strcpy(outbuf + 3 *
sizeof(vrpn_int32), service_name);
104 strcpy(outbuf + 3 *
sizeof(vrpn_int32) + strlen(service_name),
112 vrpn_int32 *remote_port,
122 if (!buffer || !remote_port || !message_type)
return;
127 memcpy(&port, buffer,
sizeof(vrpn_int32));
128 *remote_port = ntohl(port);
129 memcpy(&Slength, buffer +
sizeof(vrpn_int32),
sizeof(vrpn_int32));
130 Slength = ntohl(Slength);
131 try { Soutbuf =
new char[1 + Slength]; }
134 *service_name = NULL;
135 *message_type = NULL;
138 memcpy(&Tlength, buffer + 2 *
sizeof(vrpn_int32),
sizeof(vrpn_int32));
139 Tlength = ntohl(Tlength);
140 try { Toutbuf =
new char[1 + Tlength]; }
143 *service_name = NULL;
144 *message_type = NULL;
147 strncpy(Soutbuf, buffer + 3 *
sizeof(vrpn_int32), Slength);
148 Soutbuf[Slength] =
'\0';
149 *service_name = Soutbuf;
150 strncpy(Toutbuf, buffer + 3 *
sizeof(vrpn_int32) + Slength, Tlength);
151 Toutbuf[Tlength] =
'\0';
152 *message_type = Toutbuf;
157 , d_myForwarders(NULL)
183 fprintf(stderr,
"vrpn_Forwarder_Server::~vrpn_Forwarder_Server(): delete failed\n");
191 fprintf(stderr,
"vrpn_Forwarder_Server::~vrpn_Forwarder_Server(): delete failed\n");
214 if (fp->
port == remote_port) {
215 fprintf(stderr,
"vrpn_Forwarder_Server::start_remote_forwarding: "
216 "Already open on port %d.\n",
225 fprintf(stderr,
"vrpn_Forwarder_Server::start_remote_forwarding: "
230 fp->
port = remote_port;
234 fprintf(stderr,
"vrpn_Forwarder_Server::start_remote_forwarding: "
248 const char *service_name,
249 const char *message_type)
259 if (fp->
port == remote_port) it = fp;
263 "vrpn_Forwarder_Server: No forwarder open on port %d.\n",
273 fprintf(stderr,
"vrpn_Forwarder_Server: Couldn't forward messages of "
274 "type \"%s\" on port %d.\n",
275 message_type, remote_port);
300 if (!servicebuffer || !typebuffer)
return -1;
304 delete[] servicebuffer;
307 fprintf(stderr,
"vrpn_Forwarder_Server::handle_forward(): delete failed\n");
330 if (!buffer)
return false;
337 fprintf(stderr,
"vrpn_Forwarder_Server::start_remote_forwarding(): delete failed\n");
344 const char *service_name,
345 const char *message_type)
362 fprintf(stderr,
"vrpn_Forwarder_Server::forward_message_type(): delete failed\n");
int forward(const char *sourceName, const char *sourceServiceName, const char *destinationName, const char *destinationServiceName, vrpn_uint32 classOfService=vrpn_CONNECTION_RELIABLE)
Generic connection class not specific to the transport mechanism.
void addReference()
Counting references to this connection.
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 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 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...
vrpn_Connection * d_connection
vrpn_Forwarder_Brain(vrpn_Connection *)
static char * encode_start_remote_forwarding(vrpn_int32 *length, vrpn_int32 remote_port)
virtual ~vrpn_Forwarder_Brain(void)
vrpn_int32 d_forward_type
static void decode_forward_message_type(const char *buffer, vrpn_int32 *remote_port, char **service_name, char **message_type)
vrpn_int32 d_start_forwarding_type
static void decode_start_remote_forwarding(const char *buffer, vrpn_int32 *remote_port)
static char * encode_forward_message_type(vrpn_int32 *length, vrpn_int32 remote_port, const char *service_name, const char *message_type)
virtual vrpn_bool start_remote_forwarding(vrpn_int32 remote_port)
vrpn_Forwarder_Controller(vrpn_Connection *)
~vrpn_Forwarder_Controller(void)
virtual void forward_message_type(vrpn_int32 remote_port, const char *service_name, const char *message_type)
virtual void mainloop(void)
virtual void forward_message_type(vrpn_int32 remote_port, const char *service_name, const char *message_type)
vrpn_Forwarder_Server(vrpn_Connection *)
virtual vrpn_bool start_remote_forwarding(vrpn_int32 remote_port)
virtual ~vrpn_Forwarder_Server(void)
vrpn_Forwarder_List * d_myForwarders
vrpn_Forwarder_List * next
vrpn_ConnectionForwarder * forwarder
vrpn_Connection * connection
This structure is what is passed to a vrpn_Connection message callback.
vrpn_Connection * vrpn_create_server_connection(const char *cname, const char *local_in_logfile_name, const char *local_out_logfile_name)
Create a server 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...
class VRPN_API vrpn_ConnectionForwarder
#define vrpn_gettimeofday