AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Channel.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_AFML_INCLUDE_AFML_CHANNEL_H_
17 #define ALEXA_CLIENT_SDK_AFML_INCLUDE_AFML_CHANNEL_H_
18 
19 #include <algorithm>
20 #include <chrono>
21 #include <list>
22 #include <memory>
23 #include <string>
24 
30 
32 
33 namespace alexaClientSDK {
34 namespace afml {
35 
44 class Channel {
45 public:
46  /*
47  * This class contains the states of the @c Channel.
48  */
49  struct State {
51  State(const std::string& name);
52 
54  State();
55 
56  /*
57  * The channel's name. Although the name is not dynamic, it is useful for identifying which channel the state
58  * belongs to.
59  */
61 
64 
67 
69  std::chrono::steady_clock::time_point timeAtIdle;
70  };
71 
81  Channel(const std::string& name, const unsigned int priority, bool isVirtual = false);
82 
88  const std::string& getName() const;
89 
95  unsigned int getPriority() const;
96 
111  bool setFocus(avsCommon::avs::FocusState focus, avsCommon::avs::MixingBehavior behavior, bool forceUpdate = false);
112 
120  void setPrimaryActivity(std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface::Activity> activity);
121 
128  bool releaseActivity(std::shared_ptr<avsCommon::sdkInterfaces::ChannelObserverInterface> observer);
129 
136 
143  bool isActive();
144 
151  bool operator>(const Channel& rhs) const;
152 
158  std::string getInterface() const;
159 
165  Channel::State getState() const;
166 
173  std::vector<Channel::State> getActivityUpdates();
174 
180  std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface::Activity> getPrimaryActivity();
181 
188  std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface::Activity> getActivity(
189  const std::string& interfaceName);
190 
194  std::vector<std::string> getInterfaceList() const;
195 
196 private:
206 
213  bool releaseActivityLocked(
214  std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface::Activity> activityToRelease);
215 
222  bool removeActivityHelperLocked(
223  std::list<std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface::Activity>>::iterator
224  activityToRemoveIt);
232  void addToChannelUpdatesLocked(const std::string& interfaceName, avsCommon::avs::FocusState focusState);
233 
241  void processPolicyLocked(
242  std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface::Activity> incomingActivity,
243  std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface::Activity> currentActivity);
244 
250  void patienceTimerCallback(std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface::Activity> activity);
251 
255  void updateChannelInterfaceLocked();
256 
262  std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface::Activity> getPrimaryActivityLocked() const;
263 
264 private:
266  const unsigned int m_priority;
267 
269  bool m_isVirtual;
270 
272  State m_state;
273 
275  std::list<std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface::Activity>> m_activities;
276 
278  mutable std::mutex m_mutex;
279 
281  std::vector<Channel::State> m_activityUpdates;
282 
284  avsCommon::utils::timing::Timer m_patienceTimer;
285 
287  std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface::Activity> m_patienceInitiator;
288 
290  std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface::Activity> m_patienceReceiver;
291 
293  std::shared_ptr<avsCommon::utils::power::PowerResource> m_powerResource;
294 };
295 } // namespace afml
296 } // namespace alexaClientSDK
297 
298 #endif // ALEXA_CLIENT_SDK_AFML_INCLUDE_AFML_CHANNEL_H_
bool setFocus(avsCommon::avs::FocusState focus, avsCommon::avs::MixingBehavior behavior, bool forceUpdate=false)
std::vector< Channel::State > getActivityUpdates()
MixingBehavior
Definition: MixingBehavior.h:25
void setPrimaryActivity(std::shared_ptr< avsCommon::sdkInterfaces::FocusManagerInterface::Activity > activity)
Channel(const std::string &name, const unsigned int priority, bool isVirtual=false)
unsigned int getPriority() const
::std::string string
Definition: gtest-port.h:1097
const std::string & getName() const
std::shared_ptr< avsCommon::sdkInterfaces::FocusManagerInterface::Activity > getPrimaryActivity()
std::string name
Definition: Channel.h:60
FocusState
Definition: FocusState.h:29
avsCommon::avs::FocusState focusState
The current Focus of the Channel.
Definition: Channel.h:63
std::string interfaceName
The name of the AVS interface that is occupying the Channel.
Definition: Channel.h:66
std::shared_ptr< avsCommon::sdkInterfaces::FocusManagerInterface::Activity > getActivity(const std::string &interfaceName)
std::vector< std::string > getInterfaceList() const
std::chrono::steady_clock::time_point timeAtIdle
Time at which the channel goes to NONE focus.
Definition: Channel.h:69
Timer to schedule task for delayed and periodic execution.
Definition: Timer.h:39
Channel::State getState() const
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
bool operator>(const Channel &rhs) const
Definition: Channel.h:49
std::string getInterface() const
bool releaseActivity(std::shared_ptr< avsCommon::sdkInterfaces::ChannelObserverInterface > observer)
Definition: Channel.h:44

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