Added a looper to handle devices related requests
Before it was deadlocking when an addon asks for a new keymap on a notification message git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9219 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -20,12 +20,15 @@
|
|||||||
|
|
||||||
#include "AddOnManager.h"
|
#include "AddOnManager.h"
|
||||||
#include "InputServer.h"
|
#include "InputServer.h"
|
||||||
|
#include "InputServerTypes.h"
|
||||||
|
|
||||||
|
|
||||||
AddOnManager::AddOnManager(bool safeMode)
|
AddOnManager::AddOnManager(bool safeMode)
|
||||||
: fLock("add-on manager"),
|
: BLooper("addon_manager"),
|
||||||
|
fLock("add-on manager"),
|
||||||
fSafeMode(safeMode)
|
fSafeMode(safeMode)
|
||||||
{
|
{
|
||||||
|
Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -408,3 +411,172 @@ AddOnManager::RegisterMethod(BInputServerMethod *method, const entry_ref &ref, i
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: AddOnManager::MessageReceived()
|
||||||
|
* Descr:
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
AddOnManager::MessageReceived(BMessage *message)
|
||||||
|
{
|
||||||
|
CALLED();
|
||||||
|
|
||||||
|
BMessage reply;
|
||||||
|
status_t status = B_OK;
|
||||||
|
|
||||||
|
PRINT(("%s what:%c%c%c%c\n", __PRETTY_FUNCTION__, message->what>>24, message->what>>16, message->what>>8, message->what));
|
||||||
|
|
||||||
|
switch(message->what)
|
||||||
|
{
|
||||||
|
case IS_FIND_DEVICES:
|
||||||
|
status = HandleFindDevices(message, &reply);
|
||||||
|
break;
|
||||||
|
case IS_WATCH_DEVICES:
|
||||||
|
status = HandleWatchDevices(message, &reply);
|
||||||
|
break;
|
||||||
|
case IS_IS_DEVICE_RUNNING:
|
||||||
|
status = HandleIsDeviceRunning(message, &reply);
|
||||||
|
break;
|
||||||
|
case IS_START_DEVICE:
|
||||||
|
status = HandleStartStopDevices(message, &reply);
|
||||||
|
break;
|
||||||
|
case IS_STOP_DEVICE:
|
||||||
|
status = HandleStartStopDevices(message, &reply);
|
||||||
|
break;
|
||||||
|
case IS_CONTROL_DEVICES:
|
||||||
|
status = HandleControlDevices(message, &reply);
|
||||||
|
break;
|
||||||
|
case SYSTEM_SHUTTING_DOWN:
|
||||||
|
status = HandleSystemShuttingDown(message, &reply);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reply.AddInt32("status", status);
|
||||||
|
message->SendReply(&reply);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: AddOnManager::HandleStartStopDevices()
|
||||||
|
* Descr:
|
||||||
|
*/
|
||||||
|
status_t
|
||||||
|
AddOnManager::HandleStartStopDevices(BMessage *message,
|
||||||
|
BMessage *reply)
|
||||||
|
{
|
||||||
|
const char *name = NULL;
|
||||||
|
int32 type = 0;
|
||||||
|
if (! ((message->FindInt32("type", &type)!=B_OK) ^ (message->FindString("device", &name)!=B_OK)))
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
return InputServer::StartStopDevices(name, (input_device_type)type, message->what == IS_START_DEVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: AddOnManager::HandleFindDevices()
|
||||||
|
* Descr:
|
||||||
|
*/
|
||||||
|
status_t
|
||||||
|
AddOnManager::HandleFindDevices(BMessage *message,
|
||||||
|
BMessage *reply)
|
||||||
|
{
|
||||||
|
CALLED();
|
||||||
|
const char *name = NULL;
|
||||||
|
message->FindString("device", &name);
|
||||||
|
|
||||||
|
for (int i = InputServer::gInputDeviceList.CountItems() - 1; i >= 0; i--) {
|
||||||
|
InputDeviceListItem* item = (InputDeviceListItem*)InputServer::gInputDeviceList.ItemAt(i);
|
||||||
|
if (!item)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!name || strcmp(name, item->mDev.name) == 0) {
|
||||||
|
reply->AddString("device", item->mDev.name);
|
||||||
|
reply->AddInt32("type", item->mDev.type);
|
||||||
|
if (name)
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: AddOnManager::HandleWatchDevices()
|
||||||
|
* Descr:
|
||||||
|
*/
|
||||||
|
status_t
|
||||||
|
AddOnManager::HandleWatchDevices(BMessage *message,
|
||||||
|
BMessage *reply)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: AddOnManager::HandleIsDeviceRunning()
|
||||||
|
* Descr:
|
||||||
|
*/
|
||||||
|
status_t
|
||||||
|
AddOnManager::HandleIsDeviceRunning(BMessage *message,
|
||||||
|
BMessage *reply)
|
||||||
|
{
|
||||||
|
const char *name = NULL;
|
||||||
|
if (message->FindString("device", &name)!=B_OK)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
for (int i = InputServer::gInputDeviceList.CountItems() - 1; i >= 0; i--) {
|
||||||
|
InputDeviceListItem* item = (InputDeviceListItem*)InputServer::gInputDeviceList.ItemAt(i);
|
||||||
|
if (!item)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (strcmp(name, item->mDev.name) == 0)
|
||||||
|
return (item->mStarted) ? B_OK : B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: AddOnManager::HandleControlDevices()
|
||||||
|
* Descr:
|
||||||
|
*/
|
||||||
|
status_t
|
||||||
|
AddOnManager::HandleControlDevices(BMessage *message,
|
||||||
|
BMessage *reply)
|
||||||
|
{
|
||||||
|
CALLED();
|
||||||
|
const char *name = NULL;
|
||||||
|
int32 type = 0;
|
||||||
|
if (! ((message->FindInt32("type", &type)!=B_OK) ^ (message->FindString("device", &name)!=B_OK)))
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
uint32 code = 0;
|
||||||
|
BMessage msg;
|
||||||
|
bool isMessage = true;
|
||||||
|
if (message->FindInt32("code", (int32*)&code)!=B_OK)
|
||||||
|
return B_ERROR;
|
||||||
|
if (message->FindMessage("message", &msg)!=B_OK)
|
||||||
|
isMessage = false;
|
||||||
|
|
||||||
|
return InputServer::ControlDevices(name, (input_device_type)type, code, isMessage ? &msg : NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: AddOnManager::HandleSystemShuttingDown()
|
||||||
|
* Descr:
|
||||||
|
*/
|
||||||
|
status_t
|
||||||
|
AddOnManager::HandleSystemShuttingDown(BMessage *message,
|
||||||
|
BMessage *reply)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
// Manager for input_server add-ons (devices, filters, methods)
|
// Manager for input_server add-ons (devices, filters, methods)
|
||||||
|
|
||||||
#include <Locker.h>
|
#include <Locker.h>
|
||||||
|
#include <Looper.h>
|
||||||
#include <InputServerDevice.h>
|
#include <InputServerDevice.h>
|
||||||
#include <InputServerFilter.h>
|
#include <InputServerFilter.h>
|
||||||
#include <InputServerMethod.h>
|
#include <InputServerMethod.h>
|
||||||
@@ -18,14 +19,14 @@
|
|||||||
#include "AddOnMonitorHandler.h"
|
#include "AddOnMonitorHandler.h"
|
||||||
#include "TList.h"
|
#include "TList.h"
|
||||||
|
|
||||||
class AddOnManager {
|
class AddOnManager : public BLooper {
|
||||||
public:
|
public:
|
||||||
AddOnManager(bool safeMode);
|
AddOnManager(bool safeMode);
|
||||||
~AddOnManager();
|
~AddOnManager();
|
||||||
|
|
||||||
void LoadState();
|
void LoadState();
|
||||||
void SaveState();
|
void SaveState();
|
||||||
|
void MessageReceived(BMessage *message);
|
||||||
private:
|
private:
|
||||||
status_t RegisterAddOn(BEntry &entry);
|
status_t RegisterAddOn(BEntry &entry);
|
||||||
status_t UnregisterAddOn(BEntry &entry);
|
status_t UnregisterAddOn(BEntry &entry);
|
||||||
@@ -36,6 +37,14 @@ class AddOnManager {
|
|||||||
void RegisterFilter(BInputServerFilter *isf, const entry_ref &ref, image_id addon_image);
|
void RegisterFilter(BInputServerFilter *isf, const entry_ref &ref, image_id addon_image);
|
||||||
void RegisterMethod(BInputServerMethod *ism, const entry_ref &ref, image_id addon_image);
|
void RegisterMethod(BInputServerMethod *ism, const entry_ref &ref, image_id addon_image);
|
||||||
|
|
||||||
|
status_t HandleFindDevices(BMessage*, BMessage*);
|
||||||
|
status_t HandleWatchDevices(BMessage*, BMessage*);
|
||||||
|
status_t HandleIsDeviceRunning(BMessage*, BMessage*);
|
||||||
|
status_t HandleStartStopDevices(BMessage*, BMessage*);
|
||||||
|
status_t HandleControlDevices(BMessage*, BMessage*);
|
||||||
|
status_t HandleSystemShuttingDown(BMessage*, BMessage*);
|
||||||
|
status_t HandleNodeMonitor(BMessage*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct device_info {
|
struct device_info {
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class IAHandler : public BHandler {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeviceManager {
|
class DeviceManager : public BLooper {
|
||||||
public:
|
public:
|
||||||
DeviceManager();
|
DeviceManager();
|
||||||
~DeviceManager();
|
~DeviceManager();
|
||||||
|
|||||||
+123
-233
@@ -132,7 +132,7 @@ InputServer::InputServer(void) : BApplication(INPUTSERVER_SIGNATURE),
|
|||||||
|
|
||||||
fCloneArea = clone_area("isClone", (void**)&fAppBuffer, B_ANY_ADDRESS, B_READ_AREA|B_WRITE_AREA, appArea);
|
fCloneArea = clone_area("isClone", (void**)&fAppBuffer, B_ANY_ADDRESS, B_READ_AREA|B_WRITE_AREA, appArea);
|
||||||
if (fCloneArea < B_OK) {
|
if (fCloneArea < B_OK) {
|
||||||
PRINT(("clone_area error : %s\n", strerror(fCloneArea)));
|
PRINTERR(("clone_area error : %s\n", strerror(fCloneArea)));
|
||||||
}
|
}
|
||||||
|
|
||||||
fAsPort = create_port(100, "is_as");
|
fAsPort = create_port(100, "is_as");
|
||||||
@@ -144,7 +144,7 @@ InputServer::InputServer(void) : BApplication(INPUTSERVER_SIGNATURE),
|
|||||||
|
|
||||||
status_t err;
|
status_t err;
|
||||||
if ((err = send_data(appThreadId, 0, buffer, sizeof(buffer)))!=B_OK)
|
if ((err = send_data(appThreadId, 0, buffer, sizeof(buffer)))!=B_OK)
|
||||||
PRINT(("error when send_data %s\n", strerror(err)));
|
PRINTERR(("error when send_data %s\n", strerror(err)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -186,14 +186,14 @@ InputServer::ArgvReceived(int32 argc, char** argv)
|
|||||||
if (2 == argc) {
|
if (2 == argc) {
|
||||||
if (0 == strcmp("-q", argv[1]) ) {
|
if (0 == strcmp("-q", argv[1]) ) {
|
||||||
// :TODO: Shutdown and restart the InputServer.
|
// :TODO: Shutdown and restart the InputServer.
|
||||||
printf("InputServer::ArgvReceived - Restarting ...\n");
|
PRINT(("InputServer::ArgvReceived - Restarting ...\n"));
|
||||||
status_t quit_status;
|
status_t quit_status;
|
||||||
BMessenger msgr = BMessenger(INPUTSERVER_SIGNATURE, -1, &quit_status);
|
BMessenger msgr = BMessenger(INPUTSERVER_SIGNATURE, -1, &quit_status);
|
||||||
if (B_OK == quit_status) {
|
if (B_OK == quit_status) {
|
||||||
BMessage msg = BMessage(B_QUIT_REQUESTED);
|
BMessage msg = BMessage(B_QUIT_REQUESTED);
|
||||||
msgr.SendMessage(&msg);
|
msgr.SendMessage(&msg);
|
||||||
} else {
|
} else {
|
||||||
printf("Unable to send Quit message to running InputServer.");
|
PRINTERR(("Unable to send Quit message to running InputServer."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -286,7 +286,7 @@ InputServer::LoadSystemKeymap()
|
|||||||
|
|
||||||
BFile file(&ref, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
|
BFile file(&ref, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
|
||||||
if ((err = file.InitCheck()) != B_OK) {
|
if ((err = file.InitCheck()) != B_OK) {
|
||||||
printf("error %s\n", strerror(err));
|
PRINTERR(("error %s\n", strerror(err)));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -448,34 +448,16 @@ InputServer::MessageReceived(BMessage *message)
|
|||||||
|
|
||||||
// device looper related
|
// device looper related
|
||||||
case IS_FIND_DEVICES:
|
case IS_FIND_DEVICES:
|
||||||
status = HandleFindDevices(message, &reply);
|
|
||||||
break;
|
|
||||||
case IS_WATCH_DEVICES:
|
case IS_WATCH_DEVICES:
|
||||||
status = HandleWatchDevices(message, &reply);
|
|
||||||
break;
|
|
||||||
case IS_IS_DEVICE_RUNNING:
|
case IS_IS_DEVICE_RUNNING:
|
||||||
status = HandleIsDeviceRunning(message, &reply);
|
|
||||||
break;
|
|
||||||
case IS_START_DEVICE:
|
case IS_START_DEVICE:
|
||||||
status = HandleStartStopDevices(message, &reply);
|
|
||||||
break;
|
|
||||||
case IS_STOP_DEVICE:
|
case IS_STOP_DEVICE:
|
||||||
status = HandleStartStopDevices(message, &reply);
|
|
||||||
break;
|
|
||||||
case IS_CONTROL_DEVICES:
|
case IS_CONTROL_DEVICES:
|
||||||
status = HandleControlDevices(message, &reply);
|
|
||||||
break;
|
|
||||||
case SYSTEM_SHUTTING_DOWN:
|
case SYSTEM_SHUTTING_DOWN:
|
||||||
status = HandleSystemShuttingDown(message, &reply);
|
fAddOnManager->PostMessage(message);
|
||||||
break;
|
return;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
PRINT(("Default message ... \n"));
|
|
||||||
//PRINT_OBJECT(*message);
|
|
||||||
BMessenger app_server("application/x-vnd.Be-APPS", -1, NULL);
|
|
||||||
if (app_server.IsValid()) {
|
|
||||||
//app_server->SendMessage(message);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -507,7 +489,12 @@ InputServer::HandleGetSetMouseType(BMessage* message,
|
|||||||
int32 type;
|
int32 type;
|
||||||
if (message->FindInt32("mouse_type", &type)==B_OK) {
|
if (message->FindInt32("mouse_type", &type)==B_OK) {
|
||||||
fMouseSettings.SetMouseType(type);
|
fMouseSettings.SetMouseType(type);
|
||||||
status = ControlDevices(NULL, B_POINTING_DEVICE, B_MOUSE_TYPE_CHANGED, NULL);
|
|
||||||
|
BMessage msg(IS_CONTROL_DEVICES);
|
||||||
|
msg.AddInt32("type", B_POINTING_DEVICE);
|
||||||
|
msg.AddInt32("code", B_MOUSE_TYPE_CHANGED);
|
||||||
|
status = fAddOnManager->PostMessage(&msg);
|
||||||
|
|
||||||
} else
|
} else
|
||||||
status = reply->AddInt32("mouse_type", fMouseSettings.MouseType());
|
status = reply->AddInt32("mouse_type", fMouseSettings.MouseType());
|
||||||
return status;
|
return status;
|
||||||
@@ -526,7 +513,11 @@ InputServer::HandleGetSetMouseAcceleration(BMessage* message,
|
|||||||
int32 factor;
|
int32 factor;
|
||||||
if (message->FindInt32("speed", &factor) == B_OK) {
|
if (message->FindInt32("speed", &factor) == B_OK) {
|
||||||
fMouseSettings.SetAccelerationFactor(factor);
|
fMouseSettings.SetAccelerationFactor(factor);
|
||||||
status = ControlDevices(NULL, B_POINTING_DEVICE, B_MOUSE_ACCELERATION_CHANGED, NULL);
|
|
||||||
|
BMessage msg(IS_CONTROL_DEVICES);
|
||||||
|
msg.AddInt32("type", B_POINTING_DEVICE);
|
||||||
|
msg.AddInt32("code", B_MOUSE_ACCELERATION_CHANGED);
|
||||||
|
status = fAddOnManager->PostMessage(&msg);
|
||||||
} else
|
} else
|
||||||
status = reply->AddInt32("speed", fMouseSettings.AccelerationFactor());
|
status = reply->AddInt32("speed", fMouseSettings.AccelerationFactor());
|
||||||
return status;
|
return status;
|
||||||
@@ -545,7 +536,11 @@ InputServer::HandleGetSetKeyRepeatDelay(BMessage* message,
|
|||||||
bigtime_t delay;
|
bigtime_t delay;
|
||||||
if (message->FindInt64("delay", &delay) == B_OK) {
|
if (message->FindInt64("delay", &delay) == B_OK) {
|
||||||
fKeyboardSettings.SetKeyboardRepeatDelay(delay);
|
fKeyboardSettings.SetKeyboardRepeatDelay(delay);
|
||||||
status = ControlDevices(NULL, B_KEYBOARD_DEVICE, B_KEY_REPEAT_DELAY_CHANGED, NULL);
|
|
||||||
|
BMessage msg(IS_CONTROL_DEVICES);
|
||||||
|
msg.AddInt32("type", B_KEYBOARD_DEVICE);
|
||||||
|
msg.AddInt32("code", B_KEY_REPEAT_DELAY_CHANGED);
|
||||||
|
status = fAddOnManager->PostMessage(&msg);
|
||||||
} else
|
} else
|
||||||
status = reply->AddInt64("delay", fKeyboardSettings.KeyboardRepeatDelay());
|
status = reply->AddInt64("delay", fKeyboardSettings.KeyboardRepeatDelay());
|
||||||
return status;
|
return status;
|
||||||
@@ -632,7 +627,10 @@ InputServer::HandleSetModifierKey(BMessage *message,
|
|||||||
|
|
||||||
//TODO : unmap the key ?
|
//TODO : unmap the key ?
|
||||||
|
|
||||||
status = ControlDevices(NULL, B_KEYBOARD_DEVICE, B_KEY_MAP_CHANGED, NULL);
|
BMessage msg(IS_CONTROL_DEVICES);
|
||||||
|
msg.AddInt32("type", B_KEYBOARD_DEVICE);
|
||||||
|
msg.AddInt32("code", B_KEY_MAP_CHANGED);
|
||||||
|
status = fAddOnManager->PostMessage(&msg);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -647,8 +645,12 @@ InputServer::HandleSetKeyboardLocks(BMessage *message,
|
|||||||
BMessage *reply)
|
BMessage *reply)
|
||||||
{
|
{
|
||||||
status_t status = B_ERROR;
|
status_t status = B_ERROR;
|
||||||
if (message->FindInt32("locks", (int32*)&fKeys.lock_settings) == B_OK)
|
if (message->FindInt32("locks", (int32*)&fKeys.lock_settings) == B_OK) {
|
||||||
status = ControlDevices(NULL, B_KEYBOARD_DEVICE, B_KEY_LOCKS_CHANGED, NULL);
|
BMessage msg(IS_CONTROL_DEVICES);
|
||||||
|
msg.AddInt32("type", B_KEYBOARD_DEVICE);
|
||||||
|
msg.AddInt32("code", B_KEY_LOCKS_CHANGED);
|
||||||
|
status = fAddOnManager->PostMessage(&msg);
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -666,7 +668,11 @@ InputServer::HandleGetSetMouseSpeed(BMessage* message,
|
|||||||
int32 speed;
|
int32 speed;
|
||||||
if (message->FindInt32("speed", &speed) == B_OK) {
|
if (message->FindInt32("speed", &speed) == B_OK) {
|
||||||
fMouseSettings.SetMouseSpeed(speed);
|
fMouseSettings.SetMouseSpeed(speed);
|
||||||
status = ControlDevices(NULL, B_POINTING_DEVICE, B_MOUSE_SPEED_CHANGED, NULL);
|
|
||||||
|
BMessage msg(IS_CONTROL_DEVICES);
|
||||||
|
msg.AddInt32("type", B_POINTING_DEVICE);
|
||||||
|
msg.AddInt32("code", B_MOUSE_SPEED_CHANGED);
|
||||||
|
status = fAddOnManager->PostMessage(&msg);
|
||||||
} else
|
} else
|
||||||
status = reply->AddInt32("speed", fMouseSettings.MouseSpeed());
|
status = reply->AddInt32("speed", fMouseSettings.MouseSpeed());
|
||||||
return status;
|
return status;
|
||||||
@@ -743,7 +749,12 @@ InputServer::HandleGetSetMouseMap(BMessage* message,
|
|||||||
|
|
||||||
if (message->FindData("mousemap", B_RAW_TYPE, (const void**)&map, &size) == B_OK) {
|
if (message->FindData("mousemap", B_RAW_TYPE, (const void**)&map, &size) == B_OK) {
|
||||||
fMouseSettings.SetMapping(*map);
|
fMouseSettings.SetMapping(*map);
|
||||||
status = ControlDevices(NULL, B_POINTING_DEVICE, B_MOUSE_MAP_CHANGED, NULL);
|
|
||||||
|
BMessage msg(IS_CONTROL_DEVICES);
|
||||||
|
msg.AddInt32("type", B_POINTING_DEVICE);
|
||||||
|
msg.AddInt32("code", B_MOUSE_MAP_CHANGED);
|
||||||
|
status = fAddOnManager->PostMessage(&msg);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
mouse_map map;
|
mouse_map map;
|
||||||
fMouseSettings.Mapping(map);
|
fMouseSettings.Mapping(map);
|
||||||
@@ -777,7 +788,12 @@ InputServer::HandleGetSetClickSpeed(BMessage *message,
|
|||||||
bigtime_t click_speed;
|
bigtime_t click_speed;
|
||||||
if (message->FindInt64("speed", &click_speed) == B_OK) {
|
if (message->FindInt64("speed", &click_speed) == B_OK) {
|
||||||
fMouseSettings.SetClickSpeed(click_speed);
|
fMouseSettings.SetClickSpeed(click_speed);
|
||||||
status = ControlDevices(NULL, B_POINTING_DEVICE, B_CLICK_SPEED_CHANGED, NULL);
|
|
||||||
|
BMessage msg(IS_CONTROL_DEVICES);
|
||||||
|
msg.AddInt32("type", B_POINTING_DEVICE);
|
||||||
|
msg.AddInt32("code", B_CLICK_SPEED_CHANGED);
|
||||||
|
status = fAddOnManager->PostMessage(&msg);
|
||||||
|
|
||||||
} else
|
} else
|
||||||
status = reply->AddInt64("speed", fMouseSettings.ClickSpeed());
|
status = reply->AddInt64("speed", fMouseSettings.ClickSpeed());
|
||||||
return status;
|
return status;
|
||||||
@@ -796,7 +812,11 @@ InputServer::HandleGetSetKeyRepeatRate(BMessage* message,
|
|||||||
int32 key_repeat_rate;
|
int32 key_repeat_rate;
|
||||||
if (message->FindInt32("rate", &key_repeat_rate) == B_OK) {
|
if (message->FindInt32("rate", &key_repeat_rate) == B_OK) {
|
||||||
fKeyboardSettings.SetKeyboardRepeatRate(key_repeat_rate);
|
fKeyboardSettings.SetKeyboardRepeatRate(key_repeat_rate);
|
||||||
status = ControlDevices(NULL, B_KEYBOARD_DEVICE, B_KEY_REPEAT_RATE_CHANGED, NULL);
|
|
||||||
|
BMessage msg(IS_CONTROL_DEVICES);
|
||||||
|
msg.AddInt32("type", B_KEYBOARD_DEVICE);
|
||||||
|
msg.AddInt32("code", B_KEY_REPEAT_RATE_CHANGED);
|
||||||
|
status = fAddOnManager->PostMessage(&msg);
|
||||||
} else
|
} else
|
||||||
status = reply->AddInt32("rate", fKeyboardSettings.KeyboardRepeatRate());
|
status = reply->AddInt32("rate", fKeyboardSettings.KeyboardRepeatRate());
|
||||||
return status;
|
return status;
|
||||||
@@ -821,7 +841,10 @@ InputServer::HandleGetSetKeyMap(BMessage *message,
|
|||||||
if (LoadKeymap()!=B_OK)
|
if (LoadKeymap()!=B_OK)
|
||||||
LoadSystemKeymap();
|
LoadSystemKeymap();
|
||||||
|
|
||||||
status = ControlDevices(NULL, B_KEYBOARD_DEVICE, B_KEY_MAP_CHANGED, NULL);
|
BMessage msg(IS_CONTROL_DEVICES);
|
||||||
|
msg.AddInt32("type", B_KEYBOARD_DEVICE);
|
||||||
|
msg.AddInt32("code", B_KEY_MAP_CHANGED);
|
||||||
|
status = fAddOnManager->PostMessage(&msg);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -840,176 +863,6 @@ InputServer::HandleFocusUnfocusIMAwareView(BMessage *,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Method: InputServer::HandleFindDevices()
|
|
||||||
* Descr:
|
|
||||||
*/
|
|
||||||
status_t
|
|
||||||
InputServer::HandleFindDevices(BMessage *message,
|
|
||||||
BMessage *reply)
|
|
||||||
{
|
|
||||||
const char *name = NULL;
|
|
||||||
message->FindString("device", &name);
|
|
||||||
|
|
||||||
for (int i = gInputDeviceList.CountItems() - 1; i >= 0; i--) {
|
|
||||||
InputDeviceListItem* item = (InputDeviceListItem*)gInputDeviceList.ItemAt(i);
|
|
||||||
if (!item)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!name || strcmp(name, item->mDev.name) == 0) {
|
|
||||||
reply->AddString("device", item->mDev.name);
|
|
||||||
reply->AddInt32("type", item->mDev.type);
|
|
||||||
if (name)
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Method: InputServer::HandleWatchDevices()
|
|
||||||
* Descr:
|
|
||||||
*/
|
|
||||||
status_t
|
|
||||||
InputServer::HandleWatchDevices(BMessage *message,
|
|
||||||
BMessage *reply)
|
|
||||||
{
|
|
||||||
// TODO
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Method: InputServer::HandleIsDeviceRunning()
|
|
||||||
* Descr:
|
|
||||||
*/
|
|
||||||
status_t
|
|
||||||
InputServer::HandleIsDeviceRunning(BMessage *message,
|
|
||||||
BMessage *reply)
|
|
||||||
{
|
|
||||||
const char *name = NULL;
|
|
||||||
if (message->FindString("device", &name)!=B_OK)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
for (int i = gInputDeviceList.CountItems() - 1; i >= 0; i--) {
|
|
||||||
InputDeviceListItem* item = (InputDeviceListItem*)gInputDeviceList.ItemAt(i);
|
|
||||||
if (!item)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (strcmp(name, item->mDev.name) == 0)
|
|
||||||
return (item->mStarted) ? B_OK : B_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Method: InputServer::HandleStartStopDevices()
|
|
||||||
* Descr:
|
|
||||||
*/
|
|
||||||
status_t
|
|
||||||
InputServer::HandleStartStopDevices(BMessage *message,
|
|
||||||
BMessage *reply)
|
|
||||||
{
|
|
||||||
const char *name = NULL;
|
|
||||||
int32 type = 0;
|
|
||||||
if (! ((message->FindInt32("type", &type)!=B_OK) ^ (message->FindString("device", &name)!=B_OK)))
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
for (int i = gInputDeviceList.CountItems() - 1; i >= 0; i--) {
|
|
||||||
InputDeviceListItem* item = (InputDeviceListItem*)gInputDeviceList.ItemAt(i);
|
|
||||||
if (!item)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if ((name && strcmp(name, item->mDev.name) == 0) || item->mDev.type == type) {
|
|
||||||
if (!item->mIsd)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
input_device_ref dev = item->mDev;
|
|
||||||
|
|
||||||
if (message->what == IS_START_DEVICE) {
|
|
||||||
PRINT((" Starting: %s\n", dev.name));
|
|
||||||
item->mIsd->Start(dev.name, dev.cookie);
|
|
||||||
item->mStarted = true;
|
|
||||||
} else {
|
|
||||||
PRINT((" Stopping: %s\n", dev.name));
|
|
||||||
item->mIsd->Stop(dev.name, dev.cookie);
|
|
||||||
item->mStarted = false;
|
|
||||||
}
|
|
||||||
if (name)
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name)
|
|
||||||
return B_ERROR;
|
|
||||||
else
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Method: InputServer::HandleControlDevices()
|
|
||||||
* Descr:
|
|
||||||
*/
|
|
||||||
status_t
|
|
||||||
InputServer::HandleControlDevices(BMessage *message,
|
|
||||||
BMessage *reply)
|
|
||||||
{
|
|
||||||
const char *name = NULL;
|
|
||||||
int32 type = 0;
|
|
||||||
if (! ((message->FindInt32("type", &type)!=B_OK) ^ (message->FindString("device", &name)!=B_OK)))
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
uint32 code = 0;
|
|
||||||
BMessage msg;
|
|
||||||
if (message->FindInt32("code", (int32*)&code)!=B_OK)
|
|
||||||
return B_ERROR;
|
|
||||||
if (message->FindMessage("message", &msg)!=B_OK)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
for (int i = gInputDeviceList.CountItems() - 1; i >= 0; i--) {
|
|
||||||
InputDeviceListItem* item = (InputDeviceListItem*)gInputDeviceList.ItemAt(i);
|
|
||||||
if (!item)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if ((name && strcmp(name, item->mDev.name) == 0) || item->mDev.type == type) {
|
|
||||||
if (!item->mIsd)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
input_device_ref dev = item->mDev;
|
|
||||||
|
|
||||||
item->mIsd->Control(dev.name, dev.cookie, code, &msg);
|
|
||||||
|
|
||||||
if (name)
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name)
|
|
||||||
return B_ERROR;
|
|
||||||
else
|
|
||||||
return B_OK;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Method: InputServer::HandleSystemShuttingDown()
|
|
||||||
* Descr:
|
|
||||||
*/
|
|
||||||
status_t
|
|
||||||
InputServer::HandleSystemShuttingDown(BMessage *message,
|
|
||||||
BMessage *reply)
|
|
||||||
{
|
|
||||||
// TODO
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method: InputServer::EnqueueDeviceMessage()
|
* Method: InputServer::EnqueueDeviceMessage()
|
||||||
* Descr:
|
* Descr:
|
||||||
@@ -1114,7 +967,7 @@ InputServer::EventLoop()
|
|||||||
CALLED();
|
CALLED();
|
||||||
fEventLooperPort = create_port(100, "obos_is_event_port");
|
fEventLooperPort = create_port(100, "obos_is_event_port");
|
||||||
if(fEventLooperPort < 0) {
|
if(fEventLooperPort < 0) {
|
||||||
_sPrintf("OBOS InputServer: create_port error: (0x%x) %s\n", fEventLooperPort, strerror(fEventLooperPort));
|
PRINTERR(("OBOS InputServer: create_port error: (0x%x) %s\n", fEventLooperPort, strerror(fEventLooperPort)));
|
||||||
}
|
}
|
||||||
fISPortThread = spawn_thread(ISPortWatcher, "_input_server_event_loop_", B_REAL_TIME_DISPLAY_PRIORITY+3, this);
|
fISPortThread = spawn_thread(ISPortWatcher, "_input_server_event_loop_", B_REAL_TIME_DISPLAY_PRIORITY+3, this);
|
||||||
resume_thread(fISPortThread);
|
resume_thread(fISPortThread);
|
||||||
@@ -1505,6 +1358,48 @@ InputServer::MethodizeEvents(BList *,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Method: InputServer::StartStopDevices()
|
||||||
|
* Descr:
|
||||||
|
*/
|
||||||
|
status_t
|
||||||
|
InputServer::StartStopDevices(const char *name, input_device_type type, bool doStart)
|
||||||
|
{
|
||||||
|
CALLED();
|
||||||
|
|
||||||
|
for (int i = gInputDeviceList.CountItems() - 1; i >= 0; i--) {
|
||||||
|
InputDeviceListItem* item = (InputDeviceListItem*)gInputDeviceList.ItemAt(i);
|
||||||
|
if (!item)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ((name && strcmp(name, item->mDev.name) == 0) || item->mDev.type == type) {
|
||||||
|
if (!item->mIsd)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
input_device_ref dev = item->mDev;
|
||||||
|
|
||||||
|
if (doStart) {
|
||||||
|
PRINT((" Starting: %s\n", dev.name));
|
||||||
|
item->mIsd->Start(dev.name, dev.cookie);
|
||||||
|
item->mStarted = true;
|
||||||
|
} else {
|
||||||
|
PRINT((" Stopping: %s\n", dev.name));
|
||||||
|
item->mIsd->Stop(dev.name, dev.cookie);
|
||||||
|
item->mStarted = false;
|
||||||
|
}
|
||||||
|
if (name)
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name)
|
||||||
|
return B_ERROR;
|
||||||
|
else
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method: InputServer::StartStopDevices()
|
* Method: InputServer::StartStopDevices()
|
||||||
* Descr:
|
* Descr:
|
||||||
@@ -1544,37 +1439,32 @@ InputServer::StartStopDevices(BInputServerDevice *isd,
|
|||||||
* Descr:
|
* Descr:
|
||||||
*/
|
*/
|
||||||
status_t
|
status_t
|
||||||
InputServer::ControlDevices(const char* deviceName,
|
InputServer::ControlDevices(const char* name, input_device_type type, uint32 code, BMessage* msg)
|
||||||
input_device_type deviceType,
|
|
||||||
unsigned long command,
|
|
||||||
BMessage* message)
|
|
||||||
{
|
{
|
||||||
status_t status = B_OK;
|
CALLED();
|
||||||
|
for (int i = gInputDeviceList.CountItems() - 1; i >= 0; i--) {
|
||||||
for (int i = gInputDeviceList.CountItems() - 1; i >= 0; i--)
|
|
||||||
{
|
|
||||||
PRINT(("%s Device #%d\n", __PRETTY_FUNCTION__, i));
|
|
||||||
InputDeviceListItem* item = (InputDeviceListItem*)gInputDeviceList.ItemAt(i);
|
InputDeviceListItem* item = (InputDeviceListItem*)gInputDeviceList.ItemAt(i);
|
||||||
if (NULL != item)
|
if (!item)
|
||||||
{
|
continue;
|
||||||
BInputServerDevice* isd = item->mIsd;
|
|
||||||
|
if ((name && strcmp(name, item->mDev.name) == 0) || item->mDev.type == type) {
|
||||||
|
if (!item->mIsd)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
input_device_ref dev = item->mDev;
|
input_device_ref dev = item->mDev;
|
||||||
if ( (NULL != isd) )
|
|
||||||
{
|
|
||||||
PRINT((" Controlling: %s\n", dev.name));
|
|
||||||
if (deviceType == dev.type)
|
|
||||||
{
|
|
||||||
// :TODO: Descriminate based on Device Name also.
|
|
||||||
|
|
||||||
// :TODO: Pass non-NULL Device Name and Cookie.
|
item->mIsd->Control(dev.name, dev.cookie, code, msg);
|
||||||
|
|
||||||
status = isd->Control(NULL /*Name*/, NULL /*Cookie*/, command, message);
|
if (name)
|
||||||
}
|
return B_OK;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
if (name)
|
||||||
|
return B_ERROR;
|
||||||
|
else
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1666,9 +1556,9 @@ InputServer::WatchPort()
|
|||||||
status_t err = read_port(fEventLooperPort, &code, buffer, length);
|
status_t err = read_port(fEventLooperPort, &code, buffer, length);
|
||||||
if(err != length) {
|
if(err != length) {
|
||||||
if(err >= 0) {
|
if(err >= 0) {
|
||||||
PRINT(("InputServer: failed to read full packet (read %lu of %lu)\n", err, length));
|
PRINTERR(("InputServer: failed to read full packet (read %lu of %lu)\n", err, length));
|
||||||
} else {
|
} else {
|
||||||
PRINT(("InputServer: read_port error: (0x%lx) %s\n", err, strerror(err)));
|
PRINTERR(("InputServer: read_port error: (0x%lx) %s\n", err, strerror(err)));
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1676,7 +1566,7 @@ InputServer::WatchPort()
|
|||||||
BMessage *event = new BMessage;
|
BMessage *event = new BMessage;
|
||||||
|
|
||||||
if ((err = event->Unflatten(buffer)) < 0) {
|
if ((err = event->Unflatten(buffer)) < 0) {
|
||||||
PRINT(("[InputServer] Unflatten() error: (0x%lx) %s\n", err, strerror(err)));
|
PRINTERR(("[InputServer] Unflatten() error: (0x%lx) %s\n", err, strerror(err)));
|
||||||
delete event;
|
delete event;
|
||||||
} else {
|
} else {
|
||||||
// This is where the message should be processed.
|
// This is where the message should be processed.
|
||||||
|
|||||||
@@ -125,14 +125,6 @@ public:
|
|||||||
status_t HandleGetSetKeyMap(BMessage*, BMessage*);
|
status_t HandleGetSetKeyMap(BMessage*, BMessage*);
|
||||||
status_t HandleFocusUnfocusIMAwareView(BMessage*, BMessage*);
|
status_t HandleFocusUnfocusIMAwareView(BMessage*, BMessage*);
|
||||||
|
|
||||||
status_t HandleFindDevices(BMessage*, BMessage*);
|
|
||||||
status_t HandleWatchDevices(BMessage*, BMessage*);
|
|
||||||
status_t HandleIsDeviceRunning(BMessage*, BMessage*);
|
|
||||||
status_t HandleStartStopDevices(BMessage*, BMessage*);
|
|
||||||
status_t HandleControlDevices(BMessage*, BMessage*);
|
|
||||||
status_t HandleSystemShuttingDown(BMessage*, BMessage*);
|
|
||||||
status_t HandleNodeMonitor(BMessage*);
|
|
||||||
|
|
||||||
status_t EnqueueDeviceMessage(BMessage*);
|
status_t EnqueueDeviceMessage(BMessage*);
|
||||||
status_t EnqueueMethodMessage(BMessage*);
|
status_t EnqueueMethodMessage(BMessage*);
|
||||||
status_t UnlockMethodQueue(void);
|
status_t UnlockMethodQueue(void);
|
||||||
@@ -152,8 +144,9 @@ public:
|
|||||||
bool SanitizeEvents(BList*);
|
bool SanitizeEvents(BList*);
|
||||||
bool MethodizeEvents(BList*, bool);
|
bool MethodizeEvents(BList*, bool);
|
||||||
|
|
||||||
|
static status_t StartStopDevices(const char *name, input_device_type type, bool doStart);
|
||||||
static status_t StartStopDevices(BInputServerDevice *isd, bool);
|
static status_t StartStopDevices(BInputServerDevice *isd, bool);
|
||||||
status_t ControlDevices(const char *, input_device_type, unsigned long, BMessage*);
|
static status_t ControlDevices(const char *, input_device_type, unsigned long, BMessage*);
|
||||||
|
|
||||||
bool DoMouseAcceleration(long*, long*);
|
bool DoMouseAcceleration(long*, long*);
|
||||||
bool SetMousePos(long*, long*, long, long);
|
bool SetMousePos(long*, long*, long, long);
|
||||||
@@ -232,13 +225,15 @@ public:
|
|||||||
inline void _iprint(const char *fmt, ...) { char buf[1024]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); va_end(ap); \
|
inline void _iprint(const char *fmt, ...) { char buf[1024]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); va_end(ap); \
|
||||||
fputs(buf, InputServer::sLogFile); fflush(InputServer::sLogFile); }
|
fputs(buf, InputServer::sLogFile); fflush(InputServer::sLogFile); }
|
||||||
#define PRINT(x) _iprint x
|
#define PRINT(x) _iprint x
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#define PRINTERR(x) PRINT(x)
|
||||||
#define EXIT() PRINT(("EXIT %s\n", __PRETTY_FUNCTION__))
|
#define EXIT() PRINT(("EXIT %s\n", __PRETTY_FUNCTION__))
|
||||||
#define CALLED() PRINT(("CALLED %s\n", __PRETTY_FUNCTION__))
|
#define CALLED() PRINT(("CALLED %s\n", __PRETTY_FUNCTION__))
|
||||||
#else
|
#else
|
||||||
#define EXIT() ((void)0)
|
#define EXIT() ((void)0)
|
||||||
#define CALLED() ((void)0)
|
#define CALLED() ((void)0)
|
||||||
|
#define PRINTERR(x) fprintf(stderr, x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user