AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
NotificationsCapabilityAgent.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 ACSDKNOTIFICATIONS_NOTIFICATIONSCAPABILITYAGENT_H_
17 #define ACSDKNOTIFICATIONS_NOTIFICATIONSCAPABILITYAGENT_H_
18 
19 #include <memory>
20 #include <unordered_set>
21 
41 
44 
45 namespace alexaClientSDK {
46 namespace acsdkNotifications {
47 
65  , public std::enable_shared_from_this<NotificationsCapabilityAgent> {
66 public:
83  static std::shared_ptr<NotificationsCapabilityAgent> createNotificationsCapabilityAgent(
84  const std::shared_ptr<acsdkNotificationsInterfaces::NotificationsStorageInterface>& notificationsStorage,
85  const std::shared_ptr<acsdkNotificationsInterfaces::NotificationRendererInterface>& renderer,
86  const std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface>& contextManager,
87  const std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface>& exceptionSender,
88  const std::shared_ptr<avsCommon::sdkInterfaces::audio::AudioFactoryInterface>& audioFactory,
89  const std::shared_ptr<registrationManager::CustomerDataManagerInterface>& dataManager,
90  const std::shared_ptr<acsdkShutdownManagerInterfaces::ShutdownNotifierInterface>& shutdownNotifier,
94  const std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface>& metricRecorder);
95 
110  static std::shared_ptr<NotificationsCapabilityAgent> create(
111  std::shared_ptr<acsdkNotificationsInterfaces::NotificationsStorageInterface> notificationsStorage,
112  std::shared_ptr<acsdkNotificationsInterfaces::NotificationRendererInterface> renderer,
113  std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> contextManager,
114  std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionSender,
115  std::shared_ptr<avsCommon::sdkInterfaces::audio::NotificationsAudioFactoryInterface> notificationsAudioFactory,
116  std::shared_ptr<registrationManager::CustomerDataManagerInterface> dataManager,
117  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder = nullptr);
118 
123 
129  std::shared_ptr<acsdkNotificationsInterfaces::NotificationsNotifierInterface> getNotificationsNotifierInterface();
130 
133  void handleDirectiveImmediately(std::shared_ptr<avsCommon::avs::AVSDirective> directive) override;
134  void preHandleDirective(std::shared_ptr<DirectiveInfo> info) override;
135  void handleDirective(std::shared_ptr<DirectiveInfo> info) override;
136  void cancelDirective(std::shared_ptr<DirectiveInfo> info) override;
139 
142  void provideState(const avsCommon::avs::NamespaceAndName& stateProviderName, unsigned int stateRequestToken)
143  override;
145 
148 
152  void onNotificationRenderingFinished() override;
154 
158  void clearData() override;
159 
162  std::unordered_set<std::shared_ptr<avsCommon::avs::CapabilityConfiguration>> getCapabilityConfigurations() override;
164 
165 private:
186  std::shared_ptr<acsdkNotificationsInterfaces::NotificationsStorageInterface> notificationsStorage,
187  std::shared_ptr<acsdkNotificationsInterfaces::NotificationRendererInterface> renderer,
188  std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> contextManager,
189  std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionSender,
190  std::shared_ptr<avsCommon::sdkInterfaces::audio::NotificationsAudioFactoryInterface> notificationsAudioFactory,
191  std::shared_ptr<registrationManager::CustomerDataManagerInterface> dataManager,
192  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder);
193 
200  bool init();
201 
210  bool parseDirectivePayload(std::shared_ptr<DirectiveInfo> info, rapidjson::Document* document);
211 
217  void handleSetIndicatorDirective(std::shared_ptr<DirectiveInfo> info);
218 
224  void handleClearIndicatorDirective(std::shared_ptr<DirectiveInfo> info);
225 
228  void doShutdown() override;
230 
236  void setHandlingCompleted(std::shared_ptr<DirectiveInfo> info);
237 
246 
257  void executeRenderNotification(const NotificationIndicator& notificationIndicator);
258 
268  void executePossibleIndicatorStateChange(const avsCommon::avs::IndicatorState& nextIndicatorState);
269 
276  void executeSetState(NotificationsCapabilityAgentState newState);
277 
290  void executeProvideState(bool sendToken = false, unsigned int stateRequestToken = 0);
291 
297  void notifyObserversOfIndicatorState(avsCommon::avs::IndicatorState state);
298 
302  void notifyObserversOfNotificationReceived();
303 
309  void executeInit();
310 
315  void executeOnPlayFinished();
316 
324 
331  void executeStartQueueNotEmpty();
332 
339  void executeSetIndicator(
340  const NotificationIndicator& nextNotificationIndicator,
341  std::shared_ptr<DirectiveInfo> info);
342 
347  void executeClearIndicator(std::shared_ptr<DirectiveInfo> info);
348 
353  void executePlayFinishedZeroQueued();
354 
362  void executePlayFinishedOneQueued();
363 
368  void executePlayFinishedMultipleQueued();
369 
373  void executeShutdown();
374 
377 
379  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> m_metricRecorder;
380 
383  std::shared_ptr<acsdkNotificationsInterfaces::NotificationsStorageInterface> m_notificationsStorage;
384 
386  std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> m_contextManager;
387 
389  std::shared_ptr<acsdkNotificationsInterfaces::NotificationRendererInterface> m_renderer;
390 
392  std::shared_ptr<avsCommon::sdkInterfaces::audio::NotificationsAudioFactoryInterface> m_notificationsAudioFactory;
393 
396  std::string m_currentAssetId;
397 
401  bool m_isEnabled;
402 
404  std::shared_ptr<acsdkNotificationsInterfaces::NotificationsNotifierInterface> m_notifier;
405 
407  NotificationsCapabilityAgentState m_currentState;
408 
411  std::unordered_set<std::shared_ptr<avsCommon::avs::CapabilityConfiguration>> m_capabilityConfigurations;
412 
421 
424  std::condition_variable m_shutdownTrigger;
425 
427  std::mutex m_shutdownMutex;
428 };
429 
430 } // namespace acsdkNotifications
431 } // namespace alexaClientSDK
432 
433 #endif // ACSDKNOTIFICATIONS_NOTIFICATIONSCAPABILITYAGENT_H_
Definition: CapabilityAgent.h:47
void preHandleDirective(std::shared_ptr< DirectiveInfo > info) override
Definition: NamespaceAndName.h:32
std::shared_ptr< acsdkNotificationsInterfaces::NotificationsNotifierInterface > getNotificationsNotifierInterface()
::std::string string
Definition: gtest-port.h:1097
Single-thread executor implementation.
Definition: Executor.h:45
Definition: NotificationsCapabilityAgent.h:59
void cancelDirective(std::shared_ptr< DirectiveInfo > info) override
avsCommon::avs::DirectiveHandlerConfiguration getConfiguration() const override
static std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder
Metric recorder shared ptr.
Definition: BaseAPLCapabilityAgentTest.cpp:261
void provideState(const avsCommon::avs::NamespaceAndName &stateProviderName, unsigned int stateRequestToken) override
static std::shared_ptr< NotificationsCapabilityAgent > createNotificationsCapabilityAgent(const std::shared_ptr< acsdkNotificationsInterfaces::NotificationsStorageInterface > &notificationsStorage, const std::shared_ptr< acsdkNotificationsInterfaces::NotificationRendererInterface > &renderer, const std::shared_ptr< avsCommon::sdkInterfaces::ContextManagerInterface > &contextManager, const std::shared_ptr< avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface > &exceptionSender, const std::shared_ptr< avsCommon::sdkInterfaces::audio::AudioFactoryInterface > &audioFactory, const std::shared_ptr< registrationManager::CustomerDataManagerInterface > &dataManager, const std::shared_ptr< acsdkShutdownManagerInterfaces::ShutdownNotifierInterface > &shutdownNotifier, acsdkManufactory::Annotated< avsCommon::sdkInterfaces::endpoints::DefaultEndpointAnnotation, avsCommon::sdkInterfaces::endpoints::EndpointCapabilitiesRegistrarInterface > endpointCapabilitiesRegistrar, const std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > &metricRecorder)
std::unordered_map< directiveRoutingRule::DirectiveRoutingRule, BlockingPolicy > DirectiveHandlerConfiguration
Definition: DirectiveHandlerConfiguration.h:32
static std::shared_ptr< NotificationsCapabilityAgent > create(std::shared_ptr< acsdkNotificationsInterfaces::NotificationsStorageInterface > notificationsStorage, std::shared_ptr< acsdkNotificationsInterfaces::NotificationRendererInterface > renderer, std::shared_ptr< avsCommon::sdkInterfaces::ContextManagerInterface > contextManager, std::shared_ptr< avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface > exceptionSender, std::shared_ptr< avsCommon::sdkInterfaces::audio::NotificationsAudioFactoryInterface > notificationsAudioFactory, std::shared_ptr< registrationManager::CustomerDataManagerInterface > dataManager, std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder=nullptr)
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
std::unordered_set< std::shared_ptr< avsCommon::avs::CapabilityConfiguration > > getCapabilityConfigurations() override
IndicatorState
Definition: IndicatorState.h:30
NotificationsCapabilityAgentState
Definition: NotificationsCapabilityAgentState.h:25
Definition: NotificationIndicator.h:29
void handleDirective(std::shared_ptr< DirectiveInfo > info) override
void handleDirectiveImmediately(std::shared_ptr< avsCommon::avs::AVSDirective > directive) override

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