Panda3D

vrpnDial.cxx

00001 // Filename: vrpnDial.cxx
00002 // Created by:  drose (26Jan01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
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 //     Function: VrpnDial::Constructor
00026 //       Access: Public
00027 //  Description:
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 //     Function: VrpnDial::Destructor
00040 //       Access: Public
00041 //  Description:
00042 ////////////////////////////////////////////////////////////////////
00043 VrpnDial::
00044 ~VrpnDial() {
00045   delete _dial;
00046 }
00047 
00048 ////////////////////////////////////////////////////////////////////
00049 //     Function: VrpnDial::mark
00050 //       Access: Public
00051 //  Description: Adds the indicated VrpnDialDevice to the list of
00052 //               devices that are sharing this VrpnDial.
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 //     Function: VrpnDial::unmark
00064 //       Access: Public
00065 //  Description: Removes the indicated VrpnDialDevice from the list
00066 //               of devices that are sharing this VrpnDial.
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 //     Function: VrpnDial::output
00084 //       Access: Public
00085 //  Description:
00086 ////////////////////////////////////////////////////////////////////
00087 void VrpnDial::
00088 output(ostream &out) const {
00089   out << _dial_name;
00090 }
00091 
00092 ////////////////////////////////////////////////////////////////////
00093 //     Function: VrpnDial::write
00094 //       Access: Public
00095 //  Description:
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 //     Function: VrpnDial::vrpn_dial_callback
00106 //       Access: Private, Static
00107 //  Description: Receives the dial event data from the VRPN
00108 //               code and sends it to any interested
00109 //               VrpnDialDevices.
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 }
 All Classes Functions Variables Enumerations