* Coding style cleanup
* Applied the changes that were done to MouseInputDevice: - use BObjectList, - take adventage of BPathMonitor node monitor message fieds - remove the device in the polling thread upon ioctl() error * Added TODOs about refactoring the code together with MouseInputDevice. Untested, but the code is so similar, I am pretty confident it still works. (famous last words... will test soon anyways) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28421 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,13 +1,7 @@
|
|||||||
SubDir HAIKU_TOP src add-ons input_server devices touchpad ;
|
SubDir HAIKU_TOP src add-ons input_server devices touchpad ;
|
||||||
|
|
||||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
UsePrivateHeaders input shared ;
|
||||||
|
|
||||||
UsePrivateHeaders input ;
|
|
||||||
|
|
||||||
Addon <input>touchpad :
|
Addon <input>touchpad :
|
||||||
TouchpadInputDevice.cpp
|
TouchpadInputDevice.cpp
|
||||||
: be input_server ;
|
: be input_server ;
|
||||||
|
|
||||||
Package haiku-inputkit-cvs :
|
|
||||||
<input>touchpad :
|
|
||||||
boot home config add-ons input_server devices ;
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ const static char *kTouchpadDevicesDirectoryPS2 = "input/touchpad/ps2";
|
|||||||
|
|
||||||
class TouchpadDevice {
|
class TouchpadDevice {
|
||||||
public:
|
public:
|
||||||
TouchpadDevice(BInputServerDevice& target, const char* path);
|
TouchpadDevice(TouchpadInputDevice& target, const char* path);
|
||||||
~TouchpadDevice();
|
~TouchpadDevice();
|
||||||
|
|
||||||
status_t Start();
|
status_t Start();
|
||||||
@@ -76,22 +76,22 @@ class TouchpadDevice {
|
|||||||
|
|
||||||
char* _BuildShortName() const;
|
char* _BuildShortName() const;
|
||||||
|
|
||||||
status_t GetSettingsPath(BPath &path);
|
status_t _GetSettingsPath(BPath &path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BInputServerDevice& fTarget;
|
TouchpadInputDevice& fTarget;
|
||||||
BString fPath;
|
BString fPath;
|
||||||
int fDevice;
|
int fDevice;
|
||||||
|
|
||||||
input_device_ref fDeviceRef;
|
input_device_ref fDeviceRef;
|
||||||
mouse_settings fSettings;
|
mouse_settings fSettings;
|
||||||
bool fDeviceRemapsButtons;
|
bool fDeviceRemapsButtons;
|
||||||
|
|
||||||
thread_id fThread;
|
thread_id fThread;
|
||||||
volatile bool fActive;
|
volatile bool fActive;
|
||||||
|
|
||||||
bool fIsTouchpad;
|
bool fIsTouchpad;
|
||||||
touchpad_settings fTouchpadSettings;
|
touchpad_settings fTouchpadSettings;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -118,10 +118,12 @@ instantiate_input_device()
|
|||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
TouchpadDevice::TouchpadDevice(BInputServerDevice& target, const char *driverPath)
|
TouchpadDevice::TouchpadDevice(TouchpadInputDevice& target,
|
||||||
|
const char* driverPath)
|
||||||
:
|
:
|
||||||
fTarget(target),
|
fTarget(target),
|
||||||
fDevice(-1),
|
fDevice(-1),
|
||||||
|
fDeviceRemapsButtons(false),
|
||||||
fThread(-1),
|
fThread(-1),
|
||||||
fActive(false),
|
fActive(false),
|
||||||
fIsTouchpad(false)
|
fIsTouchpad(false)
|
||||||
@@ -138,7 +140,6 @@ TouchpadDevice::TouchpadDevice(BInputServerDevice& target, const char *driverPat
|
|||||||
fSettings.map.button[2] = B_TERTIARY_MOUSE_BUTTON;
|
fSettings.map.button[2] = B_TERTIARY_MOUSE_BUTTON;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fDeviceRemapsButtons = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -152,13 +153,12 @@ TouchpadDevice::~TouchpadDevice()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
TouchpadDevice::GetSettingsPath(BPath &path)
|
TouchpadDevice::_GetSettingsPath(BPath &path)
|
||||||
{
|
{
|
||||||
status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
||||||
if(status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
return status;
|
||||||
path.Append(TOUCHPAD_SETTINGS_FILE);
|
return path.Append(TOUCHPAD_SETTINGS_FILE);
|
||||||
return B_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ TouchpadDevice::Start()
|
|||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
// touchpad settings
|
// touchpad settings
|
||||||
if(ioctl(fDevice, MS_IS_TOUCHPAD, NULL) == B_OK){
|
if (ioctl(fDevice, MS_IS_TOUCHPAD, NULL) == B_OK) {
|
||||||
LOG("is touchpad %s\n", fPath.String());
|
LOG("is touchpad %s\n", fPath.String());
|
||||||
fIsTouchpad = true;
|
fIsTouchpad = true;
|
||||||
}
|
}
|
||||||
@@ -178,25 +178,23 @@ TouchpadDevice::Start()
|
|||||||
fTouchpadSettings = kDefaultTouchpadSettings;
|
fTouchpadSettings = kDefaultTouchpadSettings;
|
||||||
|
|
||||||
BPath path;
|
BPath path;
|
||||||
status_t status = GetSettingsPath(path);
|
status_t status = _GetSettingsPath(path);
|
||||||
BFile settingsFile(path.Path(), B_READ_ONLY);
|
BFile settingsFile(path.Path(), B_READ_ONLY);
|
||||||
if(status == B_OK && settingsFile.InitCheck() == B_OK){
|
if (status == B_OK && settingsFile.InitCheck() == B_OK) {
|
||||||
if(settingsFile.Read(&fTouchpadSettings, sizeof(touchpad_settings))
|
if (settingsFile.Read(&fTouchpadSettings, sizeof(touchpad_settings))
|
||||||
!= sizeof(touchpad_settings))
|
!= sizeof(touchpad_settings)) {
|
||||||
{
|
|
||||||
LOG("failed to load settings\n");
|
LOG("failed to load settings\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateTouchpadSettings();
|
UpdateTouchpadSettings();
|
||||||
|
|
||||||
UpdateSettings();
|
UpdateSettings();
|
||||||
|
|
||||||
char threadName[B_OS_NAME_LENGTH];
|
char threadName[B_OS_NAME_LENGTH];
|
||||||
snprintf(threadName, B_OS_NAME_LENGTH, "%s watcher", fDeviceRef.name);
|
snprintf(threadName, B_OS_NAME_LENGTH, "%s watcher", fDeviceRef.name);
|
||||||
|
|
||||||
fThread = spawn_thread(_ThreadFunction, threadName,
|
fThread = spawn_thread(_ThreadFunction, threadName,
|
||||||
kMouseThreadPriority, (void *)this);
|
kMouseThreadPriority, (void*)this);
|
||||||
|
|
||||||
if (fThread < B_OK)
|
if (fThread < B_OK)
|
||||||
status = fThread;
|
status = fThread;
|
||||||
@@ -222,6 +220,9 @@ TouchpadDevice::Stop()
|
|||||||
fActive = false;
|
fActive = false;
|
||||||
// this will stop the thread as soon as it reads the next packet
|
// this will stop the thread as soon as it reads the next packet
|
||||||
|
|
||||||
|
close(fDevice);
|
||||||
|
fDevice = -1;
|
||||||
|
|
||||||
if (fThread >= B_OK) {
|
if (fThread >= B_OK) {
|
||||||
// unblock the thread, which might wait on a semaphore.
|
// unblock the thread, which might wait on a semaphore.
|
||||||
suspend_thread(fThread);
|
suspend_thread(fThread);
|
||||||
@@ -230,14 +231,14 @@ TouchpadDevice::Stop()
|
|||||||
status_t dummy;
|
status_t dummy;
|
||||||
wait_for_thread(fThread, &dummy);
|
wait_for_thread(fThread, &dummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fDevice);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
TouchpadDevice::UpdateSettings()
|
TouchpadDevice::UpdateSettings()
|
||||||
{
|
{
|
||||||
|
// TODO: This is duplicated in MouseInputDevice.cpp -> Refactor
|
||||||
|
|
||||||
CALLED();
|
CALLED();
|
||||||
|
|
||||||
// retrieve current values
|
// retrieve current values
|
||||||
@@ -272,21 +273,28 @@ TouchpadDevice::UpdateSettings()
|
|||||||
ioctl(fDevice, MS_SET_TYPE, &fSettings.type);
|
ioctl(fDevice, MS_SET_TYPE, &fSettings.type);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
TouchpadDevice::ReadTouchpadSettingsMsg(BMessage* msg)
|
TouchpadDevice::ReadTouchpadSettingsMsg(BMessage* msg)
|
||||||
{
|
{
|
||||||
msg->FindBool("scroll_twofinger", &(fTouchpadSettings.scroll_twofinger));
|
msg->FindBool("scroll_twofinger",
|
||||||
msg->FindBool("scroll_multifinger", &(fTouchpadSettings.scroll_multifinger));
|
&(fTouchpadSettings.scroll_twofinger));
|
||||||
msg->FindFloat("scroll_rightrange", &(fTouchpadSettings.scroll_rightrange));
|
msg->FindBool("scroll_multifinger",
|
||||||
msg->FindFloat("scroll_bottomrange", &(fTouchpadSettings.scroll_bottomrange));
|
&(fTouchpadSettings.scroll_multifinger));
|
||||||
msg->FindInt16("scroll_xstepsize", (int16*)&(fTouchpadSettings.scroll_xstepsize));
|
msg->FindFloat("scroll_rightrange",
|
||||||
msg->FindInt16("scroll_ystepsize", (int16*)&(fTouchpadSettings.scroll_ystepsize));
|
&(fTouchpadSettings.scroll_rightrange));
|
||||||
msg->FindInt8("scroll_acceleration", (int8*)&(fTouchpadSettings.scroll_acceleration));
|
msg->FindFloat("scroll_bottomrange",
|
||||||
msg->FindInt8("tapgesture_sensibility", (int8*)&(fTouchpadSettings.tapgesture_sensibility));
|
&(fTouchpadSettings.scroll_bottomrange));
|
||||||
|
msg->FindInt16("scroll_xstepsize",
|
||||||
|
(int16*)&(fTouchpadSettings.scroll_xstepsize));
|
||||||
|
msg->FindInt16("scroll_ystepsize",
|
||||||
|
(int16*)&(fTouchpadSettings.scroll_ystepsize));
|
||||||
|
msg->FindInt8("scroll_acceleration",
|
||||||
|
(int8*)&(fTouchpadSettings.scroll_acceleration));
|
||||||
|
msg->FindInt8("tapgesture_sensibility",
|
||||||
|
(int8*)&(fTouchpadSettings.tapgesture_sensibility));
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -295,7 +303,7 @@ TouchpadDevice::ReadTouchpadSettingsMsg(BMessage* msg)
|
|||||||
status_t
|
status_t
|
||||||
TouchpadDevice::UpdateTouchpadSettings()
|
TouchpadDevice::UpdateTouchpadSettings()
|
||||||
{
|
{
|
||||||
if(fIsTouchpad){
|
if (fIsTouchpad) {
|
||||||
ioctl(fDevice, MS_SET_TOUCHPAD_SETTINGS, &fTouchpadSettings);
|
ioctl(fDevice, MS_SET_TOUCHPAD_SETTINGS, &fTouchpadSettings);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -306,14 +314,27 @@ TouchpadDevice::UpdateTouchpadSettings()
|
|||||||
void
|
void
|
||||||
TouchpadDevice::_Run()
|
TouchpadDevice::_Run()
|
||||||
{
|
{
|
||||||
|
// TODO: Exact duplicate of MouseDevice::_Run() -> Refactor
|
||||||
uint32 lastButtons = 0;
|
uint32 lastButtons = 0;
|
||||||
|
|
||||||
while (fActive) {
|
while (fActive) {
|
||||||
mouse_movement movements;
|
mouse_movement movements;
|
||||||
memset(&movements, 0, sizeof(movements));
|
memset(&movements, 0, sizeof(movements));
|
||||||
|
|
||||||
if (ioctl(fDevice, MS_READ, &movements) != B_OK)
|
if (ioctl(fDevice, MS_READ, &movements) != B_OK) {
|
||||||
|
if (fActive) {
|
||||||
|
fThread = -1;
|
||||||
|
fTarget._RemoveDevice(fPath.String());
|
||||||
|
} else {
|
||||||
|
// In case active is already false, another thread
|
||||||
|
// waits for this thread to quit, and may already hold
|
||||||
|
// locks that _RemoveDevice() wants to acquire. In another
|
||||||
|
// words, the device is already being removed, so we simply
|
||||||
|
// quit here.
|
||||||
|
}
|
||||||
|
// TOAST!
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
uint32 buttons = lastButtons ^ movements.buttons;
|
uint32 buttons = lastButtons ^ movements.buttons;
|
||||||
|
|
||||||
@@ -326,8 +347,6 @@ TouchpadDevice::_Run()
|
|||||||
movements.clicks, movements.wheel_xdelta, movements.wheel_ydelta);
|
movements.clicks, movements.wheel_xdelta, movements.wheel_ydelta);
|
||||||
LOG("%s: x: %ld, y: %ld\n", device->device_ref.name, deltaX, deltaY);*/
|
LOG("%s: x: %ld, y: %ld\n", device->device_ref.name, deltaX, deltaY);*/
|
||||||
|
|
||||||
BMessage *message = NULL;
|
|
||||||
|
|
||||||
// Send single messages for each event
|
// Send single messages for each event
|
||||||
|
|
||||||
if (buttons != 0) {
|
if (buttons != 0) {
|
||||||
@@ -355,7 +374,7 @@ TouchpadDevice::_Run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((movements.wheel_ydelta != 0) || (movements.wheel_xdelta != 0)) {
|
if ((movements.wheel_ydelta != 0) || (movements.wheel_xdelta != 0)) {
|
||||||
message = new BMessage(B_MOUSE_WHEEL_CHANGED);
|
BMessage* message = new BMessage(B_MOUSE_WHEEL_CHANGED);
|
||||||
if (message == NULL)
|
if (message == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -373,7 +392,7 @@ TouchpadDevice::_Run()
|
|||||||
status_t
|
status_t
|
||||||
TouchpadDevice::_ThreadFunction(void* arg)
|
TouchpadDevice::_ThreadFunction(void* arg)
|
||||||
{
|
{
|
||||||
TouchpadDevice* device = (TouchpadDevice *)arg;
|
TouchpadDevice* device = (TouchpadDevice*)arg;
|
||||||
device->_Run();
|
device->_Run();
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -383,6 +402,8 @@ BMessage*
|
|||||||
TouchpadDevice::_BuildMouseMessage(uint32 what, uint64 when, uint32 buttons,
|
TouchpadDevice::_BuildMouseMessage(uint32 what, uint64 when, uint32 buttons,
|
||||||
int32 deltaX, int32 deltaY) const
|
int32 deltaX, int32 deltaY) const
|
||||||
{
|
{
|
||||||
|
// TODO: Exact duplicate of MouseDevice::_BuildMouseMessage() -> Refactor
|
||||||
|
|
||||||
BMessage* message = new BMessage(what);
|
BMessage* message = new BMessage(what);
|
||||||
if (message == NULL)
|
if (message == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -403,6 +424,8 @@ void
|
|||||||
TouchpadDevice::_ComputeAcceleration(const mouse_movement& movements,
|
TouchpadDevice::_ComputeAcceleration(const mouse_movement& movements,
|
||||||
int32& deltaX, int32& deltaY) const
|
int32& deltaX, int32& deltaY) const
|
||||||
{
|
{
|
||||||
|
// TODO: Exact duplicate of MouseDevice::_ComputeAcceleration() -> Refactor
|
||||||
|
|
||||||
// basic mouse speed
|
// basic mouse speed
|
||||||
deltaX = movements.xdelta * fSettings.accel.speed >> 16;
|
deltaX = movements.xdelta * fSettings.accel.speed >> 16;
|
||||||
deltaY = movements.ydelta * fSettings.accel.speed >> 16;
|
deltaY = movements.ydelta * fSettings.accel.speed >> 16;
|
||||||
@@ -430,6 +453,8 @@ TouchpadDevice::_ComputeAcceleration(const mouse_movement& movements,
|
|||||||
uint32
|
uint32
|
||||||
TouchpadDevice::_RemapButtons(uint32 buttons) const
|
TouchpadDevice::_RemapButtons(uint32 buttons) const
|
||||||
{
|
{
|
||||||
|
// TODO: Exact duplicate of MouseDevice::_RemapButtons() -> Refactor
|
||||||
|
|
||||||
if (fDeviceRemapsButtons)
|
if (fDeviceRemapsButtons)
|
||||||
return buttons;
|
return buttons;
|
||||||
|
|
||||||
@@ -464,8 +489,8 @@ TouchpadDevice::_BuildShortName() const
|
|||||||
string.CopyInto(name, slash + 1, string.Length() - slash);
|
string.CopyInto(name, slash + 1, string.Length() - slash);
|
||||||
//int32 index = atoi(name.String()) + 1;
|
//int32 index = atoi(name.String()) + 1;
|
||||||
|
|
||||||
BString final = "Touchpad_";
|
BString final = "Touchpad ";
|
||||||
final+= name;
|
final += name;
|
||||||
|
|
||||||
LOG("NAME %s, %s\n", final.String(), fPath.String());
|
LOG("NAME %s, %s\n", final.String(), fPath.String());
|
||||||
|
|
||||||
@@ -484,7 +509,6 @@ TouchpadInputDevice::TouchpadInputDevice()
|
|||||||
CALLED();
|
CALLED();
|
||||||
|
|
||||||
StartMonitoringDevice(kTouchpadDevicesDirectoryPS2);
|
StartMonitoringDevice(kTouchpadDevicesDirectoryPS2);
|
||||||
|
|
||||||
_RecursiveScan(kTouchpadDevicesDirectoryPS2);
|
_RecursiveScan(kTouchpadDevicesDirectoryPS2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -493,11 +517,7 @@ TouchpadInputDevice::~TouchpadInputDevice()
|
|||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
StopMonitoringDevice(kTouchpadDevicesDirectoryPS2);
|
StopMonitoringDevice(kTouchpadDevicesDirectoryPS2);
|
||||||
|
fDevices.MakeEmpty();
|
||||||
int32 count = fDevices.CountItems();
|
|
||||||
while (count-- > 0) {
|
|
||||||
delete (TouchpadDevice *)fDevices.RemoveItem(count);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
fclose(sLogFile);
|
fclose(sLogFile);
|
||||||
@@ -541,14 +561,14 @@ TouchpadInputDevice::Control(const char* name, void* cookie,
|
|||||||
LOG("%s(%s, code: %lu)\n", __PRETTY_FUNCTION__, name, command);
|
LOG("%s(%s, code: %lu)\n", __PRETTY_FUNCTION__, name, command);
|
||||||
TouchpadDevice* device = (TouchpadDevice*)cookie;
|
TouchpadDevice* device = (TouchpadDevice*)cookie;
|
||||||
|
|
||||||
if (command == MS_SET_TOUCHPAD_SETTINGS){
|
if (command == B_NODE_MONITOR)
|
||||||
|
return _HandleMonitor(message);
|
||||||
|
|
||||||
|
if (command == MS_SET_TOUCHPAD_SETTINGS) {
|
||||||
device->ReadTouchpadSettingsMsg(message);
|
device->ReadTouchpadSettingsMsg(message);
|
||||||
return device->UpdateTouchpadSettings();
|
return device->UpdateTouchpadSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command == B_NODE_MONITOR)
|
|
||||||
return _HandleMonitor(message);
|
|
||||||
|
|
||||||
if (command >= B_MOUSE_TYPE_CHANGED
|
if (command >= B_MOUSE_TYPE_CHANGED
|
||||||
&& command <= B_MOUSE_ACCELERATION_CHANGED)
|
&& command <= B_MOUSE_ACCELERATION_CHANGED)
|
||||||
return device->UpdateSettings();
|
return device->UpdateSettings();
|
||||||
@@ -557,46 +577,46 @@ TouchpadInputDevice::Control(const char* name, void* cookie,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: Test this. USB doesn't work on my machine
|
|
||||||
status_t
|
status_t
|
||||||
TouchpadInputDevice::_HandleMonitor(BMessage* message)
|
TouchpadInputDevice::_HandleMonitor(BMessage* message)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
|
|
||||||
|
const char* path;
|
||||||
int32 opcode;
|
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;
|
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)
|
if (opcode == B_ENTRY_CREATED)
|
||||||
status = _AddDevice(path.Path());
|
return _AddDevice(path);
|
||||||
else
|
|
||||||
status = _RemoveDevice(path.Path());
|
|
||||||
|
|
||||||
return status;
|
#if 0
|
||||||
|
return _RemoveDevice(path);
|
||||||
|
#else
|
||||||
|
// Don't handle B_ENTRY_REMOVED, let the control thread take care of it.
|
||||||
|
return B_OK;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TouchpadInputDevice::_RecursiveScan(const char* directory)
|
||||||
|
{
|
||||||
|
CALLED();
|
||||||
|
|
||||||
|
BEntry entry;
|
||||||
|
BDirectory dir(directory);
|
||||||
|
while (dir.GetNextEntry(&entry) == B_OK) {
|
||||||
|
BPath path;
|
||||||
|
entry.GetPath(&path);
|
||||||
|
|
||||||
|
if (entry.IsDirectory())
|
||||||
|
_RecursiveScan(path.Path());
|
||||||
|
else
|
||||||
|
_AddDevice(path.Path());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -605,9 +625,9 @@ TouchpadInputDevice::_FindDevice(const char *path)
|
|||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
|
|
||||||
for (int32 i = fDevices.CountItems(); i-- > 0;) {
|
for (int32 i = fDevices.CountItems() - 1; i >= 0; i--) {
|
||||||
TouchpadDevice* device = (TouchpadDevice*)fDevices.ItemAt(i);
|
TouchpadDevice* device = fDevices.ItemAt(i);
|
||||||
if (!strcmp(device->Path(), path))
|
if (strcmp(device->Path(), path) == 0)
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -631,7 +651,7 @@ TouchpadInputDevice::_AddDevice(const char *path)
|
|||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
input_device_ref *devices[2];
|
input_device_ref* devices[2];
|
||||||
devices[0] = device->DeviceRef();
|
devices[0] = device->DeviceRef();
|
||||||
devices[1] = NULL;
|
devices[1] = NULL;
|
||||||
|
|
||||||
@@ -648,39 +668,15 @@ TouchpadInputDevice::_RemoveDevice(const char *path)
|
|||||||
if (device == NULL)
|
if (device == NULL)
|
||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
fDevices.RemoveItem(device);
|
input_device_ref* devices[2];
|
||||||
|
|
||||||
input_device_ref *devices[2];
|
|
||||||
devices[0] = device->DeviceRef();
|
devices[0] = device->DeviceRef();
|
||||||
devices[1] = NULL;
|
devices[1] = NULL;
|
||||||
|
|
||||||
UnregisterDevices(devices);
|
UnregisterDevices(devices);
|
||||||
|
|
||||||
delete device;
|
fDevices.RemoveItem(device);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
TouchpadInputDevice::_RecursiveScan(const char* directory)
|
|
||||||
{
|
|
||||||
CALLED();
|
|
||||||
|
|
||||||
BEntry entry;
|
|
||||||
BDirectory dir(directory);
|
|
||||||
while (dir.GetNextEntry(&entry) == B_OK) {
|
|
||||||
BPath path;
|
|
||||||
entry.GetPath(&path);
|
|
||||||
|
|
||||||
if (!strcmp(path.Leaf(), "serial")) {
|
|
||||||
// skip serial
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entry.IsDirectory())
|
|
||||||
_RecursiveScan(path.Path());
|
|
||||||
else
|
|
||||||
_AddDevice(path.Path());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,8 @@
|
|||||||
|
|
||||||
#include <InputServerDevice.h>
|
#include <InputServerDevice.h>
|
||||||
#include <InterfaceDefs.h>
|
#include <InterfaceDefs.h>
|
||||||
#include <List.h>
|
|
||||||
|
#include <ObjectList.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#define DEBUG 1
|
#define DEBUG 1
|
||||||
@@ -20,30 +21,34 @@
|
|||||||
class TouchpadDevice;
|
class TouchpadDevice;
|
||||||
|
|
||||||
class TouchpadInputDevice : public BInputServerDevice {
|
class TouchpadInputDevice : public BInputServerDevice {
|
||||||
public:
|
public:
|
||||||
TouchpadInputDevice();
|
TouchpadInputDevice();
|
||||||
~TouchpadInputDevice();
|
virtual ~TouchpadInputDevice();
|
||||||
|
|
||||||
virtual status_t InitCheck();
|
virtual status_t InitCheck();
|
||||||
|
|
||||||
virtual status_t Start(const char* name, void* cookie);
|
virtual status_t Start(const char* name, void* cookie);
|
||||||
virtual status_t Stop(const char* name, void* cookie);
|
virtual status_t Stop(const char* name, void* cookie);
|
||||||
|
|
||||||
virtual status_t Control(const char* name, void* cookie,
|
virtual status_t Control(const char* name, void* cookie,
|
||||||
uint32 command, BMessage* message);
|
uint32 command, BMessage* message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t _HandleMonitor(BMessage* message);
|
friend class TouchpadDevice;
|
||||||
void _RecursiveScan(const char* directory);
|
// TODO: needed by the control thread to remove a dead device
|
||||||
|
// find a better way...
|
||||||
|
|
||||||
TouchpadDevice* _FindDevice(const char* path);
|
status_t _HandleMonitor(BMessage* message);
|
||||||
status_t _AddDevice(const char* path);
|
void _RecursiveScan(const char* directory);
|
||||||
status_t _RemoveDevice(const char* path);
|
|
||||||
|
|
||||||
BList fDevices;
|
TouchpadDevice* _FindDevice(const char* path);
|
||||||
|
status_t _AddDevice(const char* path);
|
||||||
|
status_t _RemoveDevice(const char* path);
|
||||||
|
|
||||||
|
BObjectList<TouchpadDevice> fDevices;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
public:
|
public:
|
||||||
static FILE *sLogFile;
|
static FILE* sLogFile;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user