[Test] Added tests for CUtil::SplitParams
[xbmc.git] / xbmc / windowing / ios / WinEventsIOS.mm
blobb7844a8a3451e2ba386c7b449eefab720f562df0
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  */
9 #include "WinEventsIOS.h"
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"
18 #include <list>
19 #include <mutex>
21 static CCriticalSection g_inputCond;
23 static std::list<XBMC_Event> events;
25 bool CWinEventsIOS::MessagePump()
27   bool ret = false;
28   std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
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     }
45     if (appPort)
46       ret = appPort->OnEvent(pumpEvent);
47   }
48   return ret;
51 size_t CWinEventsIOS::GetQueueSize()
53   std::unique_lock<CCriticalSection> lock(g_inputCond);
54   return events.size();