1/***********************************************************************
2 * AUTHOR: Marcus Overhagen
3 *   FILE: TimedEventQueuePrivate.cpp
4 *  DESCR: implements _event_queue_imp used by BTimedEventQueue,
5 *         not thread save!
6 ***********************************************************************/
7
8#ifndef _TIMED_EVENT_QUEUE_PRIVATE_H
9#define _TIMED_EVENT_QUEUE_PRIVATE_H
10
11#include <MediaDefs.h>
12#include <Locker.h>
13#include "MediaDebug.h"
14
15struct _event_queue_imp
16{
17	_event_queue_imp();
18	~_event_queue_imp();
19
20	status_t	AddEvent(const media_timed_event &event);
21	status_t	RemoveEvent(const media_timed_event *event);
22	status_t  	RemoveFirstEvent(media_timed_event * outEvent);
23
24	bool		HasEvents() const;
25	int32		EventCount() const;
26
27	const media_timed_event *	FirstEvent() const;
28	bigtime_t					FirstEventTime() const;
29	const media_timed_event *	LastEvent() const;
30	bigtime_t					LastEventTime() const;
31
32	const media_timed_event *	FindFirstMatch(
33									bigtime_t eventTime,
34									BTimedEventQueue::time_direction direction,
35									bool inclusive,
36									int32 eventType);
37
38	status_t	DoForEach(
39					BTimedEventQueue::for_each_hook hook,
40					void *context,
41					bigtime_t eventTime,
42					BTimedEventQueue::time_direction direction,
43					bool inclusive,
44					int32 eventType);
45
46	void		SetCleanupHook(BTimedEventQueue::cleanup_hook hook, void *context);
47	status_t	FlushEvents(
48					bigtime_t eventTime,
49					BTimedEventQueue::time_direction direction,
50					bool inclusive,
51					int32 eventType);
52
53#if DEBUG > 1
54	void		Dump() const;
55#endif
56
57private:
58	struct event_queue_entry
59	{
60		struct event_queue_entry *prev;
61		struct event_queue_entry *next;
62		media_timed_event event;
63	};
64
65	void RemoveEntry(event_queue_entry *entry);
66	void CleanupEvent(media_timed_event *event);
67
68	event_queue_entry *GetEnd_BeforeTime(bigtime_t eventTime, bool inclusive);
69	event_queue_entry *GetStart_AfterTime(bigtime_t eventTime, bool inclusive);
70
71	BLocker *			fLock;
72	int32				fEventCount;
73	event_queue_entry 	*fFirstEntry;
74	event_queue_entry 	*fLastEntry;
75	void * 				fCleanupHookContext;
76	BTimedEventQueue::cleanup_hook 	fCleanupHook;
77};
78
79#endif //_TIMED_EVENT_QUEUE_PRIVATE_H
80