AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
DiscoveryEventSender.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_CAPABILITIESDELEGATE_INCLUDE_CAPABILITIESDELEGATE_DISCOVERYEVENTSENDER_H_
17 #define ALEXA_CLIENT_SDK_CAPABILITIESDELEGATE_INCLUDE_CAPABILITIESDELEGATE_DISCOVERYEVENTSENDER_H_
18 
19 #include <memory>
20 #include <mutex>
21 #include <string>
22 #include <unordered_map>
23 
32 
35 
36 namespace alexaClientSDK {
37 namespace capabilitiesDelegate {
38 
44  , public std::enable_shared_from_this<DiscoveryEventSender> {
45 public:
59  static std::shared_ptr<DiscoveryEventSender> create(
60  const std::unordered_map<std::string, std::string>& addOrUpdateReportEndpoints,
61  const std::unordered_map<std::string, std::string>& deleteReportEndpoints,
62  const std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface>& authDelegate,
63  bool waitForEventProcessed = true,
64  const std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface>& metricRecorder = nullptr,
65  bool postConnect = false);
66 
71 
75  const std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender) override;
76  void stop() override;
77  void addDiscoveryStatusObserver(const std::shared_ptr<DiscoveryStatusObserverInterface>& observer) override;
78  void removeDiscoveryStatusObserver(const std::shared_ptr<DiscoveryStatusObserverInterface>& observer) override;
80 
83  void onAlexaEventProcessedReceived(const std::string& eventCorrelationToken) override;
85 
88  void onAuthStateChange(AuthObserverInterface::State newState, AuthObserverInterface::Error newError) override;
90 private:
104  const std::unordered_map<std::string, std::string>& addOrUpdateReportEndpoints,
105  const std::unordered_map<std::string, std::string>& deleteReportEndpoints,
106  const std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface>& authDelegate,
107  bool waitForEventProcessed,
108  const std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface>& metricRecorder,
109  bool postConnect);
110 
121  bool sendDiscoveryEventWithRetries(
122  const std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender,
123  const std::vector<std::string>& endpointConfigurations,
124  bool isAddOrUpdateReportEvent = true);
125 
136  const std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender,
137  const std::string& eventString,
138  bool waitForEventProcessed = true);
139 
147  bool sendAddOrUpdateReportEvents(
148  const std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender);
149 
157  bool sendDeleteReportEvents(const std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender);
158 
168  bool sendDiscoveryEvents(
169  const std::vector<std::string>& endpointConfigurations,
170  const std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender,
171  bool isAddOrUpdateReportEvent = true);
172 
179 
187  std::string getAuthToken();
188 
194  bool isStopping();
195 
197  std::unordered_map<std::string, std::string> m_addOrUpdateReportEndpoints;
198 
200  std::unordered_map<std::string, std::string> m_deleteReportEndpoints;
201 
203  std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface> m_authDelegate;
204 
206  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> m_metricRecorder;
207 
209  AuthObserverInterface::State m_currentAuthState;
210 
212  std::mutex m_authStatusMutex;
213 
216 
219  std::string m_currentEventCorrelationToken;
220 
222  bool m_isStopping;
223 
225  avsCommon::utils::WaitEvent m_eventProcessedWaitEvent;
226 
228  avsCommon::utils::WaitEvent m_retryWait;
229 
231  std::mutex m_mutex;
232 
234  std::shared_ptr<avsCommon::avs::WaitableMessageRequest> m_messageRequest;
235 
237  std::mutex m_observerMutex;
238 
240  std::shared_ptr<DiscoveryStatusObserverInterface> m_observer;
241 
243  std::mutex m_isSendDiscoveryEventsInvokedMutex;
244 
246  bool m_isSendDiscoveryEventsInvoked;
247 
249  const bool m_waitForEventProcessed;
250 
252  const bool m_postConnect;
253 };
254 
255 } // namespace capabilitiesDelegate
256 } // namespace alexaClientSDK
257 
258 #endif // ALEXA_CLIENT_SDK_CAPABILITIESDELEGATE_INCLUDE_CAPABILITIESDELEGATE_DISCOVERYEVENTSENDER_H_
void addDiscoveryStatusObserver(const std::shared_ptr< DiscoveryStatusObserverInterface > &observer) override
Definition: DiscoveryEventSenderInterface.h:29
::std::string string
Definition: gtest-port.h:1097
static std::shared_ptr< DiscoveryEventSender > create(const std::unordered_map< std::string, std::string > &addOrUpdateReportEndpoints, const std::unordered_map< std::string, std::string > &deleteReportEndpoints, const std::shared_ptr< avsCommon::sdkInterfaces::AuthDelegateInterface > &authDelegate, bool waitForEventProcessed=true, const std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > &metricRecorder=nullptr, bool postConnect=false)
static std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder
Metric recorder shared ptr.
Definition: BaseAPLCapabilityAgentTest.cpp:261
bool sendDiscoveryEvents(const std::shared_ptr< avsCommon::sdkInterfaces::MessageSenderInterface > &messageSender) override
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
void onAlexaEventProcessedReceived(const std::string &eventCorrelationToken) override
void onAuthStateChange(AuthObserverInterface::State newState, AuthObserverInterface::Error newError) override
void removeDiscoveryStatusObserver(const std::shared_ptr< DiscoveryStatusObserverInterface > &observer) override
Status
Definition: MessageRequestObserverInterface.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