AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
SettingCallbackAdapter.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 #ifndef ALEXA_CLIENT_SDK_SETTINGS_INCLUDE_SETTINGS_SETTINGCALLBACKADAPTER_H_
16 #define ALEXA_CLIENT_SDK_SETTINGS_INCLUDE_SETTINGS_SETTINGCALLBACKADAPTER_H_
17 
18 #include <functional>
19 #include <memory>
20 
21 #include "SettingsManager.h"
23 
24 namespace alexaClientSDK {
25 namespace settings {
26 
32 template <typename ManagerT>
34 public:
35  virtual ~SettingCallbackAdapterInterface() = default;
36 
43  virtual bool addToManager(ManagerT& manager) = 0;
44 
50  virtual void removeFromManager(ManagerT& manager) = 0;
51 };
52 
74 template <typename ManagerT, size_t id>
76  : public SettingCallbackAdapterInterface<ManagerT>
77  , public ManagerT::template ObserverType<id>
78  , public std::enable_shared_from_this<SettingCallbackAdapter<ManagerT, id>> {
79 public:
81  using ValueType = typename ManagerT::template ValueType<id>;
82 
84  using FunctionType = std::function<void(const ValueType&, SettingNotifications)>;
85 
91  static std::shared_ptr<SettingCallbackAdapter> create(FunctionType callback);
92 
96  virtual ~SettingCallbackAdapter() = default;
97 
100  bool addToManager(ManagerT& manager) override;
101  void removeFromManager(ManagerT& manager) override;
103 
104 private:
110 
113  virtual void onSettingNotification(const ValueType& value, SettingNotifications notification) override;
115 
117  FunctionType m_callback;
118 };
119 
120 template <typename ManagerT, size_t id>
122  const ValueType& value,
124  m_callback(value, notification);
125 }
126 
127 template <typename ManagerT, size_t id>
129 }
130 
131 template <typename ManagerT, size_t id>
134  return manager.template addObserver<id>(this->shared_from_this());
135 };
136 
137 template <typename ManagerT, size_t id>
140  return manager.template removeObserver<id>(this->shared_from_this());
141 };
142 
143 template <typename ManagerT, size_t id>
144 std::shared_ptr<SettingCallbackAdapter<ManagerT, id>> SettingCallbackAdapter<ManagerT, id>::create(
146  if (callback) {
147  return std::shared_ptr<SettingCallbackAdapter<ManagerT, id>>(
149  }
150  return nullptr;
151 }
152 
153 } // namespace settings
154 } // namespace alexaClientSDK
155 
156 #endif // ALEXA_CLIENT_SDK_SETTINGS_INCLUDE_SETTINGS_SETTINGCALLBACKADAPTER_H_
typename ManagerT::template ValueType< id > ValueType
Setting value type.
Definition: SettingCallbackAdapter.h:81
virtual void removeFromManager(ManagerT &manager)=0
static std::shared_ptr< SettingCallbackAdapter > create(FunctionType callback)
Definition: SettingCallbackAdapter.h:144
Definition: SettingCallbackAdapter.h:75
Definition: SettingCallbackAdapter.h:33
void removeFromManager(ManagerT &manager) override
Definition: SettingCallbackAdapter.h:138
bool addToManager(ManagerT &manager) override
Definition: SettingCallbackAdapter.h:132
std::function< void(const ValueType &, SettingNotifications)> FunctionType
Callback function value type.
Definition: SettingCallbackAdapter.h:84
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
SettingNotifications
Definition: SettingObserverInterface.h:28

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