AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
SettingEventSender.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_SETTINGS_INCLUDE_SETTINGS_SETTINGEVENTSENDER_H_
17 #define ALEXA_CLIENT_SDK_SETTINGS_INCLUDE_SETTINGS_SETTINGEVENTSENDER_H_
18 
19 #include <condition_variable>
20 #include <memory>
21 #include <mutex>
22 #include <string>
23 #include <vector>
24 
33 
34 namespace alexaClientSDK {
35 namespace settings {
36 
41 public:
49  static std::unique_ptr<SettingEventSender> create(
50  const SettingEventMetadata& metadata,
51  std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
52  const std::vector<int>& retryTable = getDefaultRetryTable());
53 
59 
62  std::shared_future<bool> sendChangedEvent(const std::string& value) override;
63  std::shared_future<bool> sendReportEvent(const std::string& value) override;
64  std::shared_future<bool> sendStateReportEvent(const std::string& payload) override;
65  void cancel() override;
67 
68 private:
69  /*
70  * Constructor.
71  *
72  * @param messageSender The delivery service for the AVS events.
73  * @param retryTable A list of back-off times in milliseconds used in resending events.
74  */
76  const SettingEventMetadata& metadata,
77  std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
78  const std::vector<int>& retryTable);
79 
80  /*
81  * Helper function to send the changed and report events.
82  *
83  * @param eventJson The event json to be sent.
84  * @return A future expressing if the event has been sent to AVS.
85  */
86  std::shared_future<bool> sendEvent(const std::string& eventJson);
87 
95  std::string buildEventJson(const std::string& eventName, const std::string& value) const;
96 
102  static const std::vector<int>& getDefaultRetryTable();
103 
105  const SettingEventMetadata m_metadata;
106 
108  std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> m_messageSender;
109 
111  std::mutex m_sendMutex;
112 
114  avsCommon::utils::WaitEvent m_waitCancelEvent;
115 
117  avsCommon::utils::RetryTimer m_retryTimer;
118 
120  const std::size_t m_maxRetries;
121 };
122 
123 } // namespace settings
124 } // namespace alexaClientSDK
125 #endif // ALEXA_CLIENT_SDK_SETTINGS_INCLUDE_SETTINGS_SETTINGEVENTSENDER_H_
static std::unique_ptr< SettingEventSender > create(const SettingEventMetadata &metadata, std::shared_ptr< avsCommon::sdkInterfaces::MessageSenderInterface > messageSender, const std::vector< int > &retryTable=getDefaultRetryTable())
Definition: SettingEventMetadata.h:27
::std::string string
Definition: gtest-port.h:1097
std::shared_future< bool > sendChangedEvent(const std::string &value) override
std::shared_future< bool > sendStateReportEvent(const std::string &payload) override
Definition: SettingEventSenderInterface.h:29
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
Definition: SettingEventSender.h:40
std::shared_future< bool > sendReportEvent(const std::string &value) override

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