2 * Copyright (C) 2012-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "WinEventsTVOS.h"
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"
22 static CCriticalSection g_inputCond;
24 static std::list<XBMC_Event> events;
26 CWinEventsTVOS::CWinEventsTVOS() : CThread("CWinEventsTVOS")
28 CLog::Log(LOGDEBUG, "CWinEventsTVOS::CWinEventsTVOS");
32 CWinEventsTVOS::~CWinEventsTVOS()
38 void CWinEventsTVOS::MessagePush(XBMC_Event* newEvent)
40 std::unique_lock<CCriticalSection> lock(m_eventsCond);
42 m_events.push_back(*newEvent);
45 size_t CWinEventsTVOS::GetQueueSize()
47 std::unique_lock<CCriticalSection> lock(g_inputCond);
52 bool CWinEventsTVOS::MessagePump()
55 std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
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)
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.
65 std::unique_lock<CCriticalSection> lock(g_inputCond);
68 pumpEvent = events.front();
73 ret = appPort->OnEvent(pumpEvent);