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.
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"
23 CServiceBroker::CServiceBroker()
24 : m_pGUI(nullptr), m_pWinSystem(nullptr), m_pActiveAE(nullptr), m_decoderFilterManager(nullptr)
28 CServiceBroker::~CServiceBroker()
32 std::shared_ptr
<CAppParams
> CServiceBroker::GetAppParams()
34 if (!g_serviceBroker
.m_appParams
)
35 throw std::logic_error("AppParams not yet available / not available anymore.");
37 return g_serviceBroker
.m_appParams
;
40 void CServiceBroker::RegisterAppParams(const std::shared_ptr
<CAppParams
>& appParams
)
42 g_serviceBroker
.m_appParams
= appParams
;
45 void CServiceBroker::UnregisterAppParams()
47 g_serviceBroker
.m_appParams
.reset();
50 CLog
& CServiceBroker::GetLogging()
52 return *(g_serviceBroker
.m_logging
);
55 void CServiceBroker::CreateLogging()
57 g_serviceBroker
.m_logging
= std::make_unique
<CLog
>();
60 void CServiceBroker::DestroyLogging()
62 g_serviceBroker
.m_logging
.reset();
66 std::shared_ptr
<ANNOUNCEMENT::CAnnouncementManager
> CServiceBroker::GetAnnouncementManager()
68 return g_serviceBroker
.m_pAnnouncementManager
;
70 void CServiceBroker::RegisterAnnouncementManager(
71 std::shared_ptr
<ANNOUNCEMENT::CAnnouncementManager
> port
)
73 g_serviceBroker
.m_pAnnouncementManager
= std::move(port
);
76 void CServiceBroker::UnregisterAnnouncementManager()
78 g_serviceBroker
.m_pAnnouncementManager
.reset();
81 ADDON::CAddonMgr
& CServiceBroker::GetAddonMgr()
83 return g_application
.m_ServiceManager
->GetAddonMgr();
86 ADDON::CBinaryAddonManager
& CServiceBroker::GetBinaryAddonManager()
88 return g_application
.m_ServiceManager
->GetBinaryAddonManager();
91 ADDON::CBinaryAddonCache
& CServiceBroker::GetBinaryAddonCache()
93 return g_application
.m_ServiceManager
->GetBinaryAddonCache();
96 ADDONS::CExtsMimeSupportList
& CServiceBroker::GetExtsMimeSupportList()
98 return g_application
.m_ServiceManager
->GetExtsMimeSupportList();
101 ADDON::CVFSAddonCache
& CServiceBroker::GetVFSAddonCache()
103 return g_application
.m_ServiceManager
->GetVFSAddonCache();
107 XBPython
& CServiceBroker::GetXBPython()
109 return g_application
.m_ServiceManager
->GetXBPython();
113 #if defined(HAS_FILESYSTEM_SMB)
114 WSDiscovery::IWSDiscovery
& CServiceBroker::GetWSDiscovery()
116 return g_application
.m_ServiceManager
->GetWSDiscovery();
120 #if !defined(TARGET_WINDOWS) && defined(HAS_DVD_DRIVE)
121 MEDIA_DETECT::CDetectDVDMedia
& CServiceBroker::GetDetectDVDMedia()
123 return g_application
.m_ServiceManager
->GetDetectDVDMedia();
127 PVR::CPVRManager
& CServiceBroker::GetPVRManager()
129 return g_application
.m_ServiceManager
->GetPVRManager();
132 CContextMenuManager
& CServiceBroker::GetContextMenuManager()
134 return g_application
.m_ServiceManager
->GetContextMenuManager();
137 CDataCacheCore
& CServiceBroker::GetDataCacheCore()
139 return g_application
.m_ServiceManager
->GetDataCacheCore();
142 CPlatform
& CServiceBroker::GetPlatform()
144 return g_application
.m_ServiceManager
->GetPlatform();
147 PLAYLIST::CPlayListPlayer
& CServiceBroker::GetPlaylistPlayer()
149 return g_application
.m_ServiceManager
->GetPlaylistPlayer();
152 void CServiceBroker::RegisterSettingsComponent(const std::shared_ptr
<CSettingsComponent
>& settings
)
154 g_serviceBroker
.m_pSettingsComponent
= settings
;
157 void CServiceBroker::UnregisterSettingsComponent()
159 g_serviceBroker
.m_pSettingsComponent
.reset();
162 std::shared_ptr
<CSettingsComponent
> CServiceBroker::GetSettingsComponent()
164 return g_serviceBroker
.m_pSettingsComponent
;
167 GAME::CControllerManager
& CServiceBroker::GetGameControllerManager()
169 return g_application
.m_ServiceManager
->GetGameControllerManager();
172 GAME::CGameServices
& CServiceBroker::GetGameServices()
174 return g_application
.m_ServiceManager
->GetGameServices();
177 KODI::RETRO::CGUIGameRenderManager
& CServiceBroker::GetGameRenderManager()
179 return g_application
.m_ServiceManager
->GetGameRenderManager();
182 PERIPHERALS::CPeripherals
& CServiceBroker::GetPeripherals()
184 return g_application
.m_ServiceManager
->GetPeripherals();
187 CFavouritesService
& CServiceBroker::GetFavouritesService()
189 return g_application
.m_ServiceManager
->GetFavouritesService();
192 ADDON::CServiceAddonManager
& CServiceBroker::GetServiceAddons()
194 return g_application
.m_ServiceManager
->GetServiceAddons();
197 ADDON::CRepositoryUpdater
& CServiceBroker::GetRepositoryUpdater()
199 return g_application
.m_ServiceManager
->GetRepositoryUpdater();
202 CInputManager
& CServiceBroker::GetInputManager()
204 return g_application
.m_ServiceManager
->GetInputManager();
207 CFileExtensionProvider
& CServiceBroker::GetFileExtensionProvider()
209 return g_application
.m_ServiceManager
->GetFileExtensionProvider();
212 CNetworkBase
& CServiceBroker::GetNetwork()
214 return g_application
.m_ServiceManager
->GetNetwork();
217 bool CServiceBroker::IsAddonInterfaceUp()
219 return g_application
.m_ServiceManager
&& g_application
.m_ServiceManager
->init_level
> 1;
222 bool CServiceBroker::IsServiceManagerUp()
224 return g_application
.m_ServiceManager
&& g_application
.m_ServiceManager
->init_level
== 3;
227 CWinSystemBase
* CServiceBroker::GetWinSystem()
229 return g_serviceBroker
.m_pWinSystem
;
232 void CServiceBroker::RegisterWinSystem(CWinSystemBase
* winsystem
)
234 g_serviceBroker
.m_pWinSystem
= winsystem
;
237 void CServiceBroker::UnregisterWinSystem()
239 g_serviceBroker
.m_pWinSystem
= nullptr;
242 CRenderSystemBase
* CServiceBroker::GetRenderSystem()
244 if (g_serviceBroker
.m_pWinSystem
)
245 return g_serviceBroker
.m_pWinSystem
->GetRenderSystem();
250 CPowerManager
& CServiceBroker::GetPowerManager()
252 return g_application
.m_ServiceManager
->GetPowerManager();
255 CWeatherManager
& CServiceBroker::GetWeatherManager()
257 return g_application
.m_ServiceManager
->GetWeatherManager();
260 CPlayerCoreFactory
& CServiceBroker::GetPlayerCoreFactory()
262 return g_application
.m_ServiceManager
->GetPlayerCoreFactory();
265 CDatabaseManager
& CServiceBroker::GetDatabaseManager()
267 return g_application
.m_ServiceManager
->GetDatabaseManager();
270 CEventLog
* CServiceBroker::GetEventLog()
272 if (!g_serviceBroker
.m_pSettingsComponent
)
275 auto profileManager
= g_serviceBroker
.m_pSettingsComponent
->GetProfileManager();
279 return &profileManager
->GetEventLog();
282 CMediaManager
& CServiceBroker::GetMediaManager()
284 return g_application
.m_ServiceManager
->GetMediaManager();
287 CApplicationComponents
& CServiceBroker::GetAppComponents()
289 return g_application
;
292 CGUIComponent
* CServiceBroker::GetGUI()
294 return g_serviceBroker
.m_pGUI
;
297 void CServiceBroker::RegisterGUI(CGUIComponent
* gui
)
299 g_serviceBroker
.m_pGUI
= gui
;
302 void CServiceBroker::UnregisterGUI()
304 g_serviceBroker
.m_pGUI
= nullptr;
308 IAE
* CServiceBroker::GetActiveAE()
310 return g_serviceBroker
.m_pActiveAE
;
312 void CServiceBroker::RegisterAE(IAE
* ae
)
314 g_serviceBroker
.m_pActiveAE
= ae
;
316 void CServiceBroker::UnregisterAE()
318 g_serviceBroker
.m_pActiveAE
= nullptr;
322 std::shared_ptr
<CAppInboundProtocol
> CServiceBroker::GetAppPort()
324 return g_serviceBroker
.m_pAppPort
;
326 void CServiceBroker::RegisterAppPort(std::shared_ptr
<CAppInboundProtocol
> port
)
328 g_serviceBroker
.m_pAppPort
= std::move(port
);
330 void CServiceBroker::UnregisterAppPort()
332 g_serviceBroker
.m_pAppPort
.reset();
335 void CServiceBroker::RegisterDecoderFilterManager(CDecoderFilterManager
* manager
)
337 g_serviceBroker
.m_decoderFilterManager
= manager
;
340 CDecoderFilterManager
* CServiceBroker::GetDecoderFilterManager()
342 return g_serviceBroker
.m_decoderFilterManager
;
345 std::shared_ptr
<CCPUInfo
> CServiceBroker::GetCPUInfo()
347 return g_serviceBroker
.m_cpuInfo
;
350 void CServiceBroker::RegisterCPUInfo(std::shared_ptr
<CCPUInfo
> cpuInfo
)
352 g_serviceBroker
.m_cpuInfo
= std::move(cpuInfo
);
355 void CServiceBroker::UnregisterCPUInfo()
357 g_serviceBroker
.m_cpuInfo
.reset();
360 void CServiceBroker::RegisterTextureCache(const std::shared_ptr
<CTextureCache
>& cache
)
362 g_serviceBroker
.m_textureCache
= cache
;
365 void CServiceBroker::UnregisterTextureCache()
367 g_serviceBroker
.m_textureCache
.reset();
370 std::shared_ptr
<CTextureCache
> CServiceBroker::GetTextureCache()
372 return g_serviceBroker
.m_textureCache
;
375 void CServiceBroker::RegisterJobManager(const std::shared_ptr
<CJobManager
>& jobManager
)
377 g_serviceBroker
.m_jobManager
= jobManager
;
380 void CServiceBroker::UnregisterJobManager()
382 g_serviceBroker
.m_jobManager
.reset();
385 std::shared_ptr
<CJobManager
> CServiceBroker::GetJobManager()
387 return g_serviceBroker
.m_jobManager
;
390 void CServiceBroker::RegisterAppMessenger(
391 const std::shared_ptr
<KODI::MESSAGING::CApplicationMessenger
>& appMessenger
)
393 g_serviceBroker
.m_appMessenger
= appMessenger
;
396 void CServiceBroker::UnregisterAppMessenger()
398 g_serviceBroker
.m_appMessenger
.reset();
401 std::shared_ptr
<KODI::MESSAGING::CApplicationMessenger
> CServiceBroker::GetAppMessenger()
403 return g_serviceBroker
.m_appMessenger
;
406 void CServiceBroker::RegisterKeyboardLayoutManager(
407 const std::shared_ptr
<CKeyboardLayoutManager
>& keyboardLayoutManager
)
409 g_serviceBroker
.m_keyboardLayoutManager
= keyboardLayoutManager
;
412 void CServiceBroker::UnregisterKeyboardLayoutManager()
414 g_serviceBroker
.m_keyboardLayoutManager
.reset();
417 std::shared_ptr
<CKeyboardLayoutManager
> CServiceBroker::GetKeyboardLayoutManager()
419 return g_serviceBroker
.m_keyboardLayoutManager
;
422 void CServiceBroker::RegisterSpeechRecognition(
423 const std::shared_ptr
<speech::ISpeechRecognition
>& speechRecognition
)
425 g_serviceBroker
.m_speechRecognition
= speechRecognition
;
428 void CServiceBroker::UnregisterSpeechRecognition()
430 g_serviceBroker
.m_speechRecognition
.reset();
433 std::shared_ptr
<speech::ISpeechRecognition
> CServiceBroker::GetSpeechRecognition()
435 return g_serviceBroker
.m_speechRecognition
;