AlexaClientSDK  3.0.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 
79  , public std::enable_shared_from_this<CapabilitiesDelegate> {
80 public:
93  static std::shared_ptr<CapabilitiesDelegateInterface> createCapabilitiesDelegateInterface(
94  const std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface>& authDelegate,
95  std::unique_ptr<storage::CapabilitiesDelegateStorageInterface> storage,
96  const std::shared_ptr<registrationManager::CustomerDataManagerInterface>& customerDataManager,
97  const std::shared_ptr<
99  providerRegistrar,
100  const std::shared_ptr<acsdkShutdownManagerInterfaces::ShutdownNotifierInterface>& shutdownNotifier,
101  const std::shared_ptr<acsdkAlexaEventProcessedNotifierInterfaces::AlexaEventProcessedNotifierInterface>&
102  alexaEventProcessedNotifier,
103  const std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface>& metricRecorder = nullptr);
104 
114  static std::shared_ptr<CapabilitiesDelegate> create(
115  const std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface>& authDelegate,
116  const std::shared_ptr<storage::CapabilitiesDelegateStorageInterface>& storage,
117  const std::shared_ptr<registrationManager::CustomerDataManagerInterface>& customerDataManager,
118  const std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface>& metricRecorder = nullptr);
119 
122  bool addOrUpdateEndpoint(
123  const avsCommon::avs::AVSDiscoveryEndpointAttributes& endpointAttributes,
124  const std::vector<avsCommon::avs::CapabilityConfiguration>& capabilities) override;
125 
126  bool deleteEndpoint(
127  const avsCommon::avs::AVSDiscoveryEndpointAttributes& endpointAttributes,
128  const std::vector<avsCommon::avs::CapabilityConfiguration>& capabilities) override;
129 
130  void addCapabilitiesObserver(
131  std::shared_ptr<avsCommon::sdkInterfaces::CapabilitiesDelegateObserverInterface> observer) override;
132 
133  void removeCapabilitiesObserver(
134  std::shared_ptr<avsCommon::sdkInterfaces::CapabilitiesDelegateObserverInterface> observer) override;
135 
136  void invalidateCapabilities() override;
137 
138  void setMessageSender(
139  const std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender) override;
141 
144  void onAlexaEventProcessedReceived(const std::string& eventCorrelationToken) override;
146 
149  void doShutdown() override;
151 
154  std::shared_ptr<avsCommon::sdkInterfaces::PostConnectOperationInterface> createPostConnectOperation() override;
156 
159  void onDiscoveryCompleted(
160  const std::unordered_map<std::string, std::string>& addOrUpdateReportEndpoints,
161  const std::unordered_map<std::string, std::string>& deleteReportEndpoints) override;
162  void onDiscoveryFailure(avsCommon::sdkInterfaces::MessageRequestObserverInterface::Status status) override;
164 
167  void onAVSGatewayChanged(const std::string& avsGateway) override;
169 
172  void clearData() override;
174 
177  void onConnectionStatusChanged(const Status status, const ChangedReason reason) override;
179 
183  void setDiscoveryEventSender(const std::shared_ptr<DiscoveryEventSenderInterface>& discoveryEventSender);
184 
185 private:
194  const std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface>& authDelegate,
195  const std::shared_ptr<storage::CapabilitiesDelegateStorageInterface>& storage,
196  const std::shared_ptr<registrationManager::CustomerDataManagerInterface>& customerDataManager,
197  const std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface>& metricsRecorder);
198 
205  bool init();
206 
213  std::string getAuthToken();
214 
225  void setCapabilitiesState(
228  const std::vector<avsCommon::sdkInterfaces::endpoints::EndpointIdentifier>& addOrUpdateReportEndpoints,
229  const std::vector<avsCommon::sdkInterfaces::endpoints::EndpointIdentifier>& deleteReportEndpoints);
230 
240  bool updateEndpointConfigInStorage(
241  const std::unordered_map<std::string, std::string>& addOrUpdateReportEndpoints,
242  const std::unordered_map<std::string, std::string>& deleteReportEndpoints);
243 
248  void resetCurrentDiscoveryEventSender();
249 
254  void resetDiscoveryEventSender(const std::shared_ptr<DiscoveryEventSenderInterface>& sender);
255 
259  void executeSendPendingEndpoints();
260 
264  bool isShuttingDown();
265 
273  void addStaleEndpointsToPendingDeleteLocked(std::unordered_map<std::string, std::string>* storedEndpointConfig);
274 
282  void filterUnchangedPendingAddOrUpdateEndpointsLocked(
283  std::unordered_map<std::string, std::string>* storedEndpointConfig);
284 
289  void moveInFlightEndpointsToPendingLocked();
290 
294  void moveInFlightEndpointsToPending();
295 
299  void moveInFlightEndpointsToRegisteredEndpoints();
300 
307  bool executeSendDiscoveryEvents(
308  const std::unordered_map<std::string, std::string>& addOrUpdateEndpointsToSend,
309  const std::unordered_map<std::string, std::string>& deleteEndpointsToSend);
310 
316  bool isEndpointDeduplicated(const avsCommon::sdkInterfaces::endpoints::EndpointIdentifier& endpointId);
317 
319  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> m_metricRecorder;
320 
322  std::mutex m_observerMutex;
323 
325  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::CapabilitiesDelegateObserverInterface>>
326  m_capabilitiesObservers;
327 
330 
333 
335  std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface> m_authDelegate;
336 
338  std::shared_ptr<storage::CapabilitiesDelegateStorageInterface> m_capabilitiesDelegateStorage;
339 
341  std::mutex m_isConnectedMutex;
342 
345  bool m_isConnected;
346 
348  std::mutex m_endpointsMutex;
349 
351  InProcessEndpointsToConfigMapStruct m_addOrUpdateEndpoints;
352 
354  InProcessEndpointsToConfigMapStruct m_deleteEndpoints;
355 
357  std::unordered_map<std::string, std::string> m_endpoints;
358 
361  std::unordered_map<
364  m_endpointRegistrations;
365 
367  std::mutex m_currentDiscoveryEventSenderMutex;
368 
370  std::shared_ptr<DiscoveryEventSenderInterface> m_currentDiscoveryEventSender;
371 
373  std::mutex m_messageSenderMutex;
374 
376  std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> m_messageSender;
377 
379  std::mutex m_isShuttingDownMutex;
380 
382  bool m_isShuttingDown;
383 
391 };
392 
393 } // namespace capabilitiesDelegate
394 } // namespace alexaClientSDK
395 
396 #endif // ALEXA_CLIENT_SDK_CAPABILITIESDELEGATE_INCLUDE_CAPABILITIESDELEGATE_CAPABILITIESDELEGATE_H_
ChangedReason
Definition: ConnectionStatusObserverInterface.h:50
::std::string string
Definition: gtest-port.h:1097
Single-thread executor implementation.
Definition: Executor.h:45
Error
The enum Error encodes possible errors which may occur when changing state.
Definition: CapabilitiesDelegateObserverInterface.h:44
static std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder
Metric recorder shared ptr.
Definition: BaseAPLCapabilityAgentTest.cpp:261
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
std::string EndpointIdentifier
Definition: EndpointIdentifier.h:38
Status
Definition: MessageRequestObserverInterface.h:33
Status
Definition: ConnectionStatusObserverInterface.h:36

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