~hitmuri/vjpirate/trunk

« back to all changes in this revision

Viewing changes to os/win/include/vrpn_ForwarderController.h

  • Committer: Florent Berthaut
  • Date: 2014-07-26 18:53:16 UTC
  • mfrom: (5.1.12 mac)
  • Revision ID: flo@localhost.localdomain-20140726185316-c2ucnwmgm5kij4e2
Merged mac branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef VRPN_FORWARDER_CONTROLLER_H
 
2
#define VRPN_FORWARDER_CONTROLLER_H
 
3
 
 
4
// vrpn_Forwarder_Controller
 
5
//
 
6
// Tom Hudson, September 1998
 
7
 
 
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.
 
10
 
 
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.
 
14
 
 
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.
 
19
 
 
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.
 
22
 
 
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.
 
26
 
 
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
 
30
// listen to.
 
31
 
 
32
#include "vrpn_Connection.h"  // for vrpn_HANDLERPARAM
 
33
 
 
34
class VRPN_API vrpn_ConnectionForwarder;
 
35
 
 
36
class VRPN_API vrpn_Forwarder_Brain {
 
37
 
 
38
  public:
 
39
 
 
40
    vrpn_Forwarder_Brain (vrpn_Connection *);
 
41
    virtual ~vrpn_Forwarder_Brain (void);
 
42
 
 
43
    // Tell a Forwarder_Server to open a vrpn_Connection on remote_port.
 
44
 
 
45
    virtual void start_remote_forwarding (vrpn_int32 remote_port) = 0;
 
46
 
 
47
    // Tell a Forwarder_Server to begin forwarding messages of type
 
48
    // message_type from the sender named service_name over remote_port.
 
49
 
 
50
    virtual void forward_message_type (vrpn_int32 remote_port,
 
51
                                       const char * service_name,
 
52
                                       const char * message_type) = 0;
 
53
 
 
54
  protected:
 
55
 
 
56
    vrpn_Connection * d_connection;
 
57
 
 
58
    vrpn_int32 d_myId;
 
59
 
 
60
    vrpn_int32 d_start_forwarding_type;
 
61
    vrpn_int32 d_forward_type;
 
62
 
 
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);
 
68
 
 
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);
 
74
 
 
75
};
 
76
 
 
77
 
 
78
// Server class
 
79
 
 
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.
 
83
 
 
84
struct vrpn_Forwarder_List {
 
85
  vrpn_Forwarder_List * next;
 
86
  vrpn_int32 port;
 
87
  vrpn_Connection * connection;
 
88
  vrpn_ConnectionForwarder * forwarder;
 
89
};
 
90
 
 
91
class VRPN_API vrpn_Forwarder_Server : public vrpn_Forwarder_Brain {
 
92
 
 
93
  public:
 
94
 
 
95
    vrpn_Forwarder_Server (vrpn_Connection *);
 
96
    virtual ~vrpn_Forwarder_Server (void);
 
97
 
 
98
    virtual void mainloop (void);
 
99
 
 
100
    virtual void start_remote_forwarding
 
101
                 (vrpn_int32 remote_port);
 
102
 
 
103
    virtual void forward_message_type
 
104
                 (vrpn_int32 remote_port, const char * service_name,
 
105
                  const char * message_type);
 
106
 
 
107
  protected:
 
108
 
 
109
    vrpn_Forwarder_List * d_myForwarders;
 
110
 
 
111
  private:
 
112
 
 
113
    static int VRPN_CALLBACK handle_start (void *, vrpn_HANDLERPARAM);
 
114
    static int VRPN_CALLBACK handle_forward (void *, vrpn_HANDLERPARAM);
 
115
 
 
116
};
 
117
 
 
118
// Client class
 
119
 
 
120
// Construct a Forwarder_Controller on a connection to control a
 
121
// Forwarder_Server on its far end.
 
122
 
 
123
class VRPN_API vrpn_Forwarder_Controller : public vrpn_Forwarder_Brain {
 
124
 
 
125
  public:
 
126
 
 
127
    vrpn_Forwarder_Controller (vrpn_Connection *);
 
128
    ~vrpn_Forwarder_Controller (void);
 
129
 
 
130
    virtual void start_remote_forwarding (vrpn_int32 remote_port);
 
131
 
 
132
    virtual void forward_message_type
 
133
                 (vrpn_int32 remote_port, const char * service_name,
 
134
                  const char * message_type);
 
135
 
 
136
};
 
137
 
 
138
#endif  // VRPN_FORWARDER_CONTROLLER_H
 
139