xref: /haiku/headers/os/media/TimedEventQueue.h (revision 1e36cfc2721ef13a187c6f7354dc9cbc485e89d3)
1 /*******************************************************************************
2 /
3 /	File:			TimedEventQueue.h
4 /
5 /	Description:	A priority queue for holding media_timed_events.
6 /					Sorts by increasing time, so events near the front
7 /					of the queue are to occur earlier.
8 /
9 /	Copyright 1999, Be Incorporated, All Rights Reserved
10 /
11 *******************************************************************************/
12 
13 #ifndef _TIMED_EVENT_QUEUE_H
14 #define _TIMED_EVENT_QUEUE_H
15 
16 #include <MediaDefs.h>
17 
18 struct _event_queue_imp;
19 
20 
21 struct media_timed_event {
22 					media_timed_event();
23 					media_timed_event(bigtime_t inTime, int32 inType);
24 					media_timed_event(bigtime_t inTime, int32 inType,
25 						void *inPointer, uint32 inCleanup);
26 					media_timed_event(
27 						bigtime_t inTime, int32 inType,
28 						void *inPointer, uint32 inCleanup,
29 						int32 inData, int64 inBigdata,
30 						char *inUserData, size_t dataSize = 0);
31 
32 					media_timed_event(const media_timed_event & clone);
33 					void operator=(const media_timed_event & clone);
34 
35 					~media_timed_event();
36 
37 	bigtime_t		event_time;
38 	int32			type;
39 	void *			pointer;
40 	uint32			cleanup;
41 	int32			data;
42 	int64			bigdata;
43 	char			user_data[64];
44 	uint32			_reserved_media_timed_event_[8];
45 };
46 
47 _IMPEXP_MEDIA bool operator==(const media_timed_event & a, const media_timed_event & b);
48 _IMPEXP_MEDIA bool operator!=(const media_timed_event & a, const media_timed_event & b);
49 _IMPEXP_MEDIA bool operator<(const media_timed_event & a, const media_timed_event & b);
50 _IMPEXP_MEDIA bool operator>(const media_timed_event & a, const media_timed_event &b);
51 
52 
53 class BTimedEventQueue {
54 	public:
55 
56 		enum event_type {
57 			B_NO_EVENT = -1,		// never push this type! it will fail
58 			B_ANY_EVENT = 0,		// never push this type! it will fail
59 			B_START,
60 			B_STOP,
61 			B_SEEK,
62 			B_WARP,
63 			B_TIMER,
64 			B_HANDLE_BUFFER,
65 			B_DATA_STATUS,
66 			B_HARDWARE,
67 			B_PARAMETER,
68 			/* user defined events above this value */
69 			B_USER_EVENT = 0x4000
70 		};
71 
72 		enum cleanup_flag {
73 			B_NO_CLEANUP = 0,
74 			B_RECYCLE_BUFFER,		// recycle buffers handled by BTimedEventQueue
75 			B_EXPIRE_TIMER,			// call TimerExpired() on the event->data
76 			B_USER_CLEANUP = 0x4000	// others go to the cleanup func
77 		};
78 
79 		enum time_direction {
80 			B_ALWAYS = -1,
81 			B_BEFORE_TIME = 0,
82 			B_AT_TIME,
83 			B_AFTER_TIME
84 		};
85 
86 
87 		void * operator new(size_t s);
88 		void operator delete(void * p, size_t s);
89 
90 							BTimedEventQueue();
91 		virtual				~BTimedEventQueue();
92 
93 		status_t			AddEvent(const media_timed_event &event);
94 		status_t			RemoveEvent(const media_timed_event *event);
95 		status_t  			RemoveFirstEvent(media_timed_event * outEvent = NULL);
96 
97 		bool				HasEvents() const;
98 		int32				EventCount() const;
99 
100 		/* Accessors */
101 		const media_timed_event *	FirstEvent() const;
102 		bigtime_t					FirstEventTime() const;
103 		const media_timed_event *	LastEvent() const;
104 		bigtime_t					LastEventTime() const;
105 
106 		const media_timed_event *	FindFirstMatch(
107 										bigtime_t eventTime,
108 										time_direction direction,
109 										bool inclusive = true,
110 										int32 eventType = B_ANY_EVENT);
111 
112 
113 		/* queue manipulation */
114 		/* call DoForEach to perform a function on each event in the */
115 		/* queue.  Return an appropriate status defining an action to take */
116 		/* for that event.  DoForEach is an atomic operation ensuring the */
117 		/* consistency of the queue during the call. */
118 		enum queue_action {
119 			B_DONE = -1,
120 			B_NO_ACTION = 0,
121 			B_REMOVE_EVENT,
122 			B_RESORT_QUEUE
123 		};
124 		typedef queue_action (*for_each_hook)(media_timed_event *event, void *context);
125 
126 		status_t			DoForEach(
127 								for_each_hook hook,
128 								void *context,
129 								bigtime_t eventTime = 0,
130 								time_direction direction = B_ALWAYS,
131 								bool inclusive = true,
132 								int32 eventType = B_ANY_EVENT);
133 
134 
135 		/* flushing events */
136 		/* the cleanup hook is called when events are flushed from the queue */
137 		/* and the cleanup is not B_NO_CLEANUP or B_RECYCLE_BUFFER */
138 		typedef void (*cleanup_hook)(const media_timed_event *event, void * context);
139 		void				SetCleanupHook(cleanup_hook hook, void *context);
140 		status_t			FlushEvents(
141 								bigtime_t eventTime,
142 								time_direction direction,
143 								bool inclusive = true,
144 								int32 eventType = B_ANY_EVENT);
145 
146 
147 	private:
148 							BTimedEventQueue(					//unimplemented
149 								const BTimedEventQueue & other);
150 							BTimedEventQueue &operator =(		//unimplemented
151 								const BTimedEventQueue & other);
152 
153 
154 		/* hide actual queue implementation */
155 		_event_queue_imp *	fImp;
156 
157 		/* Mmmh, stuffing! */
158 		virtual	status_t 	_Reserved_BTimedEventQueue_0(void *, ...);
159 		virtual	status_t 	_Reserved_BTimedEventQueue_1(void *, ...);
160 		virtual	status_t 	_Reserved_BTimedEventQueue_2(void *, ...);
161 		virtual	status_t 	_Reserved_BTimedEventQueue_3(void *, ...);
162 		virtual	status_t 	_Reserved_BTimedEventQueue_4(void *, ...);
163 		virtual	status_t 	_Reserved_BTimedEventQueue_5(void *, ...);
164 		virtual	status_t 	_Reserved_BTimedEventQueue_6(void *, ...);
165 		virtual	status_t 	_Reserved_BTimedEventQueue_7(void *, ...);
166 		virtual	status_t 	_Reserved_BTimedEventQueue_8(void *, ...);
167 		virtual	status_t 	_Reserved_BTimedEventQueue_9(void *, ...);
168 		virtual	status_t 	_Reserved_BTimedEventQueue_10(void *, ...);
169 		virtual	status_t 	_Reserved_BTimedEventQueue_11(void *, ...);
170 		virtual	status_t 	_Reserved_BTimedEventQueue_12(void *, ...);
171 		virtual	status_t 	_Reserved_BTimedEventQueue_13(void *, ...);
172 		virtual	status_t 	_Reserved_BTimedEventQueue_14(void *, ...);
173 		virtual	status_t 	_Reserved_BTimedEventQueue_15(void *, ...);
174 		virtual	status_t 	_Reserved_BTimedEventQueue_16(void *, ...);
175 		virtual	status_t 	_Reserved_BTimedEventQueue_17(void *, ...);
176 		virtual	status_t 	_Reserved_BTimedEventQueue_18(void *, ...);
177 		virtual	status_t 	_Reserved_BTimedEventQueue_19(void *, ...);
178 		virtual	status_t 	_Reserved_BTimedEventQueue_20(void *, ...);
179 		virtual	status_t 	_Reserved_BTimedEventQueue_21(void *, ...);
180 		virtual	status_t 	_Reserved_BTimedEventQueue_22(void *, ...);
181 		virtual	status_t 	_Reserved_BTimedEventQueue_23(void *, ...);
182 
183 		uint32 				_reserved_timed_event_queue_[6];
184 };
185 
186 #endif
187