xref: /haiku/headers/private/app/LooperList.h (revision 2f470aec1c92ce6917b8a903e343795dc77af41f)
1 /*
2  * Copyright 2001-2007, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Erik Jaesler (erik@cgsoftware.com)
7  */
8 #ifndef LOOPERLIST_H
9 #define LOOPERLIST_H
10 
11 
12 #include <Locker.h>
13 #include <OS.h>
14 #include <SupportDefs.h>
15 
16 #include <vector>
17 
18 class BLooper;
19 
20 
21 namespace BPrivate {
22 
23 class BLooperList {
24 	public:
25 		BLooperList();
26 
27 		bool		Lock();
28 		void		Unlock();
29 		bool		IsLocked();
30 
31 		void		AddLooper(BLooper* l);
32 		bool		IsLooperValid(const BLooper* l);
33 		bool		RemoveLooper(BLooper* l);
34 		void		GetLooperList(BList* list);
35 		int32		CountLoopers();
36 		BLooper*	LooperAt(int32 index);
37 		BLooper*	LooperForThread(thread_id tid);
38 		BLooper*	LooperForName(const char* name);
39 		BLooper*	LooperForPort(port_id port);
40 
41 	private:
42 		struct LooperData {
43 			LooperData();
44 			LooperData(BLooper* looper);
45 			LooperData(const LooperData& rhs);
46 			LooperData& operator=(const LooperData& rhs);
47 
48 			BLooper*	looper;
49 		};
50 
51 		static bool EmptySlotPred(LooperData& Data);
52 		struct FindLooperPred {
53 			FindLooperPred(const BLooper* loop) : looper(loop) {;}
54 			bool operator()(LooperData& Data);
55 			const BLooper* looper;
56 		};
57 		struct FindThreadPred {
58 			FindThreadPred(thread_id tid) : thread(tid) {;}
59 			bool operator()(LooperData& Data);
60 			thread_id thread;
61 		};
62 		struct FindNamePred {
63 			FindNamePred(const char* n) : name(n) {;}
64 			bool operator()(LooperData& Data);
65 			const char* name;
66 		};
67 		struct FindPortPred {
68 			FindPortPred(port_id pid) : port(pid) {;}
69 			bool operator()(LooperData& Data);
70 			port_id port;
71 		};
72 
73 		void	AssertLocked();
74 
75 		BLocker					fLock;
76 		std::vector<LooperData>	fData;
77 };
78 
79 extern BLooperList gLooperList;
80 
81 }	// namespace BPrivate
82 
83 #endif	// LOOPERLIST_H
84