blob: e5550c7be625011888ba97df6a0f5e79e72d55ac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
/*
* Copyright (C) 2015-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#pragma once
#include "settings/lib/ISettingCallback.h"
#include "threads/CriticalSection.h"
#include "threads/Timer.h"
#include "utils/EventStream.h"
#include "utils/Job.h"
#include <memory>
#include <vector>
class CDateTime;
namespace ADDON
{
class CAddonMgr;
class CRepository;
using RepositoryPtr = std::shared_ptr<CRepository>;
class CRepositoryUpdateJob;
struct AddonEvent;
class CRepositoryUpdater : private ITimerCallback, private IJobCallback, public ISettingCallback
{
public:
explicit CRepositoryUpdater(CAddonMgr& addonMgr);
~CRepositoryUpdater() override;
void Start();
/**
* Check a single repository for updates.
*/
void CheckForUpdates(const ADDON::RepositoryPtr& repo, bool showProgress=false);
/**
* Check all repositories for updates.
*/
bool CheckForUpdates(bool showProgress=false);
/**
* Wait for any pending/in-progress updates to complete.
*/
void Await();
/**
* Schedule an automatic update to run based on settings and previous update
* times. May be called when there are external changes this updater must know
* about. Any previously scheduled update will be cancelled.
*/
void ScheduleUpdate();
/**
* Returns the time of the last check (oldest). Invalid time if never checked.
*/
CDateTime LastUpdated() const;
void OnSettingChanged(const std::shared_ptr<const CSetting>& setting) override;
struct RepositoryUpdated { };
CEventStream<RepositoryUpdated>& Events() { return m_events; }
private:
CRepositoryUpdater(const CRepositoryUpdater&) = delete;
CRepositoryUpdater(CRepositoryUpdater&&) = delete;
CRepositoryUpdater& operator=(const CRepositoryUpdater&) = delete;
CRepositoryUpdater& operator=(CRepositoryUpdater&&) = delete;
void OnJobComplete(unsigned int jobID, bool success, CJob *job) override;
void OnTimeout() override;
void OnEvent(const ADDON::AddonEvent& event);
CDateTime ClosestNextCheck() const;
CCriticalSection m_criticalSection;
CTimer m_timer;
CEvent m_doneEvent;
std::vector<CRepositoryUpdateJob*> m_jobs;
CAddonMgr& m_addonMgr;
CEventSource<RepositoryUpdated> m_events;
};
}
|