1/*
2 * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _DEBUG_LOOPER_H
6#define _DEBUG_LOOPER_H
7
8
9#include <Locker.h>
10
11#include <ObjectList.h>
12
13
14class BDebugMessageHandler;
15class BTeamDebugger;
16
17
18class BDebugLooper {
19public:
20								BDebugLooper();
21	virtual						~BDebugLooper();
22
23			status_t			Init();
24
25			thread_id			Run(bool spawnThread);
26			void				Quit();
27
28			status_t			AddTeamDebugger(BTeamDebugger* debugger,
29									BDebugMessageHandler* handler);
30			bool				RemoveTeamDebugger(BTeamDebugger* debugger);
31			bool				RemoveTeamDebugger(team_id team);
32
33private:
34			struct Debugger;
35
36			struct Job;
37			struct JobList;
38			struct AddDebuggerJob;
39			struct RemoveDebuggerJob;
40
41			friend struct AddDebuggerJob;
42			friend struct RemoveDebuggerJob;
43
44			typedef BObjectList<Debugger> DebuggerList;
45
46private:
47	static	status_t			_MessageLoopEntry(void* data);
48			status_t			_MessageLoop();
49
50			status_t			_DoJob(Job* job);
51			void				_Notify();
52
53private:
54			BLocker				fLock;
55			thread_id			fThread;
56			bool				fOwnsThread;
57			bool				fTerminating;
58			bool				fNotified;
59			JobList*			fJobs;
60			sem_id				fEventSemaphore;
61			DebuggerList		fDebuggers;
62};
63
64
65#endif	// _DEBUG_LOOPER_H
66