1//------------------------------------------------------------------------------ 2// Copyright (c) 2001-2002, Haiku 3// 4// Permission is hereby granted, free of charge, to any person obtaining a 5// copy of this software and associated documentation files (the "Software"), 6// to deal in the Software without restriction, including without limitation 7// the rights to use, copy, modify, merge, publish, distribute, sublicense, 8// and/or sell copies of the Software, and to permit persons to whom the 9// Software is furnished to do so, subject to the following conditions: 10// 11// The above copyright notice and this permission notice shall be included in 12// all copies or substantial portions of the Software. 13// 14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20// DEALINGS IN THE SOFTWARE. 21// 22// File Name: MessageRunnerManager.h 23// Author: Ingo Weinhold (bonefish@users.sf.net) 24// Description: Manages the registrar side "shadows" of BMessageRunners. 25//------------------------------------------------------------------------------ 26 27#ifndef MESSAGE_RUNNER_MANAGER_H 28#define MESSAGE_RUNNER_MANAGER_H 29 30#include <List.h> 31#include <Locker.h> 32 33class BMessage; 34class EventQueue; 35 36class MessageRunnerManager { 37public: 38 MessageRunnerManager(EventQueue *eventQueue); 39 virtual ~MessageRunnerManager(); 40 41 void HandleRegisterRunner(BMessage *request); 42 void HandleUnregisterRunner(BMessage *request); 43 void HandleSetRunnerParams(BMessage *request); 44 void HandleGetRunnerInfo(BMessage *request); 45 46 bool Lock(); 47 void Unlock(); 48 49private: 50 class RunnerEvent; 51 struct RunnerInfo; 52 friend class RunnerEvent; 53 54private: 55 bool _AddInfo(RunnerInfo *info); 56 bool _RemoveInfo(RunnerInfo *info); 57 RunnerInfo *_RemoveInfo(int32 index); 58 RunnerInfo *_RemoveInfoWithToken(int32 token); 59 bool _DeleteInfo(RunnerInfo *info, bool eventRemoved); 60 61 int32 _CountInfos() const; 62 63 RunnerInfo *_InfoAt(int32 index) const; 64 RunnerInfo *_InfoForToken(int32 token) const; 65 66 bool _HasInfo(RunnerInfo *info) const; 67 68 int32 _IndexOf(RunnerInfo *info) const; 69 int32 _IndexOfToken(int32 token) const; 70 71 bool _DoEvent(RunnerInfo *info); 72 bool _ScheduleEvent(RunnerInfo *info); 73 74 int32 _NextToken(); 75 76private: 77 BList fRunnerInfos; 78 BLocker fLock; 79 EventQueue *fEventQueue; 80 int32 fNextToken; 81}; 82 83#endif // MESSAGE_RUNNER_MANAGER_H 84