Friendly LWM2M client
FirmwareUpdate.h
Go to the documentation of this file.
1 /*
2  * FirmwareUpdate
3  * Generated on: 2024-04-03 15:26:42
4  * Created by: Sinai RnD
5  */
6 
7 #ifndef WPP_O_5_FIRMWARE_UPDATE_H
8 #define WPP_O_5_FIRMWARE_UPDATE_H
9 
10 #include "FirmwareUpdateConfig.h"
11 #include "FirmwareUpdateInfo.h"
12 #include "Instance.h"
13 #include "InstSubject.h"
14 
15 /* --------------- Сode_h block 0 start --------------- */
16 #include "WppTaskQueue.h"
17 #include "FwTypes.h"
19 #if RES_5_8
21 #endif
23 /* --------------- Сode_h block 0 end --------------- */
24 
25 namespace wpp {
26 
27 class WppClient;
28 class Object;
29 
30 /* --------------- Сode_h block 1 start --------------- */
31 /* --------------- Сode_h block 1 end --------------- */
32 
33 class FirmwareUpdate : public Instance {
34 public:
35  enum ID: ID_T {
36  PACKAGE_0 = 0,
38  UPDATE_2 = 2,
39  STATE_3 = 3,
41  #if RES_5_6
42  PKGNAME_6 = 6,
43  #endif
44  #if RES_5_7
46  #endif
47  #if RES_5_8
49  #endif
51  #if RES_5_10
52  CANCEL_10 = 10,
53  #endif
54  #if RES_5_11
55  SEVERITY_11 = 11,
56  #endif
57  #if RES_5_12
58  LAST_STATE_CHANGE_TIME_12 = 12,
59  #endif
60  #if RES_5_13
61  MAXIMUM_DEFER_PERIOD_13 = 13,
62  #endif
63  };
64 
65  /* --------------- Code_h block 2 start --------------- */
66  /* --------------- Code_h block 2 end --------------- */
67 
68 public:
69  FirmwareUpdate(lwm2m_context_t &context, const OBJ_LINK_T &id);
71 
72  /* --------------- Helpful methods --------------- */
78  static Object & object(WppClient &ctx);
79 
86  static FirmwareUpdate * instance(WppClient &ctx, ID_T instId = ID_T_MAX_VAL);
87 
94  static FirmwareUpdate * createInst(WppClient &ctx, ID_T instId = ID_T_MAX_VAL);
95 
102  static bool removeInst(WppClient &ctx, ID_T instId);
103 
104  /* --------------- Code_h block 3 start --------------- */
112  static bool setFwUpdater(WppClient &ctx, FwUpdater &updater);
113 
114  #if RES_5_8
119  static std::vector<FwUpdProtocol> supportedProtocols(WppClient &ctx);
120 
128  static bool setFwExternalDownloader(WppClient &ctx, FwExternalDl &downloader);
129  #endif
130 
138  static bool setFwInternalDownloader(WppClient &ctx, FwInternalDl &downloader);
139  /* --------------- Code_h block 3 end --------------- */
140 
141 protected:
142  /* --------------- Instance implementation part --------------- */
143  /*
144  * Handles information about resource operation that made server
145  */
146  void serverOperationNotifier(Instance *securityInst, ItemOp::TYPE type, const ResLink &resLink) override;
147  /*
148  * Handles information about resource operation that made user
149  */
150  void userOperationNotifier(ItemOp::TYPE type, const ResLink &resLink) override;
151 
152  /* --------------- Code_h block 4 start --------------- */
153  /* --------------- Code_h block 4 end --------------- */
154 
155 private:
156  /* --------------- Class private methods --------------- */
157  /*
158  * Creates resources without initializing.
159  */
160  void resourcesCreate();
161  /*
162  * Initialize resources with default values
163  * SINGLE resource always must have at least one instance.
164  */
165  void resourcesInit();
166 
167  /* --------------- Code_h block 5 start --------------- */
168  bool pkgUpdaterHandler();
169  #if RES_5_8
170  void externalDownloaderHandler(Instance *securityInst);
171  #endif
172  void internalDownloaderHandler();
173 
174  void changeUpdRes(FwUpdRes res);
175  void changeState(FwUpdState state);
176  void resetStateMachine();
177  void clearArtifacts();
178 
179  bool isUriValid(STRING_T uri);
180  STRING_T extractSchemeFromUri(STRING_T uri);
181  bool isSchemeValid(STRING_T scheme);
182  #if RES_5_8
183  bool isSchemeSupported(STRING_T scheme);
184  FwUpdProtocol schemeToProtId(STRING_T scheme);
185  #endif
186 
187  bool isDeliveryTypeSupported(FwUpdDelivery type);
188  /* --------------- Code_h block 5 end --------------- */
189 
190 private:
191  /* --------------- Class private properties --------------- */
192  /* --------------- Code_h block 6 start --------------- */
193  FwUpdater *_pkgUpdater;
194  FwInternalDl *_internalDownloader;
195  #if RES_5_8
196  FwExternalDl *_externalDownloader;
197  WppTaskQueue::task_id_t _externalDownloaderTaskId;
198  #endif
199  WppTaskQueue::task_id_t _internalDownloaderTaskId;
200  WppTaskQueue::task_id_t _updaterTaskId;
201  /* --------------- Code_h block 6 end --------------- */
202 };
203 
204 } /* namespace wpp */
205 
206 #endif /* WPP_O_5_FIRMWARE_UPDATE_H */
#define ID_T_MAX_VAL
Definition: WppTypes.h:16
void serverOperationNotifier(Instance *securityInst, ItemOp::TYPE type, const ResLink &resLink) override
This method must be implemented by the derived class, and handle information about resource operation...
static bool setFwExternalDownloader(WppClient &ctx, FwExternalDl &downloader)
Set the FwExternalDl object for downloading the firmware package from the specified URI.
void userOperationNotifier(ItemOp::TYPE type, const ResLink &resLink) override
This method must be implemented by the derived class, and handle information about resource operation...
static bool setFwInternalDownloader(WppClient &ctx, FwInternalDl &downloader)
Set the FwInternalDl object for auto downloading firmware.
static std::vector< FwUpdProtocol > supportedProtocols(WppClient &ctx)
Return the list of supported protocols for downloading the firmware through uri.
static bool setFwUpdater(WppClient &ctx, FwUpdater &updater)
Set the FwUpdater object for updating the firmware package.
FirmwareUpdate(lwm2m_context_t &context, const OBJ_LINK_T &id)
static FirmwareUpdate * instance(WppClient &ctx, ID_T instId=ID_T_MAX_VAL)
Gets an instance of the object.
static bool removeInst(WppClient &ctx, ID_T instId)
Removes an instance of the object.
static Object & object(WppClient &ctx)
Gets the Object reference.
static FirmwareUpdate * createInst(WppClient &ctx, ID_T instId=ID_T_MAX_VAL)
Creates an instance of the object.
Instance is interface class that implements manipulation with derived class resources....
Definition: Instance.h:40
The Object class implements manipulation with Instance interface class and its inheritors.
Definition: Object.h:32
Represents a client interface for Wpp library.
Definition: WppClient.h:37
uint32_t task_id_t
Definition: WppTaskQueue.h:52
The WppConnection class represents a connection interface for the Wpp library.
Definition: WppClient.cpp:14
FwUpdState
Definition: FwTypes.h:35
FwUpdDelivery
Definition: FwTypes.h:43
FwUpdProtocol
Definition: FwTypes.h:24
uint16_t ID_T
Definition: WppTypes.h:15
FwUpdRes
Definition: FwTypes.h:9
std::string STRING_T
Definition: WppTypes.h:45
TYPE
Enum representing the different types of operations.
Definition: ItemOp.h:29