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 "libaktualizr/config.h"
8 
9 #include "bootloader/bootloader.h"
10 #include "crypto/keymanager.h"
11 #include "http/httpinterface.h"
12 #include "storage/invstorage.h"
13 #include "uptane/fetcher.h"
14 #include "utilities/apiqueue.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  const FetcherProgressCb& progress_cb, const api::FlowControlToken* token);
53  virtual TargetStatus verifyTarget(const Uptane::Target& target) const;
54  virtual bool checkAvailableDiskSpace(const uint64_t required_bytes) const;
55  virtual boost::optional<std::pair<uintmax_t, std::string>> checkTargetFile(const Uptane::Target& target) const;
56  virtual std::ofstream createTargetFile(const Uptane::Target& target);
57  virtual std::ofstream appendTargetFile(const Uptane::Target& target);
58  virtual std::ifstream openTargetFile(const Uptane::Target& target) const;
59  virtual void removeTargetFile(const Uptane::Target& target);
60  virtual std::vector<Uptane::Target> getTargetFiles();
61 
62  protected:
63  PackageConfig config;
64  std::shared_ptr<INvStorage> storage_;
65  std::shared_ptr<HttpInterface> http_;
66 };
67 #endif // PACKAGEMANAGERINTERFACE_H_
Provides a thread-safe way to pause and terminate task execution.
Definition: apiqueue.h:19