AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
FocusManagerInterface.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_AVSCOMMON_SDKINTERFACES_INCLUDE_AVSCOMMON_SDKINTERFACES_FOCUSMANAGERINTERFACE_H_
17 #define ALEXA_CLIENT_SDK_AVSCOMMON_SDKINTERFACES_INCLUDE_AVSCOMMON_SDKINTERFACES_FOCUSMANAGERINTERFACE_H_
18 
19 #include <future>
20 #include <memory>
21 #include <mutex>
22 #include <string>
23 #include <vector>
24 
28 
29 namespace alexaClientSDK {
30 namespace avsCommon {
31 namespace sdkInterfaces {
32 
55 public:
64  class Activity {
65  public:
74  static std::shared_ptr<Activity> create(
75  const std::string& interfaceName,
76  const std::shared_ptr<avsCommon::sdkInterfaces::ChannelObserverInterface>& channelObserver,
77  const std::chrono::milliseconds& patienceDuration = std::chrono::milliseconds::zero(),
79 
80  bool operator==(const Activity& rhs) {
81  return this->m_interface == rhs.m_interface;
82  }
83 
89  const std::string getInterface() const;
90 
98  std::chrono::milliseconds getPatienceDuration() const;
99 
106 
113 
120 
126  std::shared_ptr<avsCommon::sdkInterfaces::ChannelObserverInterface> getChannelObserver() const;
127 
134 
135  private:
144  Activity(
145  const std::string& interfaceName,
146  const std::chrono::milliseconds& patienceDuration,
147  const std::shared_ptr<avsCommon::sdkInterfaces::ChannelObserverInterface>& channelObserver,
148  const avsCommon::avs::ContentType contentType) :
149  m_interface{interfaceName},
150  m_patienceDuration{patienceDuration},
151  m_channelObserver{channelObserver},
152  m_contentType{contentType},
154  }
155 
161  void setMixingBehavior(avsCommon::avs::MixingBehavior behavior);
162 
163  // The mutex that synchronizes all operations within the activity
164  mutable std::mutex m_mutex;
165 
166  // The interface name of the Activity.
167  const std::string m_interface;
168 
169  // The duration of patience in milliseconds of the Activity.
170  const std::chrono::milliseconds m_patienceDuration;
171 
172  // The channel observer of the Activity.
173  const std::shared_ptr<avsCommon::sdkInterfaces::ChannelObserverInterface> m_channelObserver;
174 
175  // The ContentType associated with this Activity
176  avsCommon::avs::ContentType m_contentType;
177 
178  // Last MixingBehavior associated with this activity
179  avsCommon::avs::MixingBehavior m_mixingBehavior;
180  };
181 
183  static constexpr const char* DIALOG_CHANNEL_NAME = "Dialog";
184 
186  static constexpr unsigned int DIALOG_CHANNEL_PRIORITY = 100;
187 
189  static constexpr const char* COMMUNICATIONS_CHANNEL_NAME = "Communications";
190 
192  static constexpr unsigned int COMMUNICATIONS_CHANNEL_PRIORITY = 150;
193 
195  static constexpr const char* ALERT_CHANNEL_NAME = "Alert";
196 
198  static constexpr unsigned int ALERT_CHANNEL_PRIORITY = 200;
199 
201  static constexpr const char* CONTENT_CHANNEL_NAME = "Content";
202 
204  static constexpr unsigned int CONTENT_CHANNEL_PRIORITY = 300;
205 
207  static constexpr const char* VISUAL_CHANNEL_NAME = "Visual";
208 
210  static constexpr unsigned int VISUAL_CHANNEL_PRIORITY = 100;
211 
213  virtual ~FocusManagerInterface() = default;
214 
228  virtual bool acquireChannel(
229  const std::string& channelName,
230  std::shared_ptr<avsCommon::sdkInterfaces::ChannelObserverInterface> channelObserver,
231  const std::string& interfaceName) = 0;
232 
243  virtual bool acquireChannel(
244  const std::string& channelName,
245  std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface::Activity> channelActivity) = 0;
246 
257  virtual std::future<bool> releaseChannel(
258  const std::string& channelName,
259  std::shared_ptr<avsCommon::sdkInterfaces::ChannelObserverInterface> channelObserver) = 0;
260 
267  virtual void stopForegroundActivity() = 0;
268 
273  virtual void stopAllActivities() = 0;
274 
280  virtual void addObserver(
281  const std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerObserverInterface>& observer) = 0;
282 
288  virtual void removeObserver(
289  const std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerObserverInterface>& observer) = 0;
290 
300  virtual void modifyContentType(
301  const std::string& channelName,
302  const std::string& interfaceName,
303  avsCommon::avs::ContentType contentType) = 0;
304 };
305 
306 inline std::shared_ptr<FocusManagerInterface::Activity> FocusManagerInterface::Activity::create(
307  const std::string& interfaceName,
308  const std::shared_ptr<avsCommon::sdkInterfaces::ChannelObserverInterface>& channelObserver,
309  const std::chrono::milliseconds& patienceDuration,
310  const avsCommon::avs::ContentType contentType) {
311  if (interfaceName.empty() || patienceDuration.count() < 0 || channelObserver == nullptr) {
312  return nullptr;
313  }
314 
315  auto activity = std::shared_ptr<FocusManagerInterface::Activity>(
316  new FocusManagerInterface::Activity(interfaceName, patienceDuration, channelObserver, contentType));
317  return activity;
318 }
319 
321  return m_interface;
322 }
323 
324 inline std::chrono::milliseconds FocusManagerInterface::Activity::getPatienceDuration() const {
325  return m_patienceDuration;
326 }
327 
329  std::unique_lock<std::mutex> lock(m_mutex);
330  return m_contentType;
331 }
332 
334  std::unique_lock<std::mutex> lock(m_mutex);
335  m_contentType = contentType;
336 }
337 
339  std::lock_guard<std::mutex> lock(m_mutex);
340  return m_mixingBehavior;
341 }
342 
343 inline std::shared_ptr<avsCommon::sdkInterfaces::ChannelObserverInterface> FocusManagerInterface::Activity::
345  return m_channelObserver;
346 }
347 
349  avs::FocusState focus,
351  if (m_channelObserver) {
352  avsCommon::avs::MixingBehavior overrideBehavior{behavior};
353  // If the activity/channelObserver is already paused , do not duck
357  }
358 
359  m_channelObserver->onFocusChanged(focus, overrideBehavior);
360  // Set the current mixing behavior that the observer received.
361  setMixingBehavior(overrideBehavior);
362  return true;
363  }
364  return false;
365 }
366 
367 inline void FocusManagerInterface::Activity::setMixingBehavior(avsCommon::avs::MixingBehavior behavior) {
368  std::unique_lock<std::mutex> lock(m_mutex);
369  m_mixingBehavior = behavior;
370 }
371 
372 } // namespace sdkInterfaces
373 } // namespace avsCommon
374 } // namespace alexaClientSDK
375 
376 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_SDKINTERFACES_INCLUDE_AVSCOMMON_SDKINTERFACES_FOCUSMANAGERINTERFACE_H_
virtual bool acquireChannel(const std::string &channelName, std::shared_ptr< avsCommon::sdkInterfaces::ChannelObserverInterface > channelObserver, const std::string &interfaceName)=0
static constexpr unsigned int VISUAL_CHANNEL_PRIORITY
The default Visual Channel priority.
Definition: FocusManagerInterface.h:210
MixingBehavior
Definition: MixingBehavior.h:25
static constexpr unsigned int ALERT_CHANNEL_PRIORITY
The default Alert Channel priority.
Definition: FocusManagerInterface.h:198
avsCommon::avs::MixingBehavior getMixingBehavior() const
Definition: FocusManagerInterface.h:338
avsCommon::avs::ContentType getContentType() const
Definition: FocusManagerInterface.h:328
::std::string string
Definition: gtest-port.h:1097
static constexpr unsigned int DIALOG_CHANNEL_PRIORITY
The default dialog Channel priority.
Definition: FocusManagerInterface.h:186
static std::shared_ptr< Activity > create(const std::string &interfaceName, const std::shared_ptr< avsCommon::sdkInterfaces::ChannelObserverInterface > &channelObserver, const std::chrono::milliseconds &patienceDuration=std::chrono::milliseconds::zero(), const avsCommon::avs::ContentType contentType=avsCommon::avs::ContentType::NONMIXABLE)
Definition: FocusManagerInterface.h:306
bool notifyObserver(avs::FocusState focus, avsCommon::avs::MixingBehavior behavior)
Definition: FocusManagerInterface.h:348
virtual void addObserver(const std::shared_ptr< avsCommon::sdkInterfaces::FocusManagerObserverInterface > &observer)=0
Indicates that the corresponding ContentType was undefined/unitialized.
std::shared_ptr< avsCommon::sdkInterfaces::ChannelObserverInterface > getChannelObserver() const
Definition: FocusManagerInterface.h:344
FocusState
Definition: FocusState.h:29
static constexpr const char * VISUAL_CHANNEL_NAME
The default Visual Channel name.
Definition: FocusManagerInterface.h:207
virtual void removeObserver(const std::shared_ptr< avsCommon::sdkInterfaces::FocusManagerObserverInterface > &observer)=0
static constexpr const char * CONTENT_CHANNEL_NAME
The default Content Channel name.
Definition: FocusManagerInterface.h:201
bool operator==(const Activity &rhs)
Definition: FocusManagerInterface.h:80
std::chrono::milliseconds getPatienceDuration() const
Definition: FocusManagerInterface.h:324
static constexpr const char * COMMUNICATIONS_CHANNEL_NAME
The default Communications Channel name.
Definition: FocusManagerInterface.h:189
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
static constexpr const char * ALERT_CHANNEL_NAME
The default Alert Channel name.
Definition: FocusManagerInterface.h:195
ContentType
Definition: ContentType.h:25
virtual void modifyContentType(const std::string &channelName, const std::string &interfaceName, avsCommon::avs::ContentType contentType)=0
static constexpr unsigned int CONTENT_CHANNEL_PRIORITY
The default Content Channel priority.
Definition: FocusManagerInterface.h:204
Indicates that the corresponding Activity must pause.
const std::string getInterface() const
Definition: FocusManagerInterface.h:320
static constexpr unsigned int COMMUNICATIONS_CHANNEL_PRIORITY
The default Communications Channel priority.
Definition: FocusManagerInterface.h:192
virtual std::future< bool > releaseChannel(const std::string &channelName, std::shared_ptr< avsCommon::sdkInterfaces::ChannelObserverInterface > channelObserver)=0
void setContentType(avsCommon::avs::ContentType contentType)
Definition: FocusManagerInterface.h:333
static constexpr const char * DIALOG_CHANNEL_NAME
The default Dialog Channel name.
Definition: FocusManagerInterface.h:183

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