| 1 |
/* |
| 2 |
* Copyright (C) 2012-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "WinEventsTVOS.h" |
| 10 |
|
| 11 |
#include "ServiceBroker.h" |
| 12 |
#include "application/AppInboundProtocol.h" |
| 13 |
#include "guilib/GUIWindowManager.h" |
| 14 |
#include "input/InputManager.h" |
| 15 |
#include "input/keyboard/XBMC_vkeys.h" |
| 16 |
#include "threads/CriticalSection.h" |
| 17 |
#include "utils/log.h" |
| 18 |
|
| 19 |
#include <list> |
| 20 |
#include <mutex> |
| 21 |
|
| 22 |
static CCriticalSection g_inputCond; |
| 23 |
|
| 24 |
static std::list<XBMC_Event> events; |
| 25 |
|
| 26 |
CWinEventsTVOS::CWinEventsTVOS() : CThread("CWinEventsTVOS") |
| 27 |
{ |
| 28 |
CLog::Log(LOGDEBUG, "CWinEventsTVOS::CWinEventsTVOS"); |
| 29 |
Create(); |
| 30 |
} |
| 31 |
|
| 32 |
CWinEventsTVOS::~CWinEventsTVOS() |
| 33 |
{ |
| 34 |
m_bStop = true; |
| 35 |
StopThread(true); |
| 36 |
} |
| 37 |
|
| 38 |
void CWinEventsTVOS::MessagePush(XBMC_Event* newEvent) |
| 39 |
{ |
| 40 |
std::unique_lock<CCriticalSection> lock(m_eventsCond); |
| 41 |
|
| 42 |
m_events.push_back(*newEvent); |
| 43 |
} |
| 44 |
|
| 45 |
size_t CWinEventsTVOS::GetQueueSize() |
| 46 |
{ |
| 47 |
std::unique_lock<CCriticalSection> lock(g_inputCond); |
| 48 |
return events.size(); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
bool CWinEventsTVOS::MessagePump() |
| 53 |
{ |
| 54 |
bool ret = false; |
| 55 |
std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort(); |
| 56 |
|
| 57 |
// Do not always loop, only pump the initial queued count events. else if ui keep pushing |
| 58 |
// events the loop won't finish then it will block xbmc main message loop. |
| 59 |
for (size_t pumpEventCount = GetQueueSize(); pumpEventCount > 0; --pumpEventCount) |
| 60 |
{ |
| 61 |
// Pop up only one event per time since in App::OnEvent it may init modal dialog which init |
| 62 |
// deeper message loop and call the deeper MessagePump from there. |
| 63 |
XBMC_Event pumpEvent; |
| 64 |
{ |
| 65 |
std::unique_lock<CCriticalSection> lock(g_inputCond); |
| 66 |
if (events.empty()) |
| 67 |
return ret; |
| 68 |
pumpEvent = events.front(); |
| 69 |
events.pop_front(); |
| 70 |
} |
| 71 |
|
| 72 |
if (appPort) |
| 73 |
ret = appPort->OnEvent(pumpEvent); |
| 74 |
} |
| 75 |
return ret; |
| 76 |
} |