1 /* 2 * Copyright 2009, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _TIMED_EVENT_QUEUE_H 6 #define _TIMED_EVENT_QUEUE_H 7 8 #include <MediaDefs.h> 9 10 struct _event_queue_imp; 11 12 13 struct media_timed_event { 14 media_timed_event(); 15 media_timed_event(bigtime_t inTime, 16 int32 inType); 17 media_timed_event(bigtime_t inTime, 18 int32 inType, void*inPointer, 19 uint32 inCleanup); 20 media_timed_event( 21 bigtime_t inTime, int32 inType, 22 void* inPointer, uint32 inCleanup, 23 int32 inData, int64 inBigdata, 24 char* inUserData, size_t dataSize = 0); 25 26 media_timed_event( 27 const media_timed_event& other); 28 29 ~media_timed_event(); 30 31 // TODO: Should this not return "media_timed_event&" ?! 32 void operator=(const media_timed_event& other); 33 34 bigtime_t event_time; 35 int32 type; 36 void* pointer; 37 uint32 cleanup; 38 int32 data; 39 int64 bigdata; 40 char user_data[64]; 41 bigtime_t enqueue_time; 42 43 uint32 _reserved_media_timed_event_[6]; 44 }; 45 46 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); 50 bool operator>(const media_timed_event& a, const media_timed_event&b); 51 52 53 /*! A priority queue for holding media_timed_events. Sorts by increasing time, 54 so events near the front of the queue are to occur earlier. 55 */ 56 class BTimedEventQueue { 57 public: 58 59 enum event_type { 60 B_NO_EVENT = -1, // Pushing this type will always fail. 61 B_ANY_EVENT = 0, // Pushing this type will always fail. 62 B_START, 63 B_STOP, 64 B_SEEK, 65 B_WARP, 66 B_TIMER, 67 B_HANDLE_BUFFER, 68 B_DATA_STATUS, 69 B_HARDWARE, 70 B_PARAMETER, 71 72 // User defined events are greater than this value. 73 B_USER_EVENT = 0x4000 74 }; 75 76 enum cleanup_flag { 77 B_NO_CLEANUP = 0, 78 B_RECYCLE_BUFFER, // Specifies to recycle buffers handled by 79 // BTimedEventQueue. 80 B_EXPIRE_TIMER, // Specifies to call TimerExpired() on the 81 // event->data. 82 B_USER_CLEANUP = 0x4000 83 }; 84 85 enum time_direction { 86 B_ALWAYS = -1, 87 B_BEFORE_TIME = 0, 88 B_AT_TIME, 89 B_AFTER_TIME 90 }; 91 92 93 void* operator new(size_t size); 94 void operator delete(void* ptr, size_t size); 95 96 BTimedEventQueue(); 97 virtual ~BTimedEventQueue(); 98 99 status_t AddEvent(const media_timed_event& event); 100 status_t RemoveEvent(const media_timed_event* event); 101 status_t RemoveFirstEvent( 102 media_timed_event* _event = NULL); 103 104 bool HasEvents() const; 105 int32 EventCount() const; 106 107 108 const media_timed_event* FirstEvent() const; 109 bigtime_t FirstEventTime() const; 110 const media_timed_event* LastEvent() const; 111 bigtime_t LastEventTime() const; 112 113 const media_timed_event* FindFirstMatch(bigtime_t eventTime, 114 time_direction direction, 115 bool inclusive = true, 116 int32 eventType = B_ANY_EVENT); 117 118 119 // Queue manipulation 120 // Call DoForEach to perform a function on each event in the queue. 121 // Return an appropriate status defining an action to take for that event. 122 // DoForEach is an atomic operation ensuring the consistency of the queue 123 // during the call. 124 enum queue_action { 125 B_DONE = -1, 126 B_NO_ACTION = 0, 127 B_REMOVE_EVENT, 128 B_RESORT_QUEUE 129 }; 130 typedef queue_action (*for_each_hook)(media_timed_event* event, 131 void* context); 132 133 status_t DoForEach(for_each_hook hook, void* context, 134 bigtime_t eventTime = 0, 135 time_direction direction = B_ALWAYS, 136 bool inclusive = true, 137 int32 eventType = B_ANY_EVENT); 138 139 140 // Flushing events 141 // The cleanup hook is called when events are flushed from the queue and 142 // the cleanup is not B_NO_CLEANUP or B_RECYCLE_BUFFER. 143 typedef void (*cleanup_hook)(const media_timed_event* event, 144 void* context); 145 void SetCleanupHook(cleanup_hook hook, 146 void* context); 147 status_t FlushEvents(bigtime_t eventTime, 148 time_direction direction, 149 bool inclusive = true, 150 int32 eventType = B_ANY_EVENT); 151 152 private: 153 // FBC padding and forbidden methods 154 BTimedEventQueue( 155 const BTimedEventQueue& other); 156 BTimedEventQueue& operator=(const BTimedEventQueue& other); 157 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 private: 184 _event_queue_imp* fImp; 185 186 uint32 _reserved_timed_event_queue_[6]; 187 }; 188 189 #endif 190