From b9e43e2c1298f456a6de0ff70bac2e3723860427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 18 Nov 2005 09:43:37 +0000 Subject: [PATCH] Just another manager - not yet used, though. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15011 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/InputManager.cpp | 90 ++++++++++++++++++++++++++++++++ src/servers/app/InputManager.h | 36 +++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 src/servers/app/InputManager.cpp create mode 100644 src/servers/app/InputManager.h diff --git a/src/servers/app/InputManager.cpp b/src/servers/app/InputManager.cpp new file mode 100644 index 0000000000..df05a8160d --- /dev/null +++ b/src/servers/app/InputManager.cpp @@ -0,0 +1,90 @@ +/* + * Copyright 2005, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Axel Dörfler, axeld@pinc-software.de + */ + +// TODO: introduce means to define event stream features (like local vs. net) +// TODO: introduce the possibility to identify a stream by a unique name + + +#include "EventStream.h" +#include "InputManager.h" + +#include + + +InputManager* gInputManager; + // the global input manager will be created by the AppServer + + +InputManager::InputManager() + : BLocker("input manager"), + fFreeStreams(2, true), + fUsedStreams(2, true) +{ +} + + +InputManager::~InputManager() +{ +} + + +bool +InputManager::AddStream(EventStream* stream) +{ + BAutolock _(this); +printf("got stream: %p\n", stream); + return fFreeStreams.AddItem(stream); +} + + +void +InputManager::RemoveStream(EventStream* stream) +{ + BAutolock _(this); + fFreeStreams.RemoveItem(stream); +} + + +EventStream* +InputManager::GetStream() +{ + BAutolock _(this); + + EventStream* stream = NULL; + do { +printf("remove invalid stream: %p\n", stream); + delete stream; + // this deletes the previous invalid stream + + stream = fFreeStreams.RemoveItemAt(0); + } while (stream != NULL && !stream->IsValid()); + + if (stream == NULL) + return NULL; + + fUsedStreams.AddItem(stream); +printf("return stream: %p\n", stream); + return stream; +} + + +void +InputManager::PutStream(EventStream* stream) +{ + if (stream == NULL) + return; + + BAutolock _(this); + + fUsedStreams.RemoveItem(stream, false); + if (stream->IsValid()) + fFreeStreams.AddItem(stream); + else + delete stream; +} + diff --git a/src/servers/app/InputManager.h b/src/servers/app/InputManager.h new file mode 100644 index 0000000000..8aa3385868 --- /dev/null +++ b/src/servers/app/InputManager.h @@ -0,0 +1,36 @@ +/* + * Copyright 2005, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Axel Dörfler, axeld@pinc-software.de + */ +#ifndef INPUT_MANAGER_H +#define INPUT_MANAGER_H + + +#include +#include + + +class EventStream; + +class InputManager : public BLocker { + public: + InputManager(); + virtual ~InputManager(); + + bool AddStream(EventStream* stream); + void RemoveStream(EventStream* stream); + + EventStream* GetStream(); + void PutStream(EventStream* stream); + + private: + BObjectList fFreeStreams; + BObjectList fUsedStreams; +}; + +extern InputManager* gInputManager; + +#endif /* INPUT_MANAGER_H */