Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[addons] fix deinitialization order of RepositoryUpdater #12427

Merged
merged 1 commit into from Jul 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion xbmc/Application.cpp
Expand Up @@ -1216,7 +1216,7 @@ bool CApplication::Initialize()
RegisterActionListener(&CSeekHandler::GetInstance());
RegisterActionListener(&CPlayerController::GetInstance());

CRepositoryUpdater::GetInstance().Start();
CServiceBroker::GetRepositoryUpdater().Start();
CServiceBroker::GetServiceAddons().Start();

CLog::Log(LOGNOTICE, "initialize done");
Expand Down
4 changes: 2 additions & 2 deletions xbmc/LangInfo.cpp
Expand Up @@ -705,8 +705,8 @@ bool CLangInfo::SetLanguage(bool& fallback, const std::string &strLanguage /* =
if (addondb.Open())
{
// update the addon repositories to check if there's a matching language addon available for download
if (ADDON::CRepositoryUpdater::GetInstance().CheckForUpdates())
ADDON::CRepositoryUpdater::GetInstance().Await();
if (CServiceBroker::GetRepositoryUpdater().CheckForUpdates())
CServiceBroker::GetRepositoryUpdater().Await();

ADDON::VECADDONS languageAddons;
if (addondb.GetRepositoryContent(languageAddons) && !languageAddons.empty())
Expand Down
5 changes: 5 additions & 0 deletions xbmc/ServiceBroker.cpp
Expand Up @@ -105,6 +105,11 @@ ADDON::CServiceAddonManager& CServiceBroker::GetServiceAddons()
return g_application.m_ServiceManager->GetServiceAddons();
}

ADDON::CRepositoryUpdater& CServiceBroker::GetRepositoryUpdater()
{
return g_application.m_ServiceManager->GetRepositoryUpdater();
}

CInputManager& CServiceBroker::GetInputManager()
{
return g_application.m_ServiceManager->GetInputManager();
Expand Down
2 changes: 2 additions & 0 deletions xbmc/ServiceBroker.h
Expand Up @@ -26,6 +26,7 @@ class CBinaryAddonManager;
class CBinaryAddonCache;
class CVFSAddonCache;
class CServiceAddonManager;
class CRepositoryUpdater;
}

namespace ActiveAE {
Expand Down Expand Up @@ -87,6 +88,7 @@ class CServiceBroker
static PERIPHERALS::CPeripherals& GetPeripherals();
static CFavouritesService& GetFavouritesService();
static ADDON::CServiceAddonManager& GetServiceAddons();
static ADDON::CRepositoryUpdater& GetRepositoryUpdater();
static CInputManager& GetInputManager();
static bool IsBinaryAddonCacheUp();
};
7 changes: 7 additions & 0 deletions xbmc/ServiceManager.cpp
Expand Up @@ -89,6 +89,7 @@ bool CServiceManager::Init2()
return false;
}

m_repositoryUpdater.reset(new ADDON::CRepositoryUpdater(*m_addonMgr));
m_vfsAddonCache.reset(new ADDON::CVFSAddonCache());
m_vfsAddonCache->Init();

Expand Down Expand Up @@ -160,6 +161,7 @@ void CServiceManager::Deinit()
if (m_PVRManager)
m_PVRManager->Deinit();
m_PVRManager.reset();
m_repositoryUpdater.reset();
m_vfsAddonCache.reset();
m_binaryAddonManager.reset();
m_addonMgr.reset();
Expand Down Expand Up @@ -196,6 +198,11 @@ ADDON::CServiceAddonManager &CServiceManager::GetServiceAddons()
return *m_serviceAddons;
}

ADDON::CRepositoryUpdater &CServiceManager::GetRepositoryUpdater()
{
return *m_repositoryUpdater;
}

ANNOUNCEMENT::CAnnouncementManager& CServiceManager::GetAnnouncementManager()
{
return *m_announcementManager;
Expand Down
3 changes: 3 additions & 0 deletions xbmc/ServiceManager.h
Expand Up @@ -29,6 +29,7 @@ class CBinaryAddonManager;
class CBinaryAddonCache;
class CVFSAddonCache;
class CServiceAddonManager;
class CRepositoryUpdater;
}

namespace ActiveAE {
Expand Down Expand Up @@ -92,6 +93,7 @@ class CServiceManager
ADDON::CBinaryAddonCache& GetBinaryAddonCache();
ADDON::CVFSAddonCache& GetVFSAddonCache();
ADDON::CServiceAddonManager& GetServiceAddons();
ADDON::CRepositoryUpdater& GetRepositoryUpdater();
ANNOUNCEMENT::CAnnouncementManager& GetAnnouncementManager();
#ifdef HAS_PYTHON
XBPython& GetXBPython();
Expand Down Expand Up @@ -139,6 +141,7 @@ class CServiceManager
std::unique_ptr<ADDON::CBinaryAddonCache> m_binaryAddonCache;
std::unique_ptr<ADDON::CVFSAddonCache> m_vfsAddonCache;
std::unique_ptr<ADDON::CServiceAddonManager> m_serviceAddons;
std::unique_ptr<ADDON::CRepositoryUpdater> m_repositoryUpdater;
std::unique_ptr<ANNOUNCEMENT::CAnnouncementManager> m_announcementManager;
#ifdef HAS_PYTHON
std::unique_ptr<XBPython> m_XBPython;
Expand Down
4 changes: 2 additions & 2 deletions xbmc/addons/AddonSystemSettings.cpp
Expand Up @@ -144,8 +144,8 @@ std::vector<std::string> CAddonSystemSettings::MigrateAddons(std::function<void(
{
onMigrate();

if (CRepositoryUpdater::GetInstance().CheckForUpdates())
CRepositoryUpdater::GetInstance().Await();
if (CServiceBroker::GetRepositoryUpdater().CheckForUpdates())
CServiceBroker::GetRepositoryUpdater().Await();

CLog::Log(LOGINFO, "ADDON: waiting for add-ons to update...");
CAddonInstaller::GetInstance().InstallUpdatesAndWait();
Expand Down
3 changes: 2 additions & 1 deletion xbmc/addons/ContextMenus.cpp
Expand Up @@ -22,6 +22,7 @@
#include "AddonManager.h"
#include "Repository.h"
#include "RepositoryUpdater.h"
#include "ServiceBroker.h"
#include "GUIDialogAddonInfo.h"
#include "settings/GUIDialogAddonSettings.h"

Expand Down Expand Up @@ -56,7 +57,7 @@ bool CCheckForUpdates::Execute(const CFileItemPtr& item) const
AddonPtr addon;
if (item->HasAddonInfo() && CAddonMgr::GetInstance().GetAddon(item->GetAddonInfo()->ID(), addon, ADDON_REPOSITORY))
{
CRepositoryUpdater::GetInstance().CheckForUpdates(std::static_pointer_cast<CRepository>(addon), true);
CServiceBroker::GetRepositoryUpdater().CheckForUpdates(std::static_pointer_cast<CRepository>(addon), true);
return true;
}
return false;
Expand Down
8 changes: 4 additions & 4 deletions xbmc/addons/GUIWindowAddonBrowser.cpp
Expand Up @@ -72,7 +72,7 @@ bool CGUIWindowAddonBrowser::OnMessage(CGUIMessage& message)
{
case GUI_MSG_WINDOW_DEINIT:
{
CRepositoryUpdater::GetInstance().Events().Unsubscribe(this);
CServiceBroker::GetRepositoryUpdater().Events().Unsubscribe(this);
CAddonMgr::GetInstance().Events().Unsubscribe(this);

if (m_thumbLoader.IsLoading())
Expand All @@ -81,7 +81,7 @@ bool CGUIWindowAddonBrowser::OnMessage(CGUIMessage& message)
break;
case GUI_MSG_WINDOW_INIT:
{
CRepositoryUpdater::GetInstance().Events().Subscribe(this, &CGUIWindowAddonBrowser::OnEvent);
CServiceBroker::GetRepositoryUpdater().Events().Subscribe(this, &CGUIWindowAddonBrowser::OnEvent);
CAddonMgr::GetInstance().Events().Subscribe(this, &CGUIWindowAddonBrowser::OnEvent);

SetProperties();
Expand All @@ -106,7 +106,7 @@ bool CGUIWindowAddonBrowser::OnMessage(CGUIMessage& message)
}
else if (iControl == CONTROL_CHECK_FOR_UPDATES)
{
CRepositoryUpdater::GetInstance().CheckForUpdates(true);
CServiceBroker::GetRepositoryUpdater().CheckForUpdates(true);
return true;
}
else if (iControl == CONTROL_SETTINGS)
Expand Down Expand Up @@ -157,7 +157,7 @@ bool CGUIWindowAddonBrowser::OnMessage(CGUIMessage& message)

void CGUIWindowAddonBrowser::SetProperties()
{
auto lastUpdated = CRepositoryUpdater::GetInstance().LastUpdated();
auto lastUpdated = CServiceBroker::GetRepositoryUpdater().LastUpdated();
SetProperty("Updated", lastUpdated.IsValid() ?
lastUpdated.GetAsLocalizedDateTime() : g_localizeStrings.Get(21337));
}
Expand Down
11 changes: 3 additions & 8 deletions xbmc/addons/RepositoryUpdater.cpp
Expand Up @@ -40,17 +40,12 @@
namespace ADDON
{

CRepositoryUpdater::CRepositoryUpdater() :
CRepositoryUpdater::CRepositoryUpdater(CAddonMgr& addonMgr) :
m_timer(this),
m_doneEvent(true)
m_doneEvent(true),
m_addonMgr(addonMgr)
{}

CRepositoryUpdater &CRepositoryUpdater::GetInstance()
{
static CRepositoryUpdater instance;
return instance;
}

void CRepositoryUpdater::Start()
{
CServiceBroker::GetAddonMgr().Events().Subscribe(this, &CRepositoryUpdater::OnEvent);
Expand Down
5 changes: 2 additions & 3 deletions xbmc/addons/RepositoryUpdater.h
Expand Up @@ -34,8 +34,7 @@ namespace ADDON
class CRepositoryUpdater : private ITimerCallback, private IJobCallback, public ISettingCallback
{
public:
static CRepositoryUpdater& GetInstance();

explicit CRepositoryUpdater(CAddonMgr& addonMgr);
~CRepositoryUpdater() override;

void Start();
Expand Down Expand Up @@ -75,7 +74,6 @@ class CRepositoryUpdater : private ITimerCallback, private IJobCallback, public
CEventStream<RepositoryUpdated>& Events() { return m_events; }

private:
CRepositoryUpdater();
CRepositoryUpdater(const CRepositoryUpdater&) = delete;
CRepositoryUpdater(CRepositoryUpdater&&) = delete;
CRepositoryUpdater& operator=(const CRepositoryUpdater&) = delete;
Expand All @@ -91,6 +89,7 @@ class CRepositoryUpdater : private ITimerCallback, private IJobCallback, public
CTimer m_timer;
CEvent m_doneEvent;
std::vector<CRepositoryUpdateJob*> m_jobs;
CAddonMgr& m_addonMgr;

CEventSource<RepositoryUpdated> m_events;
};
Expand Down
4 changes: 2 additions & 2 deletions xbmc/filesystem/AddonsDirectory.cpp
Expand Up @@ -552,8 +552,8 @@ static bool Browse(const CURL& path, CFileItemList &items)
if (!database.GetRepositoryContent(addon->ID(), addons))
{
//Repo content is invalid. Ask for update and wait.
CRepositoryUpdater::GetInstance().CheckForUpdates(std::static_pointer_cast<CRepository>(addon));
CRepositoryUpdater::GetInstance().Await();
CServiceBroker::GetRepositoryUpdater().CheckForUpdates(std::static_pointer_cast<CRepository>(addon));
CServiceBroker::GetRepositoryUpdater().Await();

if (!database.GetRepositoryContent(addon->ID(), addons))
{
Expand Down
5 changes: 0 additions & 5 deletions xbmc/games/controllers/windows/GUIControllerWindow.cpp
Expand Up @@ -234,16 +234,11 @@ void CGUIControllerWindow::OnInitWindow(void)
// Enable button mapping support
CServiceBroker::GetPeripherals().EnableButtonMapping();

// FIXME: not thread safe
// ADDON::CRepositoryUpdater::GetInstance().Events().Subscribe(this, &CGUIControllerWindow::OnEvent);

UpdateButtons();
}

void CGUIControllerWindow::OnDeinitWindow(int nextWindowID)
{
ADDON::CRepositoryUpdater::GetInstance().Events().Unsubscribe(this);

if (m_controllerList)
{
m_controllerList->Deinitialize();
Expand Down
2 changes: 1 addition & 1 deletion xbmc/interfaces/builtins/AddonBuiltins.cpp
Expand Up @@ -316,7 +316,7 @@ static int StopScript(const std::vector<std::string>& params)
*/
static int UpdateRepos(const std::vector<std::string>& params)
{
CRepositoryUpdater::GetInstance().CheckForUpdates();
CServiceBroker::GetRepositoryUpdater().CheckForUpdates();

return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions xbmc/settings/Settings.cpp
Expand Up @@ -826,7 +826,7 @@ void CSettings::UninitializeISettingsHandlers()
GetSettingsManager()->UnregisterCallback(&CNetworkServices::GetInstance());
GetSettingsManager()->UnregisterCallback(&g_passwordManager);
GetSettingsManager()->UnregisterCallback(&CRssManager::GetInstance());
GetSettingsManager()->UnregisterCallback(&ADDON::CRepositoryUpdater::GetInstance());
GetSettingsManager()->UnregisterCallback(&CServiceBroker::GetRepositoryUpdater());
#if defined(TARGET_LINUX)
GetSettingsManager()->UnregisterCallback(&g_timezone);
#endif // defined(TARGET_LINUX)
Expand Down Expand Up @@ -1044,7 +1044,7 @@ void CSettings::InitializeISettingCallbacks()

settingSet.clear();
settingSet.insert(CSettings::SETTING_ADDONS_AUTOUPDATES);
GetSettingsManager()->RegisterCallback(&ADDON::CRepositoryUpdater::GetInstance(), settingSet);
GetSettingsManager()->RegisterCallback(&CServiceBroker::GetRepositoryUpdater(), settingSet);

settingSet.clear();
settingSet.insert(CSettings::SETTING_ADDONS_SHOW_RUNNING);
Expand Down Expand Up @@ -1094,7 +1094,7 @@ void CSettings::UninitializeISettingCallbacks()
GetSettingsManager()->UnregisterCallback(&CNetworkServices::GetInstance());
GetSettingsManager()->UnregisterCallback(&g_passwordManager);
GetSettingsManager()->UnregisterCallback(&CRssManager::GetInstance());
GetSettingsManager()->UnregisterCallback(&ADDON::CRepositoryUpdater::GetInstance());
GetSettingsManager()->UnregisterCallback(&CServiceBroker::GetRepositoryUpdater());
GetSettingsManager()->UnregisterCallback(&GAME::CGameSettings::GetInstance());
#if defined(TARGET_LINUX)
GetSettingsManager()->UnregisterCallback(&g_timezone);
Expand Down