Aktualizr
C++ SOTA Client
secondaryinterface.h
1 #ifndef UPTANE_SECONDARYINTERFACE_H
2 #define UPTANE_SECONDARYINTERFACE_H
3 
4 #include <future>
5 #include <string>
6 
7 #include "json/json.h"
8 
9 #include "uptane/secondaryconfig.h"
10 #include "uptane/tuf.h"
11 #include "utilities/events.h"
12 
13 /* Json snippet returned by sendMetaXXX():
14  * {
15  * valid = true/false,
16  * wait_for_target = true/false
17  * }
18  */
19 
20 namespace Uptane {
21 
23  public:
24  explicit SecondaryInterface(SecondaryConfig sconfig_in) : sconfig(std::move(sconfig_in)) {}
25  virtual ~SecondaryInterface() = default;
26  virtual void Initialize(){}; // optional step, called after device registration
27  virtual EcuSerial getSerial() { return Uptane::EcuSerial(sconfig.ecu_serial); }
28  virtual Uptane::HardwareIdentifier getHwId() { return Uptane::HardwareIdentifier(sconfig.ecu_hardware_id); }
29  virtual PublicKey getPublicKey() = 0;
30 
31  virtual Json::Value getManifest() = 0;
32  virtual bool putMetadata(const RawMetaPack& meta_pack) = 0;
33  virtual int32_t getRootVersion(bool director) = 0;
34  virtual bool putRoot(const std::string& root, bool director) = 0;
35 
36  virtual bool sendFirmware(const std::shared_ptr<std::string>& data) = 0;
37  const SecondaryConfig sconfig;
38  void addEventsChannel(std::shared_ptr<event::Channel> channel) { events_channel = std::move(channel); }
39 
40  protected:
41  template <class T, class... Args>
42  void sendEvent(Args&&... args) {
43  std::shared_ptr<event::BaseEvent> event = std::make_shared<T>(std::forward<Args>(args)...);
44  if (events_channel) {
45  (*events_channel)(std::move(event));
46  } else if (event->variant != "DownloadProgressReport") {
47  LOG_INFO << "got " << event->variant << " event";
48  }
49  }
50 
51  private:
52  std::shared_ptr<event::Channel> events_channel;
53 };
54 } // namespace Uptane
55 
56 #endif // UPTANE_SECONDARYINTERFACE_H
General data structures.
Definition: types.cc:44
Base data types that are used in The Update Framework (TUF), part of UPTANE.
Aktualizr status events.
Definition: events.h:17