1 /* 2 * Copyright 2009-2024, 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 9 #include <MediaDefs.h> 10 11 12 struct media_timed_event { 13 media_timed_event(); 14 media_timed_event(bigtime_t inTime, int32 inType); 15 media_timed_event(bigtime_t inTime, int32 inType, 16 void* inPointer, uint32 inCleanup); 17 media_timed_event(bigtime_t inTime, int32 inType, 18 void* inPointer, uint32 inCleanup, 19 int32 inData, int64 inBigdata, 20 const char* inUserData, size_t dataSize = 0); 21 22 media_timed_event( 23 const media_timed_event& other); 24 25 ~media_timed_event(); 26 27 void operator=(const media_timed_event& other); 28 29 public: 30 bigtime_t event_time; 31 int32 type; 32 void* pointer; 33 uint32 cleanup; 34 int32 data; 35 int64 bigdata; 36 char user_data[64]; 37 38 private: 39 uint32 _reserved_media_timed_event_[8]; 40 }; 41 42 43 bool operator==(const media_timed_event& a, const media_timed_event& b); 44 bool operator!=(const media_timed_event& a, const media_timed_event& b); 45 bool operator<(const media_timed_event& a, const media_timed_event& b); 46 bool operator>(const media_timed_event& a, const media_timed_event&b); 47 48 49 namespace BPrivate { 50 class TimedEventQueueData; 51 }; 52 53 class BTimedEventQueue { 54 public: 55 enum event_type { 56 B_NO_EVENT = -1, 57 B_ANY_EVENT = 0, 58 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 69 B_USER_EVENT = 0x4000 70 }; 71 72 enum cleanup_flag { 73 B_NO_CLEANUP = 0, 74 B_RECYCLE_BUFFER, 75 B_EXPIRE_TIMER, 76 B_USER_CLEANUP = 0x4000 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 public: 87 void* operator new(size_t size); 88 void operator delete(void* ptr, size_t size); 89 90 BTimedEventQueue(); 91 virtual ~BTimedEventQueue(); 92 93 typedef void (*cleanup_hook)(const media_timed_event* event, 94 void* context); 95 void SetCleanupHook(cleanup_hook hook, 96 void* context); 97 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); 102 103 bool HasEvents() const; 104 int32 EventCount() const; 105 106 const media_timed_event* FirstEvent() const; 107 bigtime_t FirstEventTime() const; 108 const media_timed_event* LastEvent() const; 109 bigtime_t LastEventTime() const; 110 111 const media_timed_event* FindFirstMatch(bigtime_t eventTime, 112 time_direction direction, 113 bool inclusive = true, 114 int32 eventType = B_ANY_EVENT); 115 116 enum queue_action { 117 B_DONE = -1, 118 B_NO_ACTION = 0, 119 B_REMOVE_EVENT, 120 B_RESORT_QUEUE 121 }; 122 typedef queue_action (*for_each_hook)(media_timed_event* event, 123 void* context); 124 125 status_t DoForEach(for_each_hook hook, void* context, 126 bigtime_t eventTime = 0, 127 time_direction direction = B_ALWAYS, 128 bool inclusive = true, 129 int32 eventType = B_ANY_EVENT); 130 131 status_t FlushEvents(bigtime_t eventTime, 132 time_direction direction, 133 bool inclusive = true, 134 int32 eventType = B_ANY_EVENT); 135 136 private: 137 // FBC padding and forbidden methods 138 virtual void _ReservedTimedEventQueue0(); 139 virtual void _ReservedTimedEventQueue1(); 140 virtual void _ReservedTimedEventQueue2(); 141 virtual void _ReservedTimedEventQueue3(); 142 virtual void _ReservedTimedEventQueue4(); 143 virtual void _ReservedTimedEventQueue5(); 144 virtual void _ReservedTimedEventQueue6(); 145 virtual void _ReservedTimedEventQueue7(); 146 virtual void _ReservedTimedEventQueue8(); 147 virtual void _ReservedTimedEventQueue9(); 148 virtual void _ReservedTimedEventQueue10(); 149 virtual void _ReservedTimedEventQueue11(); 150 virtual void _ReservedTimedEventQueue12(); 151 virtual void _ReservedTimedEventQueue13(); 152 virtual void _ReservedTimedEventQueue14(); 153 virtual void _ReservedTimedEventQueue15(); 154 virtual void _ReservedTimedEventQueue16(); 155 virtual void _ReservedTimedEventQueue17(); 156 virtual void _ReservedTimedEventQueue18(); 157 virtual void _ReservedTimedEventQueue19(); 158 virtual void _ReservedTimedEventQueue20(); 159 virtual void _ReservedTimedEventQueue21(); 160 virtual void _ReservedTimedEventQueue22(); 161 virtual void _ReservedTimedEventQueue23(); 162 163 BTimedEventQueue(const BTimedEventQueue&); 164 BTimedEventQueue& operator=(const BTimedEventQueue&); 165 166 private: 167 static int _Match(const media_timed_event& event, 168 bigtime_t eventTime, 169 time_direction direction, 170 bool inclusive, int32 eventType); 171 172 private: 173 BPrivate::TimedEventQueueData* fData; 174 175 uint32 _reserved[6]; 176 }; 177 178 179 #endif 180