-
Notifications
You must be signed in to change notification settings - Fork 0
/
AampEventManager.h
213 lines (199 loc) · 5.68 KB
/
AampEventManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
* If not stated otherwise in this file or this component's license file the
* following copyright and licenses apply:
*
* Copyright 2021 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file AampEventManager.h
* @brief Event Handler for AAMP Player
*/
#ifndef AAMP_EVENT_MANAGER_H
#define AAMP_EVENT_MANAGER_H
#include "AampDefine.h"
#include "AampConfig.h"
#include "AampEvent.h"
#include "AampEventListener.h"
#include "AampLogManager.h"
#include "AampUtils.h"
#include <pthread.h>
#include <signal.h>
#include <mutex>
#include <queue>
#include <glib.h>
/**
* @struct ListenerData
* @brief Structure of the event listener list
*/
struct ListenerData {
EventListener* eventListener; /**< Event listener */
ListenerData* pNext; /**< Next listener */
};
/**
* @class AampEventManager
* @brief Class to Handle Aamp Events
*/
class AampEventManager
{
private:
bool mIsFakeTune; /**< Flag indicating if fake tune enabled or not */
bool mAsyncTuneEnabled; /**< Flag indicating if Async tune enabled or not */
PrivAAMPState mPlayerState; /**< Player state flag , updated only at start and Release */
pthread_mutex_t mMutexVar ; /**< Mutex variable to handle pending and dispatch operation */
int mEventPriority; /**< Async Event task Priority */
// Separate registration for each event
ListenerData* mEventListeners[AAMP_MAX_NUM_EVENTS]; /**< Event listener registration */
int mEventStats[AAMP_MAX_NUM_EVENTS]; /**< Event stats */
typedef std::queue<AAMPEventPtr> EventWorkerDataQ; /**< Event Queue for Async processing */
EventWorkerDataQ mEventWorkerDataQue;
typedef std::map<guint, bool> AsyncEventList; /**< Collection of Async tasks pending */
typedef std::map<guint, bool>::iterator AsyncEventListIter;
AsyncEventList mPendingAsyncEvents;
AampLogManager *mLogObj;
private:
/**
* @fn AsyncEvent
* @return void
*/
void AsyncEvent();
/**
* @fn GetSourceID
*/
guint GetSourceID();
/**
* @fn SetCallbackAsDispatched
* @param id - CallbackId for the IdleEvent
* @return void
*/
void SetCallbackAsDispatched(guint id);
/**
* @fn SetCallbackAsPending
* @param id - CallbackId for the IdleEvent
* @return void
*/
void SetCallbackAsPending(guint id);
/**
* @brief Thread entry function for Async Event Processing
*/
static gboolean EventManagerThreadFunction(gpointer This)
{
guint callbackId = g_source_get_id(g_main_current_source());
AampEventManager *evtMgr = (AampEventManager *)This;
evtMgr->SetCallbackAsDispatched(callbackId);
evtMgr->AsyncEvent();
return G_SOURCE_REMOVE ;
}
/**
* @fn SendEventAsync
* @param eventData - Event data
* @return void
*/
void SendEventAsync(const AAMPEventPtr &eventData);
/**
* @fn SendEventSync
* @param eventData - Event data
* @return void
*/
void SendEventSync(const AAMPEventPtr &eventData);
public:
/**
* @fn AampEventManager
* @return void
*/
AampEventManager(AampLogManager *logObj);
/**
* @fn ~AampEventManager
*/
~AampEventManager();
/**
* @fn SetFakeTuneFlag
* @param isFakeTuneSetting - True for FakeTune
* @return void
*/
void SetFakeTuneFlag(bool isFakeTuneSetting);
/**
* @fn SetAsyncTuneState
* @param isAsyncTuneSetting - True for Async tune
* @return void
*/
void SetAsyncTuneState(bool isAsyncTuneSetting);
/**
* @fn SetPlayerState
* @param state - Aamp Player state
* @return void
*/
void SetPlayerState(PrivAAMPState state);
/**
* @fn SendEvent
* @param eventData - Event data
* @param eventMode - Aamp Event mode
* @return void
*/
void SendEvent(const AAMPEventPtr &eventData, AAMPEventMode eventMode=AAMP_EVENT_DEFAULT_MODE);
/**
* @fn AddListenerForAllEvents
* @param eventListener - listerner for events
* @return void
*/
void AddListenerForAllEvents(EventListener* eventListener);
/**
* @fn RemoveListenerForAllEvents
* @param eventListener - listerner for events
* @return void
*/
void RemoveListenerForAllEvents(EventListener* eventListener);
/**
* @fn AddEventListener
* @param eventType - Aamp Event type
* @param eventListener - listerner for events
* @return void
*/
void AddEventListener(AAMPEventType eventType, EventListener* eventListener);
/**
* @fn RemoveEventListener
* @param eventType - Aamp Event type
* @param eventListener - listerner for events
* @return void
*/
void RemoveEventListener(AAMPEventType eventType, EventListener* eventListener);
/**
* @fn IsEventListenerAvailable - Check if any listners present for this event
* @param eventType - Aamp Event Type
* @return True if listner present
*/
bool IsEventListenerAvailable(AAMPEventType eventType);
/**
* @fn IsSpecificEventListenerAvailable
* @param eventType - Event Type
* @return True if listner present
*/
bool IsSpecificEventListenerAvailable(AAMPEventType eventType);
/**
* @fn FlushPendingEvents
* @return void
*/
void FlushPendingEvents();
/**
* @brief Copy constructor disabled
*
*/
AampEventManager(const AampEventManager&) = delete;
/**
* @brief assignment operator disabled
*
*/
AampEventManager& operator=(const AampEventManager&) = delete;
};
#endif