Aktualizr
C++ SOTA Client
aktualizr.h
1 #ifndef AKTUALIZR_H_
2 #define AKTUALIZR_H_
3 
4 #include <atomic>
5 #include <memory>
6 
7 #include <boost/signals2.hpp>
8 
9 #include "config/config.h"
10 #include "sotauptaneclient.h"
11 #include "storage/invstorage.h"
12 #include "uptane/secondaryinterface.h"
13 #include "utilities/events.h"
14 
15 /**
16  * This class provides the main APIs necessary for launching and controlling
17  * libaktualizr.
18  */
19 class Aktualizr {
20  public:
21  /** Aktualizr requires a configuration object. Examples can be found in the
22  * config directory. */
23  explicit Aktualizr(Config& config);
24  Aktualizr(const Aktualizr&) = delete;
25  Aktualizr& operator=(const Aktualizr&) = delete;
26 
27  /**
28  * Launch aktualizr. Depending on the \ref RunningMode in the configuration,
29  * this may run indefinitely, so you may want to run this on its own thread.
30  */
31  int Run();
32 
33  /**
34  * Asynchronously shutdown Aktualizr
35  */
36  void Shutdown();
37 
38  /**
39  * Asynchronously perform a check for campaigns.
40  * Campaigns are a concept outside of Uptane, and allow for user approval of
41  * updates before the contents of the update are known.
42  */
43  void CampaignCheck();
44 
45  /**
46  * Asynchronously accept a campaign for the current device
47  * Campaigns are a concept outside of Uptane, and allow for user approval of
48  * updates before the contents of the update are known.
49  */
50  void CampaignAccept(const std::string& campaign_id);
51 
52  /**
53  * Asynchronously send local device data to the server.
54  * This includes network status, installed packages, hardware etc.
55  */
56  void SendDeviceData();
57 
58  /**
59  * Asynchronously fetch Uptane metadata.
60  * This collects a client manifest, PUTs it to the director, then updates
61  * the Uptane metadata, including root and targets.
62  */
63  void FetchMetadata();
64 
65  /**
66  * Asynchronously load already-fetched Uptane metadata from disk.
67  * This is only needed when the metadata fetch and downloads/installation are
68  * in separate aktualizr runs.
69  */
70  void CheckUpdates();
71 
72  /**
73  * Asynchronously download targets.
74  */
75  void Download(const std::vector<Uptane::Target>& updates);
76 
77  /**
78  * Asynchronously install targets.
79  */
80  void Install(const std::vector<Uptane::Target>& updates);
81 
82  /**
83  * Add new secondary to aktualizr.
84  */
85  void AddSecondary(const std::shared_ptr<Uptane::SecondaryInterface>& secondary);
86 
87  /**
88  * Provide a function to receive event notifications.
89  * @param handler a function that can receive event objects.
90  * @return a signal connection object, which can be disconnected if desired.
91  */
92  boost::signals2::connection SetSignalHandler(std::function<void(std::shared_ptr<event::BaseEvent>)>& handler);
93 
94  private:
95  Config& config_;
96  std::shared_ptr<INvStorage> storage_;
97  std::shared_ptr<SotaUptaneClient> uptane_client_;
98  std::shared_ptr<event::Channel> sig_;
99  std::atomic<bool> shutdown_ = {false};
100 };
101 
102 #endif // AKTUALIZR_H_
void Install(const std::vector< Uptane::Target > &updates)
Asynchronously install targets.
Definition: aktualizr.cc:62
void CampaignAccept(const std::string &campaign_id)
Asynchronously accept a campaign for the current device Campaigns are a concept outside of Uptane...
Definition: aktualizr.cc:52
void Download(const std::vector< Uptane::Target > &updates)
Asynchronously download targets.
Definition: aktualizr.cc:60
void AddSecondary(const std::shared_ptr< Uptane::SecondaryInterface > &secondary)
Add new secondary to aktualizr.
Definition: aktualizr.cc:44
boost::signals2::connection SetSignalHandler(std::function< void(std::shared_ptr< event::BaseEvent >)> &handler)
Provide a function to receive event notifications.
Definition: aktualizr.cc:64
void CheckUpdates()
Asynchronously load already-fetched Uptane metadata from disk.
Definition: aktualizr.cc:58
void SendDeviceData()
Asynchronously send local device data to the server.
Definition: aktualizr.cc:54
int Run()
Launch aktualizr.
Definition: aktualizr.cc:35
void FetchMetadata()
Asynchronously fetch Uptane metadata.
Definition: aktualizr.cc:56
Configuration object for an aktualizr instance running on a primary ECU.
Definition: config.h:100
void Shutdown()
Asynchronously shutdown Aktualizr.
Definition: aktualizr.cc:48
Aktualizr(Config &config)
Aktualizr requires a configuration object.
Definition: aktualizr.cc:14
void CampaignCheck()
Asynchronously perform a check for campaigns.
Definition: aktualizr.cc:50
This class provides the main APIs necessary for launching and controlling libaktualizr.
Definition: aktualizr.h:19