2 * Copyright 2009, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 #ifndef _TIMED_EVENT_QUEUE_H
6 #define _TIMED_EVENT_QUEUE_H
10 struct _event_queue_imp
;
13 struct media_timed_event
{
15 media_timed_event(bigtime_t inTime
,
17 media_timed_event(bigtime_t inTime
,
18 int32 inType
, void*inPointer
,
21 bigtime_t inTime
, int32 inType
,
22 void* inPointer
, uint32 inCleanup
,
23 int32 inData
, int64 inBigdata
,
24 char* inUserData
, size_t dataSize
= 0);
27 const media_timed_event
& other
);
31 // TODO: Should this not return "media_timed_event&" ?!
32 void operator=(const media_timed_event
& other
);
42 uint32 _reserved_media_timed_event_
[8];
46 bool operator==(const media_timed_event
& a
, const media_timed_event
& b
);
47 bool operator!=(const media_timed_event
& a
, const media_timed_event
& b
);
48 bool operator<(const media_timed_event
& a
, const media_timed_event
& b
);
49 bool operator>(const media_timed_event
& a
, const media_timed_event
&b
);
52 /*! A priority queue for holding media_timed_events. Sorts by increasing time,
53 so events near the front of the queue are to occur earlier.
55 class BTimedEventQueue
{
59 B_NO_EVENT
= -1, // Pushing this type will always fail.
60 B_ANY_EVENT
= 0, // Pushing this type will always fail.
71 // User defined events are greater than this value.
77 B_RECYCLE_BUFFER
, // Specifies to recycle buffers handled by
79 B_EXPIRE_TIMER
, // Specifies to call TimerExpired() on the
81 B_USER_CLEANUP
= 0x4000
92 void* operator new(size_t size
);
93 void operator delete(void* ptr
, size_t size
);
96 virtual ~BTimedEventQueue();
98 status_t
AddEvent(const media_timed_event
& event
);
99 status_t
RemoveEvent(const media_timed_event
* event
);
100 status_t
RemoveFirstEvent(
101 media_timed_event
* _event
= NULL
);
103 bool HasEvents() const;
104 int32
EventCount() const;
107 const media_timed_event
* FirstEvent() const;
108 bigtime_t
FirstEventTime() const;
109 const media_timed_event
* LastEvent() const;
110 bigtime_t
LastEventTime() const;
112 const media_timed_event
* FindFirstMatch(bigtime_t eventTime
,
113 time_direction direction
,
114 bool inclusive
= true,
115 int32 eventType
= B_ANY_EVENT
);
118 // Queue manipulation
119 // Call DoForEach to perform a function on each event in the queue.
120 // Return an appropriate status defining an action to take for that event.
121 // DoForEach is an atomic operation ensuring the consistency of the queue
129 typedef queue_action (*for_each_hook
)(media_timed_event
* event
,
132 status_t
DoForEach(for_each_hook hook
, void* context
,
133 bigtime_t eventTime
= 0,
134 time_direction direction
= B_ALWAYS
,
135 bool inclusive
= true,
136 int32 eventType
= B_ANY_EVENT
);
140 // The cleanup hook is called when events are flushed from the queue and
141 // the cleanup is not B_NO_CLEANUP or B_RECYCLE_BUFFER.
142 typedef void (*cleanup_hook
)(const media_timed_event
* event
,
144 void SetCleanupHook(cleanup_hook hook
,
146 status_t
FlushEvents(bigtime_t eventTime
,
147 time_direction direction
,
148 bool inclusive
= true,
149 int32 eventType
= B_ANY_EVENT
);
152 // FBC padding and forbidden methods
154 const BTimedEventQueue
& other
);
155 BTimedEventQueue
& operator=(const BTimedEventQueue
& other
);
157 virtual status_t
_Reserved_BTimedEventQueue_0(void*, ...);
158 virtual status_t
_Reserved_BTimedEventQueue_1(void*, ...);
159 virtual status_t
_Reserved_BTimedEventQueue_2(void*, ...);
160 virtual status_t
_Reserved_BTimedEventQueue_3(void*, ...);
161 virtual status_t
_Reserved_BTimedEventQueue_4(void*, ...);
162 virtual status_t
_Reserved_BTimedEventQueue_5(void*, ...);
163 virtual status_t
_Reserved_BTimedEventQueue_6(void*, ...);
164 virtual status_t
_Reserved_BTimedEventQueue_7(void*, ...);
165 virtual status_t
_Reserved_BTimedEventQueue_8(void*, ...);
166 virtual status_t
_Reserved_BTimedEventQueue_9(void*, ...);
167 virtual status_t
_Reserved_BTimedEventQueue_10(void*, ...);
168 virtual status_t
_Reserved_BTimedEventQueue_11(void*, ...);
169 virtual status_t
_Reserved_BTimedEventQueue_12(void*, ...);
170 virtual status_t
_Reserved_BTimedEventQueue_13(void*, ...);
171 virtual status_t
_Reserved_BTimedEventQueue_14(void*, ...);
172 virtual status_t
_Reserved_BTimedEventQueue_15(void*, ...);
173 virtual status_t
_Reserved_BTimedEventQueue_16(void*, ...);
174 virtual status_t
_Reserved_BTimedEventQueue_17(void*, ...);
175 virtual status_t
_Reserved_BTimedEventQueue_18(void*, ...);
176 virtual status_t
_Reserved_BTimedEventQueue_19(void*, ...);
177 virtual status_t
_Reserved_BTimedEventQueue_20(void*, ...);
178 virtual status_t
_Reserved_BTimedEventQueue_21(void*, ...);
179 virtual status_t
_Reserved_BTimedEventQueue_22(void*, ...);
180 virtual status_t
_Reserved_BTimedEventQueue_23(void*, ...);
183 _event_queue_imp
* fImp
;
185 uint32 _reserved_timed_event_queue_
[6];