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