AddOnManager improved, initializations, message handling improved

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8610 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2004-08-19 22:09:27 +00:00
parent 5359f0d4cc
commit 173f7185f4
6 changed files with 347 additions and 264 deletions
+129 -101
View File
@@ -2,7 +2,8 @@
** Copyright 2004, the OpenBeOS project. All rights reserved. ** Copyright 2004, the OpenBeOS project. All rights reserved.
** Distributed under the terms of the OpenBeOS License. ** Distributed under the terms of the OpenBeOS License.
** **
** Authors: Marcus Overhagen, Axel Dörfler ** Author : Jérôme Duval
** Original authors: Marcus Overhagen, Axel Dörfler
*/ */
@@ -18,36 +19,16 @@
#include <string.h> #include <string.h>
#include "AddOnManager.h" #include "AddOnManager.h"
#include "InputServer.h"
// #pragma mark ImageLoader
/** The ImageLoader class is a convenience class to temporarily load
* an image file, and unload it on deconstruction automatically.
*/
class ImageLoader {
public:
ImageLoader(BPath &path)
{
fImage = load_add_on(path.Path());
}
~ImageLoader()
{
if (fImage >= B_OK)
unload_add_on(fImage);
}
status_t InitCheck() const { return fImage; }
image_id Image() const { return fImage; }
private:
image_id fImage;
};
// #pragma mark - #if DEBUG>=1
#define EXIT() printf("EXIT %s\n", __PRETTY_FUNCTION__)
#define CALLED() printf("CALLED %s\n", __PRETTY_FUNCTION__)
#else
#define EXIT() ((void)0)
#define CALLED() ((void)0)
#endif
AddOnManager::AddOnManager() AddOnManager::AddOnManager()
: :
@@ -74,59 +55,6 @@ AddOnManager::SaveState()
} }
/*status_t
AddOnManager::GetDecoderForFormat(xfer_entry_ref *_decoderRef,
const media_format &format)
{
if ((format.type == B_MEDIA_ENCODED_VIDEO
|| format.type == B_MEDIA_ENCODED_AUDIO
|| format.type == B_MEDIA_MULTISTREAM)
&& format.Encoding() == 0)
return B_MEDIA_BAD_FORMAT;
if (format.type == B_MEDIA_NO_TYPE
|| format.type == B_MEDIA_UNKNOWN_TYPE)
return B_MEDIA_BAD_FORMAT;
BAutolock locker(fLock);
printf("AddOnManager::GetDecoderForFormat: searching decoder for encoding %ld\n", format.Encoding());
decoder_info *info;
for (fDecoderList.Rewind(); fDecoderList.GetNext(&info);) {
media_format *decoderFormat;
for (info->formats.Rewind(); info->formats.GetNext(&decoderFormat);) {
// check if the decoder matches the supplied format
if (!decoderFormat->Matches(&format))
continue;
printf("AddOnManager::GetDecoderForFormat: found decoder %s for encoding %ld\n",
info->ref.name, decoderFormat->Encoding());
*_decoderRef = info->ref;
return B_OK;
}
}
return B_ENTRY_NOT_FOUND;
}
status_t
AddOnManager::GetReaders(xfer_entry_ref *out_res, int32 *out_count, int32 max_count)
{
BAutolock locker(fLock);
*out_count = 0;
fReaderList.Rewind();
reader_info *info;
for (*out_count = 0; fReaderList.GetNext(&info) && *out_count <= max_count; *out_count += 1)
out_res[*out_count] = info->ref;
return B_OK;
}*/
status_t status_t
AddOnManager::RegisterAddOn(BEntry &entry) AddOnManager::RegisterAddOn(BEntry &entry)
{ {
@@ -139,9 +67,10 @@ AddOnManager::RegisterAddOn(BEntry &entry)
printf("AddOnManager::RegisterAddOn(): trying to load \"%s\"\n", path.Path()); printf("AddOnManager::RegisterAddOn(): trying to load \"%s\"\n", path.Path());
ImageLoader loader(path); image_id addon_image = load_add_on(path.Path());
if ((status = loader.InitCheck()) < B_OK)
return status; if (addon_image < B_OK)
return addon_image;
BEntry parent; BEntry parent;
entry.GetParent(&parent); entry.GetParent(&parent);
@@ -151,66 +80,150 @@ AddOnManager::RegisterAddOn(BEntry &entry)
if (pathString.FindFirst("input_server/devices")>0) { if (pathString.FindFirst("input_server/devices")>0) {
BInputServerDevice *(*instantiate_func)(); BInputServerDevice *(*instantiate_func)();
if (get_image_symbol(loader.Image(), "instantiate_input_device", if (get_image_symbol(addon_image, "instantiate_input_device",
B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) { B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) {
printf("AddOnManager::RegisterAddOn(): can't find instantiate_input_device in \"%s\"\n", printf("AddOnManager::RegisterAddOn(): can't find instantiate_input_device in \"%s\"\n",
path.Path()); path.Path());
return B_BAD_TYPE; goto exit_error;
} }
BInputServerDevice *isd = (*instantiate_func)(); BInputServerDevice *isd = (*instantiate_func)();
if (isd == NULL) { if (isd == NULL) {
printf("AddOnManager::RegisterAddOn(): instantiate_input_device in \"%s\" returned NULL\n", printf("AddOnManager::RegisterAddOn(): instantiate_input_device in \"%s\" returned NULL\n",
path.Path()); path.Path());
return B_ERROR; goto exit_error;
}
status_t status = isd->InitCheck();
if (status != B_OK) {
printf("AddOnManager::RegisterAddOn(): BInputServerDevice.InitCheck in \"%s\" returned %s\n",
path.Path(), strerror(status));
delete isd;
goto exit_error;
} }
RegisterDevice(isd, ref); RegisterDevice(isd, ref, addon_image);
} else if (pathString.FindFirst("input_server/filters")>0) { } else if (pathString.FindFirst("input_server/filters")>0) {
BInputServerFilter *(*instantiate_func)(); BInputServerFilter *(*instantiate_func)();
if (get_image_symbol(loader.Image(), "instantiate_input_filter", if (get_image_symbol(addon_image, "instantiate_input_filter",
B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) { B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) {
printf("AddOnManager::RegisterAddOn(): can't find instantiate_input_filter in \"%s\"\n", printf("AddOnManager::RegisterAddOn(): can't find instantiate_input_filter in \"%s\"\n",
path.Path()); path.Path());
return B_BAD_TYPE; goto exit_error;
} }
BInputServerFilter *isf = (*instantiate_func)(); BInputServerFilter *isf = (*instantiate_func)();
if (isf == NULL) { if (isf == NULL) {
printf("AddOnManager::RegisterAddOn(): instantiate_input_filter in \"%s\" returned NULL\n", printf("AddOnManager::RegisterAddOn(): instantiate_input_filter in \"%s\" returned NULL\n",
path.Path()); path.Path());
return B_ERROR; goto exit_error;
}
status_t status = isf->InitCheck();
if (status != B_OK) {
printf("AddOnManager::RegisterAddOn(): BInputServerFilter.InitCheck in \"%s\" returned %s\n",
path.Path(), strerror(status));
delete isf;
goto exit_error;
} }
RegisterFilter(isf, ref); RegisterFilter(isf, ref, addon_image);
} else if (pathString.FindFirst("input_server/methods")>0) { } else if (pathString.FindFirst("input_server/methods")>0) {
BInputServerMethod *(*instantiate_func)(); BInputServerMethod *(*instantiate_func)();
if (get_image_symbol(loader.Image(), "instantiate_input_method", if (get_image_symbol(addon_image, "instantiate_input_method",
B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) { B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) {
printf("AddOnManager::RegisterAddOn(): can't find instantiate_input_method in \"%s\"\n", printf("AddOnManager::RegisterAddOn(): can't find instantiate_input_method in \"%s\"\n",
path.Path()); path.Path());
return B_BAD_TYPE; goto exit_error;
} }
BInputServerMethod *ism = (*instantiate_func)(); BInputServerMethod *ism = (*instantiate_func)();
if (ism == NULL) { if (ism == NULL) {
printf("AddOnManager::RegisterAddOn(): instantiate_input_method in \"%s\" returned NULL\n", printf("AddOnManager::RegisterAddOn(): instantiate_input_method in \"%s\" returned NULL\n",
path.Path()); path.Path());
return B_ERROR; goto exit_error;
}
status_t status = ism->InitCheck();
if (status != B_OK) {
printf("AddOnManager::RegisterAddOn(): BInputServerMethod.InitCheck in \"%s\" returned %s\n",
path.Path(), strerror(status));
delete ism;
goto exit_error;
} }
RegisterMethod(ism, ref); RegisterMethod(ism, ref, addon_image);
} }
return B_OK; return B_OK;
exit_error:
unload_add_on(addon_image);
return status;
} }
status_t
AddOnManager::UnregisterAddOn(BEntry &entry)
{
BPath path(&entry);
entry_ref ref;
status_t status = entry.GetRef(&ref);
if (status < B_OK)
return status;
PRINT(("AddOnManager::UnregisterAddOn(): trying to unload \"%s\"\n", path.Path()));
BEntry parent;
entry.GetParent(&parent);
BPath parentPath(&parent);
BString pathString = parentPath.Path();
BAutolock locker(fLock);
if (pathString.FindFirst("input_server/devices")>0) {
device_info *pinfo;
for (fDeviceList.Rewind(); fDeviceList.GetNext(&pinfo);) {
if (!strcmp(pinfo->ref.name, ref.name)) {
delete pinfo->isd;
delete pinfo->addon;
if (pinfo->addon_image >= B_OK)
unload_add_on(pinfo->addon_image);
fDeviceList.RemoveCurrent();
break;
}
}
} else if (pathString.FindFirst("input_server/filters")>0) {
filter_info *pinfo;
for (fFilterList.Rewind(); fFilterList.GetNext(&pinfo);) {
if (!strcmp(pinfo->ref.name, ref.name)) {
delete pinfo->isf;
if (pinfo->addon_image >= B_OK)
unload_add_on(pinfo->addon_image);
fFilterList.RemoveCurrent();
break;
}
}
} else if (pathString.FindFirst("input_server/methods")>0) {
method_info *pinfo;
for (fMethodList.Rewind(); fMethodList.GetNext(&pinfo);) {
if (!strcmp(pinfo->ref.name, ref.name)) {
delete pinfo->ism;
delete pinfo->addon;
if (pinfo->addon_image >= B_OK)
unload_add_on(pinfo->addon_image);
fMethodList.RemoveCurrent();
break;
}
}
}
return B_OK;
}
void void
AddOnManager::RegisterAddOns() AddOnManager::RegisterAddOns()
{ {
@@ -224,6 +237,7 @@ AddOnManager::RegisterAddOns()
virtual void AddOnCreated(const add_on_entry_info * entry_info) { virtual void AddOnCreated(const add_on_entry_info * entry_info) {
} }
virtual void AddOnEnabled(const add_on_entry_info * entry_info) { virtual void AddOnEnabled(const add_on_entry_info * entry_info) {
CALLED();
entry_ref ref; entry_ref ref;
make_entry_ref(entry_info->dir_nref.device, entry_info->dir_nref.node, make_entry_ref(entry_info->dir_nref.device, entry_info->dir_nref.node,
entry_info->name, &ref); entry_info->name, &ref);
@@ -231,6 +245,12 @@ AddOnManager::RegisterAddOns()
fManager->RegisterAddOn(entry); fManager->RegisterAddOn(entry);
} }
virtual void AddOnDisabled(const add_on_entry_info * entry_info) { virtual void AddOnDisabled(const add_on_entry_info * entry_info) {
CALLED();
entry_ref ref;
make_entry_ref(entry_info->dir_nref.device, entry_info->dir_nref.node,
entry_info->name, &ref);
BEntry entry(&ref, false);
fManager->UnregisterAddOn(entry);
} }
virtual void AddOnRemoved(const add_on_entry_info * entry_info) { virtual void AddOnRemoved(const add_on_entry_info * entry_info) {
} }
@@ -253,7 +273,7 @@ AddOnManager::RegisterAddOns()
BDirectory directory; BDirectory directory;
BPath path; BPath path;
for (uint i = 0 ; i < sizeof(directories) / sizeof(directory_which) ; i++) for (uint i = 0 ; i < sizeof(directories) / sizeof(directory_which) ; i++)
for (uint j = 0 ; j < 2 ; j++) { for (uint j = 0 ; j < sizeof(subDirectories) / sizeof(char[24]) ; j++) {
if ((find_directory(directories[i], &path) == B_OK) if ((find_directory(directories[i], &path) == B_OK)
&& (path.Append(subDirectories[j]) == B_OK) && (path.Append(subDirectories[j]) == B_OK)
&& (directory.SetTo(path.Path()) == B_OK) && (directory.SetTo(path.Path()) == B_OK)
@@ -272,7 +292,7 @@ AddOnManager::RegisterAddOns()
void void
AddOnManager::RegisterDevice(BInputServerDevice *isd, const entry_ref &ref) AddOnManager::RegisterDevice(BInputServerDevice *device, const entry_ref &ref, image_id addon_image)
{ {
BAutolock locker(fLock); BAutolock locker(fLock);
@@ -288,13 +308,16 @@ AddOnManager::RegisterDevice(BInputServerDevice *isd, const entry_ref &ref)
device_info info; device_info info;
info.ref = ref; info.ref = ref;
info.addon_image = addon_image;
info.isd = device;
info.addon = new _BDeviceAddOn_;
fDeviceList.Insert(info); fDeviceList.Insert(info);
} }
void void
AddOnManager::RegisterFilter(BInputServerFilter *filter, const entry_ref &ref) AddOnManager::RegisterFilter(BInputServerFilter *filter, const entry_ref &ref, image_id addon_image)
{ {
BAutolock locker(fLock); BAutolock locker(fLock);
@@ -310,13 +333,15 @@ AddOnManager::RegisterFilter(BInputServerFilter *filter, const entry_ref &ref)
filter_info info; filter_info info;
info.ref = ref; info.ref = ref;
info.addon_image = addon_image;
info.isf = filter;
fFilterList.Insert(info); fFilterList.Insert(info);
} }
void void
AddOnManager::RegisterMethod(BInputServerMethod *method, const entry_ref &ref) AddOnManager::RegisterMethod(BInputServerMethod *method, const entry_ref &ref, image_id addon_image)
{ {
BAutolock locker(fLock); BAutolock locker(fLock);
@@ -332,6 +357,9 @@ AddOnManager::RegisterMethod(BInputServerMethod *method, const entry_ref &ref)
method_info info; method_info info;
info.ref = ref; info.ref = ref;
info.addon_image = addon_image;
info.ism = method;
info.addon = new _BMethodAddOn_;
fMethodList.Insert(info); fMethodList.Insert(info);
} }
+12 -3
View File
@@ -28,21 +28,30 @@ class AddOnManager {
private: private:
status_t RegisterAddOn(BEntry &entry); status_t RegisterAddOn(BEntry &entry);
status_t UnregisterAddOn(BEntry &entry);
void RegisterAddOns(); void RegisterAddOns();
void RegisterDevice(BInputServerDevice *isd, const entry_ref &ref); void RegisterDevice(BInputServerDevice *isd, const entry_ref &ref, image_id addon_image);
void RegisterFilter(BInputServerFilter *isf, const entry_ref &ref); void RegisterFilter(BInputServerFilter *isf, const entry_ref &ref, image_id addon_image);
void RegisterMethod(BInputServerMethod *ism, const entry_ref &ref); void RegisterMethod(BInputServerMethod *ism, const entry_ref &ref, image_id addon_image);
private: private:
struct device_info { struct device_info {
entry_ref ref; entry_ref ref;
_BDeviceAddOn_* addon;
image_id addon_image;
BInputServerDevice *isd;
}; };
struct filter_info { struct filter_info {
entry_ref ref; entry_ref ref;
image_id addon_image;
BInputServerFilter *isf;
}; };
struct method_info { struct method_info {
entry_ref ref; entry_ref ref;
_BMethodAddOn_* addon;
image_id addon_image;
BInputServerMethod *ism;
}; };
BLocker fLock; BLocker fLock;
+146 -115
View File
@@ -42,6 +42,7 @@
#include <Path.h> #include <Path.h>
#include <String.h> #include <String.h>
#if DEBUG>=1 #if DEBUG>=1
#define EXIT() printf("EXIT %s\n", __PRETTY_FUNCTION__) #define EXIT() printf("EXIT %s\n", __PRETTY_FUNCTION__)
#define CALLED() printf("CALLED %s\n", __PRETTY_FUNCTION__) #define CALLED() printf("CALLED %s\n", __PRETTY_FUNCTION__)
@@ -85,9 +86,7 @@ BList InputServer::mInputServerMethodList;
*/ */
int main() int main()
{ {
InputServer *myInputServer; InputServer *myInputServer = new InputServer;
myInputServer = new InputServer;
myInputServer->Run(); myInputServer->Run();
@@ -106,7 +105,7 @@ InputServer::InputServer(void) : BApplication("application/x-vnd.OBOS-input_serv
EventLoop(pointer); EventLoop(pointer);
InitTestDevice(); // InitTestDevice();
fAddOnManager = new AddOnManager(); fAddOnManager = new AddOnManager();
fAddOnManager->LoadState(); fAddOnManager->LoadState();
@@ -578,10 +577,10 @@ InputServer::MessageReceived(BMessage *message)
HandleGetKeyboardID(message, reply); HandleGetKeyboardID(message, reply);
break; break;
case IS_GET_CLICK_SPEED: case IS_GET_CLICK_SPEED:
HandleGetClickSpeed(message, reply); HandleGetSetClickSpeed(message, reply);
break; break;
case IS_SET_CLICK_SPEED: case IS_SET_CLICK_SPEED:
HandleSetClickSpeed(message, reply); HandleGetSetClickSpeed(message, reply);
break; break;
case IS_GET_KEY_REPEAT_RATE: case IS_GET_KEY_REPEAT_RATE:
HandleGetSetKeyRepeatRate(message, reply); HandleGetSetKeyRepeatRate(message, reply);
@@ -658,7 +657,7 @@ InputServer::HandleSetMethod(BMessage *)
* Method: InputServer::HandleGetSetMouseType() * Method: InputServer::HandleGetSetMouseType()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleGetSetMouseType(BMessage* message, InputServer::HandleGetSetMouseType(BMessage* message,
BMessage* reply) BMessage* reply)
{ {
@@ -667,7 +666,7 @@ InputServer::HandleGetSetMouseType(BMessage* message,
status = ControlDevices(NULL, B_POINTING_DEVICE, B_MOUSE_TYPE_CHANGED, NULL); status = ControlDevices(NULL, B_POINTING_DEVICE, B_MOUSE_TYPE_CHANGED, NULL);
else else
status = reply->AddInt32("mouse_type", sMouseType); status = reply->AddInt32("mouse_type", sMouseType);
message->SendReply(status, reply); return status;
} }
@@ -675,7 +674,7 @@ InputServer::HandleGetSetMouseType(BMessage* message,
* Method: InputServer::HandleGetSetMouseAcceleration() * Method: InputServer::HandleGetSetMouseAcceleration()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleGetSetMouseAcceleration(BMessage* message, InputServer::HandleGetSetMouseAcceleration(BMessage* message,
BMessage* reply) BMessage* reply)
{ {
@@ -684,7 +683,7 @@ InputServer::HandleGetSetMouseAcceleration(BMessage* message,
status = ControlDevices(NULL, B_POINTING_DEVICE, B_MOUSE_ACCELERATION_CHANGED, NULL); status = ControlDevices(NULL, B_POINTING_DEVICE, B_MOUSE_ACCELERATION_CHANGED, NULL);
else else
status = reply->AddInt32("mouse_acceleration", sMouseAcceleration); status = reply->AddInt32("mouse_acceleration", sMouseAcceleration);
message->SendReply(status, reply); return status;
} }
@@ -692,7 +691,7 @@ InputServer::HandleGetSetMouseAcceleration(BMessage* message,
* Method: InputServer::HandleGetSetKeyRepeatDelay() * Method: InputServer::HandleGetSetKeyRepeatDelay()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleGetSetKeyRepeatDelay(BMessage* message, InputServer::HandleGetSetKeyRepeatDelay(BMessage* message,
BMessage* reply) BMessage* reply)
{ {
@@ -701,7 +700,7 @@ InputServer::HandleGetSetKeyRepeatDelay(BMessage* message,
status = ControlDevices(NULL, B_KEYBOARD_DEVICE, B_KEY_REPEAT_DELAY_CHANGED, NULL); status = ControlDevices(NULL, B_KEYBOARD_DEVICE, B_KEY_REPEAT_DELAY_CHANGED, NULL);
else else
status = reply->AddInt64("key_repeat_delay", sKeyRepeatDelay); status = reply->AddInt64("key_repeat_delay", sKeyRepeatDelay);
message->SendReply(status, reply); return status;
} }
@@ -709,10 +708,11 @@ InputServer::HandleGetSetKeyRepeatDelay(BMessage* message,
* Method: InputServer::HandleGetKeyInfo() * Method: InputServer::HandleGetKeyInfo()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleGetKeyInfo(BMessage *message, InputServer::HandleGetKeyInfo(BMessage *message,
BMessage *reply) BMessage *reply)
{ {
return reply->AddData("key_info", B_ANY_TYPE, &s_key_info, sizeof(s_key_info));
} }
@@ -720,10 +720,11 @@ InputServer::HandleGetKeyInfo(BMessage *message,
* Method: InputServer::HandleGetModifiers() * Method: InputServer::HandleGetModifiers()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleGetModifiers(BMessage *message, InputServer::HandleGetModifiers(BMessage *message,
BMessage *reply) BMessage *reply)
{ {
return reply->AddInt32("modifiers", s_key_info.modifiers);
} }
@@ -731,10 +732,21 @@ InputServer::HandleGetModifiers(BMessage *message,
* Method: InputServer::HandleSetModifierKey() * Method: InputServer::HandleSetModifierKey()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleSetModifierKey(BMessage *message, InputServer::HandleSetModifierKey(BMessage *message,
BMessage *reply) BMessage *reply)
{ {
status_t status = B_ERROR;
int32 modifier, key;
if (message->FindInt32("modifier", &modifier) == B_OK
&& message->FindInt32("key", &key) == B_OK) {
// TODO : impact the keymap
// is SetModifierKey a keymap change ?
status = ControlDevices(NULL, B_KEYBOARD_DEVICE, B_KEY_MAP_CHANGED, NULL);
}
return status;
} }
@@ -742,9 +754,15 @@ InputServer::HandleSetModifierKey(BMessage *message,
* Method: InputServer::HandleSetKeyboardLocks() * Method: InputServer::HandleSetKeyboardLocks()
* Descr: * Descr:
*/ */
void InputServer::HandleSetKeyboardLocks(BMessage *message, status_t
InputServer::HandleSetKeyboardLocks(BMessage *message,
BMessage *reply) BMessage *reply)
{ {
status_t status = B_ERROR;
if (message->FindInt32("locks", &sKeyboardLocks) == B_OK)
status = ControlDevices(NULL, B_KEYBOARD_DEVICE, B_KEY_LOCKS_CHANGED, NULL);
return status;
} }
@@ -752,7 +770,7 @@ void InputServer::HandleSetKeyboardLocks(BMessage *message,
* Method: InputServer::HandleGetSetMouseSpeed() * Method: InputServer::HandleGetSetMouseSpeed()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleGetSetMouseSpeed(BMessage* message, InputServer::HandleGetSetMouseSpeed(BMessage* message,
BMessage* reply) BMessage* reply)
{ {
@@ -761,7 +779,7 @@ InputServer::HandleGetSetMouseSpeed(BMessage* message,
status = ControlDevices(NULL, B_POINTING_DEVICE, B_MOUSE_SPEED_CHANGED, NULL); status = ControlDevices(NULL, B_POINTING_DEVICE, B_MOUSE_SPEED_CHANGED, NULL);
else else
status = reply->AddInt32("mouse_speed", sMouseSpeed); status = reply->AddInt32("mouse_speed", sMouseSpeed);
message->SendReply(status, reply); return status;
} }
@@ -769,7 +787,7 @@ InputServer::HandleGetSetMouseSpeed(BMessage* message,
* Method: InputServer::HandleSetMousePosition() * Method: InputServer::HandleSetMousePosition()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleSetMousePosition(BMessage *message, BMessage *outbound) InputServer::HandleSetMousePosition(BMessage *message, BMessage *outbound)
{ {
@@ -803,6 +821,8 @@ InputServer::HandleSetMousePosition(BMessage *message, BMessage *outbound)
break; break;
} }
return B_OK;
} }
@@ -810,7 +830,7 @@ InputServer::HandleSetMousePosition(BMessage *message, BMessage *outbound)
* Method: InputServer::HandleGetMouseMap() * Method: InputServer::HandleGetMouseMap()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleGetSetMouseMap(BMessage* message, InputServer::HandleGetSetMouseMap(BMessage* message,
BMessage* reply) BMessage* reply)
{ {
@@ -823,7 +843,7 @@ InputServer::HandleGetSetMouseMap(BMessage* message,
status = ControlDevices(NULL, B_POINTING_DEVICE, B_MOUSE_MAP_CHANGED, NULL); status = ControlDevices(NULL, B_POINTING_DEVICE, B_MOUSE_MAP_CHANGED, NULL);
} else } else
status = reply->AddData("mouse_map", B_RAW_TYPE, &sMouseMap, sizeof(sMouseMap) ); status = reply->AddData("mouse_map", B_RAW_TYPE, &sMouseMap, sizeof(sMouseMap) );
message->SendReply(status, reply); return status;
} }
@@ -831,36 +851,28 @@ InputServer::HandleGetSetMouseMap(BMessage* message,
* Method: InputServer::HandleGetKeyboardID() * Method: InputServer::HandleGetKeyboardID()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleGetKeyboardID(BMessage *, InputServer::HandleGetKeyboardID(BMessage *message,
BMessage *) BMessage *reply)
{ {
return reply->AddInt16("id", sKeyboardID);
} }
/* /*
* Method: InputServer::HandleGetClickSpeed() * Method: InputServer::HandleGetSetClickSpeed()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleGetClickSpeed(BMessage* message, InputServer::HandleGetSetClickSpeed(BMessage *message,
BMessage* reply) BMessage *reply)
{ {
status_t status = reply->AddInt64("mouse_click_speed", sMouseClickSpeed); status_t status = B_ERROR;
message->SendReply(status, reply); if (message->FindInt64("mouse_click_speed", &sMouseClickSpeed) == B_OK)
} status = ControlDevices(NULL, B_POINTING_DEVICE, B_CLICK_SPEED_CHANGED, NULL);
else
/* status = reply->AddInt64("mouse_click_speed", sMouseClickSpeed);
* Method: InputServer::HandleSetClickSpeed() return status;
* Descr:
*/
void
InputServer::HandleSetClickSpeed(BMessage* message,
BMessage* reply)
{
message->FindInt64("mouse_click_speed", &sMouseClickSpeed);
status_t status = ControlDevices(NULL, B_POINTING_DEVICE, B_CLICK_SPEED_CHANGED, NULL);
message->SendReply(status, reply);
} }
@@ -868,7 +880,7 @@ InputServer::HandleSetClickSpeed(BMessage* message,
* Method: InputServer::HandleGetSetKeyRepeatRate() * Method: InputServer::HandleGetSetKeyRepeatRate()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleGetSetKeyRepeatRate(BMessage* message, InputServer::HandleGetSetKeyRepeatRate(BMessage* message,
BMessage* reply) BMessage* reply)
{ {
@@ -877,7 +889,7 @@ InputServer::HandleGetSetKeyRepeatRate(BMessage* message,
status = ControlDevices(NULL, B_KEYBOARD_DEVICE, B_KEY_REPEAT_RATE_CHANGED, NULL); status = ControlDevices(NULL, B_KEYBOARD_DEVICE, B_KEY_REPEAT_RATE_CHANGED, NULL);
else else
status = reply->AddInt32("key_repeat_rate", sKeyRepeatRate); status = reply->AddInt32("key_repeat_rate", sKeyRepeatRate);
message->SendReply(status, reply); return status;
} }
@@ -885,10 +897,21 @@ InputServer::HandleGetSetKeyRepeatRate(BMessage* message,
* Method: InputServer::HandleGetSetKeyMap() * Method: InputServer::HandleGetSetKeyMap()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleGetSetKeyMap(BMessage *message, InputServer::HandleGetSetKeyMap(BMessage *message,
BMessage *reply) BMessage *reply)
{ {
status_t status;
if (message->what == IS_GET_KEY_MAP) {
status = reply->AddData("keymap", B_ANY_TYPE, &s_key_map, sizeof(s_key_map));
if (status == B_OK)
status = reply->AddData("key_buffer", B_ANY_TYPE, sChars, sCharCount);
} else {
// TODO : reload keymap
status = ControlDevices(NULL, B_KEYBOARD_DEVICE, B_KEY_MAP_CHANGED, NULL);
}
return status;
} }
@@ -896,7 +919,7 @@ InputServer::HandleGetSetKeyMap(BMessage *message,
* Method: InputServer::HandleFocusUnfocusIMAwareView() * Method: InputServer::HandleFocusUnfocusIMAwareView()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleFocusUnfocusIMAwareView(BMessage *, InputServer::HandleFocusUnfocusIMAwareView(BMessage *,
BMessage *) BMessage *)
{ {
@@ -907,10 +930,11 @@ InputServer::HandleFocusUnfocusIMAwareView(BMessage *,
* Method: InputServer::HandleFindDevices() * Method: InputServer::HandleFindDevices()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleFindDevices(BMessage *message, InputServer::HandleFindDevices(BMessage *message,
BMessage *reply) BMessage *reply)
{ {
} }
@@ -918,7 +942,7 @@ InputServer::HandleFindDevices(BMessage *message,
* Method: InputServer::HandleWatchDevices() * Method: InputServer::HandleWatchDevices()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleWatchDevices(BMessage *message, InputServer::HandleWatchDevices(BMessage *message,
BMessage *reply) BMessage *reply)
{ {
@@ -929,10 +953,11 @@ InputServer::HandleWatchDevices(BMessage *message,
* Method: InputServer::HandleIsDeviceRunning() * Method: InputServer::HandleIsDeviceRunning()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleIsDeviceRunning(BMessage *message, InputServer::HandleIsDeviceRunning(BMessage *message,
BMessage *reply) BMessage *reply)
{ {
} }
@@ -940,7 +965,7 @@ InputServer::HandleIsDeviceRunning(BMessage *message,
* Method: InputServer::HandleStartStopDevices() * Method: InputServer::HandleStartStopDevices()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleStartStopDevices(BMessage *message, InputServer::HandleStartStopDevices(BMessage *message,
BMessage *reply) BMessage *reply)
{ {
@@ -951,7 +976,7 @@ InputServer::HandleStartStopDevices(BMessage *message,
* Method: InputServer::HandleControlDevices() * Method: InputServer::HandleControlDevices()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleControlDevices(BMessage *message, InputServer::HandleControlDevices(BMessage *message,
BMessage *reply) BMessage *reply)
{ {
@@ -962,10 +987,12 @@ InputServer::HandleControlDevices(BMessage *message,
* Method: InputServer::HandleSystemShuttingDown() * Method: InputServer::HandleSystemShuttingDown()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleSystemShuttingDown(BMessage *message, InputServer::HandleSystemShuttingDown(BMessage *message,
BMessage *reply) BMessage *reply)
{ {
status_t status;
return status;
} }
@@ -973,9 +1000,10 @@ InputServer::HandleSystemShuttingDown(BMessage *message,
* Method: InputServer::HandleNodeMonitor() * Method: InputServer::HandleNodeMonitor()
* Descr: * Descr:
*/ */
void status_t
InputServer::HandleNodeMonitor(BMessage *message) InputServer::HandleNodeMonitor(BMessage *message)
{ {
} }
@@ -983,7 +1011,8 @@ InputServer::HandleNodeMonitor(BMessage *message)
* Method: InputServer::EnqueueDeviceMessage() * Method: InputServer::EnqueueDeviceMessage()
* Descr: * Descr:
*/ */
status_t InputServer::EnqueueDeviceMessage(BMessage *message) status_t
InputServer::EnqueueDeviceMessage(BMessage *message)
{ {
//return (write_port(fEventPort, (int32)message, NULL, 0)); //return (write_port(fEventPort, (int32)message, NULL, 0));
return (write_port(EventLooperPort, (int32)message, NULL, 0)); return (write_port(EventLooperPort, (int32)message, NULL, 0));
@@ -1333,70 +1362,70 @@ const BList* InputServer::GetNextEvents(BList *)
* The method returns true if the filters were applied to all * The method returns true if the filters were applied to all
* events without error and false otherwise. * events without error and false otherwise.
*/ */
bool InputServer::FilterEvents(BList *eventsToFilter) bool
InputServer::FilterEvents(BList *eventsToFilter)
{ {
if (NULL != eventsToFilter) if (NULL == eventsToFilter)
return false;
BInputServerFilter* current_filter;
BMessage* current_event;
int32 filter_index = 0;
int32 event_index = 0;
while (NULL != (current_filter = (BInputServerFilter*)mInputServerFilterList.ItemAt(filter_index) ) )
{ {
BInputServerFilter* current_filter; // Apply the current filter to all available event messages.
BMessage* current_event; //
int32 filter_index = 0; while (NULL != (current_event = (BMessage*)eventsToFilter->ItemAt(event_index) ) )
int32 event_index = 0;
while (NULL != (current_filter = (BInputServerFilter*)mInputServerFilterList.ItemAt(filter_index) ) )
{ {
// Apply the current filter to all available event messages. // Storage for new event messages generated by the filter.
// //
while (NULL != (current_event = (BMessage*)eventsToFilter->ItemAt(event_index) ) ) BList out_list;
// Apply the current filter to the current event message.
//
filter_result result = current_filter->Filter(current_event, &out_list);
if (B_DISPATCH_MESSAGE == result)
{ {
// Storage for new event messages generated by the filter. // Use the result in current_message; ignore out_list.
// //
BList out_list; event_index++;
// Apply the current filter to the current event message. // Free resources associated with items in out_list.
// //
filter_result result = current_filter->Filter(current_event, &out_list); void *out_item;
if (B_DISPATCH_MESSAGE == result) for (int32 i = 0; NULL != (out_item = out_list.ItemAt(i) ); i++)
{ {
// Use the result in current_message; ignore out_list. delete out_item;
//
event_index++;
// Free resources associated with items in out_list.
//
void* out_item;
for (int32 i = 0; NULL != (out_item = out_list.ItemAt(i) ); i++)
{
delete out_item;
}
} }
else if (B_SKIP_MESSAGE == result) }
else if (B_SKIP_MESSAGE == result)
{
// Use the result in out_list (if any); ignore current message.
//
eventsToFilter->RemoveItem(event_index);
eventsToFilter->AddList(&out_list, event_index);
event_index += out_list.CountItems();
// NOTE: eventsToFilter now owns out_list's items.
}
else
{
// Error - Free resources associated with items in out_list and return.
//
void* out_item;
for (int32 i = 0; NULL != (out_item = out_list.ItemAt(i) ); i++)
{ {
// Use the result in out_list (if any); ignore current message. delete out_item;
//
eventsToFilter->RemoveItem(event_index);
eventsToFilter->AddList(&out_list, event_index);
event_index += out_list.CountItems();
// NOTE: eventsToFilter now owns out_list's items.
} }
else return false;
{
// Error - Free resources associated with items in out_list and return.
//
void* out_item;
for (int32 i = 0; NULL != (out_item = out_list.ItemAt(i) ); i++)
{
delete out_item;
}
return false;
}
// NOTE: The BList destructor frees out_lists's resources here.
// It does NOT free the resources associated with out_list's
// member items - those should either already be deleted or
// should be owned by eventsToFilter.
} }
// NOTE: The BList destructor frees out_lists's resources here.
// It does NOT free the resources associated with out_list's
// member items - those should either already be deleted or
// should be owned by eventsToFilter.
} // while() } // while()
filter_index++; filter_index++;
@@ -1444,15 +1473,17 @@ status_t InputServer::StartStopDevices(const char* deviceName,
if (NULL != item) if (NULL != item)
{ {
BInputServerDevice* isd = item->mIsd; BInputServerDevice* isd = item->mIsd;
input_device_ref* dev = item->mDev; input_device_ref dev = item->mDev;
PRINT(("Hey\n")); PRINT(("Hey\n"));
if ( (NULL != isd) && (NULL != dev) ) if ( (NULL != isd) )
{ {
PRINT((" Starting/stopping: %s\n", dev->name)); PRINT((" Starting/stopping: %s\n", dev.name));
if (deviceType == dev->type) if (deviceType == dev.type)
{ {
if (doStart) isd->Start(dev->name, dev->cookie); if (doStart)
else isd->Stop(dev->name, dev->cookie); isd->Start(dev.name, dev.cookie);
else
isd->Stop(dev.name, dev.cookie);
} }
} }
} }
@@ -1481,11 +1512,11 @@ status_t InputServer::ControlDevices(const char* deviceName,
if (NULL != item) if (NULL != item)
{ {
BInputServerDevice* isd = item->mIsd; BInputServerDevice* isd = item->mIsd;
input_device_ref* dev = item->mDev; input_device_ref dev = item->mDev;
if ( (NULL != isd) && (NULL != dev) ) if ( (NULL != isd) )
{ {
PRINT((" Controlling: %s\n", dev->name)); PRINT((" Controlling: %s\n", dev.name));
if (deviceType == dev->type) if (deviceType == dev.type)
{ {
// :TODO: Descriminate based on Device Name also. // :TODO: Descriminate based on Device Name also.
+46 -29
View File
@@ -31,9 +31,9 @@
// BeAPI Headers // BeAPI Headers
#include <Application.h> #include <Application.h>
#include "InputServerDevice.h" #include <InputServerDevice.h>
#include "InputServerFilter.h" #include <InputServerFilter.h>
#include "InputServerMethod.h" #include <InputServerMethod.h>
#include "AddOnManager.h" #include "AddOnManager.h"
#include <stdlib.h> #include <stdlib.h>
@@ -54,10 +54,21 @@ class InputDeviceListItem
{ {
public: public:
BInputServerDevice* mIsd; BInputServerDevice* mIsd;
input_device_ref* mDev; input_device_ref mDev;
bool mStarted;
InputDeviceListItem(BInputServerDevice* isd, input_device_ref dev):
mIsd(isd), mDev(dev), mStarted(false) {};
};
class _BDeviceAddOn_
{
};
class _BMethodAddOn_
{
InputDeviceListItem(BInputServerDevice* isd, input_device_ref* dev):
mIsd(isd), mDev(dev) {};
}; };
/*****************************************************************************/ /*****************************************************************************/
@@ -87,30 +98,29 @@ public:
virtual void MessageReceived(BMessage*); virtual void MessageReceived(BMessage*);
void HandleSetMethod(BMessage*); void HandleSetMethod(BMessage*);
void HandleGetSetMouseType(BMessage*, BMessage*); status_t HandleGetSetMouseType(BMessage*, BMessage*);
void HandleGetSetMouseAcceleration(BMessage*, BMessage*); status_t HandleGetSetMouseAcceleration(BMessage*, BMessage*);
void HandleGetSetKeyRepeatDelay(BMessage*, BMessage*); status_t HandleGetSetKeyRepeatDelay(BMessage*, BMessage*);
void HandleGetKeyInfo(BMessage*, BMessage*); status_t HandleGetKeyInfo(BMessage*, BMessage*);
void HandleGetModifiers(BMessage*, BMessage*); status_t HandleGetModifiers(BMessage*, BMessage*);
void HandleSetModifierKey(BMessage*, BMessage*); status_t HandleSetModifierKey(BMessage*, BMessage*);
void HandleSetKeyboardLocks(BMessage*, BMessage*); status_t HandleSetKeyboardLocks(BMessage*, BMessage*);
void HandleGetSetMouseSpeed(BMessage*, BMessage*); status_t HandleGetSetMouseSpeed(BMessage*, BMessage*);
void HandleSetMousePosition(BMessage*, BMessage*); status_t HandleSetMousePosition(BMessage*, BMessage*);
void HandleGetSetMouseMap(BMessage*, BMessage*); status_t HandleGetSetMouseMap(BMessage*, BMessage*);
void HandleGetKeyboardID(BMessage*, BMessage*); status_t HandleGetKeyboardID(BMessage*, BMessage*);
void HandleGetClickSpeed(BMessage*, BMessage*); status_t HandleGetSetClickSpeed(BMessage*, BMessage*);
void HandleSetClickSpeed(BMessage*, BMessage*); status_t HandleGetSetKeyRepeatRate(BMessage*, BMessage*);
void HandleGetSetKeyRepeatRate(BMessage*, BMessage*); status_t HandleGetSetKeyMap(BMessage*, BMessage*);
void HandleGetSetKeyMap(BMessage*, BMessage*); status_t HandleFocusUnfocusIMAwareView(BMessage*, BMessage*);
void HandleFocusUnfocusIMAwareView(BMessage*, BMessage*);
void HandleFindDevices(BMessage*, BMessage*); status_t HandleFindDevices(BMessage*, BMessage*);
void HandleWatchDevices(BMessage*, BMessage*); status_t HandleWatchDevices(BMessage*, BMessage*);
void HandleIsDeviceRunning(BMessage*, BMessage*); status_t HandleIsDeviceRunning(BMessage*, BMessage*);
void HandleStartStopDevices(BMessage*, BMessage*); status_t HandleStartStopDevices(BMessage*, BMessage*);
void HandleControlDevices(BMessage*, BMessage*); status_t HandleControlDevices(BMessage*, BMessage*);
void HandleSystemShuttingDown(BMessage*, BMessage*); status_t HandleSystemShuttingDown(BMessage*, BMessage*);
void HandleNodeMonitor(BMessage*); status_t HandleNodeMonitor(BMessage*);
status_t EnqueueDeviceMessage(BMessage*); status_t EnqueueDeviceMessage(BMessage*);
status_t EnqueueMethodMessage(BMessage*); status_t EnqueueMethodMessage(BMessage*);
@@ -161,8 +171,15 @@ private:
bigtime_t sMouseClickSpeed; bigtime_t sMouseClickSpeed;
int32 sKeyRepeatRate; int32 sKeyRepeatRate;
bigtime_t sKeyRepeatDelay; bigtime_t sKeyRepeatDelay;
int32 sKeyboardLocks;
uint16 sKeyboardID;
mouse_map sMouseMap; mouse_map sMouseMap;
key_info s_key_info; // current key info
key_map s_key_map; // current key_map
char *sChars; // current keymap chars
int32 sCharCount; // current keymap char count
port_id ISPort; port_id ISPort;
port_id EventLooperPort; port_id EventLooperPort;
thread_id ISPortThread; thread_id ISPortThread;
+2 -2
View File
@@ -32,7 +32,7 @@
/*****************************************************************************/ /*****************************************************************************/
#include "InputServerDevice.h" #include <InputServerDevice.h>
#include "InputServer.h" #include "InputServer.h"
/** /**
@@ -198,7 +198,7 @@ BInputServerDevice::EnqueueMessage(BMessage *message)
} }
return err; return err;
*/ */
return B_OK; return ((InputServer*)be_app)->EnqueueDeviceMessage(message);
} }
+4 -6
View File
@@ -31,9 +31,9 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
/*****************************************************************************/ /*****************************************************************************/
#include <InputServerMethod.h>
#include "InputServerMethod.h" #include <Messenger.h>
#include "Messenger.h" #include "InputServer.h"
/** /**
* Method: BInputServerMethod::BInputServerMethod() * Method: BInputServerMethod::BInputServerMethod()
@@ -72,9 +72,7 @@ BInputServerMethod::MethodActivated(bool active)
status_t status_t
BInputServerMethod::EnqueueMessage(BMessage *message) BInputServerMethod::EnqueueMessage(BMessage *message)
{ {
status_t dummy; return ((InputServer*)be_app)->EnqueueMethodMessage(message);
return dummy;
} }