diff --git a/src/tests/servers/input/Jamfile b/src/tests/servers/input/Jamfile index 82bf439788..78b3b03487 100644 --- a/src/tests/servers/input/Jamfile +++ b/src/tests/servers/input/Jamfile @@ -6,3 +6,4 @@ SubInclude OBOS_TOP src tests servers input msgspy ; SubInclude OBOS_TOP src tests servers input portspy ; SubInclude OBOS_TOP src tests servers input prefs ; SubInclude OBOS_TOP src tests servers input replicant ; +SubInclude OBOS_TOP src tests servers input view_input_device ; diff --git a/src/tests/servers/input/view_input_device/Jamfile b/src/tests/servers/input/view_input_device/Jamfile new file mode 100644 index 0000000000..106b3943de --- /dev/null +++ b/src/tests/servers/input/view_input_device/Jamfile @@ -0,0 +1,6 @@ +SubDir OBOS_TOP src tests servers input view_input_device ; + +Addon ViewInputDevice : input_server devices : ViewInputDevice.cpp ; +LinkSharedOSLibs ViewInputDevice : be input_server libopenbeos.so ; + +MakeLocate ViewInputDevice : [ FDirName $(OBOS_TEST_DIR) servers input view_input_device input_server devices ] ; diff --git a/src/tests/servers/input/view_input_device/ViewInputDevice.cpp b/src/tests/servers/input/view_input_device/ViewInputDevice.cpp new file mode 100644 index 0000000000..98afc637c9 --- /dev/null +++ b/src/tests/servers/input/view_input_device/ViewInputDevice.cpp @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------- +// Handy InputDevice that queue all events from app_server's ViewHWInterface. +//------------------------------------------------------------------------- +/* + Copyright 1999, Be Incorporated. All Rights Reserved. + This file may be used under the terms of the Be Sample Code License. +*/ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +extern "C" _EXPORT BInputServerDevice* instantiate_input_device(); + +class ViewInputDevice; + +class ViewInputDevice : public BInputServerDevice { +public: + ViewInputDevice(); + virtual ~ViewInputDevice(); + + virtual status_t Start(const char *device, void *cookie); + virtual status_t Stop(const char *device, void *cookie); + +private: + thread_id _Thread; + static int32 _StartWatchPort(void *arg); + void _WatchPort(); + port_id _Port; +}; + + +BInputServerDevice* instantiate_input_device() +{ + return (new ViewInputDevice()); +} + + +ViewInputDevice::ViewInputDevice() + : BInputServerDevice() +{ + input_device_ref *device[2]; + input_device_ref mover = {"ViewInputDevice", B_POINTING_DEVICE, NULL}; + device[0] = &mover; + device[1] = NULL; + _Port = -1; + + RegisterDevices(device); +} + + +ViewInputDevice::~ViewInputDevice() +{ +} + + +status_t ViewInputDevice::Start(const char *device, void *cookie) +{ + _Port = find_port("ViewInputDevice"); + if(_Port < 0) { + _sPrintf("ViewInputDevice: find_port error: (0x%x) %s\n",_Port,strerror(_Port)); + return(_Port); + } + _Thread = spawn_thread(_StartWatchPort, device, B_REAL_TIME_DISPLAY_PRIORITY+4, this); + resume_thread(_Thread); + return (B_NO_ERROR); +} + + +status_t ViewInputDevice::Stop(const char *device, void *cookie) +{ + kill_thread(_Thread); + _Port = -1; + return (B_NO_ERROR); +} + +int32 ViewInputDevice::_StartWatchPort(void *arg) +{ + ViewInputDevice *self = (ViewInputDevice*)arg; + self->_WatchPort(); + return (B_NO_ERROR); +} + +void ViewInputDevice::_WatchPort() +{ + int32 code; + ssize_t length; + char *buffer; + BMessage *event; + status_t err; + + while (true) { + // Block until we find the size of the next message + length = port_buffer_size(_Port); + buffer = (char*)malloc(length); + event = NULL; + event = new BMessage(); + err = read_port(_Port, &code, buffer, length); + if(err != length) { + if(err >= 0) { + _sPrintf("ViewInputDevice: failed to read full packet (read %u of %u)\n",err,length); + } else { + _sPrintf("ViewInputDevice: read_port error: (0x%x) %s\n",err,strerror(err)); + } + } else if ((err = event->Unflatten(buffer)) < 0) { + _sPrintf("ViewInputDevice: (0x%x) %s\n",err,strerror(err)); + } else { + EnqueueMessage(event); + event = NULL; + } + free( buffer); + if(event!=NULL) { + delete(event); + event = NULL; + } + } +} +