* Removed the log file stuff; debug output is now using debug_printf() instead.

* Removed an inconsistency: both mouse and keyboad input device add-ons would
  scan /dev/input/keyboard respectively /dev/input/mouse when loaded, but then
  only monitor certain subdirectories from it. Now they monitor all.
* Made KeyboardInputDevice::InitCheck() do what the name says, ie. nothing
  else.
* Now uses BObjectList instead of BList, which also simplifies the code a bit.
* Make use of the new BPathMonitor messages: as those contain a path, they
  greatly simplify their handling.
* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28242 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-10-19 15:59:23 +00:00
parent 23debb05d0
commit b6a7b20419
7 changed files with 233 additions and 335 deletions
@@ -2,7 +2,7 @@ SubDir HAIKU_TOP src add-ons input_server devices keyboard ;
SetSubDirSupportedPlatformsBeOSCompatible ;
UsePrivateHeaders input interface tracker ;
UsePrivateHeaders input interface shared tracker ;
UsePrivateSystemHeaders ;
Addon <input>keyboard :
@@ -1,11 +1,18 @@
/*
* Copyright 2004-2006, Jérôme Duval. All rights reserved.
* Copyright 2005-2008, Axel Dörfler, [email protected].
*
* Distributed under the terms of the MIT License.
*/
#include "KeyboardInputDevice.h"
#include "kb_mouse_driver.h"
#include <errno.h>
#include <new>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <Application.h>
#include <Autolock.h>
@@ -15,23 +22,24 @@
#include <Path.h>
#include <String.h>
#include <errno.h>
#include <new>
#include <stdlib.h>
#include <unistd.h>
#include "kb_mouse_driver.h"
#if DEBUG
FILE *KeyboardInputDevice::sLogFile = NULL;
//#define TRACE_KEYBOARD_DEVICE
#ifdef TRACE_KEYBOARD_DEVICE
# define LOG(text...) debug_printf(text)
# define LOG_ERR(text...) LOG(text)
#else
# define LOG(text...) do {} while (0)
# define LOG_ERR(text...) debug_printf(text)
#endif
#define CALLED() LOG("%s\n", __PRETTY_FUNCTION__)
const static uint32 kKeyboardThreadPriority = B_FIRST_REAL_TIME_PRIORITY + 4;
const static char* kKeyboardDevicesDirectory = "/dev/input/keyboard";
// "/dev/" is automatically prepended by StartMonitoringDevice()
const static char *kKeyboardDevicesDirectoryPS2 = "input/keyboard/at";
const static char *kKeyboardDevicesDirectoryUSB = "input/keyboard/usb";
const static uint32 kATKeycodeMap[] = {
0x1, // Esc
0x12, // 1
@@ -327,8 +335,7 @@ const static uint32 kATKeycodeMap[] = {
};
extern "C"
BInputServerDevice *
extern "C" BInputServerDevice*
instantiate_input_device()
{
return new(std::nothrow) KeyboardInputDevice();
@@ -366,31 +373,21 @@ get_short_name(const char *longName)
KeyboardInputDevice::KeyboardInputDevice()
:
fTMWindow(NULL),
fDevices(2, true),
fTeamMonitorWindow(NULL),
fKeymapLock("keymap lock")
{
#if DEBUG
if (sLogFile == NULL)
sLogFile = fopen("/var/log/keyboard_device_log.log", "a");
#endif
CALLED();
StartMonitoringDevice(kKeyboardDevicesDirectory);
_RecursiveScan(kKeyboardDevicesDirectory);
}
KeyboardInputDevice::~KeyboardInputDevice()
{
CALLED();
StopMonitoringDevice(kKeyboardDevicesDirectoryUSB);
StopMonitoringDevice(kKeyboardDevicesDirectoryPS2);
int count = fDevices.CountItems();
while (count-- > 0) {
delete (keyboard_device *)fDevices.RemoveItem((int32)0);
}
#if DEBUG
fclose(sLogFile);
#endif
StopMonitoringDevice(kKeyboardDevicesDirectory);
}
@@ -398,8 +395,8 @@ status_t
KeyboardInputDevice::SystemShuttingDown()
{
CALLED();
if (fTMWindow)
fTMWindow->PostMessage(SYSTEM_SHUTTING_DOWN);
if (fTeamMonitorWindow)
fTeamMonitorWindow->PostMessage(SYSTEM_SHUTTING_DOWN);
return B_OK;
}
@@ -428,8 +425,7 @@ KeyboardInputDevice::_InitFromSettings(void *cookie, uint32 opcode)
LOG_ERR("error when KB_SET_KEY_REPEAT_DELAY, fd:%d\n", device->fd);
}
if (opcode == 0
|| opcode == B_KEY_MAP_CHANGED
if (opcode == 0 || opcode == B_KEY_MAP_CHANGED
|| opcode == B_KEY_LOCKS_CHANGED) {
BAutolock lock(fKeymapLock);
fKeymap.LoadCurrent();
@@ -445,17 +441,7 @@ status_t
KeyboardInputDevice::InitCheck()
{
CALLED();
status_t status = BInputServerDevice::InitCheck();
if (status < B_OK)
return status;
// TODO: this doesn't belong here!
_RecursiveScan(kKeyboardDevicesDirectory);
StartMonitoringDevice(kKeyboardDevicesDirectoryPS2);
StartMonitoringDevice(kKeyboardDevicesDirectoryUSB);
return B_OK;
return BInputServerDevice::InitCheck();
}
@@ -505,9 +491,9 @@ KeyboardInputDevice::Stop(const char *name, void *cookie)
wait_for_thread(device->device_watcher, &dummy);
}
if (fTMWindow) {
fTMWindow->PostMessage(B_QUIT_REQUESTED);
fTMWindow = NULL;
if (fTeamMonitorWindow) {
fTeamMonitorWindow->PostMessage(B_QUIT_REQUESTED);
fTeamMonitorWindow = NULL;
}
return B_OK;
@@ -535,40 +521,18 @@ status_t
KeyboardInputDevice::_HandleMonitor(BMessage* message)
{
CALLED();
int32 opcode = 0;
status_t status;
if ((status = message->FindInt32("opcode", &opcode)) < B_OK)
return status;
if (opcode != B_ENTRY_CREATED
&& opcode != B_ENTRY_REMOVED)
return B_OK;
BEntry entry;
BPath path;
dev_t device;
ino_t directory;
const char *name = NULL;
message->FindInt32("device", &device);
message->FindInt64("directory", &directory);
message->FindString("name", &name);
entry_ref ref(device, directory, name);
if ((status = entry.SetTo(&ref)) != B_OK)
return status;
if ((status = entry.GetPath(&path)) != B_OK)
return status;
if ((status = path.InitCheck()) != B_OK)
return status;
const char* path;
int32 opcode;
if (message->FindInt32("opcode", &opcode) != B_OK
|| opcode != B_ENTRY_CREATED && opcode != B_ENTRY_REMOVED
|| message->FindString("path", &path) != B_OK)
return B_BAD_VALUE;
if (opcode == B_ENTRY_CREATED)
_AddDevice(path.Path());
else
_RemoveDevice(path.Path());
return _AddDevice(path);
return status;
return _RemoveDevice(path);
}
@@ -597,9 +561,9 @@ KeyboardInputDevice::_RemoveDevice(const char *path)
{
CALLED();
keyboard_device* device;
for (int i = 0; (device = (keyboard_device *)fDevices.ItemAt(i)) != NULL; i++) {
for (int i = 0; (device = fDevices.ItemAt(i)) != NULL; i++) {
if (!strcmp(device->path, path)) {
fDevices.RemoveItem(device);
fDevices.RemoveItemAt(i);
input_device_ref* devices[2];
devices[0] = &device->device_ref;
@@ -643,17 +607,17 @@ KeyboardInputDevice::_DeviceWatcher(void *arg)
LOG("KB_READ :");
if (device->isAT) {
at_kbd_io *at_kbd = (at_kbd_io *)buffer;
if (at_kbd->scancode > 0)
keycode = kATKeycodeMap[at_kbd->scancode-1];
isKeyDown = at_kbd->is_keydown;
timestamp = at_kbd->timestamp;
LOG(" %02x", at_kbd->scancode);
at_kbd_io* atKeyboard = (at_kbd_io*)buffer;
if (atKeyboard->scancode > 0)
keycode = kATKeycodeMap[atKeyboard->scancode - 1];
isKeyDown = atKeyboard->is_keydown;
timestamp = atKeyboard->timestamp;
LOG(" %02x", atKeyboard->scancode);
} else {
raw_key_info *raw_kbd = (raw_key_info *)buffer;
isKeyDown = raw_kbd->is_keydown;
timestamp = raw_kbd->timestamp;
keycode = raw_kbd->be_keycode;
raw_key_info* rawKeyInfo= (raw_key_info*)buffer;
isKeyDown = rawKeyInfo->is_keydown;
timestamp = rawKeyInfo->timestamp;
keycode = rawKeyInfo->be_keycode;
}
if (keycode == 0)
@@ -692,11 +656,11 @@ KeyboardInputDevice::_DeviceWatcher(void *arg)
LOG("TeamMonitor called\n");
// show the team monitor
if (owner->fTMWindow == NULL)
owner->fTMWindow = new (std::nothrow) TMWindow();
if (owner->fTeamMonitorWindow == NULL)
owner->fTeamMonitorWindow = new (std::nothrow) TMWindow();
if (owner->fTMWindow != NULL) {
owner->fTMWindow->Enable();
if (owner->fTeamMonitorWindow != NULL) {
owner->fTeamMonitorWindow->Enable();
// cancel timer only for R5
if (ioctl(device->fd, KB_CANCEL_CONTROL_ALT_DEL, NULL) == B_OK)
@@ -739,7 +703,8 @@ KeyboardInputDevice::_DeviceWatcher(void *arg)
newDeadKey = keymap->IsDeadKey(keycode, device->modifiers);
if (newDeadKey == 0) {
char *string = NULL, *rawString = NULL;
char* string = NULL;
char* rawString = NULL;
int32 numBytes = 0, rawNumBytes = 0;
keymap->GetChars(keycode, device->modifiers, activeDeadKey, &string, &numBytes);
keymap->GetChars(keycode, 0, 0, &rawString, &rawNumBytes);
@@ -1,5 +1,5 @@
/*
* Copyright 2004-2006, Jérôme Duval. All rights reserved.
* Copyright 2004-2008, Jérôme Duval. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef KEYBOARD_INPUT_DEVICE_H
@@ -15,7 +15,7 @@
#include <Locker.h>
#include <List.h>
#include <stdio.h>
#include <ObjectList.h>
class KeyboardInputDevice;
@@ -25,8 +25,10 @@ struct keyboard_device : public BHandler {
virtual ~keyboard_device();
virtual void MessageReceived(BMessage* message);
status_t EnqueueInlineInputMethod(int32 opcode, const char* string = NULL,
bool confirmed = false, BMessage* keyDown = NULL);
status_t EnqueueInlineInputMethod(int32 opcode,
const char* string = NULL,
bool confirmed = false,
BMessage* keyDown = NULL);
KeyboardInputDevice* owner;
input_device_ref device_ref;
@@ -56,10 +58,6 @@ class KeyboardInputDevice : public BInputServerDevice {
virtual status_t SystemShuttingDown();
#ifdef DEBUG
static FILE *sLogFile;
#endif
private:
status_t _HandleMonitor(BMessage* message);
status_t _InitFromSettings(void* cookie, uint32 opcode = 0);
@@ -68,27 +66,16 @@ class KeyboardInputDevice : public BInputServerDevice {
status_t _AddDevice(const char* path);
status_t _RemoveDevice(const char* path);
static int32 _DeviceWatcher(void *arg);
void _SetLeds(keyboard_device* device);
BList fDevices;
static int32 _DeviceWatcher(void* arg);
BObjectList<keyboard_device> fDevices;
Keymap fKeymap;
TMWindow *fTMWindow;
TMWindow* fTeamMonitorWindow;
BLocker fKeymapLock;
};
extern "C" BInputServerDevice* instantiate_input_device();
#if DEBUG
inline void LOG(const char *fmt, ...) { char buf[1024]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); va_end(ap); \
fputs(buf, KeyboardInputDevice::sLogFile); fflush(KeyboardInputDevice::sLogFile); }
#define LOG_ERR(text...) LOG(text)
#else
#define LOG(text...)
#define LOG_ERR(text...) fprintf(stderr, text)
#endif
#define CALLED() LOG("%s\n", __PRETTY_FUNCTION__)
#endif // KEYBOARD_INPUT_DEVICE_H
@@ -259,7 +259,6 @@ TMView::Pulse()
void
TMView::UpdateList()
{
CALLED();
bool changed = false;
for (int32 i = 0; i < fListView->CountItems(); i++) {
@@ -2,7 +2,7 @@ SubDir HAIKU_TOP src add-ons input_server devices mouse ;
SetSubDirSupportedPlatformsBeOSCompatible ;
UsePrivateHeaders input ;
UsePrivateHeaders input shared ;
Addon <input>mouse :
MouseInputDevice.cpp
@@ -10,8 +10,12 @@
#include "MouseInputDevice.h"
#include "kb_mouse_settings.h"
#include "kb_mouse_driver.h"
#include <errno.h>
#include <new>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <Debug.h>
#include <Directory.h>
@@ -21,28 +25,25 @@
#include <String.h>
#include <View.h>
#include <errno.h>
#include <new>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "kb_mouse_settings.h"
#include "kb_mouse_driver.h"
#if DEBUG
FILE *MouseInputDevice::sLogFile = NULL;
//#define TRACE_MOUSE_DEVICE
#ifdef TRACE_MOUSE_DEVICE
# define LOG(text...) debug_printf(text)
# define LOG_ERR(text...) LOG(text)
#else
# define LOG(text...)
# define LOG_ERR(text...) fprintf(stderr, text)
# define LOG(text...) do {} while (0)
# define LOG_ERR(text...) debug_printf(text)
#endif
#define CALLED() LOG("%s\n", __PRETTY_FUNCTION__)
const static uint32 kMouseThreadPriority = B_FIRST_REAL_TIME_PRIORITY + 4;
const static char* kMouseDevicesDirectory = "/dev/input/mouse";
// "/dev/" is automatically prepended by StartMonitoringDevice()
const static char *kMouseDevicesDirectoryPS2 = "input/mouse/ps2";
const static char *kMouseDevicesDirectoryUSB = "input/mouse/usb";
class MouseDevice {
public:
@@ -83,19 +84,6 @@ class MouseDevice {
};
#if DEBUG
inline void
LOG(const char *fmt, ...)
{
char buf[1024];
va_list ap;
va_start(ap, fmt);
vsprintf(buf, fmt, ap); va_end(ap);
fputs(buf, MouseInputDevice::sLogFile); fflush(MouseInputDevice::sLogFile);
}
#endif
extern "C" BInputServerDevice*
instantiate_input_device()
{
@@ -412,15 +400,12 @@ MouseDevice::_BuildShortName() const
MouseInputDevice::MouseInputDevice()
:
fDevices(2, true)
{
#if DEBUG
sLogFile = fopen("/var/log/mouse_device_log.log", "a");
#endif
CALLED();
StartMonitoringDevice(kMouseDevicesDirectoryPS2);
StartMonitoringDevice(kMouseDevicesDirectoryUSB);
StartMonitoringDevice(kMouseDevicesDirectory);
_RecursiveScan(kMouseDevicesDirectory);
}
@@ -428,17 +413,7 @@ MouseInputDevice::MouseInputDevice()
MouseInputDevice::~MouseInputDevice()
{
CALLED();
StopMonitoringDevice(kMouseDevicesDirectoryUSB);
StopMonitoringDevice(kMouseDevicesDirectoryPS2);
int32 count = fDevices.CountItems();
while (count-- > 0) {
delete (MouseDevice *)fDevices.RemoveItem(count);
}
#if DEBUG
fclose(sLogFile);
#endif
StopMonitoringDevice(kMouseDevicesDirectory);
}
@@ -495,40 +470,17 @@ MouseInputDevice::_HandleMonitor(BMessage* message)
{
CALLED();
const char* path;
int32 opcode;
if (message->FindInt32("opcode", &opcode) < B_OK)
if (message->FindInt32("opcode", &opcode) != B_OK
|| opcode != B_ENTRY_CREATED && opcode != B_ENTRY_REMOVED
|| message->FindString("path", &path) != B_OK)
return B_BAD_VALUE;
if (opcode != B_ENTRY_CREATED && opcode != B_ENTRY_REMOVED)
return B_OK;
BEntry entry;
BPath path;
dev_t device;
ino_t directory;
const char *name;
if (message->FindInt32("device", &device) < B_OK
|| message->FindInt64("directory", &directory) < B_OK
|| message->FindString("name", &name) < B_OK)
return B_BAD_VALUE;
entry_ref ref(device, directory, name);
status_t status;
if ((status = entry.SetTo(&ref)) != B_OK)
return status;
if ((status = entry.GetPath(&path)) != B_OK)
return status;
if ((status = path.InitCheck()) != B_OK)
return status;
if (opcode == B_ENTRY_CREATED)
status = _AddDevice(path.Path());
else
status = _RemoveDevice(path.Path());
return _AddDevice(path);
return status;
return _RemoveDevice(path);
}
@@ -538,7 +490,7 @@ MouseInputDevice::_FindDevice(const char *path)
CALLED();
for (int32 i = fDevices.CountItems(); i-- > 0;) {
MouseDevice* device = (MouseDevice*)fDevices.ItemAt(i);
MouseDevice* device = fDevices.ItemAt(i);
if (!strcmp(device->Path(), path))
return device;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2004-2006, Haiku.
* Copyright 2004-2008, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -11,9 +11,8 @@
#include <InputServerDevice.h>
#include <InterfaceDefs.h>
#include <List.h>
#include <stdio.h>
#include <ObjectList.h>
class MouseDevice;
@@ -39,11 +38,7 @@ class MouseInputDevice : public BInputServerDevice {
status_t _AddDevice(const char* path);
status_t _RemoveDevice(const char* path);
BList fDevices;
#ifdef DEBUG
public:
static FILE *sLogFile;
#endif
BObjectList<MouseDevice> fDevices;
};
extern "C" BInputServerDevice* instantiate_input_device();