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