Cleanup:
- keyboard_device now frees device_ref.name by itself when it's deleted - made 'active' variable volatile Bugfixes: - delete keyboard_device from fDevices list when the object is deleted. - removed deadlock from RemoveDevice - call UnregisterDevice from inside RemoveDevice - terminate devicer watcher thread on read error git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16926 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -349,6 +349,10 @@ KeyboardInputDevice::~KeyboardInputDevice()
|
|||||||
StopMonitoringDevice(kKeyboardDevicesDirectoryUSB);
|
StopMonitoringDevice(kKeyboardDevicesDirectoryUSB);
|
||||||
StopMonitoringDevice(kKeyboardDevicesDirectoryPS2);
|
StopMonitoringDevice(kKeyboardDevicesDirectoryPS2);
|
||||||
|
|
||||||
|
int count = fDevices.CountItems();
|
||||||
|
while (count-- > 0)
|
||||||
|
delete (keyboard_device *)fDevices.RemoveItem((int32)0);
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
fclose(sLogFile);
|
fclose(sLogFile);
|
||||||
#endif
|
#endif
|
||||||
@@ -529,17 +533,13 @@ status_t
|
|||||||
KeyboardInputDevice::AddDevice(const char *path)
|
KeyboardInputDevice::AddDevice(const char *path)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
keyboard_device *device = new keyboard_device();
|
keyboard_device *device = new keyboard_device(path);
|
||||||
if (!device)
|
if (!device)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
device->fd = -1;
|
device->fd = -1;
|
||||||
device->device_watcher = -1;
|
device->device_watcher = -1;
|
||||||
device->active = false;
|
device->active = false;
|
||||||
strcpy(device->path, path);
|
|
||||||
device->device_ref.name = GetShortName(path);
|
|
||||||
device->device_ref.type = B_KEYBOARD_DEVICE;
|
|
||||||
device->device_ref.cookie = device;
|
|
||||||
device->owner = this;
|
device->owner = this;
|
||||||
device->isAT = false;
|
device->isAT = false;
|
||||||
if (strstr(device->path, "keyboard/at") != NULL)
|
if (strstr(device->path, "keyboard/at") != NULL)
|
||||||
@@ -559,12 +559,16 @@ status_t
|
|||||||
KeyboardInputDevice::RemoveDevice(const char *path)
|
KeyboardInputDevice::RemoveDevice(const char *path)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
int32 i = 0;
|
keyboard_device *device;
|
||||||
keyboard_device *device = NULL;
|
for (int i = 0; (device = (keyboard_device *)fDevices.ItemAt(i)) != NULL; i++) {
|
||||||
while ((device = (keyboard_device *)fDevices.ItemAt(i)) != NULL) {
|
|
||||||
if (!strcmp(device->path, path)) {
|
if (!strcmp(device->path, path)) {
|
||||||
free(device->device_ref.name);
|
|
||||||
fDevices.RemoveItem(device);
|
fDevices.RemoveItem(device);
|
||||||
|
|
||||||
|
input_device_ref *devices[2];
|
||||||
|
devices[0] = &device->device_ref;
|
||||||
|
devices[1] = NULL;
|
||||||
|
UnregisterDevices(devices);
|
||||||
|
|
||||||
delete device;
|
delete device;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -593,8 +597,7 @@ KeyboardInputDevice::DeviceWatcher(void *arg)
|
|||||||
while (dev->active) {
|
while (dev->active) {
|
||||||
|
|
||||||
if (ioctl(dev->fd, KB_READ, &buffer) != B_OK) {
|
if (ioctl(dev->fd, KB_READ, &buffer) != B_OK) {
|
||||||
snooze(10000); // this is a realtime thread, and something is wrong...
|
return 0;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 keycode = 0;
|
uint32 keycode = 0;
|
||||||
@@ -754,8 +757,8 @@ KeyboardInputDevice::DeviceWatcher(void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *
|
static char *
|
||||||
KeyboardInputDevice::GetShortName(const char *longName)
|
GetShortName(const char *longName)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
BString string(longName);
|
BString string(longName);
|
||||||
@@ -815,3 +818,20 @@ KeyboardInputDevice::SetLeds(keyboard_device *device)
|
|||||||
|
|
||||||
ioctl(device->fd, KB_SET_LEDS, &lock_io);
|
ioctl(device->fd, KB_SET_LEDS, &lock_io);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
keyboard_device::keyboard_device(const char *path)
|
||||||
|
// todo: initialize other members
|
||||||
|
{
|
||||||
|
strcpy(this->path, path);
|
||||||
|
device_ref.name = GetShortName(path);
|
||||||
|
device_ref.type = B_KEYBOARD_DEVICE;
|
||||||
|
device_ref.cookie = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
keyboard_device::~keyboard_device()
|
||||||
|
{
|
||||||
|
free(device_ref.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,13 +37,16 @@
|
|||||||
class KeyboardInputDevice;
|
class KeyboardInputDevice;
|
||||||
|
|
||||||
struct keyboard_device {
|
struct keyboard_device {
|
||||||
|
keyboard_device(const char *path);
|
||||||
|
~keyboard_device();
|
||||||
|
|
||||||
KeyboardInputDevice *owner;
|
KeyboardInputDevice *owner;
|
||||||
input_device_ref device_ref;
|
input_device_ref device_ref;
|
||||||
char path[B_PATH_NAME_LENGTH];
|
char path[B_PATH_NAME_LENGTH];
|
||||||
int fd;
|
int fd;
|
||||||
thread_id device_watcher;
|
thread_id device_watcher;
|
||||||
kb_settings settings;
|
kb_settings settings;
|
||||||
bool active;
|
volatile bool active;
|
||||||
bool isAT;
|
bool isAT;
|
||||||
uint32 modifiers;
|
uint32 modifiers;
|
||||||
};
|
};
|
||||||
@@ -75,7 +78,6 @@ private:
|
|||||||
status_t RemoveDevice(const char *path);
|
status_t RemoveDevice(const char *path);
|
||||||
|
|
||||||
static int32 DeviceWatcher(void *arg);
|
static int32 DeviceWatcher(void *arg);
|
||||||
static char *GetShortName(const char *longName);
|
|
||||||
|
|
||||||
void SetLeds(keyboard_device *device);
|
void SetLeds(keyboard_device *device);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user