From 393f282c79633a272e3f3da5c50551405fe43fb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 27 Oct 2008 22:19:55 +0000 Subject: [PATCH] * Mark InputDeviceListItems only as running if calling Start() for the device returned B_OK. * In the InputServer destructor, don't check the fAddOnManager pointer, but check the success of calling Lock() on it instead, which should be much safer. * In StartStopDevices(), really start or stop all published devices for the given BInputServerDevice, not only the first one found. Simplify the check whether anything needs to be done. * Change a bit the return codes of StartStopDevices(). Especially the version that's supposed to start or stop all devices will still try to do it for the rest of them. * Removed no longer needed _FindInputDeviceListItem(). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28351 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/input/InputServer.cpp | 46 +++++++++++++------------------ src/servers/input/InputServer.h | 2 -- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/src/servers/input/InputServer.cpp b/src/servers/input/InputServer.cpp index c5d9e990d0..c01b146262 100644 --- a/src/servers/input/InputServer.cpp +++ b/src/servers/input/InputServer.cpp @@ -94,7 +94,7 @@ InputDeviceListItem::Start() if (err != B_OK) { PRINTERR((" error: %s (%lx)\n", strerror(err), err)); } - fRunning = true; + fRunning = err == B_OK; } @@ -240,10 +240,8 @@ InputServer::InputServer() InputServer::~InputServer() { CALLED(); - if (fAddOnManager != NULL) { - fAddOnManager->Lock(); + if (fAddOnManager->Lock()) fAddOnManager->Quit(); - } _ReleaseInput(NULL); } @@ -1067,21 +1065,6 @@ InputServer::EventLoopRunning() } -/*! The fInputDeviceListLocker must be locked when calling this function */ -InputDeviceListItem* -InputServer::_FindInputDeviceListItem(BInputServerDevice& device) -{ - for (int32 i = fInputDeviceList.CountItems() - 1; i >= 0; i--) { - InputDeviceListItem* item = (InputDeviceListItem*)fInputDeviceList.ItemAt(i); - - if (item->ServerDevice() == &device) - return item; - } - - return NULL; -} - - status_t InputServer::GetDeviceInfo(const char* name, input_device_type *_type, bool *_isRunning) @@ -1220,8 +1203,12 @@ InputServer::StartStopDevices(const char* name, input_device_type type, continue; if (item->Matches(name, type)) { - if (!doStart ^ item->Running()) - return B_ERROR; + if (doStart == item->Running()) { + if (name) + return B_OK; + else + continue; + } if (doStart) item->Start(); @@ -1233,8 +1220,10 @@ InputServer::StartStopDevices(const char* name, input_device_type type, } } - if (name) + if (name) { + // item not found return B_ERROR; + } return B_OK; } @@ -1247,17 +1236,20 @@ InputServer::StartStopDevices(BInputServerDevice& serverDevice, bool doStart) CALLED(); BAutolock lock(fInputDeviceListLocker); - InputDeviceListItem* item = _FindInputDeviceListItem(serverDevice); - if (item != NULL) { - if (!doStart ^ item->Running()) - return B_ERROR; + for (int32 i = fInputDeviceList.CountItems() - 1; i >= 0; i--) { + InputDeviceListItem* item = (InputDeviceListItem*)fInputDeviceList.ItemAt(i); + + if (item->ServerDevice() != &serverDevice) + continue; + + if (doStart == item->Running()) + continue; if (doStart) item->Start(); else item->Stop(); } - EXIT(); return B_OK; } diff --git a/src/servers/input/InputServer.h b/src/servers/input/InputServer.h index 079d75bb60..7e5c05e428 100644 --- a/src/servers/input/InputServer.h +++ b/src/servers/input/InputServer.h @@ -206,8 +206,6 @@ class InputServer : public BApplication { status_t _AcquireInput(BMessage& message, BMessage& reply); void _ReleaseInput(BMessage* message); - InputDeviceListItem* _FindInputDeviceListItem(BInputServerDevice& device); - private: bool fEventLoopRunning; bool fSafeMode;