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 "ServiceManager.h"
11 #include "ContextMenuManager.h"
12 #include "DatabaseManager.h"
13 #include "PlayListPlayer.h"
14 #include "addons/AddonManager.h"
15 #include "addons/BinaryAddonCache.h"
16 #include "addons/ExtsMimeSupportList.h"
17 #include "addons/RepositoryUpdater.h"
18 #include "addons/Service.h"
19 #include "addons/VFSEntry.h"
20 #include "addons/binary-addons/BinaryAddonManager.h"
21 #include "cores/DataCacheCore.h"
22 #include "cores/RetroPlayer/guibridge/GUIGameRenderManager.h"
23 #include "cores/playercorefactory/PlayerCoreFactory.h"
24 #include "favourites/FavouritesService.h"
25 #include "games/GameServices.h"
26 #include "games/controllers/ControllerManager.h"
27 #include "input/InputManager.h"
28 #include "interfaces/generic/ScriptInvocationManager.h"
29 #include "interfaces/python/XBPython.h"
30 #include "network/Network.h"
31 #include "peripherals/Peripherals.h"
32 #if defined(HAS_FILESYSTEM_SMB)
33 #include "network/IWSDiscovery.h"
34 #if defined(TARGET_WINDOWS)
35 #include "platform/win32/network/WSDiscoveryWin32.h"
36 #else // !defined(TARGET_WINDOWS)
37 #include "platform/posix/filesystem/SMBWSDiscovery.h"
38 #endif // defined(TARGET_WINDOWS)
39 #endif // HAS_FILESYSTEM_SMB
40 #include "powermanagement/PowerManager.h"
41 #include "profiles/ProfileManager.h"
42 #include "pvr/PVRManager.h"
43 #if !defined(TARGET_WINDOWS) && defined(HAS_OPTICAL_DRIVE)
44 #include "storage/DetectDVDType.h"
46 #include "pictures/SlideShowDelegator.h"
47 #include "storage/MediaManager.h"
48 #include "utils/FileExtensionProvider.h"
49 #include "utils/log.h"
50 #include "weather/WeatherManager.h"
56 CServiceManager::CServiceManager() = default;
58 CServiceManager::~CServiceManager()
68 bool CServiceManager::InitForTesting()
70 m_network
= CNetworkBase::GetNetwork();
72 m_databaseManager
= std::make_unique
<CDatabaseManager
>();
74 m_binaryAddonManager
= std::make_unique
<ADDON::CBinaryAddonManager
>();
75 m_addonMgr
= std::make_unique
<ADDON::CAddonMgr
>();
76 if (!m_addonMgr
->Init())
78 CLog::Log(LOGFATAL
, "CServiceManager::{}: Unable to start CAddonMgr", __FUNCTION__
);
82 m_extsMimeSupportList
= std::make_unique
<ADDONS::CExtsMimeSupportList
>(*m_addonMgr
);
83 m_fileExtensionProvider
= std::make_unique
<CFileExtensionProvider
>(*m_addonMgr
);
89 void CServiceManager::DeinitTesting()
92 m_fileExtensionProvider
.reset();
93 m_extsMimeSupportList
.reset();
94 m_binaryAddonManager
.reset();
96 m_databaseManager
.reset();
100 bool CServiceManager::InitStageOne()
102 m_Platform
.reset(CPlatform::CreateInstance());
103 if (!m_Platform
->InitStageOne())
107 m_XBPython
= std::make_unique
<XBPython
>();
108 CScriptInvocationManager::GetInstance().RegisterLanguageInvocationHandler(m_XBPython
.get(),
112 m_playlistPlayer
= std::make_unique
<PLAYLIST::CPlayListPlayer
>();
113 m_slideShowDelegator
= std::make_unique
<CSlideShowDelegator
>();
115 m_network
= CNetworkBase::GetNetwork();
121 bool CServiceManager::InitStageTwo(const std::string
& profilesUserDataFolder
)
123 // Initialize the addon database (must be before the addon manager is init'd)
124 m_databaseManager
= std::make_unique
<CDatabaseManager
>();
126 m_binaryAddonManager
= std::make_unique
<
128 CBinaryAddonManager
>(); /* Need to constructed before, GetRunningInstance() of binary CAddonDll need to call them */
129 m_addonMgr
= std::make_unique
<ADDON::CAddonMgr
>();
130 if (!m_addonMgr
->Init())
132 CLog::Log(LOGFATAL
, "CServiceManager::{}: Unable to start CAddonMgr", __FUNCTION__
);
136 m_repositoryUpdater
= std::make_unique
<ADDON::CRepositoryUpdater
>(*m_addonMgr
);
138 m_extsMimeSupportList
= std::make_unique
<ADDONS::CExtsMimeSupportList
>(*m_addonMgr
);
140 m_vfsAddonCache
= std::make_unique
<ADDON::CVFSAddonCache
>();
141 m_vfsAddonCache
->Init();
143 m_PVRManager
= std::make_unique
<PVR::CPVRManager
>();
145 m_dataCacheCore
= std::make_unique
<CDataCacheCore
>();
147 m_binaryAddonCache
= std::make_unique
<ADDON::CBinaryAddonCache
>();
148 m_binaryAddonCache
->Init();
150 m_favouritesService
= std::make_unique
<CFavouritesService
>(profilesUserDataFolder
);
152 m_serviceAddons
= std::make_unique
<ADDON::CServiceAddonManager
>(*m_addonMgr
);
154 m_contextMenuManager
= std::make_unique
<CContextMenuManager
>(*m_addonMgr
);
156 m_gameControllerManager
= std::make_unique
<GAME::CControllerManager
>(*m_addonMgr
);
157 m_inputManager
= std::make_unique
<CInputManager
>();
158 m_inputManager
->InitializeInputs();
161 std::make_unique
<PERIPHERALS::CPeripherals
>(*m_inputManager
, *m_gameControllerManager
);
163 m_gameRenderManager
= std::make_unique
<RETRO::CGUIGameRenderManager
>();
165 m_fileExtensionProvider
= std::make_unique
<CFileExtensionProvider
>(*m_addonMgr
);
167 m_powerManager
= std::make_unique
<CPowerManager
>();
168 m_powerManager
->Initialize();
169 m_powerManager
->SetDefaults();
171 m_weatherManager
= std::make_unique
<CWeatherManager
>();
173 m_mediaManager
= std::make_unique
<CMediaManager
>();
174 m_mediaManager
->Initialize();
176 #if !defined(TARGET_WINDOWS) && defined(HAS_OPTICAL_DRIVE)
177 m_DetectDVDType
= std::make_unique
<MEDIA_DETECT::CDetectDVDMedia
>();
180 #if defined(HAS_FILESYSTEM_SMB)
181 m_WSDiscovery
= WSDiscovery::IWSDiscovery::GetInstance();
184 if (!m_Platform
->InitStageTwo())
191 // stage 3 is called after successful initialization of WindowManager
192 bool CServiceManager::InitStageThree(const std::shared_ptr
<CProfileManager
>& profileManager
)
194 #if !defined(TARGET_WINDOWS) && defined(HAS_OPTICAL_DRIVE)
195 // Start Thread for DVD Mediatype detection
196 CLog::Log(LOGINFO
, "[Media Detection] starting service for optical media detection");
197 m_DetectDVDType
->Create(false);
200 // Peripherals depends on strings being loaded before stage 3
201 m_peripherals
->Initialise();
204 std::make_unique
<GAME::CGameServices
>(*m_gameControllerManager
, *m_gameRenderManager
,
205 *m_peripherals
, *profileManager
, *m_inputManager
);
207 m_contextMenuManager
->Init();
209 // Init PVR manager after login, not already on login screen
210 if (!profileManager
->UsingLoginScreen())
211 m_PVRManager
->Init();
213 m_playerCoreFactory
= std::make_unique
<CPlayerCoreFactory
>(*profileManager
);
215 if (!m_Platform
->InitStageThree())
222 void CServiceManager::DeinitStageThree()
225 #if !defined(TARGET_WINDOWS) && defined(HAS_OPTICAL_DRIVE)
226 m_DetectDVDType
->StopThread();
227 m_DetectDVDType
.reset();
229 m_playerCoreFactory
.reset();
230 m_PVRManager
->Deinit();
231 m_contextMenuManager
->Deinit();
232 m_gameServices
.reset();
233 m_peripherals
->Clear();
235 m_Platform
->DeinitStageThree();
238 void CServiceManager::DeinitStageTwo()
242 #if defined(HAS_FILESYSTEM_SMB)
243 m_WSDiscovery
.reset();
246 m_weatherManager
.reset();
247 m_powerManager
.reset();
248 m_fileExtensionProvider
.reset();
249 m_gameRenderManager
.reset();
250 m_peripherals
.reset();
251 m_inputManager
.reset();
252 m_gameControllerManager
.reset();
253 m_contextMenuManager
.reset();
254 m_serviceAddons
.reset();
255 m_favouritesService
.reset();
256 m_binaryAddonCache
.reset();
257 m_dataCacheCore
.reset();
258 m_PVRManager
.reset();
259 m_extsMimeSupportList
.reset();
260 m_vfsAddonCache
.reset();
261 m_repositoryUpdater
.reset();
262 m_binaryAddonManager
.reset();
264 m_databaseManager
.reset();
266 m_mediaManager
->Stop();
267 m_mediaManager
.reset();
269 m_Platform
->DeinitStageTwo();
272 void CServiceManager::DeinitStageOne()
277 m_playlistPlayer
.reset();
278 m_slideShowDelegator
.reset();
280 CScriptInvocationManager::GetInstance().UnregisterLanguageInvocationHandler(m_XBPython
.get());
284 m_Platform
->DeinitStageOne();
288 #if defined(HAS_FILESYSTEM_SMB)
289 WSDiscovery::IWSDiscovery
& CServiceManager::GetWSDiscovery()
291 return *m_WSDiscovery
;
295 ADDON::CAddonMgr
& CServiceManager::GetAddonMgr()
300 ADDONS::CExtsMimeSupportList
& CServiceManager::GetExtsMimeSupportList()
302 return *m_extsMimeSupportList
;
305 ADDON::CBinaryAddonCache
& CServiceManager::GetBinaryAddonCache()
307 return *m_binaryAddonCache
;
310 ADDON::CBinaryAddonManager
& CServiceManager::GetBinaryAddonManager()
312 return *m_binaryAddonManager
;
315 ADDON::CVFSAddonCache
& CServiceManager::GetVFSAddonCache()
317 return *m_vfsAddonCache
;
320 ADDON::CServiceAddonManager
& CServiceManager::GetServiceAddons()
322 return *m_serviceAddons
;
325 ADDON::CRepositoryUpdater
& CServiceManager::GetRepositoryUpdater()
327 return *m_repositoryUpdater
;
331 XBPython
& CServiceManager::GetXBPython()
337 #if !defined(TARGET_WINDOWS) && defined(HAS_OPTICAL_DRIVE)
338 MEDIA_DETECT::CDetectDVDMedia
& CServiceManager::GetDetectDVDMedia()
340 return *m_DetectDVDType
;
344 PVR::CPVRManager
& CServiceManager::GetPVRManager()
346 return *m_PVRManager
;
349 CContextMenuManager
& CServiceManager::GetContextMenuManager()
351 return *m_contextMenuManager
;
354 CDataCacheCore
& CServiceManager::GetDataCacheCore()
356 return *m_dataCacheCore
;
359 CPlatform
& CServiceManager::GetPlatform()
364 PLAYLIST::CPlayListPlayer
& CServiceManager::GetPlaylistPlayer()
366 return *m_playlistPlayer
;
369 GAME::CControllerManager
& CServiceManager::GetGameControllerManager()
371 return *m_gameControllerManager
;
374 GAME::CGameServices
& CServiceManager::GetGameServices()
376 return *m_gameServices
;
379 KODI::RETRO::CGUIGameRenderManager
& CServiceManager::GetGameRenderManager()
381 return *m_gameRenderManager
;
384 PERIPHERALS::CPeripherals
& CServiceManager::GetPeripherals()
386 return *m_peripherals
;
389 CFavouritesService
& CServiceManager::GetFavouritesService()
391 return *m_favouritesService
;
394 CInputManager
& CServiceManager::GetInputManager()
396 return *m_inputManager
;
399 CFileExtensionProvider
& CServiceManager::GetFileExtensionProvider()
401 return *m_fileExtensionProvider
;
404 CPowerManager
& CServiceManager::GetPowerManager()
406 return *m_powerManager
;
409 CNetworkBase
& CServiceManager::GetNetwork()
414 CWeatherManager
& CServiceManager::GetWeatherManager()
416 return *m_weatherManager
;
419 CPlayerCoreFactory
& CServiceManager::GetPlayerCoreFactory()
421 return *m_playerCoreFactory
;
424 CDatabaseManager
& CServiceManager::GetDatabaseManager()
426 return *m_databaseManager
;
429 CMediaManager
& CServiceManager::GetMediaManager()
431 return *m_mediaManager
;
434 CSlideShowDelegator
& CServiceManager::GetSlideShowDelegator()
436 return *m_slideShowDelegator
;