2 * Copyright (C) 2015-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.
11 #include "settings/lib/ISettingCallback.h"
12 #include "threads/CriticalSection.h"
13 #include "threads/Timer.h"
14 #include "utils/EventStream.h"
15 #include "utils/Job.h"
28 using RepositoryPtr
= std::shared_ptr
<CRepository
>;
30 class CRepositoryUpdateJob
;
34 class CRepositoryUpdater
: private ITimerCallback
, private IJobCallback
, public ISettingCallback
37 explicit CRepositoryUpdater(CAddonMgr
& addonMgr
);
38 ~CRepositoryUpdater() override
;
43 * Check a single repository for updates.
45 void CheckForUpdates(const ADDON::RepositoryPtr
& repo
, bool showProgress
=false);
48 * Check all repositories for updates.
50 bool CheckForUpdates(bool showProgress
=false);
53 * Wait for any pending/in-progress updates to complete.
57 enum class UpdateScheduleType
59 /*! Update should be scheduled as the first update after application start or setting change. */
61 /*! Update should be scheduled as a regular update during application runtime. */
66 * Schedule an automatic update to run based on settings and previous update
67 * times. May be called when there are external changes this updater must know
68 * about. Any previously scheduled update will be cancelled.
70 void ScheduleUpdate(UpdateScheduleType scheduleType
);
73 * Returns the time of the last check (oldest). Invalid time if never checked.
75 CDateTime
LastUpdated() const;
78 void OnSettingChanged(const std::shared_ptr
<const CSetting
>& setting
) override
;
80 struct RepositoryUpdated
{ };
82 CEventStream
<RepositoryUpdated
>& Events() { return m_events
; }
85 CRepositoryUpdater(const CRepositoryUpdater
&) = delete;
86 CRepositoryUpdater(CRepositoryUpdater
&&) = delete;
87 CRepositoryUpdater
& operator=(const CRepositoryUpdater
&) = delete;
88 CRepositoryUpdater
& operator=(CRepositoryUpdater
&&) = delete;
90 void OnJobComplete(unsigned int jobID
, bool success
, CJob
*job
) override
;
92 void OnTimeout() override
;
94 void OnEvent(const ADDON::AddonEvent
& event
);
96 CDateTime
ClosestNextCheck() const;
98 CCriticalSection m_criticalSection
;
101 std::vector
<CRepositoryUpdateJob
*> m_jobs
;
102 CAddonMgr
& m_addonMgr
;
104 CEventSource
<RepositoryUpdated
> m_events
;