vrpn
07.35
Virtual Reality Peripheral Network
Toggle main menu visibility
Loading...
Searching...
No Matches
vrpn_Dial.h
Go to the documentation of this file.
1
// vrpn_Dial.h
2
// This implements a Dial class. A dial is an object that spins,
3
// possibly without bound. It returns the fraction of a revolution that
4
// it has turned as its message type.
5
6
#ifndef VRPN_DIAL_H
7
#define VRPN_DIAL_H
8
9
const
int
vrpn_DIAL_MAX
= 128;
10
11
#include <stddef.h>
// for NULL
12
13
#include "
vrpn_BaseClass.h
"
// for vrpn_Callback_List, etc
14
#include "
vrpn_Configure.h
"
// for VRPN_API, VRPN_CALLBACK
15
#include "
vrpn_Shared.h
"
// for timeval
16
#include "
vrpn_Types.h
"
// for vrpn_float64, vrpn_int32
17
18
class
VRPN_API
vrpn_Connection
;
19
struct
vrpn_HANDLERPARAM
;
20
21
class
VRPN_API
vrpn_Dial
:
public
vrpn_BaseClass
{
22
public
:
23
vrpn_Dial
(
const
char
*name,
vrpn_Connection
*c = NULL);
24
25
protected
:
26
vrpn_float64
dials
[
vrpn_DIAL_MAX
];
27
vrpn_int32
num_dials
;
28
struct
timeval
timestamp
;
29
vrpn_int32
change_m_id
;
// change message id
30
31
virtual
int
register_types
(
void
);
32
virtual
vrpn_int32
encode_to
(
char
*buf, vrpn_int32 buflen, vrpn_int32 dial,
33
vrpn_float64 delta);
34
virtual
void
report_changes
(
void
);
// send report iff changed
35
virtual
void
report
(
void
);
// send report
36
};
37
38
//----------------------------------------------------------
39
// Example server for an array of dials
40
// This will generate an array of dials that all spin at the same
41
// rate (revolutions/second), and which send reports at a different rate
42
// (updates/second). A real server would send reports whenever it saw
43
// dials changing, and would not have the spin_rate or update_rate parameters.
44
// This server can be used for testing to make sure a client is
45
// working correctly, and to ensure that a connection to a remote server
46
// is working (by running the example server with the name of the device that
47
// the real server would use).
48
49
class
VRPN_API
vrpn_Dial_Example_Server
:
public
vrpn_Dial
{
50
public
:
51
vrpn_Dial_Example_Server
(
const
char
*name,
vrpn_Connection
*c,
52
vrpn_int32 numdials = 1,
53
vrpn_float64 spin_rate = 1.0,
54
vrpn_float64 update_rate = 10.0);
55
virtual
void
mainloop
();
56
57
protected
:
58
vrpn_float64
_spin_rate
;
// The rate at which to spin (revolutions/sec)
59
vrpn_float64
_update_rate
;
// The rate at which to update (reports/sec)
60
// The dials[] array within the parent is used for the values
61
// The num_dials within the parent is used
62
// The timestamp field within the parent structure is used for timing
63
// The report_changes() or report() functions within the parent are used
64
};
65
66
//----------------------------------------------------------
67
//************** Users deal with the following *************
68
69
// User routine to handle a change in dial values. This is called when
70
// the dial callback is called (when a message from its counterpart
71
// across the connetion arrives).
72
73
typedef
struct
_vrpn_DIALCB {
74
struct
timeval
msg_time
;
// Timestamp when change happened
75
vrpn_int32
dial
;
// which dial changed
76
vrpn_float64
change
;
// Fraction of a revolution it changed
77
}
vrpn_DIALCB
;
78
79
typedef
void(
VRPN_CALLBACK
*
vrpn_DIALCHANGEHANDLER
)(
void
*userdata,
80
const
vrpn_DIALCB
info);
81
82
// Open a dial device that is on the other end of a connection
83
// and handle updates from it. This is the type of device
84
// that user code will deal with.
85
86
class
VRPN_API
vrpn_Dial_Remote
:
public
vrpn_Dial
{
87
public
:
88
// The name of the device to connect to.
89
// Optional argument to be used when the Remote MUST listen on
90
// a connection that is already open.
91
vrpn_Dial_Remote
(
const
char
*name,
vrpn_Connection
*c = NULL);
92
~vrpn_Dial_Remote
();
93
94
// This routine calls the mainloop of the connection it's on
95
virtual
void
mainloop
();
96
97
// (un)Register a callback handler to handle dial updates
98
virtual
int
register_change_handler
(
void
*
userdata
,
99
vrpn_DIALCHANGEHANDLER
handler
)
100
{
101
return
d_callback_list
.register_handler(
userdata
,
handler
);
102
};
103
virtual
int
unregister_change_handler
(
void
*
userdata
,
104
vrpn_DIALCHANGEHANDLER
handler
)
105
{
106
return
d_callback_list
.unregister_handler(
userdata
,
handler
);
107
}
108
109
protected
:
110
vrpn_Callback_List<vrpn_DIALCB>
d_callback_list
;
111
112
static
int
VRPN_CALLBACK
113
handle_change_message
(
void
*
userdata
,
vrpn_HANDLERPARAM
p);
114
};
115
116
#endif
vrpn_BaseClassUnique::handler
vrpn_MESSAGEHANDLER handler
Definition
vrpn_BaseClass.h:287
vrpn_BaseClassUnique::userdata
void * userdata
Definition
vrpn_BaseClass.h:290
vrpn_BaseClass::mainloop
virtual void mainloop()=0
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_BaseClass::register_types
virtual int register_types(void)=0
Register the types of messages this device sends/receives. Return 0 on success, -1 on fail.
vrpn_BaseClass::vrpn_BaseClass
vrpn_BaseClass(const char *name, vrpn_Connection *c=NULL)
Names the device and assigns or opens connection, calls registration methods.
Definition
vrpn_BaseClass.C:310
vrpn_Callback_List
Definition
vrpn_BaseClass.h:367
vrpn_Connection
Generic connection class not specific to the transport mechanism.
Definition
vrpn_Connection.h:561
vrpn_Dial_Example_Server::vrpn_Dial_Example_Server
vrpn_Dial_Example_Server(const char *name, vrpn_Connection *c, vrpn_int32 numdials=1, vrpn_float64 spin_rate=1.0, vrpn_float64 update_rate=10.0)
Definition
vrpn_Dial.C:104
vrpn_Dial_Example_Server::_spin_rate
vrpn_float64 _spin_rate
Definition
vrpn_Dial.h:58
vrpn_Dial_Example_Server::_update_rate
vrpn_float64 _update_rate
Definition
vrpn_Dial.h:59
vrpn_Dial_Remote::d_callback_list
vrpn_Callback_List< vrpn_DIALCB > d_callback_list
Definition
vrpn_Dial.h:110
vrpn_Dial_Remote::register_change_handler
virtual int register_change_handler(void *userdata, vrpn_DIALCHANGEHANDLER handler)
Definition
vrpn_Dial.h:98
vrpn_Dial_Remote::unregister_change_handler
virtual int unregister_change_handler(void *userdata, vrpn_DIALCHANGEHANDLER handler)
Definition
vrpn_Dial.h:103
vrpn_Dial_Remote::vrpn_Dial_Remote
vrpn_Dial_Remote(const char *name, vrpn_Connection *c=NULL)
Definition
vrpn_Dial.C:167
vrpn_Dial_Remote::handle_change_message
static int VRPN_CALLBACK handle_change_message(void *userdata, vrpn_HANDLERPARAM p)
Definition
vrpn_Dial.C:205
vrpn_Dial::report_changes
virtual void report_changes(void)
Definition
vrpn_Dial.C:54
vrpn_Dial::timestamp
struct timeval timestamp
Definition
vrpn_Dial.h:28
vrpn_Dial::dials
vrpn_float64 dials[vrpn_DIAL_MAX]
Definition
vrpn_Dial.h:26
vrpn_Dial::report
virtual void report(void)
Definition
vrpn_Dial.C:82
vrpn_Dial::vrpn_Dial
vrpn_Dial(const char *name, vrpn_Connection *c=NULL)
Definition
vrpn_Dial.C:8
vrpn_Dial::num_dials
vrpn_int32 num_dials
Definition
vrpn_Dial.h:27
vrpn_Dial::encode_to
virtual vrpn_int32 encode_to(char *buf, vrpn_int32 buflen, vrpn_int32 dial, vrpn_float64 delta)
Definition
vrpn_Dial.C:31
vrpn_Dial::change_m_id
vrpn_int32 change_m_id
Definition
vrpn_Dial.h:29
vrpn_DIALCB
Definition
vrpn_Dial.h:73
vrpn_DIALCB::dial
vrpn_int32 dial
Definition
vrpn_Dial.h:75
vrpn_DIALCB::msg_time
struct timeval msg_time
Definition
vrpn_Dial.h:74
vrpn_DIALCB::change
vrpn_float64 change
Definition
vrpn_Dial.h:76
vrpn_HANDLERPARAM
This structure is what is passed to a vrpn_Connection message callback.
Definition
vrpn_Connection.h:41
vrpn_BaseClass.h
All types of client/server/peer objects in VRPN should be derived from the vrpn_BaseClass type descri...
vrpn_Configure.h
VRPN_API
#define VRPN_API
Definition
vrpn_Configure.h:648
VRPN_CALLBACK
#define VRPN_CALLBACK
Definition
vrpn_Configure.h:649
vrpn_Connection
class VRPN_API vrpn_Connection
Definition
vrpn_Dial.h:18
vrpn_DIALCHANGEHANDLER
void(VRPN_CALLBACK * vrpn_DIALCHANGEHANDLER)(void *userdata, const vrpn_DIALCB info)
Definition
vrpn_Dial.h:79
vrpn_DIAL_MAX
const int vrpn_DIAL_MAX
Definition
vrpn_Dial.h:9
vrpn_Shared.h
vrpn_Types.h
vrpn_Dial.h
Generated by
1.17.0