Unify Framework Lib 1.6.0
ota_cache.hpp
Go to the documentation of this file.
1/******************************************************************************
2 * # License
3 * <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
4 ******************************************************************************
5 * The licensor of this software is Silicon Laboratories Inc. Your use of this
6 * software is governed by the terms of Silicon Labs Master Software License
7 * Agreement (MSLA) available at
8 * www.silabs.com/about-us/legal/master-software-license-agreement. This
9 * software is distributed to you in Source Code format and is governed by the
10 * sections of the MSLA applicable to Source Code.
11 *
12 *****************************************************************************/
13
23#ifndef OTA_CACHE_HPP
24#define OTA_CACHE_HPP
25
26// This component
27#include "ota.hpp"
28
29// Standard library
30#include <memory>
31#include <map>
32#include <vector>
33
34// Unify
35#include "sys/ctimer.h"
36
41using endpoint_cache_t = uint8_t;
42
51typedef struct timeout_handler {
52 std::string unid;
53 std::string subscribe_topic;
54 bool state = false;
58
65{
66 std::shared_ptr<timeout_handler_t> timeout_data;
67
68 public:
73 TimeoutHandler() = default;
74 TimeoutHandler(timeout_handler_t input_timeout_data) :
75 timeout_data {std::make_unique<timeout_handler_t>(input_timeout_data)} {};
79
84
85 std::string get_unid() const;
86 std::string get_subscribe_topic() const;
87 bool get_unid_poll_state() const;
88 void set_unid_poll_state(bool state) const;
91};
92
101{
103// Image meta info received
105
112void set_image_meta_info(const std::string &key,
113 const uic_ota::meta_t &meta_info);
114
124uic_ota::meta_t get_image_meta_info(const std::string &key);
125
131void remove_image_meta_info(const std::string &key);
132
140bool check_if_meta_info_received(const std::string &key);
141
143// Cached image files
145
152void set_images_received_cached_filepath(const std::string &key,
153 const std::string &filepath);
154
162std::string get_image_cached_filepath(const std::string &key);
163
171bool is_image_received_and_cached(const std::string &key);
172
177} // namespace image_file_handler
178
190{
192// Unid poll management
194
199void set_unid_poll(std::shared_ptr<TimeoutHandler> timeout_handler);
200
206void pop_unid_poll(const std::string &unid);
207
215bool get_unid_poll_state(const std::string &unid);
216
222void set_unid_poll_state_true(const std::string &unid);
223
229bool is_unid_in_poll(const std::string &unid);
230
239
247bool is_poll_topic_subscribed(const std::string &topic);
248
250// Unid management
252
258void set_unid_listening(const std::string &uiid, const std::string &unid);
259
267std::vector<std::string> get_unids_listening(const std::string &uiid);
268
276std::size_t get_unids_listening_count(const std::string &uiid);
277
284void remove_unid_listening(const std::string &uiid, const std::string &unid);
285
293std::vector<std::string>
294 get_uiids_unid_is_listening_to(const std::string &unid);
295
301std::map<std::string, std::vector<std::string>, std::less<>>
303
305// Unid MQTT management
307
314 const dotdot_endpoint_id_t &ep);
315
323 const dotdot_endpoint_id_t &ep);
324
330std::map<std::string, std::vector<endpoint_cache_t>, std::less<>>
332
338std::vector<endpoint_cache_t>
340} // namespace unid_state_handler
341
342#endif //OTA_CACHE_HPP
Handling timeout data and ctimers sharing data.
Definition: ota_cache.hpp:65
TimeoutHandler & operator=(TimeoutHandler &&)=delete
~TimeoutHandler()
TimeoutHandler deconstructor. Will stop ctimer in shared ptr.
TimeoutHandler(timeout_handler_t input_timeout_data)
Definition: ota_cache.hpp:74
std::string get_unid() const
std::shared_ptr< timeout_handler_t > timeout_data
Definition: ota_cache.hpp:66
bool get_unid_poll_state() const
ctimer * get_ctimer_pointer() const
TimeoutHandler & operator=(const TimeoutHandler &)=delete
void set_unid_poll_state(bool state) const
TimeoutHandler()=default
TimeoutHandler constructor.
uic_ota::image_ready_funct_t get_image_ready_cb() const
std::string get_subscribe_topic() const
TimeoutHandler(TimeoutHandler &&)=delete
Definition: ota_cache.hpp:101
bool is_image_received_and_cached(const std::string &key)
Check if image is received and cached.
void clear_images_cache()
Clear out cache of images.
uic_ota::meta_t get_image_meta_info(const std::string &key)
Get image meta info.
void set_image_meta_info(const std::string &key, const uic_ota::meta_t &meta_info)
Setting image filename.
bool check_if_meta_info_received(const std::string &key)
Checks if meta info is received for image key.
void set_images_received_cached_filepath(const std::string &key, const std::string &filepath)
Set image which is received and cache it.
void remove_image_meta_info(const std::string &key)
Remove image meta info.
std::string get_image_cached_filepath(const std::string &key)
Get image which is received and cached.
std::function< void(const image_ready_result_t, const std::string &)> image_ready_funct_t
this callback is returned when the actually firmware image is downloaded and stored to disk,...
Definition: ota.hpp:209
Definition: ota_cache.hpp:190
std::map< std::string, std::vector< endpoint_cache_t >, std::less<> > get_map_status_published_cached_and_clear()
Get map of published UNID and endpoints.
void set_status_published_cached(const dotdot_unid_t &unid, const dotdot_endpoint_id_t &ep)
Set UNID and endpoint as published to.
std::vector< std::string > get_unids_listening(const std::string &uiid)
Get all UNIDs listening to a specific UIID.
void pop_unid_poll(const std::string &unid)
Pop key from image key poll.
bool is_unid_in_poll(const std::string &unid)
Check if UNID in poll.
bool get_unid_poll_state(const std::string &unid)
Get image key poll state.
std::map< std::string, std::vector< std::string >, std::less<> > get_uiids_and_unids_listening()
Get all UIIDs and UNIDs active.
void remove_unid_listening(const std::string &uiid, const std::string &unid)
Remove UNID listening on UIID.
void set_unid_listening(const std::string &uiid, const std::string &unid)
Set UNID to listening on UIID.
bool is_status_published(const dotdot_unid_t &unid, const dotdot_endpoint_id_t &ep)
Check if UNID and ep has been published to.
std::vector< endpoint_cache_t > get_endpoints_status_published_and_pop(const dotdot_unid_t &unid)
Get published status updates on UNID and pop.
std::size_t get_unids_listening_count(const std::string &uiid)
Get count of listening UNIDs to a UIID.
std::vector< std::string > get_uiids_unid_is_listening_to(const std::string &unid)
Get all UIIDs which a single UNID is listening to.
bool is_poll_topic_subscribed(const std::string &topic)
Check if the topic is already subscribed.
void set_unid_poll(std::shared_ptr< TimeoutHandler > timeout_handler)
Setting image status of a specific image key.
void set_unid_poll_state_true(const std::string &unid)
Set UNID poll state.
uic_ota::image_ready_funct_t get_unid_callback(const std::string &unid)
Get the image callback for a specific image key.
struct timeout_handler timeout_handler_t
Setting the image callback for a specific image key.
uint8_t endpoint_cache_t
Type definition for endpoint caching.
Definition: ota_cache.hpp:41
Definition: ctimer.h:64
Setting the image callback for a specific image key.
Definition: ota_cache.hpp:51
std::string subscribe_topic
Definition: ota_cache.hpp:53
std::string unid
Definition: ota_cache.hpp:52
uic_ota::image_ready_funct_t image_ready_cb
Definition: ota_cache.hpp:55
struct ctimer timeout_timer
Definition: ota_cache.hpp:56
bool state
Definition: ota_cache.hpp:54
Struct that describes meta for a new available image.
Definition: ota.hpp:186
uint8_t dotdot_endpoint_id_t
Definition: uic_typedefs.h:38
const char * dotdot_unid_t
Definition: uic_typedefs.h:39