xref: /haiku/headers/private/app/LooperList.h (revision 51978af14a173e7fae0563b562be5603bc652aeb)
1 //------------------------------------------------------------------------------
2 //	Copyright (c) 2001-2002, OpenBeOS
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:		LooperList.h
23 //	Author(s):		Erik Jaesler (erik@cgsoftware.com)
24 //	Description:	Maintains a global list of all loopers in a given team.
25 //------------------------------------------------------------------------------
26 
27 #ifndef LOOPERLIST_H
28 #define LOOPERLIST_H
29 
30 // Standard Includes -----------------------------------------------------------
31 #include <vector>
32 
33 // System Includes -------------------------------------------------------------
34 #include <Locker.h>
35 #include <OS.h>
36 #include <SupportDefs.h>
37 
38 // Project Includes ------------------------------------------------------------
39 
40 // Local Includes --------------------------------------------------------------
41 
42 // Local Defines ---------------------------------------------------------------
43 
44 // Globals ---------------------------------------------------------------------
45 
46 class BLooper;
47 
48 namespace BPrivate {
49 
50 class BLooperList
51 {
52 	public:
53 		BLooperList();
54 
55 		bool		Lock();
56 		void		Unlock();
57 		bool		IsLocked();
58 
59 		void		AddLooper(BLooper* l);
60 		bool		IsLooperValid(const BLooper* l);
61 		bool		RemoveLooper(BLooper* l);
62 		void		GetLooperList(BList* list);
63 		int32		CountLoopers();
64 		BLooper*	LooperAt(int32 index);
65 		BLooper*	LooperForThread(thread_id tid);
66 		BLooper*	LooperForName(const char* name);
67 		BLooper*	LooperForPort(port_id port);
68 
69 		struct LooperData
70 		{
71 			LooperData();
72 			LooperData(BLooper* loop, uint32 i);
73 			LooperData(const LooperData& rhs);
74 			LooperData& operator=(const LooperData& rhs);
75 
76 			BLooper*	looper;
77 			uint32		id;
78 		};
79 
80 	private:
81 		static	bool	EmptySlotPred(LooperData& Data);
82 		struct FindLooperPred
83 		{
84 			FindLooperPred(const BLooper* loop) : looper(loop) {;}
85 			bool operator()(LooperData& Data);
86 			const BLooper* looper;
87 		};
88 		struct FindThreadPred
89 		{
90 			FindThreadPred(thread_id tid) : thread(tid) {;}
91 			bool operator()(LooperData& Data);
92 			thread_id thread;
93 		};
94 		struct FindNamePred
95 		{
96 			FindNamePred(const char* n) : name(n) {;}
97 			bool operator()(LooperData& Data);
98 			const char* name;
99 		};
100 		struct FindPortPred
101 		{
102 			FindPortPred(port_id pid) : port(pid) {;}
103 			bool operator()(LooperData& Data);
104 			port_id port;
105 		};
106 
107 		void	AssertLocked();
108 
109 		BLocker					fLock;
110 		uint32					fLooperID;
111 		std::vector<LooperData>	fData;
112 };
113 
114 extern _IMPEXP_BE BLooperList gLooperList;
115 }
116 
117 
118 #endif	//LOOPERLIST_H
119 
120 /*
121  * $Log $
122  *
123  * $Id  $
124  *
125  */
126 
127