Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
packagemanagerinterface.h
1 #ifndef PACKAGEMANAGERINTERFACE_H_
2 #define PACKAGEMANAGERINTERFACE_H_
3 
4 #include <mutex>
5 #include <string>
6 
7 #include "bootloader/bootloader.h"
8 #include "crypto/keymanager.h"
9 #include "http/httpinterface.h"
10 #include "packagemanagerconfig.h"
11 #include "storage/invstorage.h"
12 #include "uptane/fetcher.h"
13 #include "utilities/apiqueue.h"
14 #include "utilities/types.h"
15 
16 using FetcherProgressCb = std::function<void(const Uptane::Target&, const std::string&, unsigned int)>;
17 
18 /**
19  * Status of downloaded target.
20  */
21 enum class TargetStatus {
22  /* Target has been downloaded and verified. */
23  kGood = 0,
24  /* Target was not found. */
25  kNotFound,
26  /* Target was found, but is incomplete. */
27  kIncomplete,
28  /* Target was found, but is larger than expected. */
29  kOversized,
30  /* Target was found, but hash did not match the metadata. */
31  kHashMismatch,
32  /* Target was found and has valid metadata but the content is not suitable for the packagemanager */
33  kInvalid,
34 };
35 
37  public:
38  PackageManagerInterface(const PackageConfig& pconfig, const BootloaderConfig& bconfig,
39  const std::shared_ptr<INvStorage>& storage, const std::shared_ptr<HttpInterface>& http)
40  : config(pconfig), storage_(storage), http_(http) {
41  (void)bconfig;
42  }
43  virtual ~PackageManagerInterface() = default;
44  virtual std::string name() const = 0;
45  virtual Json::Value getInstalledPackages() const = 0;
46  virtual Uptane::Target getCurrent() const = 0;
47  virtual data::InstallationResult install(const Uptane::Target& target) const = 0;
48  virtual void completeInstall() const { throw std::runtime_error("Unimplemented"); };
49  virtual data::InstallationResult finalizeInstall(const Uptane::Target& target) = 0;
50  virtual void updateNotify(){};
51  virtual bool fetchTarget(const Uptane::Target& target, Uptane::Fetcher& fetcher, const KeyManager& keys,
52  FetcherProgressCb progress_cb, const api::FlowControlToken* token);
53  virtual TargetStatus verifyTarget(const Uptane::Target& target) const;
54 
55  protected:
56  PackageConfig config;
57  std::shared_ptr<INvStorage> storage_;
58  std::shared_ptr<HttpInterface> http_;
59 };
60 #endif // PACKAGEMANAGERINTERFACE_H_
Uptane::Fetcher
Definition: fetcher.h:33
PackageManagerInterface
Definition: packagemanagerinterface.h:36
KeyManager
Definition: keymanager.h:13
types.h
data::InstallationResult
Definition: types.h:182
api::FlowControlToken
Provides a thread-safe way to pause and terminate task execution.
Definition: apiqueue.h:19
PackageConfig
Definition: packagemanagerconfig.h:24
Uptane::Target
Definition: tuf.h:210
BootloaderConfig
Definition: bootloader_config.h:11