xref: /haiku/src/apps/mediaplayer/support/Notifier.h (revision 1214ef1b2100f2b3299fc9d8d6142e46f70a4c3f)
1 /*
2  * Copyright 2006-2007, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus <superstippi@gmx.de>
7  */
8 #ifndef NOTIFIER_H
9 #define NOTIFIER_H
10 
11 #include <List.h>
12 
13 class Listener;
14 
15 class Notifier {
16  public:
17 								Notifier();
18 	virtual						~Notifier();
19 
20 			bool				AddListener(Listener* listener);
21 			bool				RemoveListener(Listener* listener);
22 
23 			int32				CountListeners() const;
24 			Listener*			ListenerAtFast(int32 index) const;
25 
26 	 		void				Notify() const;
27 
28 			void				SuspendNotifications(bool suspend);
29 
30 			bool				HasPendingNotifications() const
31 									{ return fPendingNotifications; }
32 
33  private:
34 			BList				fListeners;
35 
36 			int32				fSuspended;
37 	mutable	bool				fPendingNotifications;
38 };
39 
40 class AutoNotificationSuspender {
41  public:
42 								AutoNotificationSuspender(Notifier* object)
43 									: fObject(object)
44 								{
45 									fObject->SuspendNotifications(true);
46 								}
47 
48 	virtual						~AutoNotificationSuspender()
49 								{
50 									fObject->SuspendNotifications(false);
51 								}
52  private:
53 			Notifier*			fObject;
54 };
55 
56 #endif // NOTIFIER_H
57