AlexaClientSDK  1.25.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
UserInactivityMonitor.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_CAPABILITYAGENTS_SYSTEM_INCLUDE_SYSTEM_USERINACTIVITYMONITOR_H_
17 #define ALEXA_CLIENT_SDK_CAPABILITYAGENTS_SYSTEM_INCLUDE_SYSTEM_USERINACTIVITYMONITOR_H_
18 
19 #include <atomic>
20 #include <chrono>
21 #include <memory>
22 #include <string>
23 
33 
34 namespace alexaClientSDK {
35 namespace capabilityAgents {
36 namespace system {
37 
43 public:
56  static std::shared_ptr<avsCommon::sdkInterfaces::UserInactivityMonitorInterface>
58  const std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender,
59  const std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface>&
60  exceptionEncounteredSender,
61  const std::shared_ptr<acsdkShutdownManagerInterfaces::ShutdownNotifierInterface>& shutdownNotifier,
62  const std::shared_ptr<avsCommon::sdkInterfaces::DirectiveSequencerInterface>& directiveSequencer,
63  const std::chrono::milliseconds& sendPeriod = std::chrono::hours(1));
64 
75  static std::shared_ptr<UserInactivityMonitor> create(
76  std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
77  std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionEncounteredSender,
78  const std::chrono::milliseconds& sendPeriod = std::chrono::hours(1));
79 
83  void handleDirectiveImmediately(std::shared_ptr<avsCommon::avs::AVSDirective> directive) override;
84  void preHandleDirective(std::shared_ptr<avsCommon::avs::CapabilityAgent::DirectiveInfo> info) override;
85  void handleDirective(std::shared_ptr<avsCommon::avs::CapabilityAgent::DirectiveInfo> info) override;
86  void cancelDirective(std::shared_ptr<avsCommon::avs::CapabilityAgent::DirectiveInfo> info) override;
88 
91  void onUserActive() override;
92  std::chrono::seconds timeSinceUserActivity() override;
93  void addObserver(
94  std::shared_ptr<avsCommon::sdkInterfaces::UserInactivityMonitorObserverInterface> observer) override;
95  void removeObserver(
96  std::shared_ptr<avsCommon::sdkInterfaces::UserInactivityMonitorObserverInterface> observer) override;
98 
99 private:
108  std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
109  std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionEncounteredSender,
110  const std::chrono::milliseconds& sendPeriod);
111 
114  void doShutdown() override;
116 
124  void removeDirectiveGracefully(
125  std::shared_ptr<avsCommon::avs::CapabilityAgent::DirectiveInfo> info,
126  bool isFailure = false,
127  const std::string& report = "");
128 
130  void sendInactivityReport();
131 
133  void startTimer();
134 
138  void notifyObservers();
139 
141  std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> m_messageSender;
142 
144  std::mutex m_mutex;
145 
150  avsCommon::utils::timing::Timer m_eventTimer;
151 
153  std::atomic_bool m_recentUpdateBlocked;
154 
159  std::chrono::time_point<std::chrono::steady_clock> m_lastTimeActive;
160 
162  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::UserInactivityMonitorObserverInterface>>
163  m_inactivityObservers;
164 
166  const std::chrono::milliseconds m_sendPeriod;
167 };
168 
169 } // namespace system
170 } // namespace capabilityAgents
171 } // namespace alexaClientSDK
172 
173 #endif // ALEXA_CLIENT_SDK_CAPABILITYAGENTS_SYSTEM_INCLUDE_SYSTEM_USERINACTIVITYMONITOR_H_
void removeObserver(std::shared_ptr< avsCommon::sdkInterfaces::UserInactivityMonitorObserverInterface > observer) override
Definition: UserInactivityMonitor.cpp:237
Definition: CapabilityAgent.h:47
void onUserActive() override
The function to be called when the user has become active.
Definition: UserInactivityMonitor.cpp:205
void preHandleDirective(std::shared_ptr< avsCommon::avs::CapabilityAgent::DirectiveInfo > info) override
Definition: UserInactivityMonitor.cpp:188
static std::shared_ptr< avsCommon::sdkInterfaces::UserInactivityMonitorInterface > createUserInactivityMonitorInterface(const std::shared_ptr< avsCommon::sdkInterfaces::MessageSenderInterface > &messageSender, const std::shared_ptr< avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface > &exceptionEncounteredSender, const std::shared_ptr< acsdkShutdownManagerInterfaces::ShutdownNotifierInterface > &shutdownNotifier, const std::shared_ptr< avsCommon::sdkInterfaces::DirectiveSequencerInterface > &directiveSequencer, const std::chrono::milliseconds &sendPeriod=std::chrono::hours(1))
Definition: UserInactivityMonitor.cpp:80
void addObserver(std::shared_ptr< avsCommon::sdkInterfaces::UserInactivityMonitorObserverInterface > observer) override
Definition: UserInactivityMonitor.cpp:227
void handleDirectiveImmediately(std::shared_ptr< avsCommon::avs::AVSDirective > directive) override
Definition: UserInactivityMonitor.cpp:184
avsCommon::avs::DirectiveHandlerConfiguration getConfiguration() const override
Definition: UserInactivityMonitor.cpp:179
void cancelDirective(std::shared_ptr< avsCommon::avs::CapabilityAgent::DirectiveInfo > info) override
Definition: UserInactivityMonitor.cpp:196
void handleDirective(std::shared_ptr< avsCommon::avs::CapabilityAgent::DirectiveInfo > info) override
Definition: UserInactivityMonitor.cpp:191
std::unordered_map< directiveRoutingRule::DirectiveRoutingRule, BlockingPolicy > DirectiveHandlerConfiguration
Definition: DirectiveHandlerConfiguration.h:32
std::chrono::seconds timeSinceUserActivity() override
Definition: UserInactivityMonitor.cpp:219
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
static std::shared_ptr< UserInactivityMonitor > create(std::shared_ptr< avsCommon::sdkInterfaces::MessageSenderInterface > messageSender, std::shared_ptr< avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface > exceptionEncounteredSender, const std::chrono::milliseconds &sendPeriod=std::chrono::hours(1))
Definition: UserInactivityMonitor.cpp:106
This class implements a CapabilityAgent that handles the SetEndpoint directive.
Definition: UserInactivityMonitor.h:39

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