Panda3D
vrpnDial.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file vrpnDial.cxx
10  * @author drose
11  * @date 2001-01-26
12  */
13 
14 #include "vrpnDial.h"
15 #include "vrpnDialDevice.h"
16 #include "vrpnClient.h"
17 #include "config_vrpn.h"
18 
19 #include "indent.h"
20 
21 #include <algorithm>
22 
23 /**
24  *
25  */
26 VrpnDial::
27 VrpnDial(const std::string &dial_name, vrpn_Connection *connection) :
28  _dial_name(dial_name)
29 {
30  _dial = new vrpn_Dial_Remote(_dial_name.c_str(), connection);
31 
32  _dial->register_change_handler((void*)this, &vrpn_dial_callback);
33 }
34 
35 /**
36  *
37  */
38 VrpnDial::
39 ~VrpnDial() {
40  delete _dial;
41 }
42 
43 /**
44  * Adds the indicated VrpnDialDevice to the list of devices that are sharing
45  * this VrpnDial.
46  */
47 void VrpnDial::
48 mark(VrpnDialDevice *device) {
49  if (vrpn_cat.is_debug()) {
50  vrpn_cat.debug() << *this << " marking " << *device << "\n";
51  }
52  _devices.push_back(device);
53 }
54 
55 /**
56  * Removes the indicated VrpnDialDevice from the list of devices that are
57  * sharing this VrpnDial.
58  */
59 void VrpnDial::
61  if (vrpn_cat.is_debug()) {
62  vrpn_cat.debug() << *this << " unmarking " << *device << "\n";
63  }
64 
65  Devices::iterator di =
66  find(_devices.begin(), _devices.end(), device);
67 
68  if (di != _devices.end()) {
69  _devices.erase(di);
70  }
71 }
72 
73 /**
74  *
75  */
76 void VrpnDial::
77 output(std::ostream &out) const {
78  out << _dial_name;
79 }
80 
81 /**
82  *
83  */
84 void VrpnDial::
85 write(std::ostream &out, int indent_level) const {
86  indent(out, indent_level)
87  << get_dial_name() << " ("
88  << _devices.size() << " devices)\n";
89 }
90 
91 /**
92  * Receives the dial event data from the VRPN code and sends it to any
93  * interested VrpnDialDevices.
94  */
95 void VRPN_CALLBACK VrpnDial::
96 vrpn_dial_callback(void *userdata, const vrpn_DIALCB info) {
97  VrpnDial *self = (VrpnDial *)userdata;
98 
99  if (vrpn_cat.is_debug()) {
100  vrpn_cat.debug()
101  << *self << " got dial " << info.dial << " = " << info.change << "\n";
102  }
103 
104  Devices::iterator di;
105  for (di = self->_devices.begin(); di != self->_devices.end(); ++di) {
106  VrpnDialDevice *device = (*di);
107  device->push_dial(info.dial, info.change);
108  }
109 }
void push_dial(int index, double offset)
Marks that the dial has been offset by the indicated amount.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The Panda interface to a VRPN dial device.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
void mark(VrpnDialDevice *device)
Adds the indicated VrpnDialDevice to the list of devices that are sharing this VrpnDial.
Definition: vrpnDial.cxx:48
const std::string & get_dial_name() const
Returns the name of the dial device that was used to create this VrpnDial.
Definition: vrpnDial.I:18
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the actual interface to a particular VRPN dial device, and all of its numbered dials.
Definition: vrpnDial.h:37
void unmark(VrpnDialDevice *device)
Removes the indicated VrpnDialDevice from the list of devices that are sharing this VrpnDial.
Definition: vrpnDial.cxx:60
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.