xref: /haiku/src/apps/mediaplayer/support/EventQueue.h (revision b55a57da7173b9af0432bd3e148d03f06161d036)
1 /*
2  * Copyright (c) 2000-2008, Ingo Weinhold <ingo_weinhold@gmx.de>,
3  * Copyright (c) 2000-2008, Stephan Aßmus <superstippi@gmx.de>,
4  * All Rights Reserved. Distributed under the terms of the MIT license.
5  */
6 #ifndef EVENT_QUEUE_H
7 #define EVENT_QUEUE_H
8 
9 
10 #include <List.h>
11 #include <Locker.h>
12 #include <OS.h>
13 
14 
15 class Event;
16 
17 
18 class EventQueue : public BLocker {
19  public:
20  								EventQueue();
21  	virtual						~EventQueue();
22 
23 			status_t			InitCheck();
24 
25 	static	EventQueue*			CreateDefault();
26 	static	void				DeleteDefault();
27 	static	EventQueue&			Default();
28 
29 			void				AddEvent(Event* event);
30 			bool				RemoveEvent(Event* event);
31 			void				ChangeEvent(Event* event,
32 									bigtime_t newTime);
33 
34  private:
35 			void				_AddEvent(Event* event);
36 			Event*				_EventAt(int32 index) const;
37 
38 	static	int32				_execute_events_(void *cookie);
39 			int32				_ExecuteEvents();
40 			void				_Reschedule();
41 
42 			BList				fEvents;
43 			thread_id			fEventExecutor;
44 			sem_id				fThreadControl;
45 	volatile bigtime_t			fNextEventTime;
46 			status_t			fStatus;
47 	static	EventQueue*			fDefaultQueue;
48 };
49 
50 #endif	// EVENT_QUEUE_H
51