Skip to content

Commit fe2f34c

Browse files
committed
*** empty log message ***
1 parent 0ac4045 commit fe2f34c

31 files changed

+938
-261
lines changed

panda/src/device/Sources.pp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
clientBase.I clientBase.cxx clientBase.h \
1414
clientButtonDevice.I clientButtonDevice.cxx clientButtonDevice.h \
1515
clientDevice.I clientDevice.cxx clientDevice.h \
16+
clientDialDevice.I clientDialDevice.cxx clientDialDevice.h \
1617
clientTrackerDevice.I clientTrackerDevice.cxx clientTrackerDevice.h \
1718
config_device.cxx config_device.h \
18-
dialData.I dialData.cxx dialData.h mouse.cxx mouse.h trackerData.I \
19-
trackerData.cxx trackerData.h \
19+
dialNode.I dialNode.h dialNode.cxx \
20+
mouse.cxx mouse.h \
21+
trackerData.I trackerData.cxx trackerData.h \
2022
trackerNode.I trackerNode.cxx trackerNode.h
2123

2224
#define INSTALL_HEADERS \
@@ -26,9 +28,12 @@
2628
clientBase.I clientBase.h \
2729
clientButtonDevice.I clientButtonDevice.h \
2830
clientDevice.I clientDevice.h \
31+
clientDialDevice.I clientDialDevice.h \
2932
clientTrackerDevice.I clientTrackerDevice.h \
30-
config_device.h dialData.I dialData.h mouse.h \
31-
trackerData.I trackerData.h trackerNode.I trackerNode.h
33+
config_device.h mouse.h \
34+
dialNode.I dialNode.h \
35+
trackerData.I trackerData.h \
36+
trackerNode.I trackerNode.h
3237

3338
#define IGATESCAN all
3439

panda/src/device/analogNode.I

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ is_valid() const {
3535
////////////////////////////////////////////////////////////////////
3636
INLINE int AnalogNode::
3737
get_num_controls() const {
38-
return _analog->get_num_controls();
38+
_analog->lock();
39+
int result = _analog->get_num_controls();
40+
_analog->unlock();
41+
return result;
3942
}
4043

4144
////////////////////////////////////////////////////////////////////
@@ -48,7 +51,10 @@ get_num_controls() const {
4851
////////////////////////////////////////////////////////////////////
4952
INLINE double AnalogNode::
5053
get_control_state(int index) const {
51-
return _analog->get_control_state(index);
54+
_analog->lock();
55+
double result = _analog->get_control_state(index);
56+
_analog->unlock();
57+
return result;
5258
}
5359

5460
////////////////////////////////////////////////////////////////////
@@ -60,7 +66,10 @@ get_control_state(int index) const {
6066
////////////////////////////////////////////////////////////////////
6167
INLINE bool AnalogNode::
6268
is_control_known(int index) const {
63-
return _analog->is_control_known(index);
69+
_analog->lock();
70+
bool result = _analog->is_control_known(index);
71+
_analog->unlock();
72+
return result;
6473
}
6574

6675
////////////////////////////////////////////////////////////////////

panda/src/device/analogNode.cxx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ write(ostream &out, int indent_level) const {
6767
DataNode::write(out, indent_level);
6868

6969
if (_analog != (ClientAnalogDevice *)NULL) {
70+
_analog->lock();
7071
_analog->write_controls(out, indent_level + 2);
72+
_analog->unlock();
7173
}
7274
}
7375

@@ -83,15 +85,18 @@ transmit_data(NodeAttributes &data) {
8385

8486
LPoint3f out(0.0, 0.0, 0.0);
8587

88+
_analog->lock();
8689
for (int i = 0; i < max_outputs; i++) {
87-
if (_outputs[i]._index >= 0 && is_control_known(_outputs[i]._index)) {
90+
if (_outputs[i]._index >= 0 &&
91+
_analog->is_control_known(_outputs[i]._index)) {
8892
if (_outputs[i]._flip) {
89-
out[i] = -get_control_state(_outputs[i]._index);
93+
out[i] = -_analog->get_control_state(_outputs[i]._index);
9094
} else {
91-
out[i] = get_control_state(_outputs[i]._index);
95+
out[i] = _analog->get_control_state(_outputs[i]._index);
9296
}
9397
}
9498
}
99+
_analog->unlock();
95100
_xyz->set_value(out);
96101
}
97102

panda/src/device/buttonNode.I

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ is_valid() const {
2727
////////////////////////////////////////////////////////////////////
2828
INLINE int ButtonNode::
2929
get_num_buttons() const {
30-
return _button->get_num_buttons();
30+
_button->lock();
31+
int result = _button->get_num_buttons();
32+
_button->unlock();
33+
return result;
3134
}
3235

3336
////////////////////////////////////////////////////////////////////
@@ -46,7 +49,9 @@ get_num_buttons() const {
4649
////////////////////////////////////////////////////////////////////
4750
INLINE void ButtonNode::
4851
set_button_map(int index, ButtonHandle button) {
52+
_button->lock();
4953
_button->set_button_map(index, button);
54+
_button->unlock();
5055
}
5156

5257
////////////////////////////////////////////////////////////////////
@@ -59,7 +64,10 @@ set_button_map(int index, ButtonHandle button) {
5964
////////////////////////////////////////////////////////////////////
6065
INLINE ButtonHandle ButtonNode::
6166
get_button_map(int index) const {
62-
return _button->get_button_map(index);
67+
_button->lock();
68+
ButtonHandle result = _button->get_button_map(index);
69+
_button->unlock();
70+
return result;
6371
}
6472

6573
////////////////////////////////////////////////////////////////////
@@ -71,7 +79,10 @@ get_button_map(int index) const {
7179
////////////////////////////////////////////////////////////////////
7280
INLINE bool ButtonNode::
7381
get_button_state(int index) const {
74-
return _button->get_button_state(index);
82+
_button->lock();
83+
bool result = _button->get_button_state(index);
84+
_button->unlock();
85+
return result;
7586
}
7687

7788
////////////////////////////////////////////////////////////////////
@@ -83,5 +94,8 @@ get_button_state(int index) const {
8394
////////////////////////////////////////////////////////////////////
8495
INLINE bool ButtonNode::
8596
is_button_known(int index) const {
86-
return _button->is_button_known(index);
97+
_button->lock();
98+
bool result = _button->is_button_known(index);
99+
_button->unlock();
100+
return result;
87101
}

panda/src/device/buttonNode.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ output(ostream &out) const {
7272

7373
if (_button != (ClientButtonDevice *)NULL) {
7474
out << " (";
75+
_button->lock();
7576
_button->output_buttons(out);
77+
_button->unlock();
7678
out << ")";
7779
}
7880
}
@@ -87,7 +89,9 @@ write(ostream &out, int indent_level) const {
8789
DataNode::write(out, indent_level);
8890

8991
if (_button != (ClientButtonDevice *)NULL) {
92+
_button->lock();
9093
_button->write_buttons(out, indent_level + 2);
94+
_button->unlock();
9195
}
9296
}
9397

panda/src/device/clientDevice.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,18 @@ ClientDevice::
5656
// (and it is probably a mistake to do so); it will
5757
// automatically be called when the ClientDevice object
5858
// destructs.
59+
//
60+
// The lock should *not* be held while this call is
61+
// made; it will explicitly grab the lock itself.
5962
////////////////////////////////////////////////////////////////////
6063
void ClientDevice::
6164
disconnect() {
6265
if (_is_connected) {
66+
lock();
6367
bool disconnected =
6468
_client->disconnect_device(_device_type, _device_name, this);
6569
_is_connected = false;
70+
unlock();
6671
nassertv(disconnected);
6772
}
6873
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Filename: clientDialDevice.I
2+
// Created by: drose (26Jan01)
3+
//
4+
////////////////////////////////////////////////////////////////////
5+
6+
////////////////////////////////////////////////////////////////////
7+
// Function: ClientDialDevice::DialState::Constructor
8+
// Access: Public
9+
// Description:
10+
////////////////////////////////////////////////////////////////////
11+
INLINE ClientDialDevice::DialState::
12+
DialState() :
13+
_offset(0.0),
14+
_known(false)
15+
{
16+
}
17+
18+
////////////////////////////////////////////////////////////////////
19+
// Function: ClientDialDevice::Constructor
20+
// Access: Protected
21+
// Description:
22+
////////////////////////////////////////////////////////////////////
23+
INLINE ClientDialDevice::
24+
ClientDialDevice(ClientBase *client, const string &device_name):
25+
ClientDevice(client, get_class_type(), device_name)
26+
{
27+
}
28+
29+
////////////////////////////////////////////////////////////////////
30+
// Function: ClientDialDevice::get_num_dials
31+
// Access: Public
32+
// Description: Returns the number of dial dials known to the
33+
// ClientDialDevice. This number may change as
34+
// more dials are discovered.
35+
////////////////////////////////////////////////////////////////////
36+
INLINE int ClientDialDevice::
37+
get_num_dials() const {
38+
return _dials.size();
39+
}
40+
41+
////////////////////////////////////////////////////////////////////
42+
// Function: ClientDialDevice::push_dial
43+
// Access: Public
44+
// Description: Marks that the dial has been offset by the indicated
45+
// amount. It is the user's responsibility to ensure
46+
// that this call is protected within lock().
47+
////////////////////////////////////////////////////////////////////
48+
INLINE void ClientDialDevice::
49+
push_dial(int index, double offset) {
50+
ensure_dial_index(index);
51+
nassertv(index >= 0 && index < (int)_dials.size());
52+
_dials[index]._offset += offset;
53+
_dials[index]._known = true;
54+
}
55+
56+
////////////////////////////////////////////////////////////////////
57+
// Function: ClientDialDevice::read_dial
58+
// Access: Public
59+
// Description: Returns the number of complete revolutions of the
60+
// dial since the last time read_dial() was called.
61+
// This is a destructive operation; it is not possible
62+
// to read the dial without resetting the counter.
63+
//
64+
// It is the user's responsibility to ensure that this
65+
// call is protected within lock().
66+
////////////////////////////////////////////////////////////////////
67+
INLINE double ClientDialDevice::
68+
read_dial(int index) {
69+
if (index >= 0 && index < (int)_dials.size()) {
70+
double result = _dials[index]._offset;
71+
_dials[index]._offset = 0.0;
72+
return result;
73+
} else {
74+
return 0.0;
75+
}
76+
}
77+
78+
////////////////////////////////////////////////////////////////////
79+
// Function: ClientDialDevice::is_dial_known
80+
// Access: Public
81+
// Description: Returns true if the state of the indicated dial
82+
// dial is known, or false if we have never heard
83+
// anything about this particular dial.
84+
////////////////////////////////////////////////////////////////////
85+
INLINE bool ClientDialDevice::
86+
is_dial_known(int index) const {
87+
if (index >= 0 && index < (int)_dials.size()) {
88+
return _dials[index]._known;
89+
} else {
90+
return false;
91+
}
92+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Filename: clientDialDevice.cxx
2+
// Created by: drose (26Jan01)
3+
//
4+
////////////////////////////////////////////////////////////////////
5+
6+
#include "clientDialDevice.h"
7+
8+
#include <indent.h>
9+
10+
TypeHandle ClientDialDevice::_type_handle;
11+
12+
13+
14+
////////////////////////////////////////////////////////////////////
15+
// Function: ClientDialDevice::ensure_dial_index
16+
// Access: Private
17+
// Description: Guarantees that there is a slot in the array for the
18+
// indicated index number, by filling the array up to
19+
// that index if necessary.
20+
////////////////////////////////////////////////////////////////////
21+
void ClientDialDevice::
22+
ensure_dial_index(int index) {
23+
nassertv(index >= 0);
24+
25+
_dials.reserve(index + 1);
26+
while ((int)_dials.size() <= index) {
27+
_dials.push_back(DialState());
28+
}
29+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Filename: clientDialDevice.h
2+
// Created by: drose (26Jan01)
3+
//
4+
////////////////////////////////////////////////////////////////////
5+
6+
#ifndef CLIENTDIALDEVICE_H
7+
#define CLIENTDIALDEVICE_H
8+
9+
#include <pandabase.h>
10+
11+
#include "clientDevice.h"
12+
13+
////////////////////////////////////////////////////////////////////
14+
// Class : ClientDialDevice
15+
// Description : A device, attached to the ClientBase by a
16+
// DialNode, that records the data from a single
17+
// named dial device. The named device can contain
18+
// any number of dials, numbered in sequence beginning
19+
// at zero.
20+
//
21+
// A dial is a rotating device that does not have
22+
// stops--it can keep rotating any number of times.
23+
// Therefore it does not have a specific position at any
24+
// given time, unlike an AnalogDevice.
25+
////////////////////////////////////////////////////////////////////
26+
class EXPCL_PANDA ClientDialDevice : public ClientDevice {
27+
protected:
28+
INLINE ClientDialDevice(ClientBase *client, const string &device_name);
29+
30+
public:
31+
INLINE int get_num_dials() const;
32+
33+
INLINE void push_dial(int index, double offset);
34+
INLINE double read_dial(int index);
35+
INLINE bool is_dial_known(int index) const;
36+
37+
private:
38+
void ensure_dial_index(int index);
39+
40+
protected:
41+
class DialState {
42+
public:
43+
INLINE DialState();
44+
45+
double _offset;
46+
bool _known;
47+
};
48+
49+
typedef vector<DialState> Dials;
50+
Dials _dials;
51+
52+
53+
public:
54+
static TypeHandle get_class_type() {
55+
return _type_handle;
56+
}
57+
static void init_type() {
58+
ClientDevice::init_type();
59+
register_type(_type_handle, "ClientDialDevice",
60+
ClientDevice::get_class_type());
61+
}
62+
virtual TypeHandle get_type() const {
63+
return get_class_type();
64+
}
65+
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
66+
67+
private:
68+
static TypeHandle _type_handle;
69+
};
70+
71+
#include "clientDialDevice.I"
72+
73+
#endif

0 commit comments

Comments
 (0)