AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
StateReportGenerator.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #ifndef ALEXA_CLIENT_SDK_CAPABILITYAGENTS_SYSTEM_INCLUDE_SYSTEM_STATEREPORTGENERATOR_H_
17 #define ALEXA_CLIENT_SDK_CAPABILITYAGENTS_SYSTEM_INCLUDE_SYSTEM_STATEREPORTGENERATOR_H_
18 
19 #include <array>
20 #include <memory>
21 #include <string>
22 
28 
29 namespace alexaClientSDK {
30 namespace capabilityAgents {
31 namespace system {
32 
39 public:
42  template <class SettingsManagerT>
43  using SettingConfigurations =
45 
54  template <class SettingsManagerT>
56  std::shared_ptr<SettingsManagerT> settingManager,
57  const SettingConfigurations<SettingsManagerT>& configurations);
58 
64  std::vector<std::string> generateReport();
65 
69  StateReportGenerator() = default;
70 
71 protected:
77  explicit StateReportGenerator(const std::vector<std::function<std::string()>>& reportFunctions);
78 
79 private:
86  template <class SettingsManagerT, ssize_t index = SettingsManagerT::NUMBER_OF_SETTINGS - 1>
87  struct StringFunctionWrapper {
95  void operator()(
96  const std::shared_ptr<SettingsManagerT>& manager,
97  const SettingConfigurations<SettingsManagerT>& configurations,
98  std::vector<std::function<std::string()>>& reportFunctions);
99  };
100 
106  template <class SettingsManagerT>
107  struct StringFunctionWrapper<SettingsManagerT, -1> {
115  void operator()(
116  const std::shared_ptr<SettingsManagerT>& manager,
117  const SettingConfigurations<SettingsManagerT>& configurations,
118  std::vector<std::function<std::string()>>& reportFunctions);
119  };
120 
128  static std::string generateSettingStateReport(
129  const settings::SettingEventMetadata& metadata,
130  const std::string& value);
131 
133  std::vector<std::function<std::string()>> m_reportFunctions;
134 };
135 
136 template <class SettingsManagerT>
138  std::shared_ptr<SettingsManagerT> manager,
139  const SettingConfigurations<SettingsManagerT>& configurations) {
140  if (!manager) {
142  avsCommon::utils::logger::LogEntry("StateReportGenerator", "createFailed").d("reason", "nullManager"));
144  }
145  std::vector<std::function<std::string()>> reportFunctions;
146  StringFunctionWrapper<SettingsManagerT> wrapper;
147  wrapper(manager, configurations, reportFunctions);
149 }
150 
151 template <class SettingsManagerT, ssize_t index>
152 void StateReportGenerator::StringFunctionWrapper<SettingsManagerT, index>::operator()(
153  const std::shared_ptr<SettingsManagerT>& settingsManager,
154  const SettingConfigurations<SettingsManagerT>& configurations,
155  std::vector<std::function<std::string()>>& reportFunctions) {
156  if (std::get<index>(configurations).metadata.hasValue()) {
157  auto metadata = std::get<index>(configurations).metadata.value();
158  reportFunctions.push_back([settingsManager, metadata] {
159  return generateSettingStateReport(metadata, settingsManager->template getJsonValue<index>());
160  });
161  }
162 
163  StringFunctionWrapper<SettingsManagerT, index - 1> wrapper;
164  wrapper(settingsManager, configurations, reportFunctions);
165 }
166 
167 template <class SettingsManagerT>
168 void StateReportGenerator::StringFunctionWrapper<SettingsManagerT, -1>::operator()(
169  const std::shared_ptr<SettingsManagerT>& settingsManager,
170  const SettingConfigurations<SettingsManagerT>& configurations,
171  std::vector<std::function<std::string()>>& reportFunctions) {
172  // Do nothing. This is the end of the loop.
173 }
174 
175 } // namespace system
176 } // namespace capabilityAgents
177 } // namespace alexaClientSDK
178 
179 #endif // ALEXA_CLIENT_SDK_CAPABILITYAGENTS_SYSTEM_INCLUDE_SYSTEM_STATEREPORTGENERATOR_H_
Definition: SettingEventMetadata.h:27
::std::string string
Definition: gtest-port.h:1097
typename settings::SettingsManagerBuilderBase< SettingsManagerT >::SettingConfigurations SettingConfigurations
Definition: StateReportGenerator.h:44
Definition: SettingsManagerBuilderBase.h:35
static int index
Mock buffer index.
Definition: AndroidSLESMediaQueueTest.cpp:70
static avsCommon::utils::Optional< StateReportGenerator > create(std::shared_ptr< SettingsManagerT > settingManager, const SettingConfigurations< SettingsManagerT > &configurations)
Definition: StateReportGenerator.h:137
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
void acsdkError(const LogEntry &entry)
ValueT value() const
Definition: Optional.h:208
LogEntry is used to compile the log entry text to log via Logger.
Definition: LogEntry.h:33

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0