AlexaClientSDK  1.26.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 
31 
34 
35 namespace alexaClientSDK {
36 namespace capabilitiesDelegate {
37 
43  , public std::enable_shared_from_this<DiscoveryEventSender> {
44 public:
56  static std::shared_ptr<DiscoveryEventSender> create(
57  const std::unordered_map<std::string, std::string>& addOrUpdateReportEndpoints,
58  const std::unordered_map<std::string, std::string>& deleteReportEndpoints,
59  const std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface>& authDelegate,
60  const bool waitForEventProcessed = true);
61 
66 
70  const std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender) override;
71  void stop() override;
72  void addDiscoveryStatusObserver(const std::shared_ptr<DiscoveryStatusObserverInterface>& observer) override;
73  void removeDiscoveryStatusObserver(const std::shared_ptr<DiscoveryStatusObserverInterface>& observer) override;
75 
78  void onAlexaEventProcessedReceived(const std::string& eventCorrelationToken) override;
80 
85 private:
97  const std::unordered_map<std::string, std::string>& addOrUpdateReportEndpoints,
98  const std::unordered_map<std::string, std::string>& deleteReportEndpoints,
99  const std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface>& authDelegate,
100  const bool waitForEventProcessed);
101 
112  bool sendDiscoveryEventWithRetries(
113  const std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender,
114  const std::vector<std::string>& endpointConfigurations,
115  bool isAddOrUpdateReportEvent = true);
116 
127  const std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender,
128  const std::string& eventString,
129  bool waitForEventProcessed = true);
130 
138  bool sendAddOrUpdateReportEvents(
139  const std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender);
140 
148  bool sendDeleteReportEvents(const std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender);
149 
159  bool sendDiscoveryEvents(
160  const std::vector<std::string>& endpointConfigurations,
161  const std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender,
162  bool isAddOrUpdateReportEvent = true);
163 
170 
178  std::string getAuthToken();
179 
185  bool isStopping();
186 
188  std::unordered_map<std::string, std::string> m_addOrUpdateReportEndpoints;
189 
191  std::unordered_map<std::string, std::string> m_deleteReportEndpoints;
192 
194  std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface> m_authDelegate;
195 
197  AuthObserverInterface::State m_currentAuthState;
198 
200  std::mutex m_authStatusMutex;
201 
204 
207  std::string m_currentEventCorrelationToken;
208 
210  bool m_isStopping;
211 
213  avsCommon::utils::WaitEvent m_eventProcessedWaitEvent;
214 
216  avsCommon::utils::WaitEvent m_retryWait;
217 
219  std::mutex m_mutex;
220 
222  std::shared_ptr<avsCommon::avs::WaitableMessageRequest> m_messageRequest;
223 
225  std::mutex m_observerMutex;
226 
228  std::shared_ptr<DiscoveryStatusObserverInterface> m_observer;
229 
231  std::mutex m_isSendDiscoveryEventsInvokedMutex;
232 
234  bool m_isSendDiscoveryEventsInvoked;
235 
237  const bool m_waitForEventProcessed;
238 };
239 
240 } // namespace capabilitiesDelegate
241 } // namespace alexaClientSDK
242 
243 #endif // ALEXA_CLIENT_SDK_CAPABILITIESDELEGATE_INCLUDE_CAPABILITIESDELEGATE_DISCOVERYEVENTSENDER_H_
void addDiscoveryStatusObserver(const std::shared_ptr< DiscoveryStatusObserverInterface > &observer) override
Definition: DiscoveryEventSender.cpp:355
Definition: DiscoveryEventSenderInterface.h:29
~DiscoveryEventSender()
Definition: DiscoveryEventSender.cpp:92
State
The enum State describes the state of authorization.
Definition: AuthObserverInterface.h:34
Error
The enum Error encodes possible errors which may occur when changing state.
Definition: AuthObserverInterface.h:48
bool sendDiscoveryEvents(const std::shared_ptr< avsCommon::sdkInterfaces::MessageSenderInterface > &messageSender) override
Definition: DiscoveryEventSender.cpp:96
void stop() override
Definition: DiscoveryEventSender.cpp:151
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
void onAlexaEventProcessedReceived(const std::string &eventCorrelationToken) override
Definition: DiscoveryEventSender.cpp:345
void onAuthStateChange(AuthObserverInterface::State newState, AuthObserverInterface::Error newError) override
Definition: DiscoveryEventSender.cpp:125
void removeDiscoveryStatusObserver(const std::shared_ptr< DiscoveryStatusObserverInterface > &observer) override
Definition: DiscoveryEventSender.cpp:367
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, const bool waitForEventProcessed=true)
Definition: DiscoveryEventSender.cpp:60
Status
Definition: MessageRequestObserverInterface.h:33

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