00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "vrpnDial.h"
00016 #include "vrpnDialDevice.h"
00017 #include "vrpnClient.h"
00018 #include "config_vrpn.h"
00019
00020 #include "indent.h"
00021
00022 #include <algorithm>
00023
00024
00025
00026
00027
00028
00029 VrpnDial::
00030 VrpnDial(const string &dial_name, vrpn_Connection *connection) :
00031 _dial_name(dial_name)
00032 {
00033 _dial = new vrpn_Dial_Remote(_dial_name.c_str(), connection);
00034
00035 _dial->register_change_handler((void*)this, &vrpn_dial_callback);
00036 }
00037
00038
00039
00040
00041
00042
00043 VrpnDial::
00044 ~VrpnDial() {
00045 delete _dial;
00046 }
00047
00048
00049
00050
00051
00052
00053
00054 void VrpnDial::
00055 mark(VrpnDialDevice *device) {
00056 if (vrpn_cat.is_debug()) {
00057 vrpn_cat.debug() << *this << " marking " << *device << "\n";
00058 }
00059 _devices.push_back(device);
00060 }
00061
00062
00063
00064
00065
00066
00067
00068 void VrpnDial::
00069 unmark(VrpnDialDevice *device) {
00070 if (vrpn_cat.is_debug()) {
00071 vrpn_cat.debug() << *this << " unmarking " << *device << "\n";
00072 }
00073
00074 Devices::iterator di =
00075 find(_devices.begin(), _devices.end(), device);
00076
00077 if (di != _devices.end()) {
00078 _devices.erase(di);
00079 }
00080 }
00081
00082
00083
00084
00085
00086
00087 void VrpnDial::
00088 output(ostream &out) const {
00089 out << _dial_name;
00090 }
00091
00092
00093
00094
00095
00096
00097 void VrpnDial::
00098 write(ostream &out, int indent_level) const {
00099 indent(out, indent_level)
00100 << get_dial_name() << " ("
00101 << _devices.size() << " devices)\n";
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111 void VRPN_CALLBACK VrpnDial::
00112 vrpn_dial_callback(void *userdata, const vrpn_DIALCB info) {
00113 VrpnDial *self = (VrpnDial *)userdata;
00114
00115 if (vrpn_cat.is_debug()) {
00116 vrpn_cat.debug()
00117 << *self << " got dial " << info.dial << " = " << info.change << "\n";
00118 }
00119
00120 Devices::iterator di;
00121 for (di = self->_devices.begin(); di != self->_devices.end(); ++di) {
00122 VrpnDialDevice *device = (*di);
00123 device->acquire();
00124 device->push_dial(info.dial, info.change);
00125 device->unlock();
00126 }
00127 }