1/*
2 * Copyright 2005, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Axel Dörfler, axeld@pinc-software.de
7 */
8#ifndef EVENT_STREAM_H
9#define EVENT_STREAM_H
10
11
12#include <LinkReceiver.h>
13#include <MessageQueue.h>
14#include <Messenger.h>
15
16
17struct shared_cursor;
18
19
20class EventStream {
21	public:
22		EventStream();
23		virtual ~EventStream();
24
25		virtual bool IsValid() = 0;
26		virtual void SendQuit() = 0;
27
28		virtual bool SupportsCursorThread() const;
29
30		virtual void UpdateScreenBounds(BRect bounds) = 0;
31
32		virtual bool GetNextEvent(BMessage** _event) = 0;
33		virtual status_t GetNextCursorPosition(BPoint& where,
34				bigtime_t timeout = B_INFINITE_TIMEOUT);
35
36		virtual status_t InsertEvent(BMessage* event) = 0;
37
38		virtual BMessage* PeekLatestMouseMoved() = 0;
39};
40
41
42class InputServerStream : public EventStream {
43	public:
44		InputServerStream(BMessenger& inputServerMessenger);
45#if TEST_MODE
46		InputServerStream();
47#endif
48
49		virtual ~InputServerStream();
50
51		virtual bool IsValid();
52		virtual void SendQuit();
53
54		virtual bool SupportsCursorThread() const { return fCursorSemaphore >= B_OK; }
55
56		virtual void UpdateScreenBounds(BRect bounds);
57
58		virtual bool GetNextEvent(BMessage** _event);
59		virtual status_t GetNextCursorPosition(BPoint& where,
60				bigtime_t timeout = B_INFINITE_TIMEOUT);
61
62		virtual status_t InsertEvent(BMessage* event);
63
64		virtual BMessage* PeekLatestMouseMoved();
65
66	private:
67		status_t _MessageFromPort(BMessage** _message,
68			bigtime_t timeout = B_INFINITE_TIMEOUT);
69
70		BMessenger fInputServer;
71		BMessageQueue fEvents;
72		port_id	fPort;
73		bool	fQuitting;
74		sem_id	fCursorSemaphore;
75		area_id	fCursorArea;
76		shared_cursor* fCursorBuffer;
77		BMessage* fLatestMouseMoved;
78};
79
80#endif	/* EVENT_STREAM_H */
81