Aktualizr
C++ SOTA Client
packagemanagerinterface.h
1 #ifndef PACKAGEMANAGERINTERFACE_H_
2 #define PACKAGEMANAGERINTERFACE_H_
3 
4 #include <mutex>
5 #include <string>
6 
7 #include "libaktualizr/config.h"
8 
9 class Bootloader;
10 class HttpInterface;
11 class KeyManager;
12 class INvStorage;
13 
14 namespace api {
15 class FlowControlToken;
16 }
17 
18 namespace Uptane {
19 class Fetcher;
20 }
21 
22 using FetcherProgressCb = std::function<void(const Uptane::Target&, const std::string&, unsigned int)>;
23 
24 /**
25  * Status of downloaded target.
26  */
27 enum class TargetStatus {
28  /* Target has been downloaded and verified. */
29  kGood = 0,
30  /* Target was not found. */
31  kNotFound,
32  /* Target was found, but is incomplete. */
33  kIncomplete,
34  /* Target was found, but is larger than expected. */
35  kOversized,
36  /* Target was found, but hash did not match the metadata. */
37  kHashMismatch,
38  /* Target was found and has valid metadata but the content is not suitable for the packagemanager */
39  kInvalid,
40 };
41 
43  public:
44  PackageManagerInterface(const PackageConfig& pconfig, const BootloaderConfig& bconfig,
45  const std::shared_ptr<INvStorage>& storage, const std::shared_ptr<HttpInterface>& http)
46  : config(pconfig), storage_(storage), http_(http) {
47  (void)bconfig;
48  }
49  virtual ~PackageManagerInterface() = default;
50  virtual std::string name() const = 0;
51  virtual Json::Value getInstalledPackages() const = 0;
52  virtual Uptane::Target getCurrent() const = 0;
53  virtual data::InstallationResult install(const Uptane::Target& target) const = 0;
54  virtual void completeInstall() const { throw std::runtime_error("Unimplemented"); }
55  virtual data::InstallationResult finalizeInstall(const Uptane::Target& target) = 0;
56  virtual void updateNotify() {}
57  virtual bool fetchTarget(const Uptane::Target& target, Uptane::Fetcher& fetcher, const KeyManager& keys,
58  const FetcherProgressCb& progress_cb, const api::FlowControlToken* token);
59  virtual TargetStatus verifyTarget(const Uptane::Target& target) const;
60  virtual bool checkAvailableDiskSpace(const uint64_t required_bytes) const;
61  virtual boost::optional<std::pair<uintmax_t, std::string>> checkTargetFile(const Uptane::Target& target) const;
62  virtual std::ofstream createTargetFile(const Uptane::Target& target);
63  virtual std::ofstream appendTargetFile(const Uptane::Target& target);
64  virtual std::ifstream openTargetFile(const Uptane::Target& target) const;
65  virtual void removeTargetFile(const Uptane::Target& target);
66  virtual std::vector<Uptane::Target> getTargetFiles();
67 
68  protected:
69  PackageConfig config;
70  std::shared_ptr<INvStorage> storage_;
71  std::shared_ptr<HttpInterface> http_;
72 };
73 #endif // PACKAGEMANAGERINTERFACE_H_
Uptane::Fetcher
Definition: fetcher.h:33
PackageManagerInterface
Definition: packagemanagerinterface.h:42
KeyManager
Definition: keymanager.h:13
data::InstallationResult
Definition: types.h:277
HttpInterface
Definition: httpinterface.h:38
Bootloader
Definition: bootloader.h:8
api::FlowControlToken
Provides a thread-safe way to pause and terminate task execution.
Definition: apiqueue.h:19
PackageConfig
Definition: config.h:91
Uptane::Target
Definition: types.h:379
Uptane
Base data types that are used in The Update Framework (TUF), part of Uptane.
Definition: packagemanagerinterface.h:18
BootloaderConfig
Definition: config.h:156
INvStorage
Definition: invstorage.h:43