[Test] Added tests for CUtil::SplitParams
[xbmc.git] / xbmc / ServiceBroker.cpp
blobfbcadb605322bd0ff9d5595706e3012f56a55022
1 /*
2 * Copyright (C) 2005-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.
7 */
9 #include "ServiceBroker.h"
11 #include "ServiceManager.h"
12 #include "application/Application.h"
13 #include "profiles/ProfileManager.h"
14 #include "settings/SettingsComponent.h"
15 #include "utils/log.h"
16 #include "windowing/WinSystem.h"
18 #include <stdexcept>
19 #include <utility>
21 using namespace KODI;
23 CServiceBroker::CServiceBroker()
27 CServiceBroker::~CServiceBroker()
31 std::shared_ptr<CAppParams> CServiceBroker::GetAppParams()
33 if (!g_serviceBroker.m_appParams)
34 throw std::logic_error("AppParams not yet available / not available anymore.");
36 return g_serviceBroker.m_appParams;
39 void CServiceBroker::RegisterAppParams(const std::shared_ptr<CAppParams>& appParams)
41 g_serviceBroker.m_appParams = appParams;
44 void CServiceBroker::UnregisterAppParams()
46 g_serviceBroker.m_appParams.reset();
49 CLog& CServiceBroker::GetLogging()
51 return *(g_serviceBroker.m_logging);
54 void CServiceBroker::CreateLogging()
56 g_serviceBroker.m_logging = std::make_unique<CLog>();
59 bool CServiceBroker::IsLoggingUp()
61 return g_serviceBroker.m_logging ? true : false;
64 void CServiceBroker::DestroyLogging()
66 g_serviceBroker.m_logging.reset();
69 // announcement
70 std::shared_ptr<ANNOUNCEMENT::CAnnouncementManager> CServiceBroker::GetAnnouncementManager()
72 return g_serviceBroker.m_pAnnouncementManager;
74 void CServiceBroker::RegisterAnnouncementManager(
75 std::shared_ptr<ANNOUNCEMENT::CAnnouncementManager> port)
77 g_serviceBroker.m_pAnnouncementManager = std::move(port);
80 void CServiceBroker::UnregisterAnnouncementManager()
82 g_serviceBroker.m_pAnnouncementManager.reset();
85 ADDON::CAddonMgr& CServiceBroker::GetAddonMgr()
87 return g_application.m_ServiceManager->GetAddonMgr();
90 ADDON::CBinaryAddonManager& CServiceBroker::GetBinaryAddonManager()
92 return g_application.m_ServiceManager->GetBinaryAddonManager();
95 ADDON::CBinaryAddonCache& CServiceBroker::GetBinaryAddonCache()
97 return g_application.m_ServiceManager->GetBinaryAddonCache();
100 ADDONS::CExtsMimeSupportList& CServiceBroker::GetExtsMimeSupportList()
102 return g_application.m_ServiceManager->GetExtsMimeSupportList();
105 ADDON::CVFSAddonCache& CServiceBroker::GetVFSAddonCache()
107 return g_application.m_ServiceManager->GetVFSAddonCache();
110 #ifdef HAS_PYTHON
111 XBPython& CServiceBroker::GetXBPython()
113 return g_application.m_ServiceManager->GetXBPython();
115 #endif
117 #if defined(HAS_FILESYSTEM_SMB)
118 WSDiscovery::IWSDiscovery& CServiceBroker::GetWSDiscovery()
120 return g_application.m_ServiceManager->GetWSDiscovery();
122 #endif
124 #if !defined(TARGET_WINDOWS) && defined(HAS_OPTICAL_DRIVE)
125 MEDIA_DETECT::CDetectDVDMedia& CServiceBroker::GetDetectDVDMedia()
127 return g_application.m_ServiceManager->GetDetectDVDMedia();
129 #endif
131 PVR::CPVRManager& CServiceBroker::GetPVRManager()
133 return g_application.m_ServiceManager->GetPVRManager();
136 CContextMenuManager& CServiceBroker::GetContextMenuManager()
138 return g_application.m_ServiceManager->GetContextMenuManager();
141 CDataCacheCore& CServiceBroker::GetDataCacheCore()
143 return g_application.m_ServiceManager->GetDataCacheCore();
146 CPlatform& CServiceBroker::GetPlatform()
148 return g_application.m_ServiceManager->GetPlatform();
151 PLAYLIST::CPlayListPlayer& CServiceBroker::GetPlaylistPlayer()
153 return g_application.m_ServiceManager->GetPlaylistPlayer();
156 void CServiceBroker::RegisterSettingsComponent(const std::shared_ptr<CSettingsComponent>& settings)
158 g_serviceBroker.m_pSettingsComponent = settings;
161 void CServiceBroker::UnregisterSettingsComponent()
163 g_serviceBroker.m_pSettingsComponent.reset();
166 std::shared_ptr<CSettingsComponent> CServiceBroker::GetSettingsComponent()
168 return g_serviceBroker.m_pSettingsComponent;
171 GAME::CControllerManager& CServiceBroker::GetGameControllerManager()
173 return g_application.m_ServiceManager->GetGameControllerManager();
176 GAME::CGameServices& CServiceBroker::GetGameServices()
178 return g_application.m_ServiceManager->GetGameServices();
181 KODI::RETRO::CGUIGameRenderManager& CServiceBroker::GetGameRenderManager()
183 return g_application.m_ServiceManager->GetGameRenderManager();
186 PERIPHERALS::CPeripherals& CServiceBroker::GetPeripherals()
188 return g_application.m_ServiceManager->GetPeripherals();
191 CFavouritesService& CServiceBroker::GetFavouritesService()
193 return g_application.m_ServiceManager->GetFavouritesService();
196 ADDON::CServiceAddonManager& CServiceBroker::GetServiceAddons()
198 return g_application.m_ServiceManager->GetServiceAddons();
201 ADDON::CRepositoryUpdater& CServiceBroker::GetRepositoryUpdater()
203 return g_application.m_ServiceManager->GetRepositoryUpdater();
206 CInputManager& CServiceBroker::GetInputManager()
208 return g_application.m_ServiceManager->GetInputManager();
211 CFileExtensionProvider& CServiceBroker::GetFileExtensionProvider()
213 return g_application.m_ServiceManager->GetFileExtensionProvider();
216 CNetworkBase& CServiceBroker::GetNetwork()
218 return g_application.m_ServiceManager->GetNetwork();
221 bool CServiceBroker::IsAddonInterfaceUp()
223 return g_application.m_ServiceManager && g_application.m_ServiceManager->init_level > 1;
226 bool CServiceBroker::IsServiceManagerUp()
228 return g_application.m_ServiceManager && g_application.m_ServiceManager->init_level == 3;
231 CWinSystemBase* CServiceBroker::GetWinSystem()
233 return g_serviceBroker.m_pWinSystem;
236 void CServiceBroker::RegisterWinSystem(CWinSystemBase* winsystem)
238 g_serviceBroker.m_pWinSystem = winsystem;
241 void CServiceBroker::UnregisterWinSystem()
243 g_serviceBroker.m_pWinSystem = nullptr;
246 CRenderSystemBase* CServiceBroker::GetRenderSystem()
248 if (g_serviceBroker.m_pWinSystem)
249 return g_serviceBroker.m_pWinSystem->GetRenderSystem();
251 return nullptr;
254 CPowerManager& CServiceBroker::GetPowerManager()
256 return g_application.m_ServiceManager->GetPowerManager();
259 CWeatherManager& CServiceBroker::GetWeatherManager()
261 return g_application.m_ServiceManager->GetWeatherManager();
264 CPlayerCoreFactory& CServiceBroker::GetPlayerCoreFactory()
266 return g_application.m_ServiceManager->GetPlayerCoreFactory();
269 CDatabaseManager& CServiceBroker::GetDatabaseManager()
271 return g_application.m_ServiceManager->GetDatabaseManager();
274 CSlideShowDelegator& CServiceBroker::GetSlideShowDelegator()
276 return g_application.m_ServiceManager->GetSlideShowDelegator();
279 CEventLog* CServiceBroker::GetEventLog()
281 if (!g_serviceBroker.m_pSettingsComponent)
282 return nullptr;
284 auto profileManager = g_serviceBroker.m_pSettingsComponent->GetProfileManager();
285 if (!profileManager)
286 return nullptr;
288 return &profileManager->GetEventLog();
291 CMediaManager& CServiceBroker::GetMediaManager()
293 return g_application.m_ServiceManager->GetMediaManager();
296 CApplicationComponents& CServiceBroker::GetAppComponents()
298 return g_application;
301 CGUIComponent* CServiceBroker::GetGUI()
303 return g_serviceBroker.m_pGUI;
306 void CServiceBroker::RegisterGUI(CGUIComponent* gui)
308 g_serviceBroker.m_pGUI = gui;
311 void CServiceBroker::UnregisterGUI()
313 g_serviceBroker.m_pGUI = nullptr;
316 // audio
317 IAE* CServiceBroker::GetActiveAE()
319 return g_serviceBroker.m_pActiveAE;
321 void CServiceBroker::RegisterAE(IAE* ae)
323 g_serviceBroker.m_pActiveAE = ae;
325 void CServiceBroker::UnregisterAE()
327 g_serviceBroker.m_pActiveAE = nullptr;
330 // application
331 std::shared_ptr<CAppInboundProtocol> CServiceBroker::GetAppPort()
333 return g_serviceBroker.m_pAppPort;
335 void CServiceBroker::RegisterAppPort(std::shared_ptr<CAppInboundProtocol> port)
337 g_serviceBroker.m_pAppPort = std::move(port);
339 void CServiceBroker::UnregisterAppPort()
341 g_serviceBroker.m_pAppPort.reset();
344 void CServiceBroker::RegisterDecoderFilterManager(CDecoderFilterManager* manager)
346 g_serviceBroker.m_decoderFilterManager = manager;
349 CDecoderFilterManager* CServiceBroker::GetDecoderFilterManager()
351 return g_serviceBroker.m_decoderFilterManager;
354 std::shared_ptr<CCPUInfo> CServiceBroker::GetCPUInfo()
356 return g_serviceBroker.m_cpuInfo;
359 void CServiceBroker::RegisterCPUInfo(std::shared_ptr<CCPUInfo> cpuInfo)
361 g_serviceBroker.m_cpuInfo = std::move(cpuInfo);
364 void CServiceBroker::UnregisterCPUInfo()
366 g_serviceBroker.m_cpuInfo.reset();
369 void CServiceBroker::RegisterTextureCache(const std::shared_ptr<CTextureCache>& cache)
371 g_serviceBroker.m_textureCache = cache;
374 void CServiceBroker::UnregisterTextureCache()
376 g_serviceBroker.m_textureCache.reset();
379 std::shared_ptr<CTextureCache> CServiceBroker::GetTextureCache()
381 return g_serviceBroker.m_textureCache;
384 void CServiceBroker::RegisterJobManager(const std::shared_ptr<CJobManager>& jobManager)
386 g_serviceBroker.m_jobManager = jobManager;
389 void CServiceBroker::UnregisterJobManager()
391 g_serviceBroker.m_jobManager.reset();
394 std::shared_ptr<CJobManager> CServiceBroker::GetJobManager()
396 return g_serviceBroker.m_jobManager;
399 void CServiceBroker::RegisterAppMessenger(
400 const std::shared_ptr<KODI::MESSAGING::CApplicationMessenger>& appMessenger)
402 g_serviceBroker.m_appMessenger = appMessenger;
405 void CServiceBroker::UnregisterAppMessenger()
407 g_serviceBroker.m_appMessenger.reset();
410 std::shared_ptr<KODI::MESSAGING::CApplicationMessenger> CServiceBroker::GetAppMessenger()
412 return g_serviceBroker.m_appMessenger;
415 void CServiceBroker::RegisterKeyboardLayoutManager(
416 const std::shared_ptr<KEYBOARD::CKeyboardLayoutManager>& keyboardLayoutManager)
418 g_serviceBroker.m_keyboardLayoutManager = keyboardLayoutManager;
421 void CServiceBroker::UnregisterKeyboardLayoutManager()
423 g_serviceBroker.m_keyboardLayoutManager.reset();
426 std::shared_ptr<KEYBOARD::CKeyboardLayoutManager> CServiceBroker::GetKeyboardLayoutManager()
428 return g_serviceBroker.m_keyboardLayoutManager;
431 void CServiceBroker::RegisterSpeechRecognition(
432 const std::shared_ptr<speech::ISpeechRecognition>& speechRecognition)
434 g_serviceBroker.m_speechRecognition = speechRecognition;
437 void CServiceBroker::UnregisterSpeechRecognition()
439 g_serviceBroker.m_speechRecognition.reset();
442 std::shared_ptr<speech::ISpeechRecognition> CServiceBroker::GetSpeechRecognition()
444 return g_serviceBroker.m_speechRecognition;