16 #ifndef ALEXA_CLIENT_SDK_SETTINGS_INCLUDE_SETTINGS_SETTINGSMANAGER_H_ 17 #define ALEXA_CLIENT_SDK_SETTINGS_INCLUDE_SETTINGS_SETTINGSMANAGER_H_ 22 #include <type_traits> 42 template <
typename SettingsT>
53 template <
typename... SettingsT>
57 template <
size_t index>
61 template <
size_t index>
65 template <
size_t index>
69 template <
typename SettingT>
76 static constexpr
size_t NUMBER_OF_SETTINGS{
sizeof...(SettingsT)};
85 std::shared_ptr<registrationManager::CustomerDataManagerInterface> dataManager,
94 SettingsManager(std::shared_ptr<registrationManager::CustomerDataManagerInterface> dataManager);
108 template <
size_t index>
119 template <
size_t index>
129 template <
size_t index>
139 template <
size_t index>
148 template <
size_t index>
158 template <
size_t index>
167 template <
size_t index>
176 template <
size_t index>
193 template <
size_t index>
194 std::shared_ptr<SettingType<index>> getSetting()
const;
198 void clearData()
override;
211 template <
size_t index>
212 typename std::enable_if<index >= NUMBER_OF_SETTINGS,
void>
::type doClearData() {
222 template <
size_t index>
223 typename std::enable_if<index <= NUMBER_OF_SETTINGS - 1,
void>
::type doClearData() {
224 auto&
setting = std::get<index>(m_settings);
228 .d(
"reason",
"invalidSetting")
229 .d(
"settingIndex", index));
233 LogEntry(
"SettingManager", __func__).d(
"reason",
"invalidSetting").d(
"settingIndex", index));
235 doClearData<index + 1>();
249 mutable std::mutex m_mutex;
252 std::tuple<SettingPointerType<SettingsT>...> m_settings;
258 template <
typename... SettingsT>
260 std::shared_ptr<registrationManager::CustomerDataManagerInterface> dataManager,
262 CustomerDataHandler{dataManager},
263 m_settingConfigs{settingConfiguration} {
266 template <
typename... SettingsT>
268 std::shared_ptr<registrationManager::CustomerDataManagerInterface> dataManager) :
272 template <
typename... SettingsT>
273 template <
size_t index>
276 std::lock_guard<std::mutex> lock{m_mutex};
277 auto& setting = std::get<index>(m_settings);
279 return {
true, setting->get()};
283 LogEntry(
"SettingManager",
"getValueFailed").d(
"reason",
"invalidSetting").d(
"settingIndex",
index));
284 return {
false, defaultValue};
287 template <
typename... SettingsT>
288 template <
size_t index>
290 std::lock_guard<std::mutex> lock{m_mutex};
291 auto& setting = std::get<index>(m_settings);
293 auto result = toSettingString<ValueType<index>>(setting->get());
296 .d(
"reason",
"toSettingStringFailed")
297 .d(
"settingIndex",
index));
300 return result.second;
304 LogEntry(
"SettingManager", __func__).d(
"result",
"noSettingAvailable").d(
"settingIndex",
index));
308 template <
typename... SettingsT>
309 template <
size_t index>
311 std::lock_guard<std::mutex> lock{m_mutex};
312 auto& setting = std::get<index>(m_settings);
314 return setting->setLocalChange(value);
318 LogEntry(
"SettingManager",
"setValueFailed").d(
"reason",
"invalidSetting").d(
"settingIndex",
index));
322 template <
typename... SettingsT>
323 template <
size_t index>
325 std::lock_guard<std::mutex> lock{m_mutex};
326 auto& setting = std::get<index>(m_settings);
327 if (setting && observer) {
328 return setting->addObserver(observer);
332 LogEntry(
"SettingManager",
"addObserverFailed").d(
"reason",
"invalidSetting").d(
"settingIndex",
index));
336 template <
typename... SettingsT>
337 template <
size_t index>
339 std::lock_guard<std::mutex> lock{m_mutex};
340 auto& setting = std::get<index>(m_settings);
341 if (setting && observer) {
342 setting->removeObserver(observer);
347 LogEntry(
"SettingManager",
"removeObserverFailed").d(
"reason",
"invalidSetting").d(
"settingIndex",
index));
350 template <
typename... SettingsT>
351 template <
size_t index>
353 std::lock_guard<std::mutex> lock{m_mutex};
354 auto& setting = std::get<index>(m_settings);
355 if (!setting && newSetting) {
356 setting.swap(newSetting);
361 LogEntry(
"SettingManager",
"addSettingFailed").d(
"reason",
"invalidSetting").d(
"settingIndex",
index));
365 template <
typename... SettingsT>
366 template <
size_t index>
368 std::lock_guard<std::mutex> lock{m_mutex};
369 auto& setting = std::get<index>(m_settings);
370 if (setting == oldSetting) {
374 LogEntry(
"SettingManager",
"removeSettingFailed").d(
"reason",
"invalidSetting").d(
"settingIndex",
index));
378 template <
typename... SettingsT>
379 template <
size_t index>
381 std::lock_guard<std::mutex> lock{m_mutex};
382 return std::get<index>(m_settings);
385 template <
typename... SettingsT>
387 std::lock_guard<std::mutex> lock{m_mutex};
391 template <
typename... SettingsT>
393 return m_settingConfigs;
396 template <
typename... SettingsT>
397 template <
size_t index>
400 return std::get<index>(m_settingConfigs).setting;
406 #endif // ALEXA_CLIENT_SDK_SETTINGS_INCLUDE_SETTINGS_SETTINGSMANAGER_H_ typename std::tuple_element< index, std::tuple< SettingsT... > >::type SettingType
The setting type kept at index position.
Definition: SettingsManager.h:58
Definition: SettingsManager.h:54
bool addSetting(std::shared_ptr< SettingType< index >> setting)
Definition: SettingsManager.h:352
typename SettingType< index >::ObserverType ObserverType
Define the observer type for setting kept on position index.
Definition: SettingsManager.h:66
std::shared_ptr< SettingT > SettingPointerType
Define the shared_ptr type for the given SettingT.
Definition: SettingsManager.h:70
void acsdkDebug0(const LogEntry &entry)
std::string getJsonValue() const
Definition: SettingsManager.h:289
::std::string string
Definition: gtest-port.h:1097
CustomerDataHandler(const std::shared_ptr< registrationManager::CustomerDataManagerInterface > &dataManager)
typename SettingType< index >::ValueType ValueType
Define the value type for setting kept on position index.
Definition: SettingsManager.h:62
std::pair< bool, ValueType< index > > getValue(const ValueType< index > &defaultValue=ValueType< index >()) const
SettingsManager(std::shared_ptr< registrationManager::CustomerDataManagerInterface > dataManager, SettingConfigurations settingConfigurations)
Definition: SettingsManager.h:259
Definition: Optional.h:32
The request failed because the setting requested does not exist.
bool addObserver(std::shared_ptr< ObserverType< index >> observer)
Definition: SettingsManager.h:324
void removeSetting(std::shared_ptr< SettingType< index >> setting)
Definition: SettingsManager.h:367
SettingConfigurations getConfigurations() const
Definition: SettingsManager.h:392
SetSettingResult
Definition: SetSettingResult.h:23
Definition: SettingsManager.h:43
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
bool hasSetting()
Definition: SettingsManager.h:380
SetSettingResult setValue(const ValueType< index > &value)
Definition: SettingsManager.h:310
avsCommon::utils::Optional< settings::SettingEventMetadata > metadata
The setting metadata.
Definition: SettingsManager.h:47
type
Definition: upload.py:443
void removeObserver(std::shared_ptr< ObserverType< index >> observer)
Definition: SettingsManager.h:338
void acsdkError(const LogEntry &entry)
std::shared_ptr< SettingsT > setting
The setting configured.
Definition: SettingsManager.h:45
std::shared_ptr< SettingType< index > > getSetting() const
Definition: CustomerDataHandler.h:34
std::tuple< SettingConfiguration< SettingsT >... > SettingConfigurations
The tuple holding the settings configuration.
Definition: SettingsManager.h:73
void clearData() override
Definition: SettingsManager.h:386
LogEntry is used to compile the log entry text to log via Logger.
Definition: LogEntry.h:33