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 9 // TODO: introduce means to define event stream features (like local vs. net) 10 // TODO: introduce the possibility to identify a stream by a unique name 11 12 13 #include "EventStream.h" 14 #include "InputManager.h" 15 16 #include <Autolock.h> 17 18 19 InputManager* gInputManager; 20 // the global input manager will be created by the AppServer 21 22 InputManager()23InputManager::InputManager() 24 : BLocker("input manager"), 25 fFreeStreams(2, true), 26 fUsedStreams(2, true) 27 { 28 } 29 30 ~InputManager()31InputManager::~InputManager() 32 { 33 } 34 35 36 bool AddStream(EventStream * stream)37InputManager::AddStream(EventStream* stream) 38 { 39 BAutolock _(this); 40 return fFreeStreams.AddItem(stream); 41 } 42 43 44 void RemoveStream(EventStream * stream)45InputManager::RemoveStream(EventStream* stream) 46 { 47 BAutolock _(this); 48 fFreeStreams.RemoveItem(stream); 49 } 50 51 52 EventStream* GetStream()53InputManager::GetStream() 54 { 55 BAutolock _(this); 56 57 EventStream* stream = NULL; 58 do { 59 delete stream; 60 // this deletes the previous invalid stream 61 62 stream = fFreeStreams.RemoveItemAt(0); 63 } while (stream != NULL && !stream->IsValid()); 64 65 if (stream == NULL) 66 return NULL; 67 68 fUsedStreams.AddItem(stream); 69 return stream; 70 } 71 72 73 void PutStream(EventStream * stream)74InputManager::PutStream(EventStream* stream) 75 { 76 if (stream == NULL) 77 return; 78 79 BAutolock _(this); 80 81 fUsedStreams.RemoveItem(stream, false); 82 if (stream->IsValid()) 83 fFreeStreams.AddItem(stream); 84 else 85 delete stream; 86 } 87 88 89 void UpdateScreenBounds(BRect bounds)90InputManager::UpdateScreenBounds(BRect bounds) 91 { 92 BAutolock _(this); 93 94 for (int32 i = fUsedStreams.CountItems(); i-- > 0;) { 95 fUsedStreams.ItemAt(i)->UpdateScreenBounds(bounds); 96 } 97 98 for (int32 i = fFreeStreams.CountItems(); i-- > 0;) { 99 fFreeStreams.ItemAt(i)->UpdateScreenBounds(bounds); 100 } 101 } 102 103 104