| 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 "WinEventsIOS.h" |
| 10 |
|
| 11 |
#include "application/AppInboundProtocol.h" |
| 12 |
#include "guilib/GUIWindowManager.h" |
| 13 |
#include "input/InputManager.h" |
| 14 |
#include "input/keyboard/XBMC_vkeys.h" |
| 15 |
#include "threads/CriticalSection.h" |
| 16 |
#include "utils/log.h" |
| 17 |
|
| 18 |
#include <list> |
| 19 |
#include <mutex> |
| 20 |
|
| 21 |
static CCriticalSection g_inputCond; |
| 22 |
|
| 23 |
static std::list<XBMC_Event> events; |
| 24 |
|
| 25 |
bool CWinEventsIOS::MessagePump() |
| 26 |
{ |
| 27 |
bool ret = false; |
| 28 |
std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort(); |
| 29 |
|
| 30 |
// Do not always loop, only pump the initial queued count events. else if ui keep pushing |
| 31 |
// events the loop won't finish then it will block xbmc main message loop. |
| 32 |
for (size_t pumpEventCount = GetQueueSize(); pumpEventCount > 0; --pumpEventCount) |
| 33 |
{ |
| 34 |
// Pop up only one event per time since in App::OnEvent it may init modal dialog which init |
| 35 |
// deeper message loop and call the deeper MessagePump from there. |
| 36 |
XBMC_Event pumpEvent; |
| 37 |
{ |
| 38 |
std::unique_lock<CCriticalSection> lock(g_inputCond); |
| 39 |
if (events.empty()) |
| 40 |
return ret; |
| 41 |
pumpEvent = events.front(); |
| 42 |
events.pop_front(); |
| 43 |
} |
| 44 |
|
| 45 |
if (appPort) |
| 46 |
ret = appPort->OnEvent(pumpEvent); |
| 47 |
} |
| 48 |
return ret; |
| 49 |
} |
| 50 |
|
| 51 |
size_t CWinEventsIOS::GetQueueSize() |
| 52 |
{ |
| 53 |
std::unique_lock<CCriticalSection> lock(g_inputCond); |
| 54 |
return events.size(); |
| 55 |
} |