2017-03-10 00:01:46 +00:00
|
|
|
/*
|
2018-02-12 23:31:53 +00:00
|
|
|
* Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2017-03-10 00:01:46 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License").
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
* A copy of the License is located at
|
|
|
|
*
|
|
|
|
* http://aws.amazon.com/apache2.0/
|
|
|
|
*
|
|
|
|
* or in the "license" file accompanying this file. This file is distributed
|
|
|
|
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
|
|
|
* express or implied. See the License for the specific language governing
|
|
|
|
* permissions and limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "AFML/Channel.h"
|
|
|
|
|
|
|
|
namespace alexaClientSDK {
|
|
|
|
namespace afml {
|
|
|
|
|
2017-06-23 23:26:34 +00:00
|
|
|
using namespace avsCommon::avs;
|
2017-05-18 05:02:48 +00:00
|
|
|
using namespace avsCommon::sdkInterfaces;
|
|
|
|
|
2018-03-09 00:55:39 +00:00
|
|
|
Channel::State::State(const std::string& name) :
|
|
|
|
name{name},
|
|
|
|
focusState{FocusState::NONE},
|
|
|
|
timeAtIdle{std::chrono::steady_clock::now()} {
|
|
|
|
}
|
|
|
|
|
|
|
|
Channel::State::State() : focusState{FocusState::NONE}, timeAtIdle{std::chrono::steady_clock::now()} {
|
|
|
|
}
|
|
|
|
|
|
|
|
Channel::Channel(const std::string& name, const unsigned int priority) :
|
2017-10-02 22:59:05 +00:00
|
|
|
m_priority{priority},
|
2018-03-09 00:55:39 +00:00
|
|
|
m_state{name},
|
2017-10-02 22:59:05 +00:00
|
|
|
m_observer{nullptr} {
|
2017-03-10 00:01:46 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 00:55:39 +00:00
|
|
|
const std::string& Channel::getName() const {
|
|
|
|
return m_state.name;
|
|
|
|
}
|
|
|
|
|
2017-03-10 00:01:46 +00:00
|
|
|
unsigned int Channel::getPriority() const {
|
|
|
|
return m_priority;
|
|
|
|
}
|
|
|
|
|
2018-03-09 00:55:39 +00:00
|
|
|
bool Channel::setFocus(FocusState focus) {
|
|
|
|
if (focus == m_state.focusState) {
|
|
|
|
return false;
|
2017-03-10 00:01:46 +00:00
|
|
|
}
|
2017-06-23 23:26:34 +00:00
|
|
|
|
2018-03-09 00:55:39 +00:00
|
|
|
m_state.focusState = focus;
|
2017-03-10 00:01:46 +00:00
|
|
|
if (m_observer) {
|
2018-03-09 00:55:39 +00:00
|
|
|
m_observer->onFocusChanged(m_state.focusState);
|
2017-03-10 00:01:46 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 00:55:39 +00:00
|
|
|
if (FocusState::NONE == m_state.focusState) {
|
2017-03-10 00:01:46 +00:00
|
|
|
m_observer = nullptr;
|
2018-03-09 00:55:39 +00:00
|
|
|
m_state.timeAtIdle = std::chrono::steady_clock::now();
|
2017-03-10 00:01:46 +00:00
|
|
|
}
|
2018-03-09 00:55:39 +00:00
|
|
|
return true;
|
2017-03-10 00:01:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Channel::setObserver(std::shared_ptr<ChannelObserverInterface> observer) {
|
|
|
|
m_observer = observer;
|
|
|
|
}
|
|
|
|
|
2018-03-09 00:55:39 +00:00
|
|
|
bool Channel::hasObserver() const {
|
|
|
|
return m_observer != nullptr;
|
2017-03-10 00:01:46 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 00:55:39 +00:00
|
|
|
bool Channel::operator>(const Channel& rhs) const {
|
|
|
|
return m_priority < rhs.getPriority();
|
2017-03-10 00:01:46 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 00:55:39 +00:00
|
|
|
void Channel::setInterface(const std::string& interface) {
|
|
|
|
m_state.interfaceName = interface;
|
2017-03-10 00:01:46 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 00:55:39 +00:00
|
|
|
std::string Channel::getInterface() const {
|
|
|
|
return m_state.interfaceName;
|
2017-03-10 00:01:46 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:31:58 +00:00
|
|
|
bool Channel::doesObserverOwnChannel(std::shared_ptr<ChannelObserverInterface> observer) const {
|
|
|
|
return observer == m_observer;
|
|
|
|
}
|
|
|
|
|
2018-03-09 00:55:39 +00:00
|
|
|
Channel::State Channel::getState() const {
|
|
|
|
return m_state;
|
|
|
|
}
|
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
} // namespace afml
|
|
|
|
} // namespace alexaClientSDK
|