2005-11-17 17:58:19 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2005, Haiku, Inc. All Rights Reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Axel Dörfler, axeld@pinc-software.de
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "EventStream.h"
|
|
|
|
|
* the new input event dispatcher is now actually used, although it doesn't
distribute any messages to the clients yet.
* removed the working thread from RootLayer - for now, its event handlers are
still called using input filters in the new event dispatcher, though (to
get things started).
* ServerApp is now using a BMessenger to identify its client, and no longer
stores the port/token separately.
* the input_server handshake is a bit simpler now, as it can now just reply
to the app_server message, removed unused code from ServerProtocol.h
* calmed down the MultiLocker (it always printed thread statistics on startup,
because it's compiled in debug mode).
* removed the cursor thread stuff from AppServer.cpp
* the new event dispatcher now uses a cursor thread when supported (only in
native mode, not in the test environment), although it improves cursor
movement under Qemu, the effect is not as good as expected - this might
need some more investigations (might just be a thread priority problem).
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15012 a95241bf-73f2-0310-859d-f6bbb57e9c96
2005-11-18 14:30:06 +03:00
|
|
|
#include <InputServerTypes.h>
|
|
|
|
#include <ServerProtocol.h>
|
2005-11-17 17:58:19 +03:00
|
|
|
#include <shared_cursor_area.h>
|
|
|
|
|
|
|
|
#include <new>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
|
|
EventStream::EventStream()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EventStream::~EventStream()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
EventStream::SupportsCursorThread() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
* the new input event dispatcher is now actually used, although it doesn't
distribute any messages to the clients yet.
* removed the working thread from RootLayer - for now, its event handlers are
still called using input filters in the new event dispatcher, though (to
get things started).
* ServerApp is now using a BMessenger to identify its client, and no longer
stores the port/token separately.
* the input_server handshake is a bit simpler now, as it can now just reply
to the app_server message, removed unused code from ServerProtocol.h
* calmed down the MultiLocker (it always printed thread statistics on startup,
because it's compiled in debug mode).
* removed the cursor thread stuff from AppServer.cpp
* the new event dispatcher now uses a cursor thread when supported (only in
native mode, not in the test environment), although it improves cursor
movement under Qemu, the effect is not as good as expected - this might
need some more investigations (might just be a thread priority problem).
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15012 a95241bf-73f2-0310-859d-f6bbb57e9c96
2005-11-18 14:30:06 +03:00
|
|
|
bool
|
|
|
|
EventStream::GetNextCursorPosition(BPoint& where)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-17 17:58:19 +03:00
|
|
|
// #pragma mark -
|
|
|
|
|
|
|
|
|
* the new input event dispatcher is now actually used, although it doesn't
distribute any messages to the clients yet.
* removed the working thread from RootLayer - for now, its event handlers are
still called using input filters in the new event dispatcher, though (to
get things started).
* ServerApp is now using a BMessenger to identify its client, and no longer
stores the port/token separately.
* the input_server handshake is a bit simpler now, as it can now just reply
to the app_server message, removed unused code from ServerProtocol.h
* calmed down the MultiLocker (it always printed thread statistics on startup,
because it's compiled in debug mode).
* removed the cursor thread stuff from AppServer.cpp
* the new event dispatcher now uses a cursor thread when supported (only in
native mode, not in the test environment), although it improves cursor
movement under Qemu, the effect is not as good as expected - this might
need some more investigations (might just be a thread priority problem).
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15012 a95241bf-73f2-0310-859d-f6bbb57e9c96
2005-11-18 14:30:06 +03:00
|
|
|
InputServerStream::InputServerStream(BMessenger& messenger)
|
2005-11-17 17:58:19 +03:00
|
|
|
:
|
* the new input event dispatcher is now actually used, although it doesn't
distribute any messages to the clients yet.
* removed the working thread from RootLayer - for now, its event handlers are
still called using input filters in the new event dispatcher, though (to
get things started).
* ServerApp is now using a BMessenger to identify its client, and no longer
stores the port/token separately.
* the input_server handshake is a bit simpler now, as it can now just reply
to the app_server message, removed unused code from ServerProtocol.h
* calmed down the MultiLocker (it always printed thread statistics on startup,
because it's compiled in debug mode).
* removed the cursor thread stuff from AppServer.cpp
* the new event dispatcher now uses a cursor thread when supported (only in
native mode, not in the test environment), although it improves cursor
movement under Qemu, the effect is not as good as expected - this might
need some more investigations (might just be a thread priority problem).
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15012 a95241bf-73f2-0310-859d-f6bbb57e9c96
2005-11-18 14:30:06 +03:00
|
|
|
fInputServer(messenger),
|
|
|
|
fPort(-1),
|
2005-11-17 17:58:19 +03:00
|
|
|
fQuitting(false)
|
|
|
|
{
|
* the new input event dispatcher is now actually used, although it doesn't
distribute any messages to the clients yet.
* removed the working thread from RootLayer - for now, its event handlers are
still called using input filters in the new event dispatcher, though (to
get things started).
* ServerApp is now using a BMessenger to identify its client, and no longer
stores the port/token separately.
* the input_server handshake is a bit simpler now, as it can now just reply
to the app_server message, removed unused code from ServerProtocol.h
* calmed down the MultiLocker (it always printed thread statistics on startup,
because it's compiled in debug mode).
* removed the cursor thread stuff from AppServer.cpp
* the new event dispatcher now uses a cursor thread when supported (only in
native mode, not in the test environment), although it improves cursor
movement under Qemu, the effect is not as good as expected - this might
need some more investigations (might just be a thread priority problem).
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15012 a95241bf-73f2-0310-859d-f6bbb57e9c96
2005-11-18 14:30:06 +03:00
|
|
|
BMessage message(IS_ACQUIRE_INPUT);
|
|
|
|
fCursorArea = create_area("shared cursor", (void **)&fCursorBuffer, B_ANY_ADDRESS,
|
|
|
|
B_PAGE_SIZE, B_LAZY_LOCK, B_READ_AREA | B_WRITE_AREA);
|
|
|
|
if (fCursorArea >= B_OK)
|
|
|
|
message.AddInt32("cursor area", fCursorArea);
|
|
|
|
|
|
|
|
BMessage reply;
|
|
|
|
if (messenger.SendMessage(&message, &reply) != B_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (reply.FindInt32("event port", &fPort) != B_OK)
|
|
|
|
fPort = -1;
|
|
|
|
if (reply.FindInt32("cursor semaphore", &fCursorSemaphore) != B_OK)
|
|
|
|
fCursorSemaphore = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if TEST_MODE
|
|
|
|
InputServerStream::InputServerStream()
|
|
|
|
:
|
|
|
|
fQuitting(false),
|
|
|
|
fCursorSemaphore(-1)
|
|
|
|
{
|
|
|
|
fPort = find_port(SERVER_INPUT_PORT);
|
2005-11-17 17:58:19 +03:00
|
|
|
}
|
* the new input event dispatcher is now actually used, although it doesn't
distribute any messages to the clients yet.
* removed the working thread from RootLayer - for now, its event handlers are
still called using input filters in the new event dispatcher, though (to
get things started).
* ServerApp is now using a BMessenger to identify its client, and no longer
stores the port/token separately.
* the input_server handshake is a bit simpler now, as it can now just reply
to the app_server message, removed unused code from ServerProtocol.h
* calmed down the MultiLocker (it always printed thread statistics on startup,
because it's compiled in debug mode).
* removed the cursor thread stuff from AppServer.cpp
* the new event dispatcher now uses a cursor thread when supported (only in
native mode, not in the test environment), although it improves cursor
movement under Qemu, the effect is not as good as expected - this might
need some more investigations (might just be a thread priority problem).
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15012 a95241bf-73f2-0310-859d-f6bbb57e9c96
2005-11-18 14:30:06 +03:00
|
|
|
#endif
|
2005-11-17 17:58:19 +03:00
|
|
|
|
|
|
|
|
|
|
|
InputServerStream::~InputServerStream()
|
|
|
|
{
|
* the new input event dispatcher is now actually used, although it doesn't
distribute any messages to the clients yet.
* removed the working thread from RootLayer - for now, its event handlers are
still called using input filters in the new event dispatcher, though (to
get things started).
* ServerApp is now using a BMessenger to identify its client, and no longer
stores the port/token separately.
* the input_server handshake is a bit simpler now, as it can now just reply
to the app_server message, removed unused code from ServerProtocol.h
* calmed down the MultiLocker (it always printed thread statistics on startup,
because it's compiled in debug mode).
* removed the cursor thread stuff from AppServer.cpp
* the new event dispatcher now uses a cursor thread when supported (only in
native mode, not in the test environment), although it improves cursor
movement under Qemu, the effect is not as good as expected - this might
need some more investigations (might just be a thread priority problem).
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15012 a95241bf-73f2-0310-859d-f6bbb57e9c96
2005-11-18 14:30:06 +03:00
|
|
|
delete_area(fCursorArea);
|
2005-11-17 17:58:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
InputServerStream::IsValid()
|
|
|
|
{
|
|
|
|
port_info portInfo;
|
|
|
|
if (fPort < B_OK || get_port_info(fPort, &portInfo) != B_OK)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
InputServerStream::SendQuit()
|
|
|
|
{
|
|
|
|
fQuitting = true;
|
|
|
|
write_port(fPort, 'quit', NULL, 0);
|
|
|
|
release_sem(fCursorSemaphore);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
InputServerStream::GetNextEvent(BMessage** _event)
|
|
|
|
{
|
|
|
|
if (fEvents.IsEmpty()) {
|
|
|
|
// wait for new events
|
|
|
|
BMessage* event;
|
|
|
|
status_t status = _MessageFromPort(&event);
|
|
|
|
if (status == B_OK)
|
|
|
|
fEvents.AddMessage(event);
|
|
|
|
else if (status == B_BAD_PORT_ID) {
|
|
|
|
// our port got deleted - the input_server must have died
|
|
|
|
fPort = -1;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 count = port_count(fPort);
|
|
|
|
if (count > 0) {
|
|
|
|
// empty port queue completely while we're at it
|
|
|
|
for (int32 i = 0; i < count; i++) {
|
|
|
|
if (_MessageFromPort(&event, 0) == B_OK)
|
|
|
|
fEvents.AddMessage(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// there are items in our list, so just work through them
|
|
|
|
|
|
|
|
*_event = fEvents.NextMessage();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
InputServerStream::GetNextCursorPosition(BPoint &where)
|
|
|
|
{
|
|
|
|
status_t status;
|
|
|
|
do {
|
|
|
|
status = acquire_sem(fCursorSemaphore);
|
|
|
|
} while (status == B_INTERRUPTED);
|
|
|
|
|
|
|
|
if (status == B_BAD_SEM_ID) {
|
|
|
|
// the semaphore is no longer valid - the input_server must have died
|
|
|
|
fCursorSemaphore = -1;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:43:08 +03:00
|
|
|
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
|
2005-11-17 17:58:19 +03:00
|
|
|
uint32 pos = atomic_get((int32*)&fCursorBuffer->pos);
|
2005-11-17 21:43:08 +03:00
|
|
|
#else
|
|
|
|
uint32 pos = fCursorBuffer->pos;
|
|
|
|
#endif
|
|
|
|
|
2005-11-18 14:50:34 +03:00
|
|
|
where.x = pos >> 16UL;
|
|
|
|
where.y = pos & 0xffff;
|
2005-11-17 17:58:19 +03:00
|
|
|
|
|
|
|
atomic_and(&fCursorBuffer->read, 0);
|
|
|
|
// this tells the input_server that we've read the
|
|
|
|
// cursor position and want to be notified if updated
|
|
|
|
|
|
|
|
if (fQuitting) {
|
|
|
|
fQuitting = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
InputServerStream::_MessageFromPort(BMessage** _message, bigtime_t timeout)
|
|
|
|
{
|
|
|
|
uint8 *buffer = NULL;
|
|
|
|
ssize_t bufferSize;
|
|
|
|
|
|
|
|
// read message from port
|
|
|
|
|
|
|
|
do {
|
|
|
|
bufferSize = port_buffer_size_etc(fPort, B_RELATIVE_TIMEOUT, timeout);
|
|
|
|
} while (bufferSize == B_INTERRUPTED);
|
|
|
|
|
|
|
|
if (bufferSize < B_OK)
|
|
|
|
return bufferSize;
|
|
|
|
|
|
|
|
if (bufferSize > 0) {
|
|
|
|
buffer = new (std::nothrow) uint8[bufferSize];
|
|
|
|
if (buffer == NULL)
|
|
|
|
return B_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 code;
|
|
|
|
bufferSize = read_port_etc(fPort, &code, buffer, bufferSize,
|
|
|
|
B_RELATIVE_TIMEOUT, 0);
|
|
|
|
if (bufferSize < B_OK) {
|
|
|
|
delete[] buffer;
|
|
|
|
return bufferSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (code == 'quit') {
|
|
|
|
// special code to tell our client to quit
|
|
|
|
BMessage* message = new BMessage(B_QUIT_REQUESTED);
|
|
|
|
if (message == NULL)
|
|
|
|
return B_NO_MEMORY;
|
|
|
|
|
|
|
|
*_message = message;
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we have the message, now let's unflatten it
|
|
|
|
|
|
|
|
BMessage* message = new BMessage(code);
|
|
|
|
if (message == NULL)
|
|
|
|
return B_NO_MEMORY;
|
|
|
|
|
|
|
|
if (buffer == NULL) {
|
|
|
|
*_message = message;
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t status = message->Unflatten((const char*)buffer);
|
|
|
|
delete[] buffer;
|
|
|
|
|
|
|
|
if (status != B_OK) {
|
|
|
|
printf("Unflatten event failed: port message code was: %ld - %c%c%c%c\n",
|
|
|
|
code, (int8)(code >> 24), (int8)(code >> 16), (int8)(code >> 8), (int8)code);
|
|
|
|
delete message;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
*_message = message;
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|