AlexaClientSDK  1.25.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 
118  void addCapabilitiesObserver(
119  std::shared_ptr<avsCommon::sdkInterfaces::CapabilitiesDelegateObserverInterface> observer) override;
120 
121  void removeCapabilitiesObserver(
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 
147  void onDiscoveryCompleted(
148  const std::unordered_map<std::string, std::string>& addOrUpdateReportEndpoints,
149  const std::unordered_map<std::string, std::string>& deleteReportEndpoints) override;
150  void onDiscoveryFailure(avsCommon::sdkInterfaces::MessageRequestObserverInterface::Status status) 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_
ChangedReason
Definition: ConnectionStatusObserverInterface.h:50
Error
The enum Error encodes possible errors which may occur when changing state.
Definition: CapabilitiesDelegateObserverInterface.h:44
std::unordered_map< std::string, std::string > inFlight
Definition: CapabilitiesDelegate.h:57
Definition: AVSDiscoveryEndpointAttributes.h:41
State
The enum State describes the state of the CapabilitiesDelegate.
Definition: CapabilitiesDelegateObserverInterface.h:32
Definition: DiscoveryStatusObserverInterface.h:30
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
std::unordered_map< std::string, std::string > pending
Definition: CapabilitiesDelegate.h:53
Definition: PostConnectOperationProviderInterface.h:30
Definition: PostConnectOperationProviderRegistrarInterface.h:32
Status
Definition: MessageRequestObserverInterface.h:33
Status
Definition: ConnectionStatusObserverInterface.h:36

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