Just another manager - not yet used, though.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15011 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
65f512e089
commit
b9e43e2c12
90
src/servers/app/InputManager.cpp
Normal file
90
src/servers/app/InputManager.cpp
Normal file
@ -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 <Autolock.h>
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
36
src/servers/app/InputManager.h
Normal file
36
src/servers/app/InputManager.h
Normal file
@ -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 <Locker.h>
|
||||
#include <ObjectList.h>
|
||||
|
||||
|
||||
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<EventStream> fFreeStreams;
|
||||
BObjectList<EventStream> fUsedStreams;
|
||||
};
|
||||
|
||||
extern InputManager* gInputManager;
|
||||
|
||||
#endif /* INPUT_MANAGER_H */
|
Loading…
Reference in New Issue
Block a user