diff --git a/src/servers/input/Input.cpp b/src/servers/input/Input.cpp new file mode 100644 index 0000000000..ddd856e573 --- /dev/null +++ b/src/servers/input/Input.cpp @@ -0,0 +1,155 @@ +/*********************************************************************** + * AUTHOR: nobody + * FILE: Input.cpp + * DATE: Sun Dec 16 15:57:43 2001 + * DESCR: + ***********************************************************************/ +#include "Input.h" + +/* + * Method: BInputDevice::~BInputDevice() + * Descr: + */ +BInputDevice::~BInputDevice() +{ +} + + +/* + * Method: BInputDevice::Name() + * Descr: + */ +const char * +BInputDevice::Name() const +{ + return NULL; +} + + +/* + * Method: BInputDevice::Type() + * Descr: + */ +input_device_type +BInputDevice::Type() const +{ + input_device_type dummy; + + return dummy; +} + + +/* + * Method: BInputDevice::IsRunning() + * Descr: + */ +bool +BInputDevice::IsRunning() const +{ + bool dummy; + + return dummy; +} + + +/* + * Method: BInputDevice::Start() + * Descr: + */ +status_t +BInputDevice::Start() +{ + status_t dummy; + + return dummy; +} + + +/* + * Method: BInputDevice::Stop() + * Descr: + */ +status_t +BInputDevice::Stop() +{ + status_t dummy; + + return dummy; +} + + +/* + * Method: BInputDevice::Control() + * Descr: + */ +status_t +BInputDevice::Control(uint32 code, + BMessage *message) +{ + status_t dummy; + + return dummy; +} + + +/* + * Method: BInputDevice::Start() + * Descr: + */ +status_t +BInputDevice::Start(input_device_type type) +{ + status_t dummy; + + return dummy; +} + + +/* + * Method: BInputDevice::Stop() + * Descr: + */ +status_t +BInputDevice::Stop(input_device_type type) +{ + status_t dummy; + + return dummy; +} + + +/* + * Method: BInputDevice::Control() + * Descr: + */ +status_t +BInputDevice::Control(input_device_type type, + uint32 code, + BMessage *message) +{ + status_t dummy; + + return dummy; +} + + +/* + * Method: BInputDevice::BInputDevice() + * Descr: + */ +BInputDevice::BInputDevice() +{ +} + + +/* + * Method: BInputDevice::set_name_and_type() + * Descr: + */ +void +BInputDevice::set_name_and_type(const char *name, + input_device_type type) +{ +} + + diff --git a/src/servers/input/Input.h b/src/servers/input/Input.h new file mode 100644 index 0000000000..263a94d2f0 --- /dev/null +++ b/src/servers/input/Input.h @@ -0,0 +1,88 @@ +/****************************************************************************** +/ +/ File: Input.h +/ +/ Description: Functions and class to manage input devices. +/ +/ Copyright 1998, Be Incorporated, All Rights Reserved. +/ +******************************************************************************/ + +#ifndef _INPUT_H +#define _INPUT_H + +#include +#include +#include + + +enum input_method_op { + B_INPUT_METHOD_STARTED = 0, + B_INPUT_METHOD_STOPPED = 1, + B_INPUT_METHOD_CHANGED = 2, + B_INPUT_METHOD_LOCATION_REQUEST = 3 +}; + + +enum input_device_type { + B_POINTING_DEVICE = 0, + B_KEYBOARD_DEVICE = 1, + B_UNDEFINED_DEVICE = 2 +}; + +/* + what == B_INPUT_DEVICES_CHANGED + FindString("name", name_of_device); + FindInt32("opcode", input_device_notification); +*/ + +enum input_device_notification { + B_INPUT_DEVICE_ADDED = 0x0001, + B_INPUT_DEVICE_STARTED = 0x0002, + B_INPUT_DEVICE_STOPPED = 0x0004, + B_INPUT_DEVICE_REMOVED = 0x0008 +}; + + +class BInputDevice; + + +_IMPEXP_BE BInputDevice* find_input_device(const char *name); +_IMPEXP_BE status_t get_input_devices(BList *list); +_IMPEXP_BE status_t watch_input_devices(BMessenger target, bool start); + + +class BInputDevice { +public: + ~BInputDevice(); + + const char* Name() const; + input_device_type Type() const; + bool IsRunning() const; + + status_t Start(); + status_t Stop(); + status_t Control(uint32 code, + BMessage *message); + + static status_t Start(input_device_type type); + static status_t Stop(input_device_type type); + static status_t Control(input_device_type type, + uint32 code, + BMessage *message); + +private: + friend BInputDevice* find_input_device(const char *name); + friend status_t get_input_devices(BList *list); + + BInputDevice(); + void set_name_and_type(const char *name, + input_device_type type); + + char* fName; + input_device_type fType; + uint32 _reserved[4]; +}; + + +#endif diff --git a/src/servers/input/InputServer.FileTypes.rsrc b/src/servers/input/InputServer.FileTypes.rsrc index c240c30b88..0ca0bbd537 100644 Binary files a/src/servers/input/InputServer.FileTypes.rsrc and b/src/servers/input/InputServer.FileTypes.rsrc differ diff --git a/src/servers/input/InputServer.R5.x86.proj b/src/servers/input/InputServer.R5.x86.proj new file mode 100644 index 0000000000..8f3cacd651 Binary files /dev/null and b/src/servers/input/InputServer.R5.x86.proj differ diff --git a/src/servers/input/InputServer.cpp b/src/servers/input/InputServer.cpp index 895eabc45f..aaac070dfc 100644 --- a/src/servers/input/InputServer.cpp +++ b/src/servers/input/InputServer.cpp @@ -1,3 +1,37 @@ +/*****************************************************************************/ +// OpenBeOS InputServer +// +// Version: [0.0.5] [Development Stage] +// +// [Description] +// +// +// This application and all source files used in its construction, except +// where noted, are licensed under the MIT License, and have been written +// and are: +// +// Copyright (c) 2002 OpenBeOS Project +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +/*****************************************************************************/ + + #include #include "InputServer.h" @@ -5,14 +39,44 @@ #include "Directory.h" #include "FindDirectory.h" #include "Entry.h" +#include "Locker.h" #include "InputServerDeviceListEntry.h" +#include "InputServerFilterListEntry.h" +#include "InputServerMethodListEntry.h" +#include "Message.h" + +// include app_server headers for communication + +#include "PortLink.h" +#include "ServerProtocol.h" + +#define SERVER_PORT_NAME "OBappserver" +#define SERVER_INPUT_PORT "OBinputport" +#define X_VALUE "x" +#define Y_VALUE "y" + + +extern "C" void RegisterDevices(input_device_ref** devices) +{ + printf("RegisterDevices\n"); +}; + + +// Static InputServer member variables. +// +BList InputServer::gInputDeviceList; +BLocker InputServer::gInputDeviceListLocker; + +BList InputServer::mInputServerDeviceList; +BList InputServer::mInputServerFilterList; +BList InputServer::mInputServerMethodList; /* * */ -int main(int argc, char* argv[]) +int main() { InputServer *myInputServer; @@ -21,29 +85,24 @@ int main(int argc, char* argv[]) myInputServer->Run(); delete myInputServer; +} + - return(0); -} -/* -thread_id InputServer::Run() -{ - InitDevices(); - - return 0; -} -*/ /* * Method: InputServer::InputServer() * Descr: */ -InputServer::InputServer(void) : BApplication("application/x-vnd.OpenBeOS-input_server") +InputServer::InputServer(void) : BApplication("application/x-vnd.OBOS-input_server") { void *pointer; - InitDevices(); EventLoop(pointer); - + InitTestDevice(); + +// InitDevices(); + InitFilters(); + InitMethods(); } /* @@ -59,9 +118,28 @@ InputServer::~InputServer(void) * Method: InputServer::ArgvReceived() * Descr: */ -void InputServer::ArgvReceived(long, - char **) +void InputServer::ArgvReceived(int32 argc, char** argv) { + if (2 == argc) + { + if (0 == strcmp("-q", argv[1]) ) + { + // :TODO: Shutdown and restart the InputServer. + printf("InputServer::ArgvReceived - Restarting . . .\n"); + status_t quit_status; + //BMessenger msgr = BMessenger("application/x-vnd.OpenBeOS-input_server", -1, &quit_status); + BMessenger msgr = BMessenger("application/x-vnd.OBOS-input_server", -1, &quit_status); + if (B_OK == quit_status) + { + BMessage msg = BMessage(B_QUIT_REQUESTED); + msgr.SendMessage(&msg); + } + else + { + printf("Unable to send Quit message to running InputServer."); + } + } + } } @@ -71,8 +149,60 @@ void InputServer::ArgvReceived(long, */ void InputServer::InitKeyboardMouseStates(void) { + // This is where we read in the preferences data for the mouse and keyboard as well as + // determine the screen resolution from the app_server and find the center of the screen + // sMousePos is then set to the center of the screen. + + sMousePos.x = 200; + sMousePos.y = 200; + } +void InputServer::InitTestDevice() +{ + printf("InputServer::InitTestDevice - Enter\n"); + const char* path = "/boot/home/Projects/InputServer/ISD/nervous/nervous"; + printf("InputServer::InitTestDevice - Loading add-on . . .\n"); + image_id addon_image = load_add_on(path); + if (B_ERROR != addon_image) + { + status_t isd_status = B_NO_INIT; + BInputServerDevice* (*func)() = NULL; + printf("InputServer::InitTestDevice - Resolving symbol . . .\n"); + if (B_OK == get_image_symbol(addon_image, "instantiate_input_device", B_SYMBOL_TYPE_TEXT, (void**)&func) ) + { + printf("Found instantiate_input_device.\n"); + if (NULL != func) + { + BInputServerDevice* isd = (*func)(); + if (NULL != isd) + { + printf("InputServer::InitTestDevice - Calling InitCheck . . .\n"); + isd_status = isd->InitCheck(); + mInputServerDeviceList.AddItem( + new InputServerDeviceListEntry(path, isd_status, isd) ); + if (B_OK == isd_status) + { + //printf("Starting Nervous . . .\n"); + //isd->Start("Nervous Device", NULL); + } + else + { + printf("InitCheck failed.\n"); + } + } + } + } + if (B_OK != isd_status) + { + // Free resources associated with ISD's + // that failed to initialize. + // + //unload_add_on(addon_image); + } + } + printf("InputServer::InitTestDevice - Exit\n"); +} /* * Method: InputServer::InitDevices() @@ -138,7 +268,7 @@ status_t InputServer::AddInputServerDevice(const char* path) BInputServerDevice* isd = (*func)(); if (NULL != isd) { - status_t isd_status = isd->InitCheck(); + isd_status = isd->InitCheck(); mInputServerDeviceList.AddItem( new InputServerDeviceListEntry(path, isd_status, isd) ); } @@ -179,7 +309,7 @@ void InputServer::InitFilters(void) printf("InputServer::InitFilters - Enter\n"); - // Find all Input Server Devices in each of the predefined + // Find all Input Filters in each of the predefined // addon directories. // for (int i = 0; i < addon_dir_count; i++) @@ -192,11 +322,55 @@ void InputServer::InitFilters(void) { entry.GetPath(&addon_path); printf("Adding %s . . .\n", addon_path.Path() ); - AddInputServerDevice(addon_path.Path() ); + AddInputServerFilter(addon_path.Path() ); } } } - printf("InputServer::InitDevices - Exit\n"); + printf("InputServer::InitFilters - Exit\n"); +} + + +/* + * Method: InputServer::AddInputServerFilter() + * Descr: + */ +status_t InputServer::AddInputServerFilter(const char* path) +{ + image_id addon_image= load_add_on(path); + if (B_ERROR != addon_image) + { + status_t isf_status = B_NO_INIT; + BInputServerFilter* (*func)() = NULL; + if (B_OK == get_image_symbol(addon_image, "instantiate_input_filter", B_SYMBOL_TYPE_TEXT, (void**)&func) ) + { + if (NULL != func) + { + /* + // :DANGER: Only reenable this section if this + // InputServer can start and manage the + // filters, otherwise the system will hang. + // + BInputFilter isf = (*func)(); + if (NULL != isf) + { + isf_status = isf->InitCheck(); + mInputServerFilterList.AddItem( + new InputServerFilterListEntry(path, isf_status, isf ); + } + */ + mInputServerFilterList.AddItem( + new InputServerFilterListEntry(path, B_NO_INIT, NULL) ); + } + } + if (B_OK != isf_status) + { + // Free resources associated with InputServerFilters + // that failed to initialize. + // + unload_add_on(addon_image); + } + } + return 0; } @@ -218,26 +392,70 @@ void InputServer::InitMethods(void) }; const int addon_dir_count = sizeof(addon_dirs) / sizeof(directory_which); - printf("InputServer::InitDevices - Enter\n"); + printf("InputServer::InitMethods - Enter\n"); - // Find all Input Server Devices in each of the predefined + // Find all Input Methods in each of the predefined // addon directories. // for (int i = 0; i < addon_dir_count; i++) { if (B_OK == find_directory(addon_dirs[i], &addon_dir) ) { - addon_dir.Append("input_server/devices"); + addon_dir.Append("input_server/methods"); dir.SetTo(addon_dir.Path() ); while (B_NO_ERROR == dir.GetNextEntry(&entry, false) ) { entry.GetPath(&addon_path); printf("Adding %s . . .\n", addon_path.Path() ); - AddInputServerDevice(addon_path.Path() ); + AddInputServerMethod(addon_path.Path() ); } } } - printf("InputServer::InitDevices - Exit\n"); + printf("InputServer::InitMethods - Exit\n"); +} + + +/* + * Method: InputServer::AddInputServerMethod() + * Descr: + */ +status_t InputServer::AddInputServerMethod(const char* path) +{ + image_id addon_image= load_add_on(path); + if (B_ERROR != addon_image) + { + status_t ism_status = B_NO_INIT; + BInputServerMethod* (*func)() = NULL; + if (B_OK == get_image_symbol(addon_image, "instantiate_input_method", B_SYMBOL_TYPE_TEXT, (void**)&func) ) + { + if (NULL != func) + { + /* + // :DANGER: Only reenable this section if this + // InputServer can start and manage the + // methods, otherwise the system will hang. + // + BInputServerMethod ism = (*func)(); + if (NULL != ism) + { + ism_status = ism->InitCheck(); + mInputServerMethodList.AddItem( + new InputServerMethodListEntry(path, ism_status, ism) ); + } + */ + mInputServerMethodList.AddItem( + new InputServerMethodListEntry(path, B_NO_INIT, NULL) ); + } + } + if (B_OK != ism_status) + { + // Free resources associated with InputServerMethods + // that failed to initialize. + // + unload_add_on(addon_image); + } + } + return 0; } @@ -276,7 +494,7 @@ void InputServer::ReadyToRun(void) */ void InputServer::MessageReceived(BMessage *message) { -BMessenger *app_server; + BMessenger *app_server; switch(message->what) { case SET_METHOD: @@ -404,13 +622,18 @@ BMessenger *app_server; //HandleFocusUnfocusIMAwareView(); break; } + case B_QUIT_REQUESTED: + { + QuitRequested(); + } default: { + printf("Default message . . .\n"); app_server = new BMessenger("application/x-vnd.Be-APPS", -1, NULL); if (app_server->IsValid()) { - app_server->SendMessage(message); + //app_server->SendMessage(message); } delete app_server; @@ -583,9 +806,10 @@ void InputServer::HandleFocusUnfocusIMAwareView(BMessage *, * Method: InputServer::EnqueueDeviceMessage() * Descr: */ -status_t InputServer::EnqueueDeviceMessage(BMessage *) +status_t InputServer::EnqueueDeviceMessage(BMessage *message) { - return 0; + //return (write_port(fEventPort, (int32)message, NULL, 0)); + return (write_port(EventLooperPort, (int32)message, NULL, 0)); } @@ -657,15 +881,14 @@ const BMessenger* InputServer::MethodReplicant(void) */ status_t InputServer::EventLoop(void *) { - - EventLooperPort = create_port(29,"is_event_port"); + printf("Starting event loop . . .\n"); + EventLooperPort = create_port(100, "obos_is_event_port"); if(EventLooperPort < 0) { _sPrintf("OBOS InputServer: create_port error: (0x%x) %s\n",EventLooperPort,strerror(EventLooperPort)); - } + } ISPortThread = spawn_thread(ISPortWatcher, "_input_server_event_loop_", B_REAL_TIME_DISPLAY_PRIORITY+3, this); resume_thread(ISPortThread); - return 0; } @@ -684,11 +907,55 @@ bool InputServer::EventLoopRunning(void) * Method: InputServer::DispatchEvents() * Descr: */ -bool InputServer::DispatchEvents(BList *) +bool InputServer::DispatchEvents(BList *eventList) { - return true; -} +BMessage *event; +for ( int32 i = 0; NULL != (event = (BMessage *)eventList->ItemAt(i)); i++ ) + { + // now we must send each event to the app_server + DispatchEvent(event); + } + return true; +}// end DispatchEvents() + +int InputServer::DispatchEvent(BMessage *message) +{ + // variables + int32 xValue, + yValue; + uint32 buttons = 0; + + message->FindInt32("x",xValue); + printf("[DispatchEvent] x = %lu:\n",xValue); + + port_id pid = find_port(SERVER_INPUT_PORT); + PortLink *appsvrlink = new PortLink(pid); + switch(message->what){ + case B_MOUSE_MOVED:{ + // get point and button from msg + if((message->FindInt32(X_VALUE,&xValue) == B_OK) && (message->FindInt32(Y_VALUE,&yValue) == B_OK)){ + int64 time=(int64)real_time_clock(); + appsvrlink->SetOpCode(B_MOUSE_MOVED); + appsvrlink->Attach(&time,sizeof(int64)); + appsvrlink->Attach(&xValue,sizeof(float)); + appsvrlink->Attach(&yValue,sizeof(float)); + message->FindInt32("buttons",buttons); + appsvrlink->Attach(&buttons,sizeof(int32)); + appsvrlink->Flush(); + printf("B_MOUSE_MOVED: x = %lu: y = %lu: time = %llu: buttons = %lu\n",xValue,yValue,time,buttons); + } + break; + } + // Should be some Mouse Down and Up code here .. + // Along with some Key Down and up codes .. + default: + break; + + } + delete appsvrlink; + return true; +} /* * Method: InputServer::CacheEvents() @@ -712,11 +979,83 @@ const BList* InputServer::GetNextEvents(BList *) /* * Method: InputServer::FilterEvents() - * Descr: + * Descr: This method applies all defined filters to each event in the + * supplied list. The supplied list is modified to reflect the + * output of the filters. + * The method returns true if the filters were applied to all + * events without error and false otherwise. */ -bool InputServer::FilterEvents(BList *) +bool InputServer::FilterEvents(BList *eventsToFilter) { - return true; + if (NULL != eventsToFilter) + { + 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) ) ) + { + // 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) + { + // Use the result in current_message; ignore out_list. + // + 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) + { + // 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; } @@ -745,9 +1084,34 @@ bool InputServer::MethodizeEvents(BList *, * Method: InputServer::StartStopDevices() * Descr: */ -status_t InputServer::StartStopDevices(const char* deviceName, input_device_type deviceType, bool doStart) +status_t InputServer::StartStopDevices(const char* deviceName, + input_device_type deviceType, + bool doStart) { - return 0; + printf("StartStopDevice: Enter\n"); + for (int i = gInputDeviceList.CountItems() - 1; i >= 0; i--) + { + printf("Device #%d\n", i); + InputDeviceListItem* item = (InputDeviceListItem*)gInputDeviceList.ItemAt(i); + if (NULL != item) + { + BInputServerDevice* isd = item->mIsd; + input_device_ref* dev = item->mDev; + printf("Hey\n"); + if ( (NULL != isd) && (NULL != dev) ) + { + printf(" 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); + } + } + } + } + printf("StartStopDevice: Exit\n"); + + return B_OK; } @@ -831,35 +1195,43 @@ int32 InputServer::ISPortWatcher(void *arg) void InputServer::WatchPort() { - int32 code; - ssize_t length; - char *buffer; - BMessage *event; - status_t err; + int32 code; + ssize_t length; + char *buffer; + status_t err; while (true) { // Block until we find the size of the next message length = port_buffer_size(EventLooperPort); buffer = (char*)malloc(length); - event = NULL; - event = new BMessage(); + printf("[Event Looper] BMessage Size = %d\n", length); + //event = NULL; + BMessage *event = new BMessage(); err = read_port(EventLooperPort, &code, buffer, length); if(err != length) { if(err >= 0) { - _sPrintf("InputServer: failed to read full packet (read %u of %u)\n",err,length); + printf("InputServer: failed to read full packet (read %lu of %lu)\n",err,length); } else { - _sPrintf("InputServer: read_port error: (0x%x) %s\n",err,strerror(err)); + printf("InputServer: read_port error: (0x%lx) %s\n",err,strerror(err)); } - } else if ((err = event->Unflatten(buffer)) < 0) { - _sPrintf("InputServer: (0x%x) %s\n",err,strerror(err)); - } else { - // add the event - //CacheEvents(event); - event = NULL; - } - free( buffer); - if(event!=NULL) { + }else{ + + if ((err = event->Unflatten(buffer)) < 0) { + printf("[InputServer] Unflatten() error: (0x%lx) %s\n",err,strerror(err)); + } else { + // This is where the message should be processed. + event->PrintToStream(); + + DispatchEvent(event); + + //printf("Event writen to port\n"); delete(event); + } + + } + free(buffer); + if(event!=NULL) { + //delete(event); event = NULL; } } diff --git a/src/servers/input/InputServer.h b/src/servers/input/InputServer.h index 416fd63971..e369caaa08 100644 --- a/src/servers/input/InputServer.h +++ b/src/servers/input/InputServer.h @@ -32,9 +32,13 @@ // BeAPI Headers #include #include "InputServerDevice.h" +#include "InputServerFilter.h" +#include "InputServerMethod.h" + #include #include #include +#include #include #include @@ -43,7 +47,44 @@ #include #include -#include "InputServerTypes.h" +class PortLink; + +// Constants +#define SET_METHOD 'stmd' +#define GET_MOUSE_TYPE 'gtmt' +#define SET_MOUSE_TYPE 'stmt' +#define GET_MOUSE_ACCELERATION 'gtma' +#define SET_MOUSE_ACCELERATION 'stma' +#define GET_KEY_REPEAT_DELAY 'gkrd' +#define SET_KEY_REPEAT_DELAY 'skrd' +#define GET_KEY_INFO 'ktki' +#define GET_MODIFIERS 'gtmf' +#define SET_MODIFIER_KEY 'smky' +#define SET_KEYBOARD_LOCKS 'skbl' +#define GET_MOUSE_SPEED 'gtms' +#define SET_MOUSE_SPEED 'stms' +#define SET_MOUSE_POSITION 'stmp' +#define GET_MOUSE_MAP 'gtmm' +#define SET_MOUSE_MAP 'stmm' +#define GET_KEYBOARD_ID 'gkbi' +#define GET_CLICK_SPEED 'gtcs' +#define SET_CLICK_SPEED 'stcs' +#define GET_KEY_REPEAT_RATE 'gkrr' +#define SET_KEY_REPEAT_RATE 'skrr' +#define GET_KEY_MAP 'gtkm' +#define SET_KEY_MAP 'stkm' +#define FOCUS_IM_AWARE_VIEW 'fiav' +#define UNFOCUS_IM_AWARE_VIEW 'uiav' + +class InputDeviceListItem +{ + public: + BInputServerDevice* mIsd; + input_device_ref* mDev; + + InputDeviceListItem(BInputServerDevice* isd, input_device_ref* dev): + mIsd(isd), mDev(dev) {}; +}; /*****************************************************************************/ // InputServer @@ -97,16 +138,17 @@ public: const BMessenger* MethodReplicant(void); status_t EventLoop(void*); - bool EventLoopRunning(void); + static bool EventLoopRunning(void); bool DispatchEvents(BList*); + int DispatchEvent(BMessage*); bool CacheEvents(BList*); const BList* GetNextEvents(BList*); bool FilterEvents(BList*); bool SanitizeEvents(BList*); bool MethodizeEvents(BList*, bool); - status_t StartStopDevices(const char *, input_device_type, bool); + static status_t StartStopDevices(const char *, input_device_type, bool); status_t ControlDevices(const char *, input_device_type, unsigned long, BMessage*); bool DoMouseAcceleration(long*, long*); @@ -116,22 +158,39 @@ public: bool SafeMode(void); + static BList gInputDeviceList; + static BLocker gInputDeviceListLocker; + private: + void InitTestDevice(); + status_t AddInputServerDevice(const char* path); + status_t AddInputServerFilter(const char* path); + status_t AddInputServerMethod(const char* path); - bool sEventLoopRunning; - bool sSafeMode; + bool sEventLoopRunning; + bool sSafeMode; + port_id sEventPort; + BPoint sMousePos; - BList mInputServerDeviceList; - BList mInputMethodList; - BList mInputFilterList; - port_id ISPort; - port_id EventLooperPort; - thread_id ISPortThread; - static int32 ISPortWatcher(void *arg); + port_id ISPort; + port_id EventLooperPort; + thread_id ISPortThread; + static int32 ISPortWatcher(void *arg); void WatchPort(); - + + static bool doStartStopDevice(void*, void*); + + static BList mInputServerDeviceList; + static BList mInputServerFilterList; + static BList mInputServerMethodList; + + // added this to communicate via portlink + + PortLink *serverlink; + //fMouseState; }; + #endif \ No newline at end of file diff --git a/src/servers/input/InputServerDevice.cpp b/src/servers/input/InputServerDevice.cpp index 6b64ba9519..16c7c4bbc3 100644 --- a/src/servers/input/InputServerDevice.cpp +++ b/src/servers/input/InputServerDevice.cpp @@ -1,12 +1,41 @@ -/*********************************************************************** - * AUTHOR: nobody - * FILE: InputServerDevice.cpp - * DATE: Sun Dec 16 15:57:43 2001 - * DESCR: - ***********************************************************************/ -#include "InputServerDevice.h" +/*****************************************************************************/ +// OpenBeOS InputServer +// +// Version: [0.0.5] [Development Stage] +// +// [Description] +// +// +// This application and all source files used in its construction, except +// where noted, are licensed under the MIT License, and have been written +// and are: +// +// Copyright (c) 2002 OpenBeOS Project +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +/*****************************************************************************/ -/* + +#include "InputServerDevice.h" +#include "InputServer.h" + +/** * Method: BInputServerDevice::BInputServerDevice() * Descr: */ @@ -15,7 +44,7 @@ BInputServerDevice::BInputServerDevice() } -/* +/** * Method: BInputServerDevice::~BInputServerDevice() * Descr: */ @@ -24,7 +53,7 @@ BInputServerDevice::~BInputServerDevice() } -/* +/** * Method: BInputServerDevice::InitCheck() * Descr: */ @@ -37,7 +66,7 @@ BInputServerDevice::InitCheck() } -/* +/** * Method: BInputServerDevice::SystemShuttingDown() * Descr: */ @@ -50,7 +79,7 @@ BInputServerDevice::SystemShuttingDown() } -/* +/** * Method: BInputServerDevice::Start() * Descr: */ @@ -64,7 +93,7 @@ BInputServerDevice::Start(const char *device, } -/* +/** * Method: BInputServerDevice::Stop() * Descr: */ @@ -78,7 +107,7 @@ BInputServerDevice::Stop(const char *device, } -/* +/** * Method: BInputServerDevice::Control() * Descr: */ @@ -94,20 +123,57 @@ BInputServerDevice::Control(const char *device, } -/* +/** * Method: BInputServerDevice::RegisterDevices() * Descr: */ status_t BInputServerDevice::RegisterDevices(input_device_ref **devices) { - status_t dummy; +/* + // Lock this section of code so that access to the device list + // is serialized. Be sure to release the lock before exitting. + // + InputServer::gInputDeviceListLocker.Lock(); + + bool has_pointing_device = false; + bool has_keyboard_device = false; + + input_device_ref *device = NULL; + for (int i = 0; NULL != (device = devices[i]); i++) + { + // :TODO: Check to make sure that each device is valid and + // that it is not already registered. + // getDeviceIndex() + + InputServer::gInputDeviceList.AddItem(new InputDeviceListItem(this, device) ); + + has_pointing_device = has_pointing_device || (device->type == B_POINTING_DEVICE); + has_keyboard_device = has_keyboard_device || (device->type == B_KEYBOARD_DEVICE); + } - return dummy; + // If the InputServer event loop is running, signal the InputServer + // to start all devices of the type managed by this InputServerDevice. + // + if (InputServer::EventLoopRunning() ) + { + if (has_pointing_device) + { + InputServer::StartStopDevices(NULL, B_POINTING_DEVICE, true); + } + if (has_keyboard_device) + { + InputServer::StartStopDevices(NULL, B_KEYBOARD_DEVICE, true); + } + } + + InputServer::gInputDeviceListLocker.Unlock(); + */ + return B_OK; } -/* +/** * Method: BInputServerDevice::UnregisterDevices() * Descr: */ @@ -120,20 +186,33 @@ BInputServerDevice::UnregisterDevices(input_device_ref **devices) } -/* +/** * Method: BInputServerDevice::EnqueueMessage() * Descr: */ status_t BInputServerDevice::EnqueueMessage(BMessage *message) { - status_t dummy; - - return dummy; +/* status_t err; + + ssize_t length = message->FlattenedSize(); + char* buffer = new char[length]; + if ((err = message->Flatten(buffer,length)) < 0) { + } else { + if((write_port(mEventPort, 0, buffer, length)) < 0) { + + }else { + free(buffer); + err = B_OK; + } + } + return err; + */ + return B_OK; } -/* +/** * Method: BInputServerDevice::StartMonitoringDevice() * Descr: */ @@ -146,7 +225,7 @@ BInputServerDevice::StartMonitoringDevice(const char *device) } -/* +/** * Method: BInputServerDevice::StopMonitoringDevice() * Descr: */ @@ -158,8 +237,12 @@ BInputServerDevice::StopMonitoringDevice(const char *device) return dummy; } +/** +///////////////////////// Below this line is reserved functions ///////////////////////////// +*/ -/* + +/** * Method: BInputServerDevice::_ReservedInputServerDevice1() * Descr: */ @@ -169,7 +252,7 @@ BInputServerDevice::_ReservedInputServerDevice1() } -/* +/** * Method: BInputServerDevice::_ReservedInputServerDevice2() * Descr: */ @@ -179,7 +262,7 @@ BInputServerDevice::_ReservedInputServerDevice2() } -/* +/** * Method: BInputServerDevice::_ReservedInputServerDevice3() * Descr: */ @@ -189,7 +272,7 @@ BInputServerDevice::_ReservedInputServerDevice3() } -/* +/** * Method: BInputServerDevice::_ReservedInputServerDevice4() * Descr: */ diff --git a/src/servers/input/InputServerDevice.h b/src/servers/input/InputServerDevice.h new file mode 100644 index 0000000000..51fe62a8a1 --- /dev/null +++ b/src/servers/input/InputServerDevice.h @@ -0,0 +1,78 @@ +/****************************************************************************** +/ +/ File: InputServerDevice.h +/ +/ Description: Add-on class for input_server devices. +/ +/ Copyright 1998, Be Incorporated, All Rights Reserved. +/ +******************************************************************************/ + +#ifndef _INPUTSERVERDEVICE_H +#define _INPUTSERVERDEVICE_H + +#include +#include +#include + + +struct input_device_ref { + char *name; + input_device_type type; + void *cookie; +}; + + +enum { + // B_KEYBOARD_DEVICE notifications + B_KEY_MAP_CHANGED = 1, + B_KEY_LOCKS_CHANGED, + B_KEY_REPEAT_DELAY_CHANGED, + B_KEY_REPEAT_RATE_CHANGED, + + // B_POINTING_DEVICE notifications + B_MOUSE_TYPE_CHANGED, + B_MOUSE_MAP_CHANGED, + B_MOUSE_SPEED_CHANGED, + B_CLICK_SPEED_CHANGED, + B_MOUSE_ACCELERATION_CHANGED +}; + + +class _BDeviceAddOn_; + + +class BInputServerDevice { +public: + BInputServerDevice(); + virtual ~BInputServerDevice(); + + virtual status_t InitCheck(); + virtual status_t SystemShuttingDown(); + + virtual status_t Start(const char *device, void *cookie); + virtual status_t Stop(const char *device, void *cookie); + virtual status_t Control(const char *device, + void *cookie, + uint32 code, + BMessage *message); + + status_t RegisterDevices(input_device_ref **devices); + status_t UnregisterDevices(input_device_ref **devices); + + status_t EnqueueMessage(BMessage *message); + + status_t StartMonitoringDevice(const char *device); + status_t StopMonitoringDevice(const char *device); + +private: + _BDeviceAddOn_* fOwner; + virtual void _ReservedInputServerDevice1(); + virtual void _ReservedInputServerDevice2(); + virtual void _ReservedInputServerDevice3(); + virtual void _ReservedInputServerDevice4(); + uint32 _reserved[4]; +}; + + +#endif diff --git a/src/servers/input/InputServerDeviceListEntry.h b/src/servers/input/InputServerDeviceListEntry.h index 9935282aa9..52918e12de 100644 --- a/src/servers/input/InputServerDeviceListEntry.h +++ b/src/servers/input/InputServerDeviceListEntry.h @@ -6,12 +6,12 @@ class InputServerDeviceListEntry public: inline const char* getPath() { return mPath; }; inline status_t getStatus() { return mStatus; }; - inline const BInputServerDevice* getInputServerDevice() { return mIsd; }; + inline BInputServerDevice* getInputServerDevice() { return mIsd; }; InputServerDeviceListEntry( const char* path, status_t status, - const BInputServerDevice* isd) : mPath (path), + BInputServerDevice* isd) : mPath (path), mStatus(status), mIsd (isd) { /* Do nothing */ }; @@ -22,6 +22,6 @@ class InputServerDeviceListEntry private: const char* mPath; status_t mStatus; - const BInputServerDevice* mIsd; + BInputServerDevice* mIsd; }; diff --git a/src/servers/input/InputServerFilter.cpp b/src/servers/input/InputServerFilter.cpp index 6efd612d4e..20f359b792 100644 --- a/src/servers/input/InputServerFilter.cpp +++ b/src/servers/input/InputServerFilter.cpp @@ -1,12 +1,40 @@ -/*********************************************************************** - * AUTHOR: nobody - * FILE: InputServerFilter.cpp - * DATE: Sun Dec 16 15:57:43 2001 - * DESCR: - ***********************************************************************/ +/*****************************************************************************/ +// OpenBeOS InputServer +// +// Version: [0.0.5] [Development Stage] +// +// [Description] +// +// +// This application and all source files used in its construction, except +// where noted, are licensed under the MIT License, and have been written +// and are: +// +// Copyright (c) 2002 OpenBeOS Project +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +/*****************************************************************************/ + + #include "InputServerFilter.h" -/* +/** * Method: BInputServerFilter::BInputServerFilter() * Descr: */ @@ -15,7 +43,7 @@ BInputServerFilter::BInputServerFilter() } -/* +/** * Method: BInputServerFilter::~BInputServerFilter() * Descr: */ @@ -24,7 +52,7 @@ BInputServerFilter::~BInputServerFilter() } -/* +/** * Method: BInputServerFilter::InitCheck() * Descr: */ @@ -37,7 +65,7 @@ BInputServerFilter::InitCheck() } -/* +/** * Method: BInputServerFilter::Filter() * Descr: */ @@ -51,7 +79,7 @@ BInputServerFilter::Filter(BMessage *message, } -/* +/** * Method: BInputServerFilter::GetScreenRegion() * Descr: */ @@ -64,7 +92,7 @@ BInputServerFilter::GetScreenRegion(BRegion *region) const } -/* +/** * Method: BInputServerFilter::_ReservedInputServerFilter1() * Descr: */ @@ -74,7 +102,7 @@ BInputServerFilter::_ReservedInputServerFilter1() } -/* +/** * Method: BInputServerFilter::_ReservedInputServerFilter2() * Descr: */ @@ -84,7 +112,7 @@ BInputServerFilter::_ReservedInputServerFilter2() } -/* +/** * Method: BInputServerFilter::_ReservedInputServerFilter3() * Descr: */ @@ -94,7 +122,7 @@ BInputServerFilter::_ReservedInputServerFilter3() } -/* +/** * Method: BInputServerFilter::_ReservedInputServerFilter4() * Descr: */ diff --git a/src/servers/input/InputServerFilter.h b/src/servers/input/InputServerFilter.h new file mode 100644 index 0000000000..28e37f4133 --- /dev/null +++ b/src/servers/input/InputServerFilter.h @@ -0,0 +1,39 @@ +/****************************************************************************** +/ +/ File: InputServerFilter.h +/ +/ Description: Add-on class for input_server filters. +/ +/ Copyright 1998, Be Incorporated, All Rights Reserved. +/ +*******************************************************************************/ + +#ifndef _INPUTSERVERFILTER_H +#define _INPUTSERVERFILTER_H + +#include +#include +#include + + +class BInputServerFilter { +public: + BInputServerFilter(); + virtual ~BInputServerFilter(); + + virtual status_t InitCheck(); + + virtual filter_result Filter(BMessage *message, BList *outList); + + status_t GetScreenRegion(BRegion *region) const; + +private: + virtual void _ReservedInputServerFilter1(); + virtual void _ReservedInputServerFilter2(); + virtual void _ReservedInputServerFilter3(); + virtual void _ReservedInputServerFilter4(); + uint32 _reserved[4]; +}; + + +#endif diff --git a/src/servers/input/InputServerFilterListEntry.h b/src/servers/input/InputServerFilterListEntry.h new file mode 100644 index 0000000000..6bf90b9dc6 --- /dev/null +++ b/src/servers/input/InputServerFilterListEntry.h @@ -0,0 +1,27 @@ +// +// Class to encapsulate entries in the InputServer's InputServerFilter list. +// +class InputServerFilterListEntry +{ + public: + inline const char* getPath() { return mPath; }; + inline status_t getStatus() { return mStatus; }; + inline const BInputServerFilter* getInputServerFilter() { return mIsd; }; + + InputServerFilterListEntry( + const char* path, + status_t status, + const BInputServerFilter* isd) : mPath (path), + mStatus(status), + mIsd (isd) + { /* Do nothing */ }; + + ~InputServerFilterListEntry() + { /* Do nothing */ }; + + private: + const char* mPath; + status_t mStatus; + const BInputServerFilter* mIsd; + +}; diff --git a/src/servers/input/InputServerMethod.cpp b/src/servers/input/InputServerMethod.cpp index a91582ad09..4a1fddf954 100644 --- a/src/servers/input/InputServerMethod.cpp +++ b/src/servers/input/InputServerMethod.cpp @@ -1,13 +1,41 @@ -/*********************************************************************** - * AUTHOR: nobody - * FILE: InputServerMethod.cpp - * DATE: Sun Dec 16 15:57:43 2001 - * DESCR: - ***********************************************************************/ +/*****************************************************************************/ +// OpenBeOS InputServer +// +// Version: [0.0.5] [Development Stage] +// +// [Description] +// +// +// This application and all source files used in its construction, except +// where noted, are licensed under the MIT License, and have been written +// and are: +// +// Copyright (c) 2002 OpenBeOS Project +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +/*****************************************************************************/ + + #include "InputServerMethod.h" #include "Messenger.h" -/* +/** * Method: BInputServerMethod::BInputServerMethod() * Descr: */ @@ -17,7 +45,7 @@ BInputServerMethod::BInputServerMethod(const char *name, } -/* +/** * Method: BInputServerMethod::~BInputServerMethod() * Descr: */ @@ -26,7 +54,7 @@ BInputServerMethod::~BInputServerMethod() } -/* +/** * Method: BInputServerMethod::MethodActivated() * Descr: */ @@ -39,7 +67,7 @@ BInputServerMethod::MethodActivated(bool active) } -/* +/** * Method: BInputServerMethod::EnqueueMessage() * Descr: */ @@ -52,7 +80,7 @@ BInputServerMethod::EnqueueMessage(BMessage *message) } -/* +/** * Method: BInputServerMethod::SetName() * Descr: */ @@ -65,7 +93,7 @@ BInputServerMethod::SetName(const char *name) } -/* +/** * Method: BInputServerMethod::SetIcon() * Descr: */ @@ -78,7 +106,7 @@ BInputServerMethod::SetIcon(const uchar *icon) } -/* +/** * Method: BInputServerMethod::SetMenu() * Descr: */ @@ -92,7 +120,7 @@ BInputServerMethod::SetMenu(const BMenu *menu, } -/* +/** * Method: BInputServerMethod::_ReservedInputServerMethod1() * Descr: */ @@ -102,7 +130,7 @@ BInputServerMethod::_ReservedInputServerMethod1() } -/* +/** * Method: BInputServerMethod::_ReservedInputServerMethod2() * Descr: */ @@ -112,7 +140,7 @@ BInputServerMethod::_ReservedInputServerMethod2() } -/* +/** * Method: BInputServerMethod::_ReservedInputServerMethod3() * Descr: */ @@ -122,7 +150,7 @@ BInputServerMethod::_ReservedInputServerMethod3() } -/* +/** * Method: BInputServerMethod::_ReservedInputServerMethod4() * Descr: */ diff --git a/src/servers/input/InputServerMethod.h b/src/servers/input/InputServerMethod.h new file mode 100644 index 0000000000..98a758f25c --- /dev/null +++ b/src/servers/input/InputServerMethod.h @@ -0,0 +1,47 @@ +/****************************************************************************** +/ +/ File: InputServerMethod.h +/ +/ Description: Add-on class for input_server methods. +/ +/ Copyright 1998, Be Incorporated, All Rights Reserved. +/ +******************************************************************************/ + +#ifndef _INPUTSERVERMETHOD_H +#define _INPUTSERVERMETHOD_H + +#include +#include +#include + + +class _BMethodAddOn_; + + +class BInputServerMethod : public BInputServerFilter { +public: + BInputServerMethod(const char *name, + const uchar *icon); + virtual ~BInputServerMethod(); + + virtual status_t MethodActivated(bool active); + + status_t EnqueueMessage(BMessage *message); + + status_t SetName(const char *name); + status_t SetIcon(const uchar *icon); + status_t SetMenu(const BMenu *menu, const BMessenger target); + +private: + _BMethodAddOn_* fOwner; + + virtual void _ReservedInputServerMethod1(); + virtual void _ReservedInputServerMethod2(); + virtual void _ReservedInputServerMethod3(); + virtual void _ReservedInputServerMethod4(); + uint32 _reserved[4]; +}; + + +#endif diff --git a/src/servers/input/InputServerMethodListEntry.h b/src/servers/input/InputServerMethodListEntry.h new file mode 100644 index 0000000000..dbbade0bb4 --- /dev/null +++ b/src/servers/input/InputServerMethodListEntry.h @@ -0,0 +1,27 @@ +// +// Class to encapsulate entries in the InputServer's InputServerMethod list. +// +class InputServerMethodListEntry +{ + public: + inline const char* getPath() { return mPath; }; + inline status_t getStatus() { return mStatus; }; + inline const BInputServerMethod* getInputServerMethod() { return mIsm; }; + + InputServerMethodListEntry( + const char* path, + status_t status, + const BInputServerMethod* ism) : mPath (path), + mStatus(status), + mIsm (ism) + { /* Do nothing */ }; + + ~InputServerMethodListEntry() + { /* Do nothing */ }; + + private: + const char* mPath; + status_t mStatus; + const BInputServerMethod* mIsm; + +}; diff --git a/src/servers/input/PortLink.cpp b/src/servers/input/PortLink.cpp new file mode 100644 index 0000000000..420d3327e4 --- /dev/null +++ b/src/servers/input/PortLink.cpp @@ -0,0 +1,440 @@ +/* + PortLink.cpp: + A helper class for port-based messaging + +------------------------------------------------------------------------ +How it works: + The class utilizes a fixed-size array of PortLinkData object pointers. When +data is attached, a new PortLinkData object is allocated and a copy of the +passed data is created inside it. When the time comes for the message to be sent, +the data is pieced together into a flattened array and written to the port. +------------------------------------------------------------------------ +Data members: + +*attachments[] - fixed-size array of pointers used to hold the attached data +opcode - message value which is sent along with any data +target - port to which the message is sent when Flush() is called +replyport - port used with synchronous messaging - FlushWithReply() +bufferlength - total bytes taken up by attachments +num_attachments - internal variable which is used to track which "slot" + will be the next one to receive an attachment object +*/ + +#include "PortLink.h" +#include +#include +#include + +#ifdef OPENBEOS +namespace OpenBeOS { +#endif + +//#define PLDEBUG + +// Internal data storage class for holding attached data whilst it is waiting +// to be Flattened() and then Flushed(). There is no need for this to be called outside +// the PortLink class. +class PortLinkData +{ +public: + PortLinkData(void); + ~PortLinkData(void); + bool Set(void *data, size_t size); + char *buffer; + size_t buffersize; +}; + +PortLink::PortLink(port_id port) +{ + // For this class to be useful (and to prevent a lot of init problems) + // we require a port in the constructor + target=port; + + // We start out without any data attached to the port message + num_attachments=0; + opcode=0; + bufferlength=0; + replyport=create_port(30,"PortLink reply port"); +} + +PortLink::~PortLink(void) +{ + // If, for some odd reason, this is deleted with something attached, + // free the memory used by the attachments. We do not flush the queue + // because the port may no longer be valid in cases such as the app + // is in the process of quitting + MakeEmpty(); +} + +void PortLink::SetOpCode(int32 code) +{ + // Sets the message code. This does not change once the message is sent. + // Another call to SetOpCode() is required for such things. + opcode=code; +} + +void PortLink::SetPort(port_id port) +{ + // Sets the target port. While not necessary in most uses, this exists + // mostly to prevent flexibility problems + target=port; +} + +port_id PortLink::GetPort(void) +{ + return target; +} + +void PortLink::Flush(void) +{ + // Fires a message off to the target, complete with attachments. NOTE: + // the recipient must delete all attachments, being the PortLink object assumes + // no responsiblity for the attachments once the message is sent. + int8 *msgbuffer; + int32 size; + + if(num_attachments>0) + { + FlattenData(&msgbuffer,&size); + // Dump message to port, reset attachments, and clean up + write_port(target,opcode,msgbuffer,size); + MakeEmpty(); + } + else + write_port(target,opcode,NULL,0); + +// if(size>0) +// delete msgbuffer; +} + +int8* PortLink::FlushWithReply(int32 *code, status_t *status, ssize_t *buffersize, bigtime_t timeout=B_INFINITE_TIMEOUT) +{ + // Fires a message to the target and then waits for a reply. The target will + // receive a message with the first item being the port_id to reply to. + // NOTE: like Flush(), any attached data must be deleted. + + // Effectively, an Attach() call inlined for changes + + if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS) + { + *status=B_ERROR; + return NULL; + } + + // create a new storage object and stash the data + PortLinkData *pld=new PortLinkData; + if(pld->Set(&replyport,sizeof(port_id))) + { + bufferlength+=sizeof(port_id); + } + else + { + delete pld; + *status=B_ERROR; + return NULL; + } + + // Flatten() inlined to make some necessary changes + int8 *buffer=new int8[bufferlength]; + int8 *bufferindex=buffer; + size_t size=0; + + // attach our port_id first + memcpy(bufferindex, pld->buffer, pld->buffersize); + bufferindex += pld->buffersize; + size+=pld->buffersize; + + // attach everything else + for(int i=0;ibuffer, pld->buffersize); + bufferindex += pld->buffersize; + size+=pld->buffersize; + } + + // Flush the thing....FOOSH! :P + write_port(target,opcode,buffer,size); + MakeEmpty(); + delete buffer; + + // Now we wait for the reply + if(timeout==B_INFINITE_TIMEOUT) + { + *buffersize=port_buffer_size(replyport); + if(*buffersize>0) + buffer=(int8*)new int8[*buffersize]; + read_port(replyport,code, buffer, *buffersize); + } + else + { + *buffersize=port_buffer_size_etc(replyport,0,timeout); + if(*buffersize==B_TIMED_OUT) + { + *status=*buffersize; + return NULL; + //return *buffersize; + } + if(*buffersize>0) + buffer=(int8*)new int8[*buffersize]; + read_port(replyport,code, buffer, *buffersize); + } + + // We got this far, so we apparently have some data + *status=B_OK; + return buffer; +} + +void PortLink::Attach(void *data, size_t size) +{ + // This is the member called to attach data to a message. Attachments are + // treated to be in 'Append' mode, tacking on each attached piece of data + // to the end of the list. + + // Prevent parameter problems + if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS) + return; + + if(size==0) + return; + + // create a new storage object and stash the data + PortLinkData *pld=new PortLinkData; + if(pld->Set(data,size)) + { + num_attachments++; + attachments[num_attachments-1]=pld; + bufferlength+=size; + } + else + { + delete pld; + } +} + +// These functions were added for a major convenience in passing common types +// Eventually, I'd like to templatize these, but for now, this'll do + +void PortLink::Attach(int32 data) +{ + // Prevent parameter problems + if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS) + return; + + int32 size=sizeof(int32); + + // create a new storage object and stash the data + PortLinkData *pld=new PortLinkData; + if(pld->Set(&data,size)) + { + num_attachments++; + attachments[num_attachments-1]=pld; + bufferlength+=size; + } + else + { + delete pld; + } +} + +void PortLink::Attach(int16 data) +{ + // Prevent parameter problems + if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS) + return; + + int32 size=sizeof(int16); + + // create a new storage object and stash the data + PortLinkData *pld=new PortLinkData; + if(pld->Set(&data,size)) + { + num_attachments++; + attachments[num_attachments-1]=pld; + bufferlength+=size; + } + else + { + delete pld; + } +} + +void PortLink::Attach(int8 data) +{ + // Prevent parameter problems + if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS) + return; + + int32 size=sizeof(int8); + + // create a new storage object and stash the data + PortLinkData *pld=new PortLinkData; + if(pld->Set(&data,size)) + { + num_attachments++; + attachments[num_attachments-1]=pld; + bufferlength+=size; + } + else + { + delete pld; + } +} + +void PortLink::Attach(float data) +{ + // Prevent parameter problems + if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS) + return; + + int32 size=sizeof(float); + + // create a new storage object and stash the data + PortLinkData *pld=new PortLinkData; + if(pld->Set(&data,size)) + { + num_attachments++; + attachments[num_attachments-1]=pld; + bufferlength+=size; + } + else + { + delete pld; + } +} + +void PortLink::Attach(bool data) +{ + // Prevent parameter problems + if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS) + return; + + int32 size=sizeof(bool); + + // create a new storage object and stash the data + PortLinkData *pld=new PortLinkData; + if(pld->Set(&data,size)) + { + num_attachments++; + attachments[num_attachments-1]=pld; + bufferlength+=size; + } + else + { + delete pld; + } +} + +void PortLink::Attach(BRect data) +{ + // Prevent parameter problems + if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS) + return; + + int32 size=sizeof(BRect); + + // create a new storage object and stash the data + PortLinkData *pld=new PortLinkData; + if(pld->Set(&data,size)) + { + num_attachments++; + attachments[num_attachments-1]=pld; + bufferlength+=size; + } + else + { + delete pld; + } +} + +void PortLink::Attach(BPoint data) +{ + // Prevent parameter problems + if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS) + return; + + int32 size=sizeof(BPoint); + + // create a new storage object and stash the data + PortLinkData *pld=new PortLinkData; + if(pld->Set(&data,size)) + { + num_attachments++; + attachments[num_attachments-1]=pld; + bufferlength+=size; + } + else + { + delete pld; + } +} + +void PortLink::FlattenData(int8 **buffer,int32 *size) +{ + // This function is where all the magic happens, but it is strictly internal. + // It iterates through each PortLinkData object and copies it to the main buffer + // which ends up, ultimately, being written to the PortLink's target port. + + // skip if there aree no attachments + if(bufferlength<1) + return; + + *buffer=new int8[bufferlength]; + int8 *bufferindex=*buffer; + PortLinkData *pld; + *size=0; + + for(int i=0;ibuffer, pld->buffersize); + bufferindex += pld->buffersize; + *size+=pld->buffersize; + } +} + +void PortLink::MakeEmpty(void) +{ + // Nukes all the attachments currently held by the PortLink class + if(num_attachments!=0) + { + for(int i=0; i0) + free(buffer); +} + +bool PortLinkData::Set(void *data, size_t size) +{ + // Function copies the passed to the internal buffers for storage + if(size>0 && buffersize==0 && data!=NULL) + { + buffer=(char *)malloc(size); + if(buffer==NULL) + return false; + memcpy(buffer, data, size); + buffersize=size; + return true; + } + return false; +} + +#ifdef OPENBEOS +} +#endif \ No newline at end of file diff --git a/src/servers/input/PortLink.h b/src/servers/input/PortLink.h new file mode 100644 index 0000000000..1bc389408b --- /dev/null +++ b/src/servers/input/PortLink.h @@ -0,0 +1,51 @@ +#ifndef _PORTLINK_H_ +#define _PORTLINK_H_ + +#include +#include +#include +#include + +#ifndef _PORTLINK_BUFFERSIZE +#define _PORTLINK_MAX_ATTACHMENTS 50 +#endif + +#ifdef OPENBEOS +namespace OpenBeOS { +#endif + +class PortLinkData; + +class PortLink +{ +public: + PortLink(port_id port); + ~PortLink(void); + void SetOpCode(int32 code); + void SetPort(port_id port); + port_id GetPort(void); + void Flush(void); + int8* FlushWithReply(int32 *code, status_t *status, ssize_t *buffersize, + bigtime_t timeout=B_INFINITE_TIMEOUT); + void Attach(void *data, size_t size); + void Attach(int32 data); + void Attach(int16 data); + void Attach(int8 data); + void Attach(float data); + void Attach(bool data); + void Attach(BRect data); + void Attach(BPoint data); + void MakeEmpty(void); +protected: + void FlattenData(int8 **buffer,int32 *size); + port_id target, replyport; + int32 opcode, bufferlength; + int num_attachments; + PortLinkData *attachments[_PORTLINK_MAX_ATTACHMENTS]; +}; + +#ifdef OPENBEOS +} +#endif + +#endif \ No newline at end of file diff --git a/src/servers/input/ServerProtocol.h b/src/servers/input/ServerProtocol.h new file mode 100644 index 0000000000..d2138e2c1b --- /dev/null +++ b/src/servers/input/ServerProtocol.h @@ -0,0 +1,95 @@ +#ifndef _APPSERVER_PROTOCOL_ +#define _APPSERVER_PROTOCOL_ + +#define CREATE_APP 'drca' +#define DELETE_APP 'drda' +#define QUIT_APP 'srqa' + +#define SET_SERVER_PORT 'srsp' + +#define CREATE_WINDOW 'drcw' +#define DELETE_WINDOW 'drdw' +#define SHOW_WINDOW 'drsw' +#define HIDE_WINDOW 'drhw' +#define QUIT_WINDOW 'srqw' + +#define SERVER_PORT_NAME "OBappserver" +#define SERVER_INPUT_PORT "OBinputport" + +#define SET_CURSOR_DATA 'sscd' +#define SET_CURSOR_BCURSOR 'sscb' +#define SET_CURSOR_BBITMAP 'sscB' +#define SHOW_CURSOR 'srsc' +#define HIDE_CURSOR 'srhc' +#define OBSCURE_CURSOR 'sroc' + +#define GFX_COUNT_WORKSPACES 'gcws' +#define GFX_SET_WORKSPACE_COUNT 'ggwc' +#define GFX_CURRENT_WORKSPACE 'ggcw' +#define GFX_ACTIVATE_WORKSPACE 'gaws' +#define GFX_GET_SYSTEM_COLORS 'gsyc' +#define GFX_SET_SYSTEM_COLORS 'gsyc' +#define GFX_SET_SCREEN_MODE 'gssm' +#define GFX_GET_SCROLLBAR_INFO 'ggsi' +#define GFX_SET_SCROLLBAR_INFO 'gssi' +#define GFX_IDLE_TIME 'gidt' +#define GFX_SELECT_PRINTER_PANEL 'gspp' +#define GFX_ADD_PRINTER_PANEL 'gapp' +#define GFX_RUN_BE_ABOUT 'grba' +#define GFX_SET_FOCUS_FOLLOWS_MOUSE 'gsfm' +#define GFX_FOCUS_FOLLOWS_MOUSE 'gffm' + +#define GFX_SET_HIGH_COLOR 'gshc' +#define GFX_SET_LOW_COLOR 'gslc' +#define GFX_SET_VIEW_COLOR 'gsvc' + +#define GFX_STROKE_ARC 'gsar' +#define GFX_STROKE_BEZIER 'gsbz' +#define GFX_STROKE_ELLIPSE 'gsel' +#define GFX_STROKE_LINE 'gsln' +#define GFX_STROKE_POLYGON 'gspy' +#define GFX_STROKE_RECT 'gsrc' +#define GFX_STROKE_ROUNDRECT 'gsrr' +#define GFX_STROKE_SHAPE 'gssh' +#define GFX_STROKE_TRIANGLE 'gstr' + +#define GFX_FILL_ARC 'gfar' +#define GFX_FILL_BEZIER 'gfbz' +#define GFX_FILL_ELLIPSE 'gfel' +#define GFX_FILL_POLYGON 'gfpy' +#define GFX_FILL_RECT 'gfrc' +#define GFX_FILL_REGION 'gfrg' +#define GFX_FILL_ROUNDRECT 'gfrr' +#define GFX_FILL_SHAPE 'gfsh' +#define GFX_FILL_TRIANGLE 'gftr' + +#define GFX_MOVEPENBY 'gmpb' +#define GFX_MOVEPENTO 'gmpt' +#define GFX_SETPENSIZE 'gsps' + +#define GFX_DRAW_STRING 'gdst' +#define GFX_SET_FONT 'gsft' +#define GFX_SET_FONT_SIZE 'gsfs' + +#define GFX_FLUSH 'gfsh' +#define GFX_SYNC 'gsyn' + +#define LAYER_CREATE 'lycr' +#define LAYER_DELETE 'lydl' +#define LAYER_ADD_CHILD 'lyac' +#define LAYER_REMOVE_CHILD 'lyrc' +#define LAYER_REMOVE_SELF 'lyrs' +#define LAYER_SHOW 'lysh' +#define LAYER_HIDE 'lyhd' +#define LAYER_MOVE 'lymv' +#define LAYER_RESIZE 'lyre' +#define LAYER_INVALIDATE 'lyin' +#define LAYER_DRAW 'lydr' + +#define BEGIN_RECT_TRACKING 'rtbg' +#define END_RECT_TRACKING 'rten' + +#define VIEW_GET_TOKEN 'vgtk' +#define VIEW_ADD 'vadd' +#define VIEW_REMOVE 'vrem' +#endif \ No newline at end of file