00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "buttonNode.h"
00016 #include "config_device.h"
00017 #include "dataNodeTransmit.h"
00018 #include "buttonEventList.h"
00019 #include "dcast.h"
00020
00021 TypeHandle ButtonNode::_type_handle;
00022
00023
00024
00025
00026
00027
00028 ButtonNode::
00029 ButtonNode(ClientBase *client, const string &device_name) :
00030 DataNode(device_name)
00031 {
00032 _button_events_output = define_output("button_events", ButtonEventList::get_class_type());
00033 _button_events = new ButtonEventList;
00034
00035 nassertv(client != (ClientBase *)NULL);
00036 PT(ClientDevice) device =
00037 client->get_device(ClientButtonDevice::get_class_type(), device_name);
00038
00039 if (device == (ClientDevice *)NULL) {
00040 device_cat.warning()
00041 << "Unable to open button device " << device_name << "\n";
00042 return;
00043 }
00044
00045 if (!device->is_of_type(ClientButtonDevice::get_class_type())) {
00046 device_cat.error()
00047 << "Inappropriate device type " << device->get_type()
00048 << " created; expected a ClientButtonDevice.\n";
00049 return;
00050 }
00051
00052 _button = DCAST(ClientButtonDevice, device);
00053 }
00054
00055
00056
00057
00058
00059
00060 ButtonNode::
00061 ~ButtonNode() {
00062
00063
00064
00065 }
00066
00067
00068
00069
00070
00071
00072 void ButtonNode::
00073 output(ostream &out) const {
00074 DataNode::output(out);
00075
00076 if (_button != (ClientButtonDevice *)NULL) {
00077 out << " (";
00078 _button->acquire();
00079 _button->output_buttons(out);
00080 _button->unlock();
00081 out << ")";
00082 }
00083 }
00084
00085
00086
00087
00088
00089
00090 void ButtonNode::
00091 write(ostream &out, int indent_level) const {
00092 DataNode::write(out, indent_level);
00093
00094 if (_button != (ClientButtonDevice *)NULL) {
00095 _button->acquire();
00096 _button->write_buttons(out, indent_level + 2);
00097 _button->unlock();
00098 }
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 void ButtonNode::
00115 do_transmit_data(DataGraphTraverser *, const DataNodeTransmit &,
00116 DataNodeTransmit &output) {
00117 if (is_valid()) {
00118 _button->poll();
00119 _button->acquire();
00120
00121 (*_button_events) = (*_button->get_button_events());
00122
00123 _button->get_button_events()->clear();
00124 _button->unlock();
00125
00126 output.set_data(_button_events_output, EventParameter(_button_events));
00127 }
00128 }