diff --git a/src/servers/input/AddOnManager.cpp b/src/servers/input/AddOnManager.cpp index 6d9af8c866..0d3c146ab8 100644 --- a/src/servers/input/AddOnManager.cpp +++ b/src/servers/input/AddOnManager.cpp @@ -2,7 +2,8 @@ ** Copyright 2004, the OpenBeOS project. All rights reserved. ** 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 #include "AddOnManager.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; -}; +#include "InputServer.h" -// #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() : @@ -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 AddOnManager::RegisterAddOn(BEntry &entry) { @@ -139,9 +67,10 @@ AddOnManager::RegisterAddOn(BEntry &entry) printf("AddOnManager::RegisterAddOn(): trying to load \"%s\"\n", path.Path()); - ImageLoader loader(path); - if ((status = loader.InitCheck()) < B_OK) - return status; + image_id addon_image = load_add_on(path.Path()); + + if (addon_image < B_OK) + return addon_image; BEntry parent; entry.GetParent(&parent); @@ -151,66 +80,150 @@ AddOnManager::RegisterAddOn(BEntry &entry) if (pathString.FindFirst("input_server/devices")>0) { 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) { printf("AddOnManager::RegisterAddOn(): can't find instantiate_input_device in \"%s\"\n", path.Path()); - return B_BAD_TYPE; + goto exit_error; } BInputServerDevice *isd = (*instantiate_func)(); if (isd == NULL) { printf("AddOnManager::RegisterAddOn(): instantiate_input_device in \"%s\" returned NULL\n", 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) { 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) { printf("AddOnManager::RegisterAddOn(): can't find instantiate_input_filter in \"%s\"\n", path.Path()); - return B_BAD_TYPE; + goto exit_error; } BInputServerFilter *isf = (*instantiate_func)(); if (isf == NULL) { printf("AddOnManager::RegisterAddOn(): instantiate_input_filter in \"%s\" returned NULL\n", 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) { 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) { printf("AddOnManager::RegisterAddOn(): can't find instantiate_input_method in \"%s\"\n", path.Path()); - return B_BAD_TYPE; + goto exit_error; } BInputServerMethod *ism = (*instantiate_func)(); if (ism == NULL) { printf("AddOnManager::RegisterAddOn(): instantiate_input_method in \"%s\" returned NULL\n", 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; +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 AddOnManager::RegisterAddOns() { @@ -224,6 +237,7 @@ AddOnManager::RegisterAddOns() virtual void AddOnCreated(const add_on_entry_info * entry_info) { } virtual void AddOnEnabled(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); @@ -231,6 +245,12 @@ AddOnManager::RegisterAddOns() fManager->RegisterAddOn(entry); } 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) { } @@ -253,7 +273,7 @@ AddOnManager::RegisterAddOns() BDirectory directory; BPath path; 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) && (path.Append(subDirectories[j]) == B_OK) && (directory.SetTo(path.Path()) == B_OK) @@ -272,7 +292,7 @@ AddOnManager::RegisterAddOns() void -AddOnManager::RegisterDevice(BInputServerDevice *isd, const entry_ref &ref) +AddOnManager::RegisterDevice(BInputServerDevice *device, const entry_ref &ref, image_id addon_image) { BAutolock locker(fLock); @@ -288,13 +308,16 @@ AddOnManager::RegisterDevice(BInputServerDevice *isd, const entry_ref &ref) device_info info; info.ref = ref; - + info.addon_image = addon_image; + info.isd = device; + info.addon = new _BDeviceAddOn_; + fDeviceList.Insert(info); } void -AddOnManager::RegisterFilter(BInputServerFilter *filter, const entry_ref &ref) +AddOnManager::RegisterFilter(BInputServerFilter *filter, const entry_ref &ref, image_id addon_image) { BAutolock locker(fLock); @@ -310,13 +333,15 @@ AddOnManager::RegisterFilter(BInputServerFilter *filter, const entry_ref &ref) filter_info info; info.ref = ref; + info.addon_image = addon_image; + info.isf = filter; fFilterList.Insert(info); } void -AddOnManager::RegisterMethod(BInputServerMethod *method, const entry_ref &ref) +AddOnManager::RegisterMethod(BInputServerMethod *method, const entry_ref &ref, image_id addon_image) { BAutolock locker(fLock); @@ -332,6 +357,9 @@ AddOnManager::RegisterMethod(BInputServerMethod *method, const entry_ref &ref) method_info info; info.ref = ref; + info.addon_image = addon_image; + info.ism = method; + info.addon = new _BMethodAddOn_; fMethodList.Insert(info); } diff --git a/src/servers/input/AddOnManager.h b/src/servers/input/AddOnManager.h index 0b398b00b7..4fc4382187 100644 --- a/src/servers/input/AddOnManager.h +++ b/src/servers/input/AddOnManager.h @@ -28,21 +28,30 @@ class AddOnManager { private: status_t RegisterAddOn(BEntry &entry); + status_t UnregisterAddOn(BEntry &entry); void RegisterAddOns(); - void RegisterDevice(BInputServerDevice *isd, const entry_ref &ref); - void RegisterFilter(BInputServerFilter *isf, const entry_ref &ref); - void RegisterMethod(BInputServerMethod *ism, const entry_ref &ref); + void RegisterDevice(BInputServerDevice *isd, 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); private: struct device_info { entry_ref ref; + _BDeviceAddOn_* addon; + image_id addon_image; + BInputServerDevice *isd; }; struct filter_info { entry_ref ref; + image_id addon_image; + BInputServerFilter *isf; }; struct method_info { entry_ref ref; + _BMethodAddOn_* addon; + image_id addon_image; + BInputServerMethod *ism; }; BLocker fLock; diff --git a/src/servers/input/InputServer.cpp b/src/servers/input/InputServer.cpp index 9671e755b0..b2df6513d1 100644 --- a/src/servers/input/InputServer.cpp +++ b/src/servers/input/InputServer.cpp @@ -42,6 +42,7 @@ #include #include + #if DEBUG>=1 #define EXIT() printf("EXIT %s\n", __PRETTY_FUNCTION__) #define CALLED() printf("CALLED %s\n", __PRETTY_FUNCTION__) @@ -85,9 +86,7 @@ BList InputServer::mInputServerMethodList; */ int main() { - InputServer *myInputServer; - - myInputServer = new InputServer; + InputServer *myInputServer = new InputServer; myInputServer->Run(); @@ -106,7 +105,7 @@ InputServer::InputServer(void) : BApplication("application/x-vnd.OBOS-input_serv EventLoop(pointer); - InitTestDevice(); +// InitTestDevice(); fAddOnManager = new AddOnManager(); fAddOnManager->LoadState(); @@ -578,10 +577,10 @@ InputServer::MessageReceived(BMessage *message) HandleGetKeyboardID(message, reply); break; case IS_GET_CLICK_SPEED: - HandleGetClickSpeed(message, reply); + HandleGetSetClickSpeed(message, reply); break; case IS_SET_CLICK_SPEED: - HandleSetClickSpeed(message, reply); + HandleGetSetClickSpeed(message, reply); break; case IS_GET_KEY_REPEAT_RATE: HandleGetSetKeyRepeatRate(message, reply); @@ -658,7 +657,7 @@ InputServer::HandleSetMethod(BMessage *) * Method: InputServer::HandleGetSetMouseType() * Descr: */ -void +status_t InputServer::HandleGetSetMouseType(BMessage* message, BMessage* reply) { @@ -667,7 +666,7 @@ InputServer::HandleGetSetMouseType(BMessage* message, status = ControlDevices(NULL, B_POINTING_DEVICE, B_MOUSE_TYPE_CHANGED, NULL); else status = reply->AddInt32("mouse_type", sMouseType); - message->SendReply(status, reply); + return status; } @@ -675,7 +674,7 @@ InputServer::HandleGetSetMouseType(BMessage* message, * Method: InputServer::HandleGetSetMouseAcceleration() * Descr: */ -void +status_t InputServer::HandleGetSetMouseAcceleration(BMessage* message, BMessage* reply) { @@ -684,7 +683,7 @@ InputServer::HandleGetSetMouseAcceleration(BMessage* message, status = ControlDevices(NULL, B_POINTING_DEVICE, B_MOUSE_ACCELERATION_CHANGED, NULL); else status = reply->AddInt32("mouse_acceleration", sMouseAcceleration); - message->SendReply(status, reply); + return status; } @@ -692,7 +691,7 @@ InputServer::HandleGetSetMouseAcceleration(BMessage* message, * Method: InputServer::HandleGetSetKeyRepeatDelay() * Descr: */ -void +status_t InputServer::HandleGetSetKeyRepeatDelay(BMessage* message, BMessage* reply) { @@ -701,7 +700,7 @@ InputServer::HandleGetSetKeyRepeatDelay(BMessage* message, status = ControlDevices(NULL, B_KEYBOARD_DEVICE, B_KEY_REPEAT_DELAY_CHANGED, NULL); else status = reply->AddInt64("key_repeat_delay", sKeyRepeatDelay); - message->SendReply(status, reply); + return status; } @@ -709,10 +708,11 @@ InputServer::HandleGetSetKeyRepeatDelay(BMessage* message, * Method: InputServer::HandleGetKeyInfo() * Descr: */ -void +status_t InputServer::HandleGetKeyInfo(BMessage *message, 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() * Descr: */ -void +status_t InputServer::HandleGetModifiers(BMessage *message, BMessage *reply) { + return reply->AddInt32("modifiers", s_key_info.modifiers); } @@ -731,10 +732,21 @@ InputServer::HandleGetModifiers(BMessage *message, * Method: InputServer::HandleSetModifierKey() * Descr: */ -void +status_t InputServer::HandleSetModifierKey(BMessage *message, 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() * Descr: */ -void InputServer::HandleSetKeyboardLocks(BMessage *message, +status_t +InputServer::HandleSetKeyboardLocks(BMessage *message, 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() * Descr: */ -void +status_t InputServer::HandleGetSetMouseSpeed(BMessage* message, BMessage* reply) { @@ -761,7 +779,7 @@ InputServer::HandleGetSetMouseSpeed(BMessage* message, status = ControlDevices(NULL, B_POINTING_DEVICE, B_MOUSE_SPEED_CHANGED, NULL); else status = reply->AddInt32("mouse_speed", sMouseSpeed); - message->SendReply(status, reply); + return status; } @@ -769,7 +787,7 @@ InputServer::HandleGetSetMouseSpeed(BMessage* message, * Method: InputServer::HandleSetMousePosition() * Descr: */ -void +status_t InputServer::HandleSetMousePosition(BMessage *message, BMessage *outbound) { @@ -803,6 +821,8 @@ InputServer::HandleSetMousePosition(BMessage *message, BMessage *outbound) break; } + + return B_OK; } @@ -810,7 +830,7 @@ InputServer::HandleSetMousePosition(BMessage *message, BMessage *outbound) * Method: InputServer::HandleGetMouseMap() * Descr: */ -void +status_t InputServer::HandleGetSetMouseMap(BMessage* message, BMessage* reply) { @@ -823,7 +843,7 @@ InputServer::HandleGetSetMouseMap(BMessage* message, status = ControlDevices(NULL, B_POINTING_DEVICE, B_MOUSE_MAP_CHANGED, NULL); } else 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() * Descr: */ -void -InputServer::HandleGetKeyboardID(BMessage *, - BMessage *) +status_t +InputServer::HandleGetKeyboardID(BMessage *message, + BMessage *reply) { + return reply->AddInt16("id", sKeyboardID); } /* - * Method: InputServer::HandleGetClickSpeed() + * Method: InputServer::HandleGetSetClickSpeed() * Descr: */ -void -InputServer::HandleGetClickSpeed(BMessage* message, - BMessage* reply) +status_t +InputServer::HandleGetSetClickSpeed(BMessage *message, + BMessage *reply) { - status_t status = reply->AddInt64("mouse_click_speed", sMouseClickSpeed); - message->SendReply(status, reply); -} - -/* - * Method: InputServer::HandleSetClickSpeed() - * 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); + status_t status = B_ERROR; + 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); + return status; } @@ -868,7 +880,7 @@ InputServer::HandleSetClickSpeed(BMessage* message, * Method: InputServer::HandleGetSetKeyRepeatRate() * Descr: */ -void +status_t InputServer::HandleGetSetKeyRepeatRate(BMessage* message, BMessage* reply) { @@ -877,7 +889,7 @@ InputServer::HandleGetSetKeyRepeatRate(BMessage* message, status = ControlDevices(NULL, B_KEYBOARD_DEVICE, B_KEY_REPEAT_RATE_CHANGED, NULL); else status = reply->AddInt32("key_repeat_rate", sKeyRepeatRate); - message->SendReply(status, reply); + return status; } @@ -885,10 +897,21 @@ InputServer::HandleGetSetKeyRepeatRate(BMessage* message, * Method: InputServer::HandleGetSetKeyMap() * Descr: */ -void +status_t InputServer::HandleGetSetKeyMap(BMessage *message, 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() * Descr: */ -void +status_t InputServer::HandleFocusUnfocusIMAwareView(BMessage *, BMessage *) { @@ -907,10 +930,11 @@ InputServer::HandleFocusUnfocusIMAwareView(BMessage *, * Method: InputServer::HandleFindDevices() * Descr: */ -void +status_t InputServer::HandleFindDevices(BMessage *message, BMessage *reply) { + } @@ -918,7 +942,7 @@ InputServer::HandleFindDevices(BMessage *message, * Method: InputServer::HandleWatchDevices() * Descr: */ -void +status_t InputServer::HandleWatchDevices(BMessage *message, BMessage *reply) { @@ -929,10 +953,11 @@ InputServer::HandleWatchDevices(BMessage *message, * Method: InputServer::HandleIsDeviceRunning() * Descr: */ -void +status_t InputServer::HandleIsDeviceRunning(BMessage *message, BMessage *reply) { + } @@ -940,7 +965,7 @@ InputServer::HandleIsDeviceRunning(BMessage *message, * Method: InputServer::HandleStartStopDevices() * Descr: */ -void +status_t InputServer::HandleStartStopDevices(BMessage *message, BMessage *reply) { @@ -951,7 +976,7 @@ InputServer::HandleStartStopDevices(BMessage *message, * Method: InputServer::HandleControlDevices() * Descr: */ -void +status_t InputServer::HandleControlDevices(BMessage *message, BMessage *reply) { @@ -962,10 +987,12 @@ InputServer::HandleControlDevices(BMessage *message, * Method: InputServer::HandleSystemShuttingDown() * Descr: */ -void +status_t InputServer::HandleSystemShuttingDown(BMessage *message, BMessage *reply) { + status_t status; + return status; } @@ -973,9 +1000,10 @@ InputServer::HandleSystemShuttingDown(BMessage *message, * Method: InputServer::HandleNodeMonitor() * Descr: */ -void +status_t InputServer::HandleNodeMonitor(BMessage *message) { + } @@ -983,7 +1011,8 @@ InputServer::HandleNodeMonitor(BMessage *message) * Method: InputServer::EnqueueDeviceMessage() * Descr: */ -status_t InputServer::EnqueueDeviceMessage(BMessage *message) +status_t +InputServer::EnqueueDeviceMessage(BMessage *message) { //return (write_port(fEventPort, (int32)message, NULL, 0)); return (write_port(EventLooperPort, (int32)message, NULL, 0)); @@ -1333,74 +1362,74 @@ const BList* InputServer::GetNextEvents(BList *) * The method returns true if the filters were applied to all * 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; - BMessage* current_event; - int32 filter_index = 0; - int32 event_index = 0; - - while (NULL != (current_filter = (BInputServerFilter*)mInputServerFilterList.ItemAt(filter_index) ) ) + // Apply the current filter to all available event messages. + // + while (NULL != (current_event = (BMessage*)eventsToFilter->ItemAt(event_index) ) ) { - // Apply the current filter to all available event messages. - // - while (NULL != (current_event = (BMessage*)eventsToFilter->ItemAt(event_index) ) ) + // Storage for new event messages generated by the filter. + // + 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; - - // Apply the current filter to the current event message. - // - filter_result result = current_filter->Filter(current_event, &out_list); - if (B_DISPATCH_MESSAGE == result) - { - // Use the result in current_message; ignore out_list. - // - event_index++; + 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) + // Free resources associated with items in out_list. + // + 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. - // - eventsToFilter->RemoveItem(event_index); - eventsToFilter->AddList(&out_list, event_index); - event_index += out_list.CountItems(); - - // NOTE: eventsToFilter now owns out_list's items. + delete out_item; } - 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++) - { - 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. } - + 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++) + { + 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. } // while() - + filter_index++; - + } // while() return true; @@ -1444,15 +1473,17 @@ status_t InputServer::StartStopDevices(const char* deviceName, if (NULL != item) { BInputServerDevice* isd = item->mIsd; - input_device_ref* dev = item->mDev; + input_device_ref dev = item->mDev; PRINT(("Hey\n")); - if ( (NULL != isd) && (NULL != dev) ) + if ( (NULL != isd) ) { - PRINT((" Starting/stopping: %s\n", dev->name)); - if (deviceType == dev->type) + PRINT((" Starting/stopping: %s\n", dev.name)); + if (deviceType == dev.type) { - if (doStart) isd->Start(dev->name, dev->cookie); - else isd->Stop(dev->name, dev->cookie); + if (doStart) + 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) { BInputServerDevice* isd = item->mIsd; - input_device_ref* dev = item->mDev; - if ( (NULL != isd) && (NULL != dev) ) + input_device_ref dev = item->mDev; + if ( (NULL != isd) ) { - PRINT((" Controlling: %s\n", dev->name)); - if (deviceType == dev->type) + PRINT((" Controlling: %s\n", dev.name)); + if (deviceType == dev.type) { // :TODO: Descriminate based on Device Name also. diff --git a/src/servers/input/InputServer.h b/src/servers/input/InputServer.h index c7ad7c668c..50dca95740 100644 --- a/src/servers/input/InputServer.h +++ b/src/servers/input/InputServer.h @@ -31,9 +31,9 @@ // BeAPI Headers #include -#include "InputServerDevice.h" -#include "InputServerFilter.h" -#include "InputServerMethod.h" +#include +#include +#include #include "AddOnManager.h" #include @@ -54,10 +54,21 @@ class InputDeviceListItem { public: 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*); void HandleSetMethod(BMessage*); - void HandleGetSetMouseType(BMessage*, BMessage*); - void HandleGetSetMouseAcceleration(BMessage*, BMessage*); - void HandleGetSetKeyRepeatDelay(BMessage*, BMessage*); - void HandleGetKeyInfo(BMessage*, BMessage*); - void HandleGetModifiers(BMessage*, BMessage*); - void HandleSetModifierKey(BMessage*, BMessage*); - void HandleSetKeyboardLocks(BMessage*, BMessage*); - void HandleGetSetMouseSpeed(BMessage*, BMessage*); - void HandleSetMousePosition(BMessage*, BMessage*); - void HandleGetSetMouseMap(BMessage*, BMessage*); - void HandleGetKeyboardID(BMessage*, BMessage*); - void HandleGetClickSpeed(BMessage*, BMessage*); - void HandleSetClickSpeed(BMessage*, BMessage*); - void HandleGetSetKeyRepeatRate(BMessage*, BMessage*); - void HandleGetSetKeyMap(BMessage*, BMessage*); - void HandleFocusUnfocusIMAwareView(BMessage*, BMessage*); + status_t HandleGetSetMouseType(BMessage*, BMessage*); + status_t HandleGetSetMouseAcceleration(BMessage*, BMessage*); + status_t HandleGetSetKeyRepeatDelay(BMessage*, BMessage*); + status_t HandleGetKeyInfo(BMessage*, BMessage*); + status_t HandleGetModifiers(BMessage*, BMessage*); + status_t HandleSetModifierKey(BMessage*, BMessage*); + status_t HandleSetKeyboardLocks(BMessage*, BMessage*); + status_t HandleGetSetMouseSpeed(BMessage*, BMessage*); + status_t HandleSetMousePosition(BMessage*, BMessage*); + status_t HandleGetSetMouseMap(BMessage*, BMessage*); + status_t HandleGetKeyboardID(BMessage*, BMessage*); + status_t HandleGetSetClickSpeed(BMessage*, BMessage*); + status_t HandleGetSetKeyRepeatRate(BMessage*, BMessage*); + status_t HandleGetSetKeyMap(BMessage*, BMessage*); + status_t HandleFocusUnfocusIMAwareView(BMessage*, BMessage*); - void HandleFindDevices(BMessage*, BMessage*); - void HandleWatchDevices(BMessage*, BMessage*); - void HandleIsDeviceRunning(BMessage*, BMessage*); - void HandleStartStopDevices(BMessage*, BMessage*); - void HandleControlDevices(BMessage*, BMessage*); - void HandleSystemShuttingDown(BMessage*, BMessage*); - void HandleNodeMonitor(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 EnqueueMethodMessage(BMessage*); @@ -161,7 +171,14 @@ private: bigtime_t sMouseClickSpeed; int32 sKeyRepeatRate; bigtime_t sKeyRepeatDelay; + int32 sKeyboardLocks; + uint16 sKeyboardID; 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 EventLooperPort; diff --git a/src/servers/input/InputServerDevice.cpp b/src/servers/input/InputServerDevice.cpp index a8ff3f1288..079d838e3e 100644 --- a/src/servers/input/InputServerDevice.cpp +++ b/src/servers/input/InputServerDevice.cpp @@ -32,7 +32,7 @@ /*****************************************************************************/ -#include "InputServerDevice.h" +#include #include "InputServer.h" /** @@ -198,7 +198,7 @@ BInputServerDevice::EnqueueMessage(BMessage *message) } return err; */ - return B_OK; + return ((InputServer*)be_app)->EnqueueDeviceMessage(message); } diff --git a/src/servers/input/InputServerMethod.cpp b/src/servers/input/InputServerMethod.cpp index 0055ada9c8..5365d46af7 100644 --- a/src/servers/input/InputServerMethod.cpp +++ b/src/servers/input/InputServerMethod.cpp @@ -31,9 +31,9 @@ // DEALINGS IN THE SOFTWARE. /*****************************************************************************/ - -#include "InputServerMethod.h" -#include "Messenger.h" +#include +#include +#include "InputServer.h" /** * Method: BInputServerMethod::BInputServerMethod() @@ -72,9 +72,7 @@ BInputServerMethod::MethodActivated(bool active) status_t BInputServerMethod::EnqueueMessage(BMessage *message) { - status_t dummy; - - return dummy; + return ((InputServer*)be_app)->EnqueueMethodMessage(message); }