* Add a BJoystick::RescanDevices() public function. It allows the BJoystick
to be updated with newly plugged in devices without the need to recreate a BJoystick object. * Do an initial (re-)scan on object creation instead of always scanning in CountDevices() and by extension GetDeviceName(). * This makes CountDevices() and GetDeviceName() stable with regards to the device list, so that an enumerating application doesn't suddenly get more/less devices than it might expect. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41870 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -41,6 +41,12 @@ public:
|
|||||||
status_t GetDeviceName(int32 index, char* name,
|
status_t GetDeviceName(int32 index, char* name,
|
||||||
size_t bufSize = B_OS_NAME_LENGTH);
|
size_t bufSize = B_OS_NAME_LENGTH);
|
||||||
|
|
||||||
|
status_t RescanDevices();
|
||||||
|
// Haiku extension. Updates the list of devices
|
||||||
|
// as enumerated by CountDevices() and
|
||||||
|
// GetDeviceName() with possibly newly plugged
|
||||||
|
// in devices.
|
||||||
|
|
||||||
bool EnterEnhancedMode(const entry_ref* ref = NULL);
|
bool EnterEnhancedMode(const entry_ref* ref = NULL);
|
||||||
|
|
||||||
int32 CountSticks();
|
int32 CountSticks();
|
||||||
|
|||||||
@@ -68,6 +68,8 @@ BJoystick::BJoystick()
|
|||||||
|
|
||||||
if (fJoystickInfo != NULL)
|
if (fJoystickInfo != NULL)
|
||||||
memset(fJoystickInfo, 0, sizeof(joystick_info));
|
memset(fJoystickInfo, 0, sizeof(joystick_info));
|
||||||
|
|
||||||
|
RescanDevices();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -200,12 +202,10 @@ BJoystick::CountDevices()
|
|||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
|
|
||||||
// Refresh devices list
|
if (fDevices == NULL)
|
||||||
ScanDevices(true);
|
return 0;
|
||||||
|
|
||||||
int32 count = 0;
|
int32 count = fDevices->CountItems();
|
||||||
if (fDevices != NULL)
|
|
||||||
count = fDevices->CountItems();
|
|
||||||
|
|
||||||
LOG("Count = %d\n", count);
|
LOG("Count = %d\n", count);
|
||||||
return count;
|
return count;
|
||||||
@@ -219,8 +219,7 @@ BJoystick::GetDeviceName(int32 index, char *name, size_t bufSize)
|
|||||||
if (fDevices == NULL)
|
if (fDevices == NULL)
|
||||||
return B_NO_INIT;
|
return B_NO_INIT;
|
||||||
|
|
||||||
// CountDevices() also calls ScanDevices() and therefore updates our list.
|
if (index >= fDevices->CountItems())
|
||||||
if (index >= CountDevices())
|
|
||||||
return B_BAD_INDEX;
|
return B_BAD_INDEX;
|
||||||
|
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
@@ -236,6 +235,19 @@ BJoystick::GetDeviceName(int32 index, char *name, size_t bufSize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BJoystick::RescanDevices()
|
||||||
|
{
|
||||||
|
CALLED();
|
||||||
|
|
||||||
|
if (fDevices == NULL)
|
||||||
|
return B_NO_INIT;
|
||||||
|
|
||||||
|
ScanDevices(true);
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BJoystick::EnterEnhancedMode(const entry_ref *ref)
|
BJoystick::EnterEnhancedMode(const entry_ref *ref)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user