1
#ifndef VRPN_FORWARDER_CONTROLLER_H
2
#define VRPN_FORWARDER_CONTROLLER_H
4
// vrpn_Forwarder_Controller
6
// Tom Hudson, September 1998
8
// Written to allow remote a client to tell a server to open another port
9
// and forward some messages on it to a friend of the client's.
11
// Any server that wishes to implement this needs only construct a
12
// vrpn_Forwarder_Server for each server connection it has open and
13
// to call the vrpn_Forwarder_Server mainloop frequently.
15
// Clients can construct a vrpn_Forwarder_Controller on a connection
16
// and call start_remote_forwarding(port) to tell the server to open
17
// <port>, then call forward_message_type(port, name) to start forwarding
18
// messages of the given name.
20
// This isn't an ideal solution, because it means clients need access to
21
// the names of the message, which they are normally insulated from.
23
// Some of the fancier options of the Forwarder (renaming services or
24
// types, changing class of service) are hidden from the user; this
25
// is meant to be a simple interface and simple first implementation.
27
// New Forwarder_Servers are NOT constructed on connections that a
28
// Forwarder_Server opens, so clients that are only listening to a
29
// forwarded stream cannot open new forwarders for still other clients to
32
#include "vrpn_Connection.h" // for vrpn_HANDLERPARAM
34
class VRPN_API vrpn_ConnectionForwarder;
36
class VRPN_API vrpn_Forwarder_Brain {
40
vrpn_Forwarder_Brain (vrpn_Connection *);
41
virtual ~vrpn_Forwarder_Brain (void);
43
// Tell a Forwarder_Server to open a vrpn_Connection on remote_port.
45
virtual void start_remote_forwarding (vrpn_int32 remote_port) = 0;
47
// Tell a Forwarder_Server to begin forwarding messages of type
48
// message_type from the sender named service_name over remote_port.
50
virtual void forward_message_type (vrpn_int32 remote_port,
51
const char * service_name,
52
const char * message_type) = 0;
56
vrpn_Connection * d_connection;
60
vrpn_int32 d_start_forwarding_type;
61
vrpn_int32 d_forward_type;
63
static char * encode_start_remote_forwarding (vrpn_int32 * length,
64
vrpn_int32 remote_port);
65
static char * encode_forward_message_type (vrpn_int32 * length,
66
vrpn_int32 remote_port, const char * service_name,
67
const char * message_type);
69
static void decode_start_remote_forwarding (const char * buffer,
70
vrpn_int32 * remote_port);
71
static void decode_forward_message_type (const char * buffer,
72
vrpn_int32 * remote_port, char ** service_name,
73
char ** message_type);
80
// VRPN server builders who want to enable remotely-controlled forwarding in
81
// their server need only create a Forwarder_Server on their server Connections
82
// and call its mainloop() regularly.
84
struct vrpn_Forwarder_List {
85
vrpn_Forwarder_List * next;
87
vrpn_Connection * connection;
88
vrpn_ConnectionForwarder * forwarder;
91
class VRPN_API vrpn_Forwarder_Server : public vrpn_Forwarder_Brain {
95
vrpn_Forwarder_Server (vrpn_Connection *);
96
virtual ~vrpn_Forwarder_Server (void);
98
virtual void mainloop (void);
100
virtual void start_remote_forwarding
101
(vrpn_int32 remote_port);
103
virtual void forward_message_type
104
(vrpn_int32 remote_port, const char * service_name,
105
const char * message_type);
109
vrpn_Forwarder_List * d_myForwarders;
113
static int VRPN_CALLBACK handle_start (void *, vrpn_HANDLERPARAM);
114
static int VRPN_CALLBACK handle_forward (void *, vrpn_HANDLERPARAM);
120
// Construct a Forwarder_Controller on a connection to control a
121
// Forwarder_Server on its far end.
123
class VRPN_API vrpn_Forwarder_Controller : public vrpn_Forwarder_Brain {
127
vrpn_Forwarder_Controller (vrpn_Connection *);
128
~vrpn_Forwarder_Controller (void);
130
virtual void start_remote_forwarding (vrpn_int32 remote_port);
132
virtual void forward_message_type
133
(vrpn_int32 remote_port, const char * service_name,
134
const char * message_type);
138
#endif // VRPN_FORWARDER_CONTROLLER_H