AlexaClientSDK  1.26.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
CapabilitiesDelegate.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_CAPABILITIESDELEGATE_H_
17 #define ALEXA_CLIENT_SDK_CAPABILITIESDELEGATE_INCLUDE_CAPABILITIESDELEGATE_CAPABILITIESDELEGATE_H_
18 
19 #include <unordered_map>
20 #include <memory>
21 #include <mutex>
22 #include <string>
23 
26 
43 
44 namespace alexaClientSDK {
45 namespace capabilitiesDelegate {
46 
53  std::unordered_map<std::string, std::string> pending;
54 
57  std::unordered_map<std::string, std::string> inFlight;
58 };
59 
70  , public std::enable_shared_from_this<CapabilitiesDelegate> {
71 public:
83  static std::shared_ptr<CapabilitiesDelegateInterface> createCapabilitiesDelegateInterface(
84  const std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface>& authDelegate,
85  std::unique_ptr<storage::CapabilitiesDelegateStorageInterface> storage,
86  const std::shared_ptr<registrationManager::CustomerDataManagerInterface>& customerDataManager,
87  const std::shared_ptr<
89  providerRegistrar,
90  const std::shared_ptr<acsdkShutdownManagerInterfaces::ShutdownNotifierInterface>& shutdownNotifier,
91  const std::shared_ptr<acsdkAlexaEventProcessedNotifierInterfaces::AlexaEventProcessedNotifierInterface>&
92  alexaEventProcessedNotifier);
93 
103  static std::shared_ptr<CapabilitiesDelegate> create(
104  const std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface>& authDelegate,
105  const std::shared_ptr<storage::CapabilitiesDelegateStorageInterface>& storage,
106  const std::shared_ptr<registrationManager::CustomerDataManagerInterface>& customerDataManager);
107 
110  bool addOrUpdateEndpoint(
111  const avsCommon::avs::AVSDiscoveryEndpointAttributes& endpointAttributes,
112  const std::vector<avsCommon::avs::CapabilityConfiguration>& capabilities) override;
113 
114  bool deleteEndpoint(
115  const avsCommon::avs::AVSDiscoveryEndpointAttributes& endpointAttributes,
116  const std::vector<avsCommon::avs::CapabilityConfiguration>& capabilities) override;
117 
119  std::shared_ptr<avsCommon::sdkInterfaces::CapabilitiesDelegateObserverInterface> observer) override;
120 
122  std::shared_ptr<avsCommon::sdkInterfaces::CapabilitiesDelegateObserverInterface> observer) override;
123 
124  void invalidateCapabilities() override;
125 
126  void setMessageSender(
127  const std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender) override;
129 
132  void onAlexaEventProcessedReceived(const std::string& eventCorrelationToken) override;
134 
137  void doShutdown() override;
139 
142  std::shared_ptr<avsCommon::sdkInterfaces::PostConnectOperationInterface> createPostConnectOperation() override;
144 
148  const std::unordered_map<std::string, std::string>& addOrUpdateReportEndpoints,
149  const std::unordered_map<std::string, std::string>& deleteReportEndpoints) override;
152 
155  void onAVSGatewayChanged(const std::string& avsGateway) override;
157 
160  void clearData() override;
162 
165  void onConnectionStatusChanged(const Status status, const ChangedReason reason) override;
167 
171  void setDiscoveryEventSender(const std::shared_ptr<DiscoveryEventSenderInterface>& discoveryEventSender);
172 
173 private:
182  const std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface>& authDelegate,
183  const std::shared_ptr<storage::CapabilitiesDelegateStorageInterface>& storage,
184  const std::shared_ptr<registrationManager::CustomerDataManagerInterface>& customerDataManager);
185 
192  bool init();
193 
200  std::string getAuthToken();
201 
212  void setCapabilitiesState(
215  const std::vector<avsCommon::sdkInterfaces::endpoints::EndpointIdentifier>& addOrUpdateReportEndpoints,
216  const std::vector<avsCommon::sdkInterfaces::endpoints::EndpointIdentifier>& deleteReportEndpoints);
217 
227  bool updateEndpointConfigInStorage(
228  const std::unordered_map<std::string, std::string>& addOrUpdateReportEndpoints,
229  const std::unordered_map<std::string, std::string>& deleteReportEndpoints);
230 
235  void resetCurrentDiscoveryEventSender();
236 
241  void resetDiscoveryEventSender(const std::shared_ptr<DiscoveryEventSenderInterface>& sender);
242 
246  void executeSendPendingEndpoints();
247 
251  bool isShuttingDown();
252 
260  void addStaleEndpointsToPendingDeleteLocked(std::unordered_map<std::string, std::string>* storedEndpointConfig);
261 
269  void filterUnchangedPendingAddOrUpdateEndpointsLocked(
270  std::unordered_map<std::string, std::string>* storedEndpointConfig);
271 
276  void moveInFlightEndpointsToPendingLocked();
277 
281  void moveInFlightEndpointsToPending();
282 
286  void moveInFlightEndpointsToRegisteredEndpoints();
287 
289  std::mutex m_observerMutex;
290 
292  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::CapabilitiesDelegateObserverInterface>>
293  m_capabilitiesObservers;
294 
297 
300 
302  std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface> m_authDelegate;
303 
305  std::shared_ptr<storage::CapabilitiesDelegateStorageInterface> m_capabilitiesDelegateStorage;
306 
308  std::mutex m_isConnectedMutex;
309 
312  bool m_isConnected;
313 
315  std::mutex m_endpointsMutex;
316 
318  InProcessEndpointsToConfigMapStruct m_addOrUpdateEndpoints;
319 
321  InProcessEndpointsToConfigMapStruct m_deleteEndpoints;
322 
324  std::unordered_map<std::string, std::string> m_endpoints;
325 
327  std::mutex m_currentDiscoveryEventSenderMutex;
328 
330  std::shared_ptr<DiscoveryEventSenderInterface> m_currentDiscoveryEventSender;
331 
333  std::mutex m_messageSenderMutex;
334 
336  std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> m_messageSender;
337 
339  std::mutex m_isShuttingDownMutex;
340 
342  bool m_isShuttingDown;
343 
351 };
352 
353 } // namespace capabilitiesDelegate
354 } // namespace alexaClientSDK
355 
356 #endif // ALEXA_CLIENT_SDK_CAPABILITIESDELEGATE_INCLUDE_CAPABILITIESDELEGATE_CAPABILITIESDELEGATE_H_
alexaClientSDK::capabilitiesDelegate::CapabilitiesDelegate::doShutdown
void doShutdown() override
Definition: CapabilitiesDelegate.cpp:138
alexaClientSDK::avsCommon::avs::AVSDiscoveryEndpointAttributes
Definition: AVSDiscoveryEndpointAttributes.h:41
alexaClientSDK::registrationManager::CustomerDataHandler
Definition: CustomerDataHandler.h:34
alexaClientSDK::avsCommon::utils::RequiresShutdown
Definition: RequiresShutdown.h:32
EndpointIdentifier.h
alexaClientSDK::capabilitiesDelegate::InProcessEndpointsToConfigMapStruct::inFlight
std::unordered_map< std::string, std::string > inFlight
Definition: CapabilitiesDelegate.h:57
alexaClientSDK::avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::ChangedReason
ChangedReason
Definition: ConnectionStatusObserverInterface.h:50
DiscoveryEventSender.h
alexaClientSDK::capabilitiesDelegate::InProcessEndpointsToConfigMapStruct::pending
std::unordered_map< std::string, std::string > pending
Definition: CapabilitiesDelegate.h:53
CustomerDataManagerInterface.h
alexaClientSDK::avsCommon::utils::threading::Executor
Definition: Executor.h:40
alexaClientSDK::capabilitiesDelegate::InProcessEndpointsToConfigMapStruct
Definition: CapabilitiesDelegate.h:50
alexaClientSDK::acsdkPostConnectOperationProviderRegistrarInterfaces::PostConnectOperationProviderRegistrarInterface
Definition: PostConnectOperationProviderRegistrarInterface.h:32
alexaClientSDK::avsCommon::sdkInterfaces::CapabilitiesDelegateObserverInterface::Error
Error
The enum Error encodes possible errors which may occur when changing state.
Definition: CapabilitiesDelegateObserverInterface.h:44
alexaClientSDK::capabilitiesDelegate::CapabilitiesDelegate::setMessageSender
void setMessageSender(const std::shared_ptr< avsCommon::sdkInterfaces::MessageSenderInterface > &messageSender) override
Definition: CapabilitiesDelegate.cpp:233
AVSDiscoveryEndpointAttributes.h
ShutdownNotifierInterface.h
PostConnectOperationProviderRegistrarInterface.h
RequiresShutdown.h
alexaClientSDK::capabilitiesDelegate::CapabilitiesDelegate::deleteEndpoint
bool deleteEndpoint(const avsCommon::avs::AVSDiscoveryEndpointAttributes &endpointAttributes, const std::vector< avsCommon::avs::CapabilityConfiguration > &capabilities) override
Definition: CapabilitiesDelegate.cpp:315
Executor.h
alexaClientSDK
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
AuthDelegateInterface.h
alexaClientSDK::capabilitiesDelegate::CapabilitiesDelegate
Definition: CapabilitiesDelegate.h:64
alexaClientSDK::capabilitiesDelegate::DiscoveryStatusObserverInterface
Definition: DiscoveryStatusObserverInterface.h:30
alexaClientSDK::capabilitiesDelegate::CapabilitiesDelegate::onDiscoveryCompleted
void onDiscoveryCompleted(const std::unordered_map< std::string, std::string > &addOrUpdateReportEndpoints, const std::unordered_map< std::string, std::string > &deleteReportEndpoints) override
Definition: CapabilitiesDelegate.cpp:560
alexaClientSDK::capabilitiesDelegate::CapabilitiesDelegate::removeCapabilitiesObserver
void removeCapabilitiesObserver(std::shared_ptr< avsCommon::sdkInterfaces::CapabilitiesDelegateObserverInterface > observer) override
Definition: CapabilitiesDelegate.cpp:193
CapabilitiesDelegateObserverInterface.h
CapabilitiesDelegateInterface.h
alexaClientSDK::capabilitiesDelegate::CapabilitiesDelegate::create
static std::shared_ptr< CapabilitiesDelegate > create(const std::shared_ptr< avsCommon::sdkInterfaces::AuthDelegateInterface > &authDelegate, const std::shared_ptr< storage::CapabilitiesDelegateStorageInterface > &storage, const std::shared_ptr< registrationManager::CustomerDataManagerInterface > &customerDataManager)
Definition: CapabilitiesDelegate.cpp:100
alexaClientSDK::capabilitiesDelegate::CapabilitiesDelegate::onAVSGatewayChanged
void onAVSGatewayChanged(const std::string &avsGateway) override
Definition: CapabilitiesDelegate.cpp:720
CapabilitiesDelegateStorageInterface.h
alexaClientSDK::avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::Status
Status
Definition: ConnectionStatusObserverInterface.h:36
ConnectionStatusObserverInterface.h
alexaClientSDK::capabilitiesDelegate::CapabilitiesDelegate::clearData
void clearData() override
Definition: CapabilitiesDelegate.cpp:154
alexaClientSDK::capabilitiesDelegate::CapabilitiesDelegate::onDiscoveryFailure
void onDiscoveryFailure(avsCommon::sdkInterfaces::MessageRequestObserverInterface::Status status) override
Definition: CapabilitiesDelegate.cpp:595
AlexaEventProcessedNotifierInterface.h
alexaClientSDK::avsCommon::sdkInterfaces::CapabilitiesDelegateObserverInterface::State
State
The enum State describes the state of the CapabilitiesDelegate.
Definition: CapabilitiesDelegateObserverInterface.h:32
alexaClientSDK::capabilitiesDelegate::CapabilitiesDelegate::invalidateCapabilities
void invalidateCapabilities() override
Definition: CapabilitiesDelegate.cpp:244
alexaClientSDK::capabilitiesDelegate::CapabilitiesDelegate::addCapabilitiesObserver
void addCapabilitiesObserver(std::shared_ptr< avsCommon::sdkInterfaces::CapabilitiesDelegateObserverInterface > observer) override
Definition: CapabilitiesDelegate.cpp:173
alexaClientSDK::capabilitiesDelegate::CapabilitiesDelegate::addOrUpdateEndpoint
bool addOrUpdateEndpoint(const avsCommon::avs::AVSDiscoveryEndpointAttributes &endpointAttributes, const std::vector< avsCommon::avs::CapabilityConfiguration > &capabilities) override
Definition: CapabilitiesDelegate.cpp:251
alexaClientSDK::capabilitiesDelegate::CapabilitiesDelegate::onAlexaEventProcessedReceived
void onAlexaEventProcessedReceived(const std::string &eventCorrelationToken) override
Definition: CapabilitiesDelegate.cpp:440
alexaClientSDK::capabilitiesDelegate::CapabilitiesDelegate::setDiscoveryEventSender
void setDiscoveryEventSender(const std::shared_ptr< DiscoveryEventSenderInterface > &discoveryEventSender)
Definition: CapabilitiesDelegate.cpp:677
alexaClientSDK::capabilitiesDelegate::CapabilitiesDelegate::createPostConnectOperation
std::shared_ptr< avsCommon::sdkInterfaces::PostConnectOperationInterface > createPostConnectOperation() override
Definition: CapabilitiesDelegate.cpp:456
alexaClientSDK::avsCommon::sdkInterfaces::CapabilitiesDelegateInterface
Definition: CapabilitiesDelegateInterface.h:39
alexaClientSDK::capabilitiesDelegate::CapabilitiesDelegate::onConnectionStatusChanged
void onConnectionStatusChanged(const Status status, const ChangedReason reason) override
Definition: CapabilitiesDelegate.cpp:725
alexaClientSDK::avsCommon::sdkInterfaces::PostConnectOperationProviderInterface
Definition: PostConnectOperationProviderInterface.h:30
CapabilityConfiguration.h
CustomerDataHandler.h
alexaClientSDK::avsCommon::sdkInterfaces::MessageRequestObserverInterface::Status
Status
Definition: MessageRequestObserverInterface.h:33
CapabilityConfigurationInterface.h
alexaClientSDK::capabilitiesDelegate::CapabilitiesDelegate::createCapabilitiesDelegateInterface
static std::shared_ptr< CapabilitiesDelegateInterface > createCapabilitiesDelegateInterface(const std::shared_ptr< avsCommon::sdkInterfaces::AuthDelegateInterface > &authDelegate, std::unique_ptr< storage::CapabilitiesDelegateStorageInterface > storage, const std::shared_ptr< registrationManager::CustomerDataManagerInterface > &customerDataManager, const std::shared_ptr< acsdkPostConnectOperationProviderRegistrarInterfaces::PostConnectOperationProviderRegistrarInterface > &providerRegistrar, const std::shared_ptr< acsdkShutdownManagerInterfaces::ShutdownNotifierInterface > &shutdownNotifier, const std::shared_ptr< acsdkAlexaEventProcessedNotifierInterfaces::AlexaEventProcessedNotifierInterface > &alexaEventProcessedNotifier)
Definition: CapabilitiesDelegate.cpp:65
PostConnectOperationProviderInterface.h

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