diff options
author | Kai Sommerfeld <kai.sommerfeld@gmx.com> | 2022-03-05 17:07:14 +0100 |
---|---|---|
committer | Kai Sommerfeld <kai.sommerfeld@gmx.com> | 2022-03-10 12:14:39 +0100 |
commit | 485cadb2a6d91a9c6a5710d2de95986d9a04898b (patch) | |
tree | 75119e2ec2dd95408c9f166743e0a63f08ee092c | |
parent | 1f0cbca59d050f0067784d36bc3f9ee5f67b0882 (diff) |
[ServiceBroker][JobManager] Get rid of job manager global singleton.
36 files changed, 141 insertions, 122 deletions
diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp index e76dee5eac..885d72bd81 100644 --- a/xbmc/Application.cpp +++ b/xbmc/Application.cpp @@ -622,8 +622,10 @@ bool CApplication::Initialize() // initialize (and update as needed) our databases CDatabaseManager &databaseManager = m_ServiceManager->GetDatabaseManager(); + CServiceBroker::RegisterJobManager(std::make_shared<CJobManager>()); + CEvent event(true); - CJobManager::GetInstance().Submit([&databaseManager, &event]() { + CServiceBroker::GetJobManager()->Submit([&databaseManager, &event]() { databaseManager.Initialize(); event.Set(); }); @@ -646,7 +648,7 @@ bool CApplication::Initialize() //! @todo Move GUIFontManager into service broker and drop the global reference event.Reset(); GUIFontManager& guiFontManager = g_fontManager; - CJobManager::GetInstance().Submit([&guiFontManager, &event]() { + CServiceBroker::GetJobManager()->Submit([&guiFontManager, &event]() { guiFontManager.Initialize(); event.Set(); }); @@ -686,7 +688,7 @@ bool CApplication::Initialize() { if (CAddonSystemSettings::GetInstance().GetAddonAutoUpdateMode() == AUTO_UPDATES_ON) { - CJobManager::GetInstance().Submit( + CServiceBroker::GetJobManager()->Submit( [&event, &incompatibleAddons]() { if (CServiceBroker::GetRepositoryUpdater().CheckForUpdates()) CServiceBroker::GetRepositoryUpdater().Await(); @@ -2487,6 +2489,7 @@ bool CApplication::Cleanup() m_pSettingsComponent->Deinit(); m_pSettingsComponent.reset(); + CServiceBroker::UnregisterJobManager(); CServiceBroker::UnregisterCPUInfo(); return true; @@ -2571,7 +2574,7 @@ bool CApplication::Stop(int exitCode) CLog::Log(LOGINFO, "Stopping all"); // cancel any jobs from the jobmanager - CJobManager::GetInstance().CancelJobs(); + CServiceBroker::GetJobManager()->CancelJobs(); // stop scanning before we kill the network and so on if (CMusicLibraryQueue::GetInstance().IsRunning()) @@ -3064,7 +3067,7 @@ void CApplication::OnPlayBackStarted(const CFileItem &file) */ if (file.IsVideo() || file.IsGame()) { - CJobManager::GetInstance().PauseJobs(); + CServiceBroker::GetJobManager()->PauseJobs(); } CServiceBroker::GetPVRManager().OnPlaybackStarted(m_itemCurrentFile); @@ -4195,11 +4198,11 @@ void CApplication::ProcessSlow() currentWindow == WINDOW_FULLSCREEN_GAME || currentWindow == WINDOW_SLIDESHOW) { - CJobManager::GetInstance().PauseJobs(); + CServiceBroker::GetJobManager()->PauseJobs(); } else { - CJobManager::GetInstance().UnPauseJobs(); + CServiceBroker::GetJobManager()->UnPauseJobs(); } // Check if we need to activate the screensaver / DPMS. diff --git a/xbmc/GUILargeTextureManager.cpp b/xbmc/GUILargeTextureManager.cpp index 59bdf18bc0..23d162d68c 100644 --- a/xbmc/GUILargeTextureManager.cpp +++ b/xbmc/GUILargeTextureManager.cpp @@ -197,7 +197,7 @@ void CGUILargeTextureManager::ReleaseImage(const std::string &path, bool immedia if (image->GetPath() == path && image->DecrRef(true)) { // cancel this job - CJobManager::GetInstance().CancelJob(id); + CServiceBroker::GetJobManager()->CancelJob(id); m_queued.erase(it); return; } @@ -223,7 +223,8 @@ void CGUILargeTextureManager::QueueImage(const std::string &path, bool useCache) // queue the item CLargeTexture *image = new CLargeTexture(path); - unsigned int jobID = CJobManager::GetInstance().AddJob(new CImageLoader(path, useCache), this, CJob::PRIORITY_NORMAL); + unsigned int jobID = CServiceBroker::GetJobManager()->AddJob(new CImageLoader(path, useCache), + this, CJob::PRIORITY_NORMAL); m_queued.emplace_back(jobID, image); } diff --git a/xbmc/ServiceBroker.cpp b/xbmc/ServiceBroker.cpp index 47260f1e18..013e797389 100644 --- a/xbmc/ServiceBroker.cpp +++ b/xbmc/ServiceBroker.cpp @@ -347,3 +347,18 @@ std::shared_ptr<CTextureCache> CServiceBroker::GetTextureCache() { return g_serviceBroker.m_textureCache; } + +void CServiceBroker::RegisterJobManager(const std::shared_ptr<CJobManager>& jobManager) +{ + g_serviceBroker.m_jobManager = jobManager; +} + +void CServiceBroker::UnregisterJobManager() +{ + g_serviceBroker.m_jobManager.reset(); +} + +std::shared_ptr<CJobManager> CServiceBroker::GetJobManager() +{ + return g_serviceBroker.m_jobManager; +} diff --git a/xbmc/ServiceBroker.h b/xbmc/ServiceBroker.h index c46e478bfe..283498253e 100644 --- a/xbmc/ServiceBroker.h +++ b/xbmc/ServiceBroker.h @@ -65,6 +65,7 @@ class CCPUInfo; class CLog; class CPlatform; class CTextureCache; +class CJobManager; namespace WSDiscovery { @@ -172,6 +173,10 @@ public: static void UnregisterTextureCache(); static std::shared_ptr<CTextureCache> GetTextureCache(); + static void RegisterJobManager(const std::shared_ptr<CJobManager>& jobManager); + static void UnregisterJobManager(); + static std::shared_ptr<CJobManager> GetJobManager(); + private: std::unique_ptr<CLog> m_logging; std::shared_ptr<ANNOUNCEMENT::CAnnouncementManager> m_pAnnouncementManager; @@ -183,6 +188,7 @@ private: CDecoderFilterManager* m_decoderFilterManager; std::shared_ptr<CCPUInfo> m_cpuInfo; std::shared_ptr<CTextureCache> m_textureCache; + std::shared_ptr<CJobManager> m_jobManager; }; XBMC_GLOBAL_REF(CServiceBroker, g_serviceBroker); diff --git a/xbmc/addons/AddonInstaller.cpp b/xbmc/addons/AddonInstaller.cpp index a21b67ce7d..a37488c845 100644 --- a/xbmc/addons/AddonInstaller.cpp +++ b/xbmc/addons/AddonInstaller.cpp @@ -145,7 +145,7 @@ bool CAddonInstaller::Cancel(const std::string &addonID) JobMap::iterator i = m_downloadJobs.find(addonID); if (i != m_downloadJobs.end()) { - CJobManager::GetInstance().CancelJob(i->second.jobID); + CServiceBroker::GetJobManager()->CancelJob(i->second.jobID); m_downloadJobs.erase(i); if (m_downloadJobs.empty()) m_idle.Set(); @@ -288,7 +288,8 @@ bool CAddonInstaller::DoInstall(const AddonPtr& addon, { // Workaround: because CAddonInstallJob is blocking waiting for other jobs, it needs to be run // with priority dedicated. - unsigned int jobID = CJobManager::GetInstance().AddJob(installJob, this, CJob::PRIORITY_DEDICATED); + unsigned int jobID = + CServiceBroker::GetJobManager()->AddJob(installJob, this, CJob::PRIORITY_DEDICATED); m_downloadJobs.insert(make_pair(addon->ID(), CDownloadJob(jobID))); m_idle.Reset(); diff --git a/xbmc/addons/AddonManager.cpp b/xbmc/addons/AddonManager.cpp index 07bfa056c2..3291cfc063 100644 --- a/xbmc/addons/AddonManager.cpp +++ b/xbmc/addons/AddonManager.cpp @@ -793,7 +793,7 @@ void CAddonMgr::OnPostUnInstall(const std::string& id) void CAddonMgr::UpdateLastUsed(const std::string& id) { auto time = CDateTime::GetCurrentDateTime(); - CJobManager::GetInstance().Submit([this, id, time](){ + CServiceBroker::GetJobManager()->Submit([this, id, time]() { { std::unique_lock<CCriticalSection> lock(m_critSection); m_database.SetLastUsed(id, time); diff --git a/xbmc/addons/RepositoryUpdater.cpp b/xbmc/addons/RepositoryUpdater.cpp index fab7199f42..a3068614a3 100644 --- a/xbmc/addons/RepositoryUpdater.cpp +++ b/xbmc/addons/RepositoryUpdater.cpp @@ -149,7 +149,7 @@ void CRepositoryUpdater::CheckForUpdates(const ADDON::RepositoryPtr& repo, bool m_doneEvent.Reset(); if (showProgress) SetProgressIndicator(job); - CJobManager::GetInstance().AddJob(job, this, CJob::PRIORITY_LOW); + CServiceBroker::GetJobManager()->AddJob(job, this, CJob::PRIORITY_LOW); } else { diff --git a/xbmc/addons/gui/GUIDialogAddonInfo.cpp b/xbmc/addons/gui/GUIDialogAddonInfo.cpp index fcefb9fc3d..7f2c9b8715 100644 --- a/xbmc/addons/gui/GUIDialogAddonInfo.cpp +++ b/xbmc/addons/gui/GUIDialogAddonInfo.cpp @@ -590,8 +590,8 @@ void CGUIDialogAddonInfo::OnUninstall() if (CDirectory::Exists("special://profile/addon_data/" + m_localAddon->ID())) removeData = CGUIDialogYesNo::ShowAndGetInput(CVariant{24037}, CVariant{39014}); - CJobManager::GetInstance().AddJob(new CAddonUnInstallJob(m_localAddon, removeData), - &CAddonInstaller::GetInstance()); + CServiceBroker::GetJobManager()->AddJob(new CAddonUnInstallJob(m_localAddon, removeData), + &CAddonInstaller::GetInstance()); Close(); } diff --git a/xbmc/cores/RetroPlayer/RetroPlayer.cpp b/xbmc/cores/RetroPlayer/RetroPlayer.cpp index d3f304efd2..5f584b0a09 100644 --- a/xbmc/cores/RetroPlayer/RetroPlayer.cpp +++ b/xbmc/cores/RetroPlayer/RetroPlayer.cpp @@ -499,14 +499,14 @@ void CRetroPlayer::SetPlaybackSpeed(double speed) if (speed == 1.0) { IPlayerCallback* callback = &m_callback; - CJobManager::GetInstance().Submit([callback]() { callback->OnPlayBackResumed(); }, - CJob::PRIORITY_NORMAL); + CServiceBroker::GetJobManager()->Submit([callback]() { callback->OnPlayBackResumed(); }, + CJob::PRIORITY_NORMAL); } else if (speed == 0.0) { IPlayerCallback* callback = &m_callback; - CJobManager::GetInstance().Submit([callback]() { callback->OnPlayBackPaused(); }, - CJob::PRIORITY_NORMAL); + CServiceBroker::GetJobManager()->Submit([callback]() { callback->OnPlayBackPaused(); }, + CJob::PRIORITY_NORMAL); } } } diff --git a/xbmc/cores/paplayer/PAPlayer.cpp b/xbmc/cores/paplayer/PAPlayer.cpp index f3abc0a972..aa5f9c134b 100644 --- a/xbmc/cores/paplayer/PAPlayer.cpp +++ b/xbmc/cores/paplayer/PAPlayer.cpp @@ -224,11 +224,8 @@ bool PAPlayer::OpenFile(const CFileItem& file, const CPlayerOptions &options) std::unique_lock<CCriticalSection> lock(m_streamsLock); m_jobCounter++; } - CJobManager::GetInstance().Submit( - [=]() { QueueNextFileEx(file, false); }, - this, - CJob::PRIORITY_NORMAL - ); + CServiceBroker::GetJobManager()->Submit([=]() { QueueNextFileEx(file, false); }, this, + CJob::PRIORITY_NORMAL); std::unique_lock<CCriticalSection> lock(m_streamsLock); if (m_streams.size() == 2) @@ -288,9 +285,8 @@ bool PAPlayer::QueueNextFile(const CFileItem &file) std::unique_lock<CCriticalSection> lock(m_streamsLock); m_jobCounter++; } - CJobManager::GetInstance().Submit([this, file]() { - QueueNextFileEx(file, true); - }, this, CJob::PRIORITY_NORMAL); + CServiceBroker::GetJobManager()->Submit([this, file]() { QueueNextFileEx(file, true); }, this, + CJob::PRIORITY_NORMAL); return true; } @@ -1141,9 +1137,8 @@ void PAPlayer::CloseFileCB(StreamInfo &si) bookmark.timeInSeconds -= si.m_stream->GetDelay(); bookmark.player = m_name; bookmark.playerState = GetPlayerState(); - CJobManager::GetInstance().Submit([=]() { - cb->OnPlayerCloseFile(fileItem, bookmark); - }, CJob::PRIORITY_NORMAL); + CServiceBroker::GetJobManager()->Submit([=]() { cb->OnPlayerCloseFile(fileItem, bookmark); }, + CJob::PRIORITY_NORMAL); } void PAPlayer::AdvancePlaylistOnError(CFileItem &fileItem) diff --git a/xbmc/filesystem/Directory.cpp b/xbmc/filesystem/Directory.cpp index 8a4fb15ebd..ac88a6c8c5 100644 --- a/xbmc/filesystem/Directory.cpp +++ b/xbmc/filesystem/Directory.cpp @@ -71,19 +71,15 @@ public: CGetDirectory(std::shared_ptr<IDirectory>& imp, const CURL& dir, const CURL& listDir) : m_result(new CResult(dir, listDir)) { - m_id = CJobManager::GetInstance().AddJob(new CGetJob(imp, m_result) - , NULL - , CJob::PRIORITY_HIGH); + m_id = CServiceBroker::GetJobManager()->AddJob(new CGetJob(imp, m_result), nullptr, + CJob::PRIORITY_HIGH); if (m_id == 0) { CGetJob job(imp, m_result); job.DoWork(); } } - ~CGetDirectory() - { - CJobManager::GetInstance().CancelJob(m_id); - } + ~CGetDirectory() { CServiceBroker::GetJobManager()->CancelJob(m_id); } CEvent& GetEvent() { diff --git a/xbmc/guilib/GUIMultiImage.cpp b/xbmc/guilib/GUIMultiImage.cpp index 9cdf55a3b9..39593e68ee 100644 --- a/xbmc/guilib/GUIMultiImage.cpp +++ b/xbmc/guilib/GUIMultiImage.cpp @@ -238,7 +238,8 @@ void CGUIMultiImage::LoadDirectory() // slow(er) checks necessary - do them in the background std::unique_lock<CCriticalSection> lock(m_section); m_directoryStatus = LOADING; - m_jobID = CJobManager::GetInstance().AddJob(new CMultiImageJob(m_currentPath), this, CJob::PRIORITY_NORMAL); + m_jobID = CServiceBroker::GetJobManager()->AddJob(new CMultiImageJob(m_currentPath), this, + CJob::PRIORITY_NORMAL); } void CGUIMultiImage::OnDirectoryLoaded() @@ -260,7 +261,7 @@ void CGUIMultiImage::CancelLoading() { std::unique_lock<CCriticalSection> lock(m_section); if (m_directoryStatus == LOADING) - CJobManager::GetInstance().CancelJob(m_jobID); + CServiceBroker::GetJobManager()->CancelJob(m_jobID); m_directoryStatus = UNLOADED; } diff --git a/xbmc/listproviders/DirectoryProvider.cpp b/xbmc/listproviders/DirectoryProvider.cpp index 976d334ca4..6ee7f3ce51 100644 --- a/xbmc/listproviders/DirectoryProvider.cpp +++ b/xbmc/listproviders/DirectoryProvider.cpp @@ -231,8 +231,9 @@ bool CDirectoryProvider::Update(bool forceRefresh) { CLog::Log(LOGDEBUG, "CDirectoryProvider[{}]: refreshing..", m_currentUrl); if (m_jobID) - CJobManager::GetInstance().CancelJob(m_jobID); - m_jobID = CJobManager::GetInstance().AddJob(new CDirectoryJob(m_currentUrl, m_currentSort, m_currentLimit, m_parentID), this); + CServiceBroker::GetJobManager()->CancelJob(m_jobID); + m_jobID = CServiceBroker::GetJobManager()->AddJob( + new CDirectoryJob(m_currentUrl, m_currentSort, m_currentLimit, m_parentID), this); } if (!changed) @@ -349,7 +350,7 @@ void CDirectoryProvider::Reset() { std::unique_lock<CCriticalSection> lock(m_section); if (m_jobID) - CJobManager::GetInstance().CancelJob(m_jobID); + CServiceBroker::GetJobManager()->CancelJob(m_jobID); m_jobID = 0; m_items.clear(); m_currentTarget.clear(); diff --git a/xbmc/music/MusicUtils.cpp b/xbmc/music/MusicUtils.cpp index b0c09cb849..2aecea65c4 100644 --- a/xbmc/music/MusicUtils.cpp +++ b/xbmc/music/MusicUtils.cpp @@ -183,7 +183,7 @@ namespace MUSIC_UTILS { // Asynchronously update that type of art in the database CSetArtJob *job = new CSetArtJob(pItem, strType, strArt); - CJobManager::GetInstance().AddJob(job, NULL); + CServiceBroker::GetJobManager()->AddJob(job, nullptr); } // Add art types required in Kodi and configured by the user @@ -343,7 +343,7 @@ namespace MUSIC_UTILS job = new CSetSongRatingJob(tag->GetDatabaseId(), userrating); else job = new CSetSongRatingJob(pItem->GetPath(), userrating); - CJobManager::GetInstance().AddJob(job, NULL); + CServiceBroker::GetJobManager()->AddJob(job, nullptr); } std::vector<std::string> GetArtTypesToScan(const MediaType& mediaType) diff --git a/xbmc/music/dialogs/GUIDialogMusicInfo.cpp b/xbmc/music/dialogs/GUIDialogMusicInfo.cpp index 977ef63ecb..317b9d1391 100644 --- a/xbmc/music/dialogs/GUIDialogMusicInfo.cpp +++ b/xbmc/music/dialogs/GUIDialogMusicInfo.cpp @@ -340,7 +340,7 @@ bool CGUIDialogMusicInfo::OnMessage(CGUIMessage& message) // Asynchronously update song userrating in library CSetUserratingJob *job = new CSetUserratingJob(m_item->GetMusicInfoTag()->GetAlbumId(), m_item->GetMusicInfoTag()->GetUserrating()); - CJobManager::GetInstance().AddJob(job, NULL); + CServiceBroker::GetJobManager()->AddJob(job, nullptr); } if (m_hasRefreshed || m_hasUpdatedUserrating) { @@ -444,13 +444,14 @@ bool CGUIDialogMusicInfo::SetItem(CFileItem* item) m_cancelled = false; // Happens before win_init // In a separate job fetch info and fill list of art types. - int jobid = CJobManager::GetInstance().AddJob(new CGetInfoJob(), nullptr, CJob::PRIORITY_LOW); + int jobid = + CServiceBroker::GetJobManager()->AddJob(new CGetInfoJob(), nullptr, CJob::PRIORITY_LOW); // Wait to get all data before show, allowing user to cancel if fetch is slow if (!CGUIDialogBusy::WaitOnEvent(m_event, TIME_TO_BUSY_DIALOG)) { // Cancel job still waiting in queue (unlikely) - CJobManager::GetInstance().CancelJob(jobid); + CServiceBroker::GetJobManager()->CancelJob(jobid); // Flag to stop job already in progress m_cancelled = true; return false; @@ -606,7 +607,8 @@ void CGUIDialogMusicInfo::RefreshInfo() SetScrapedInfo(false); // Start separate job to scrape info and fill list of art types. - CJobManager::GetInstance().AddJob(new CRefreshInfoJob(dlgProgress), nullptr, CJob::PRIORITY_HIGH); + CServiceBroker::GetJobManager()->AddJob(new CRefreshInfoJob(dlgProgress), nullptr, + CJob::PRIORITY_HIGH); // Wait for refresh to complete or be canceled, but render every 10ms so that the // pointer movements works on dialog even when job is reporting progress infrequently diff --git a/xbmc/music/dialogs/GUIDialogSongInfo.cpp b/xbmc/music/dialogs/GUIDialogSongInfo.cpp index 8441839548..a48b1a68a2 100644 --- a/xbmc/music/dialogs/GUIDialogSongInfo.cpp +++ b/xbmc/music/dialogs/GUIDialogSongInfo.cpp @@ -281,13 +281,14 @@ bool CGUIDialogSongInfo::SetSong(CFileItem* item) m_event.Reset(); m_cancelled = false; // SetSong happens before win_init // In a separate job fetch song info and fill list of art types. - int jobid = CJobManager::GetInstance().AddJob(new CGetSongInfoJob(), nullptr, CJob::PRIORITY_LOW); + int jobid = + CServiceBroker::GetJobManager()->AddJob(new CGetSongInfoJob(), nullptr, CJob::PRIORITY_LOW); // Wait to get all data before show, allowing user to cancel if fetch is slow if (!CGUIDialogBusy::WaitOnEvent(m_event, TIME_TO_BUSY_DIALOG)) { // Cancel job still waiting in queue (unlikely) - CJobManager::GetInstance().CancelJob(jobid); + CServiceBroker::GetJobManager()->CancelJob(jobid); // Flag to stop job already in progress m_cancelled = true; return false; diff --git a/xbmc/music/windows/GUIWindowMusicNav.cpp b/xbmc/music/windows/GUIWindowMusicNav.cpp index f117173f7b..3e8c67e192 100644 --- a/xbmc/music/windows/GUIWindowMusicNav.cpp +++ b/xbmc/music/windows/GUIWindowMusicNav.cpp @@ -562,7 +562,7 @@ void CGUIWindowMusicNav::GetContextButtons(int itemNumber, CContextButtons &butt MEDIA_DETECT::CCdInfo* pCdInfo = CServiceBroker::GetMediaManager().GetCdInfo(); if (pCdInfo->IsAudio(1) || pCdInfo->IsCDExtra(1) || pCdInfo->IsMixedMode(1)) { - if (CJobManager::GetInstance().IsProcessing("cdrip")) + if (CServiceBroker::GetJobManager()->IsProcessing("cdrip")) buttons.Add(CONTEXT_BUTTON_CANCEL_RIP_CD, 14100); else buttons.Add(CONTEXT_BUTTON_RIP_CD, 600); diff --git a/xbmc/network/WakeOnAccess.cpp b/xbmc/network/WakeOnAccess.cpp index 16a213b432..36a4e49b63 100644 --- a/xbmc/network/WakeOnAccess.cpp +++ b/xbmc/network/WakeOnAccess.cpp @@ -371,13 +371,10 @@ public: if (async) { CJob* job = new CHostProberJob(server); - m_jobId = CJobManager::GetInstance().AddJob(job, this); + m_jobId = CServiceBroker::GetJobManager()->AddJob(job, this); } } - ~PingResponseWaiter() override - { - CJobManager::GetInstance().CancelJob(m_jobId); - } + ~PingResponseWaiter() override { CServiceBroker::GetJobManager()->CancelJob(m_jobId); } bool SuccessWaiting () const override { return m_jobId ? m_hostOnline : Ping(m_server); @@ -644,7 +641,7 @@ void CWakeOnAccess::QueueMACDiscoveryForHost(const std::string& host) if (IsEnabled()) { if (URIUtils::IsHostOnLAN(host, true)) - CJobManager::GetInstance().AddJob(new CMACDiscoveryJob(host), this); + CServiceBroker::GetJobManager()->AddJob(new CMACDiscoveryJob(host), this); else CLog::Log(LOGINFO, "{} - skip Mac discovery for non-local host '{}'", __FUNCTION__, host); } diff --git a/xbmc/network/Zeroconf.cpp b/xbmc/network/Zeroconf.cpp index 3a7205e535..cf850202ab 100644 --- a/xbmc/network/Zeroconf.cpp +++ b/xbmc/network/Zeroconf.cpp @@ -71,7 +71,7 @@ bool CZeroconf::PublishService(const std::string& fcr_identifier, if(!ret.second) //identifier exists return false; if(m_started) - CJobManager::GetInstance().AddJob(new CPublish(fcr_identifier, info), NULL); + CServiceBroker::GetJobManager()->AddJob(new CPublish(fcr_identifier, info), nullptr); //not yet started, so its just queued return true; @@ -119,7 +119,7 @@ bool CZeroconf::Start() return true; m_started = true; - CJobManager::GetInstance().AddJob(new CPublish(m_service_map), NULL); + CServiceBroker::GetJobManager()->AddJob(new CPublish(m_service_map), nullptr); return true; } diff --git a/xbmc/peripherals/devices/PeripheralCecAdapter.cpp b/xbmc/peripherals/devices/PeripheralCecAdapter.cpp index 9bc0979d6b..e91e925028 100644 --- a/xbmc/peripherals/devices/PeripheralCecAdapter.cpp +++ b/xbmc/peripherals/devices/PeripheralCecAdapter.cpp @@ -1737,8 +1737,8 @@ bool CPeripheralCecAdapter::ReopenConnection(bool bAsync /* = false */) { if (bAsync) { - CJobManager::GetInstance().AddJob(new CPeripheralCecAdapterReopenJob(this), nullptr, - CJob::PRIORITY_NORMAL); + CServiceBroker::GetJobManager()->AddJob(new CPeripheralCecAdapterReopenJob(this), nullptr, + CJob::PRIORITY_NORMAL); return true; } diff --git a/xbmc/platform/win32/storage/Win32StorageProvider.cpp b/xbmc/platform/win32/storage/Win32StorageProvider.cpp index cad5f4e4ec..57d1e4233c 100644 --- a/xbmc/platform/win32/storage/Win32StorageProvider.cpp +++ b/xbmc/platform/win32/storage/Win32StorageProvider.cpp @@ -42,7 +42,7 @@ void CWin32StorageProvider::Initialize() // Can be removed once the StorageHandler supports optical media for (const auto& it : vShare) if (CServiceBroker::GetMediaManager().GetDriveStatus(it.strPath) == DRIVE_CLOSED_MEDIA_PRESENT) - CJobManager::GetInstance().AddJob(new CDetectDisc(it.strPath, false), NULL); + CServiceBroker::GetJobManager()->AddJob(new CDetectDisc(it.strPath, false), nullptr); // remove end #endif } diff --git a/xbmc/pvr/PVRManager.cpp b/xbmc/pvr/PVRManager.cpp index 9a06591fc1..4ca44b4aa4 100644 --- a/xbmc/pvr/PVRManager.cpp +++ b/xbmc/pvr/PVRManager.cpp @@ -367,7 +367,7 @@ void CPVRManager::Init() { // initial check for enabled addons // if at least one pvr addon is enabled, PVRManager start up - CJobManager::GetInstance().Submit([this] { + CServiceBroker::GetJobManager()->Submit([this] { Clients()->Start(); return true; }); @@ -792,9 +792,8 @@ void CPVRManager::TriggerPlayChannelOnStartup() { if (IsStarted()) { - CJobManager::GetInstance().Submit([this] { - return GUIActions()->PlayChannelOnStartup(); - }); + CServiceBroker::GetJobManager()->Submit( + [this] { return GUIActions()->PlayChannelOnStartup(); }); } } @@ -1009,7 +1008,7 @@ void CPVRManager::ConnectionStateChange(CPVRClient* client, PVR_CONNECTION_STATE state, const std::string& message) { - CJobManager::GetInstance().Submit([this, client, connectString, state, message] { + CServiceBroker::GetJobManager()->Submit([this, client, connectString, state, message] { Clients()->ConnectionStateChange(client, connectString, state, message); return true; }); diff --git a/xbmc/pvr/addons/PVRClients.cpp b/xbmc/pvr/addons/PVRClients.cpp index ead3c5cbcd..327e90d8e1 100644 --- a/xbmc/pvr/addons/PVRClients.cpp +++ b/xbmc/pvr/addons/PVRClients.cpp @@ -163,7 +163,10 @@ void CPVRClients::UpdateAddons(const std::string& changedAddonId /*= ""*/) { CServiceBroker::GetAddonMgr().DisableAddon(addon.first->ID(), AddonDisabledReason::PERMANENT_FAILURE); - CJobManager::GetInstance().AddJob(new CPVREventLogJob(true, true, addon.first->Name(), g_localizeStrings.Get(24070), addon.first->Icon()), nullptr); + CServiceBroker::GetJobManager()->AddJob( + new CPVREventLogJob(true, true, addon.first->Name(), g_localizeStrings.Get(24070), + addon.first->Icon()), + nullptr); } } } @@ -243,7 +246,7 @@ void CPVRClients::OnAddonEvent(const AddonEvent& event) const std::string id = event.id; if (CServiceBroker::GetAddonMgr().HasType(id, ADDON_PVRDLL)) { - CJobManager::GetInstance().Submit([this, id] { + CServiceBroker::GetJobManager()->Submit([this, id] { UpdateAddons(id); return true; }); @@ -814,7 +817,8 @@ void CPVRClients::ConnectionStateChange(CPVRClient* client, strMsg = g_localizeStrings.Get(iMsg); // Notify user. - CJobManager::GetInstance().AddJob(new CPVREventLogJob(bNotify, bError, client->Name(), strMsg, client->Icon()), nullptr); + CServiceBroker::GetJobManager()->AddJob( + new CPVREventLogJob(bNotify, bError, client->Name(), strMsg, client->Icon()), nullptr); } namespace diff --git a/xbmc/pvr/guilib/PVRGUIActions.cpp b/xbmc/pvr/guilib/PVRGUIActions.cpp index 53d2559cfe..2f447b83b9 100644 --- a/xbmc/pvr/guilib/PVRGUIActions.cpp +++ b/xbmc/pvr/guilib/PVRGUIActions.cpp @@ -2276,7 +2276,7 @@ namespace PVR name, GetAnnouncerText(timer, idEpg, idNoEpg), icon); - CJobManager::GetInstance().AddJob(job, nullptr); + CServiceBroker::GetJobManager()->AddJob(job, nullptr); } } // unnamed namespace diff --git a/xbmc/pvr/guilib/PVRGUIChannelNavigator.cpp b/xbmc/pvr/guilib/PVRGUIChannelNavigator.cpp index e1beeb32b5..e098545a18 100644 --- a/xbmc/pvr/guilib/PVRGUIChannelNavigator.cpp +++ b/xbmc/pvr/guilib/PVRGUIChannelNavigator.cpp @@ -161,10 +161,11 @@ namespace PVR { // delayed switch if (m_iChannelEntryJobId >= 0) - CJobManager::GetInstance().CancelJob(m_iChannelEntryJobId); + CServiceBroker::GetJobManager()->CancelJob(m_iChannelEntryJobId); CPVRChannelEntryTimeoutJob* job = new CPVRChannelEntryTimeoutJob(*this, timeout); - m_iChannelEntryJobId = CJobManager::GetInstance().AddJob(job, dynamic_cast<IJobCallback*>(job)); + m_iChannelEntryJobId = + CServiceBroker::GetJobManager()->AddJob(job, dynamic_cast<IJobCallback*>(job)); } else { @@ -183,7 +184,7 @@ namespace PVR if (m_iChannelEntryJobId >= 0) { - CJobManager::GetInstance().CancelJob(m_iChannelEntryJobId); + CServiceBroker::GetJobManager()->CancelJob(m_iChannelEntryJobId); m_iChannelEntryJobId = -1; } @@ -224,14 +225,15 @@ namespace PVR if (m_iChannelInfoJobId >= 0) { - CJobManager::GetInstance().CancelJob(m_iChannelInfoJobId); + CServiceBroker::GetJobManager()->CancelJob(m_iChannelInfoJobId); m_iChannelInfoJobId = -1; } if (!bForce && timeout > 0s) { CPVRChannelInfoTimeoutJob* job = new CPVRChannelInfoTimeoutJob(*this, timeout); - m_iChannelInfoJobId = CJobManager::GetInstance().AddJob(job, dynamic_cast<IJobCallback*>(job)); + m_iChannelInfoJobId = + CServiceBroker::GetJobManager()->AddJob(job, dynamic_cast<IJobCallback*>(job)); } } } @@ -247,7 +249,7 @@ namespace PVR if (m_iChannelInfoJobId >= 0) { - CJobManager::GetInstance().CancelJob(m_iChannelInfoJobId); + CServiceBroker::GetJobManager()->CancelJob(m_iChannelInfoJobId); m_iChannelInfoJobId = -1; } diff --git a/xbmc/pvr/timers/PVRTimers.cpp b/xbmc/pvr/timers/PVRTimers.cpp index 586cc34239..017e50487f 100644 --- a/xbmc/pvr/timers/PVRTimers.cpp +++ b/xbmc/pvr/timers/PVRTimers.cpp @@ -393,7 +393,7 @@ bool CPVRTimers::UpdateEntries(const CPVRTimersContainer& timers, const std::vec } } - CJobManager::GetInstance().AddJob(job, nullptr); + CServiceBroker::GetJobManager()->AddJob(job, nullptr); } } diff --git a/xbmc/storage/MediaManager.cpp b/xbmc/storage/MediaManager.cpp index 4bd5d9d6e2..b2c716c1cd 100644 --- a/xbmc/storage/MediaManager.cpp +++ b/xbmc/storage/MediaManager.cpp @@ -694,8 +694,8 @@ void CMediaManager::OnStorageAdded(const MEDIA_DETECT::STORAGE::StorageDevice& d { if (settings->GetInt(CSettings::SETTING_AUDIOCDS_AUTOACTION) == AUTOCD_RIP) { - CJobManager::GetInstance().AddJob(new CAutorunMediaJob(device.label, device.path), this, - CJob::PRIORITY_LOW); + CServiceBroker::GetJobManager()->AddJob(new CAutorunMediaJob(device.label, device.path), this, + CJob::PRIORITY_LOW); } else { @@ -708,8 +708,8 @@ void CMediaManager::OnStorageAdded(const MEDIA_DETECT::STORAGE::StorageDevice& d CLog::Log(LOGDEBUG, "{}: Could not execute autorun for optical disc with path {}", __FUNCTION__, device.path); } - CJobManager::GetInstance().AddJob(new CAutorunMediaJob(device.label, device.path), this, - CJob::PRIORITY_HIGH); + CServiceBroker::GetJobManager()->AddJob(new CAutorunMediaJob(device.label, device.path), this, + CJob::PRIORITY_HIGH); } } else diff --git a/xbmc/utils/InfoLoader.cpp b/xbmc/utils/InfoLoader.cpp index cef6b70cc2..be4697c7ed 100644 --- a/xbmc/utils/InfoLoader.cpp +++ b/xbmc/utils/InfoLoader.cpp @@ -9,6 +9,7 @@ #include "InfoLoader.h" #include "JobManager.h" +#include "ServiceBroker.h" #include "TimeUtils.h" #include "guilib/LocalizeStrings.h" @@ -33,7 +34,7 @@ std::string CInfoLoader::GetInfo(int info) if (m_refreshTime < CTimeUtils::GetFrameTime() && !m_busy) { // queue up the job m_busy = true; - CJobManager::GetInstance().AddJob(GetJob(), this); + CServiceBroker::GetJobManager()->AddJob(GetJob(), this); } if (m_busy && CTimeUtils::GetFrameTime() - m_refreshTime > 1000) { diff --git a/xbmc/utils/JobManager.cpp b/xbmc/utils/JobManager.cpp index c35b1357c0..126cb25b0b 100644 --- a/xbmc/utils/JobManager.cpp +++ b/xbmc/utils/JobManager.cpp @@ -8,6 +8,7 @@ #include "JobManager.h" +#include "ServiceBroker.h" #include "utils/XTimeUtils.h" #include "utils/log.h" @@ -66,7 +67,7 @@ void CJobWorker::Process() void CJobQueue::CJobPointer::CancelJob() { - CJobManager::GetInstance().CancelJob(m_id); + CServiceBroker::GetJobManager()->CancelJob(m_id); m_id = 0; } @@ -146,7 +147,7 @@ void CJobQueue::QueueNextJob() while (m_jobQueue.size() && m_processing.size() < m_jobsAtOnce) { CJobPointer &job = m_jobQueue.back(); - job.m_id = CJobManager::GetInstance().AddJob(job.m_job, this, m_priority); + job.m_id = CServiceBroker::GetJobManager()->AddJob(job.m_job, this, m_priority); if (job.m_id > 0) { m_processing.emplace_back(job); @@ -168,7 +169,8 @@ void CJobQueue::CancelJobs() bool CJobQueue::IsProcessing() const { - return CJobManager::GetInstance().m_running && (!m_processing.empty() || !m_jobQueue.empty()); + return CServiceBroker::GetJobManager()->m_running && + (!m_processing.empty() || !m_jobQueue.empty()); } bool CJobQueue::QueueEmpty() const @@ -177,12 +179,6 @@ bool CJobQueue::QueueEmpty() const return m_jobQueue.empty(); } -CJobManager &CJobManager::GetInstance() -{ - static CJobManager sJobManager; - return sJobManager; -} - CJobManager::CJobManager() { m_jobCounter = 0; diff --git a/xbmc/utils/JobManager.h b/xbmc/utils/JobManager.h index e09cf2b5db..d4871d1ad7 100644 --- a/xbmc/utils/JobManager.h +++ b/xbmc/utils/JobManager.h @@ -196,8 +196,8 @@ private: \brief Job Manager class for scheduling asynchronous jobs. Controls asynchronous job execution, by allowing clients to add and cancel jobs. - Should be accessed via CJobManager::GetInstance(). Jobs are allocated based on - priority levels. Lower priority jobs are executed only if there are sufficient + Should be accessed via CServiceBroker::GetJobManager(). Jobs are allocated based + on priority levels. Lower priority jobs are executed only if there are sufficient spare worker threads free to allow for higher priority jobs that may arise. \sa CJob and IJobCallback @@ -238,11 +238,7 @@ class CJobManager final }; public: - /*! - \brief The only way through which the global instance of the CJobManager should be accessed. - \return the global instance. - */ - static CJobManager &GetInstance(); + CJobManager(); /*! \brief Add a job to the threaded job manager. @@ -357,8 +353,6 @@ protected: bool OnJobProgress(unsigned int progress, unsigned int total, const CJob *job) const; private: - // private construction, and no assignments; use the provided singleton methods - CJobManager(); CJobManager(const CJobManager&) = delete; CJobManager const& operator=(CJobManager const&) = delete; diff --git a/xbmc/utils/Screenshot.cpp b/xbmc/utils/Screenshot.cpp index 9faa0bb1d1..25ecbac080 100644 --- a/xbmc/utils/Screenshot.cpp +++ b/xbmc/utils/Screenshot.cpp @@ -79,7 +79,7 @@ void CScreenShot::TakeScreenshot(const std::string& filename, bool sync) //write .png file asynchronous with CThumbnailWriter, prevents stalling of the render thread //buffer is deleted from CThumbnailWriter CThumbnailWriter* thumbnailwriter = new CThumbnailWriter(surface->GetBuffer(), surface->GetWidth(), surface->GetHeight(), surface->GetStride(), filename); - CJobManager::GetInstance().AddJob(thumbnailwriter, NULL); + CServiceBroker::GetJobManager()->AddJob(thumbnailwriter, nullptr); } } diff --git a/xbmc/utils/test/TestJobManager.cpp b/xbmc/utils/test/TestJobManager.cpp index 8c0beab0d0..86f0af981c 100644 --- a/xbmc/utils/test/TestJobManager.cpp +++ b/xbmc/utils/test/TestJobManager.cpp @@ -6,6 +6,7 @@ * See LICENSES/README.md for more information. */ +#include "ServiceBroker.h" #include "test/MtTestUtils.h" #include "utils/Job.h" #include "utils/JobManager.h" @@ -64,13 +65,14 @@ public: class TestJobManager : public testing::Test { protected: - TestJobManager() = default; + TestJobManager() { CServiceBroker::RegisterJobManager(std::make_shared<CJobManager>()); } ~TestJobManager() override { /* Always cancel jobs test completion */ - CJobManager::GetInstance().CancelJobs(); - CJobManager::GetInstance().Restart(); + CServiceBroker::GetJobManager()->CancelJobs(); + CServiceBroker::GetJobManager()->Restart(); + CServiceBroker::UnregisterJobManager(); } }; @@ -78,7 +80,7 @@ TEST_F(TestJobManager, AddJob) { Flags* flags = new Flags(); ReallyDumbJob* job = new ReallyDumbJob(flags); - CJobManager::GetInstance().AddJob(job, NULL); + CServiceBroker::GetJobManager()->AddJob(job, nullptr); ASSERT_TRUE(poll([flags]() -> bool { return flags->finished; })); delete flags; } @@ -88,13 +90,13 @@ TEST_F(TestJobManager, CancelJob) unsigned int id; Flags* flags = new Flags(); DummyJob* job = new DummyJob(flags); - id = CJobManager::GetInstance().AddJob(job, NULL); + id = CServiceBroker::GetJobManager()->AddJob(job, nullptr); // wait for the worker thread to be entered ASSERT_TRUE(poll([flags]() -> bool { return flags->started; })); // cancel the job - CJobManager::GetInstance().CancelJob(id); + CServiceBroker::GetJobManager()->CancelJob(id); // let the worker thread continue flags->lingerAtWork = false; @@ -181,7 +183,7 @@ BroadcastingJob * WaitForJobToStartProcessing(CJob::PRIORITY priority, JobControlPackage &package) { BroadcastingJob* job = new BroadcastingJob(package); - CJobManager::GetInstance().AddJob(job, NULL, priority); + CServiceBroker::GetJobManager()->AddJob(job, nullptr, priority); // We're now ready to wait, wait and then unblock once ready while (!package.ready) @@ -196,11 +198,11 @@ TEST_F(TestJobManager, PauseLowPriorityJob) JobControlPackage package; BroadcastingJob *job (WaitForJobToStartProcessing(CJob::PRIORITY_LOW_PAUSABLE, package)); - EXPECT_TRUE(CJobManager::GetInstance().IsProcessing(CJob::PRIORITY_LOW_PAUSABLE)); - CJobManager::GetInstance().PauseJobs(); - EXPECT_FALSE(CJobManager::GetInstance().IsProcessing(CJob::PRIORITY_LOW_PAUSABLE)); - CJobManager::GetInstance().UnPauseJobs(); - EXPECT_TRUE(CJobManager::GetInstance().IsProcessing(CJob::PRIORITY_LOW_PAUSABLE)); + EXPECT_TRUE(CServiceBroker::GetJobManager()->IsProcessing(CJob::PRIORITY_LOW_PAUSABLE)); + CServiceBroker::GetJobManager()->PauseJobs(); + EXPECT_FALSE(CServiceBroker::GetJobManager()->IsProcessing(CJob::PRIORITY_LOW_PAUSABLE)); + CServiceBroker::GetJobManager()->UnPauseJobs(); + EXPECT_TRUE(CServiceBroker::GetJobManager()->IsProcessing(CJob::PRIORITY_LOW_PAUSABLE)); job->FinishAndStopBlocking(); } @@ -210,7 +212,7 @@ TEST_F(TestJobManager, IsProcessing) JobControlPackage package; BroadcastingJob *job (WaitForJobToStartProcessing(CJob::PRIORITY_LOW_PAUSABLE, package)); - EXPECT_EQ(0, CJobManager::GetInstance().IsProcessing("")); + EXPECT_EQ(0, CServiceBroker::GetJobManager()->IsProcessing("")); job->FinishAndStopBlocking(); } diff --git a/xbmc/windowing/windows/WinEventsWin32.cpp b/xbmc/windowing/windows/WinEventsWin32.cpp index 54db1791ca..71bd13e9b1 100644 --- a/xbmc/windowing/windows/WinEventsWin32.cpp +++ b/xbmc/windowing/windows/WinEventsWin32.cpp @@ -775,7 +775,7 @@ LRESULT CALLBACK CWinEventsWin32::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, L if(wParam == DBT_DEVICEARRIVAL) { CLog::LogF(LOGDEBUG, "Drive {} Media has arrived.", strdrive); - CJobManager::GetInstance().AddJob(new CDetectDisc(strdrive, true), NULL); + CServiceBroker::GetJobManager()->AddJob(new CDetectDisc(strdrive, true), nullptr); } else { diff --git a/xbmc/windows/GUIMediaWindow.cpp b/xbmc/windows/GUIMediaWindow.cpp index 908abe5bb3..db92884f3f 100644 --- a/xbmc/windows/GUIMediaWindow.cpp +++ b/xbmc/windows/GUIMediaWindow.cpp @@ -2264,10 +2264,12 @@ bool CGUIMediaWindow::WaitGetDirectoryItems(CGetDirectoryItems &items) { m_updateJobActive = true; m_updateEvent.Reset(); - CJobManager::GetInstance().Submit([&]() { - items.Run(); - m_updateEvent.Set(); - }, nullptr, CJob::PRIORITY_NORMAL); + CServiceBroker::GetJobManager()->Submit( + [&]() { + items.Run(); + m_updateEvent.Set(); + }, + nullptr, CJob::PRIORITY_NORMAL); while (!m_updateEvent.Wait(1ms)) { diff --git a/xbmc/windows/GUIWindowFileManager.cpp b/xbmc/windows/GUIWindowFileManager.cpp index 18377a7edc..d5f4c6b48b 100644 --- a/xbmc/windows/GUIWindowFileManager.cpp +++ b/xbmc/windows/GUIWindowFileManager.cpp @@ -1067,7 +1067,7 @@ void CGUIWindowFileManager::OnPopupMenu(int list, int item, bool bContextDriven if (item >= 0 && pItem->m_bIsFolder && !pItem->IsParentFolder()) choices.Add(CONTROL_BTNCALCSIZE, 13393); choices.Add(CONTROL_BTNSWITCHMEDIA, 523); - if (CJobManager::GetInstance().IsProcessing("filemanager")) + if (CServiceBroker::GetJobManager()->IsProcessing("filemanager")) choices.Add(CONTROL_BTNCANCELJOB, 167); if (!pItem->m_bIsFolder) diff --git a/xbmc/windows/GUIWindowHome.cpp b/xbmc/windows/GUIWindowHome.cpp index 18bbc74676..a4118221e2 100644 --- a/xbmc/windows/GUIWindowHome.cpp +++ b/xbmc/windows/GUIWindowHome.cpp @@ -130,7 +130,7 @@ void CGUIWindowHome::AddRecentlyAddedJobs(int flag) } if (flag && getAJob) - CJobManager::GetInstance().AddJob(new CRecentlyAddedJob(flag), this); + CServiceBroker::GetJobManager()->AddJob(new CRecentlyAddedJob(flag), this); m_updateRA = 0; } |