Unify Framework Lib 1.6.0
smartstart_management.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
66#ifndef SMARTSTART_MANAGEMENT_HPP
67#define SMARTSTART_MANAGEMENT_HPP
68
69#include <unordered_map>
70#include <string>
71#include <variant>
72#include <functional>
73#include <vector>
74
75#include "sl_log.h"
76#include "sl_status.h"
77
78namespace smartstart
79{
87enum class QueryType { exact, partial };
88
89using QueryValue = std::variant<bool, std::string>;
90using notification_function_t = std::function<void(bool)>;
95class Query
96{
97 public:
107 Query(QueryType type, QueryKey key, const QueryValue &value) :
108 query_type {type}, query_key {key}, query_value {value}
109 {}
110};
111
116class Entry
117{
118 public:
119 std::string dsk;
122 std::string device_unid;
123 std::vector<std::string> preferred_protocols;
132 Entry() = default;
133 Entry(const std::string &dsk,
134 bool include,
135 const std::string &protocol_controller_unid,
136 const std::string &device_unid) :
137 dsk {dsk},
141 {}
142};
143
150{
151 private:
155 std::unordered_map<std::string, Entry> _smartstart_cache;
156
158
163
165
166 Management() = default;
167
168 public:
172 Management(Management &other) = delete;
173 void operator=(const Management &) = delete;
178
186 const std::string &protocol_controller_unid,
187 notification_function_t const &has_entries_awaiting_inclusion_callback);
194 std::vector<Entry> get_cache_entries(const Query &query);
205 sl_status_t update_smartstart_cache(const std::string &smartstart_list);
206
212
218 sl_status_t notify_node_added(const std::string &dsk,
219 const std::string &device_unid);
224 sl_status_t notify_node_removed(const std::string &unid);
225
237 set_manual_intervention_required(const std::string &dsk,
238 bool manual_intervention_required);
239
240 const std::unordered_map<std::string, Entry> &get_cache() const;
241};
242
243} /* namespace smartstart */
244
247#endif //SMARTSTART_MANAGEMENT_H
The unit data type stored in SmartStart List as value.
Definition: smartstart_management.hpp:117
Entry()=default
smartstart::Entry constructor.
std::string protocol_controller_unid
Definition: smartstart_management.hpp:121
std::vector< std::string > preferred_protocols
Definition: smartstart_management.hpp:123
std::string dsk
Definition: smartstart_management.hpp:119
bool include
Definition: smartstart_management.hpp:120
Entry(const std::string &dsk, bool include, const std::string &protocol_controller_unid, const std::string &device_unid)
Definition: smartstart_management.hpp:133
std::string device_unid
Definition: smartstart_management.hpp:122
bool manual_intervention_required
Definition: smartstart_management.hpp:124
Class that provides APIs to add, update, and access SmartStart List. Also it offers callback for noti...
Definition: smartstart_management.hpp:150
Management(Management &other)=delete
Disable assign and constructor.
bool has_entries_awaiting_inclusion()
Polling function which returns True if there is any entries with Include == true. This could be usefu...
static Management * get_instance()
Get the singleton instance.
notification_function_t _notify_has_entries_awaiting_inclusion
Function called when there are entries waiting for inclusion in the SmartStart list.
Definition: smartstart_management.hpp:162
sl_status_t update_smartstart_cache(const std::string &smartstart_list)
Update the internal cache of SmartStartList.
sl_status_t init(const std::string &protocol_controller_unid, notification_function_t const &has_entries_awaiting_inclusion_callback)
Initialize function that takes protocol controller unid and a callback function signaling when entrie...
std::string _protocol_controller_unid
Definition: smartstart_management.hpp:157
sl_status_t notify_node_removed(const std::string &unid)
Called when a node has been removed and SSM will then update the cache map.
sl_status_t teardown()
sl_status_t notify_node_added(const std::string &dsk, const std::string &device_unid)
Called when a node has been added and SSM will then update the cache map.
std::vector< Entry > get_cache_entries(const Query &query)
Get the cache entries with given query conditions.
sl_status_t set_manual_intervention_required(const std::string &dsk, bool manual_intervention_required)
Call this function to change the value of the "ManualInterventionRequired" field.
std::unordered_map< std::string, Entry > _smartstart_cache
SmartStart List cache map, key is DSK as a string.
Definition: smartstart_management.hpp:155
const std::unordered_map< std::string, Entry > & get_cache() const
static Management * _instance
Definition: smartstart_management.hpp:164
void operator=(const Management &)=delete
Class that contains key, type, an value for querying SmartStart List.
Definition: smartstart_management.hpp:96
QueryType query_type
Definition: smartstart_management.hpp:98
QueryKey query_key
Definition: smartstart_management.hpp:99
QueryValue query_value
Definition: smartstart_management.hpp:100
Query(QueryType type, QueryKey key, const QueryValue &value)
smartstart::Query constructor.
Definition: smartstart_management.hpp:107
uint32_t sl_status_t
Definition: sl_status.h:139
Definition: smartstart_management.hpp:79
QueryType
Enum class representing types for querying SmartStart List.
Definition: smartstart_management.hpp:87
QueryKey
Enum class representing keys for querying SmartStart List.
Definition: smartstart_management.hpp:83
std::function< void(bool)> notification_function_t
Definition: smartstart_management.hpp:90
std::variant< bool, std::string > QueryValue
Definition: smartstart_management.hpp:89
SL Status Codes.