Skip to content

Commit

Permalink
Merge pull request alexa#21 from xmos/xmos_v1.13
Browse files Browse the repository at this point in the history
xmos v1.13
  • Loading branch information
dfollent authored Jul 19, 2019
2 parents d9675e0 + 4d2d587 commit f68087c
Show file tree
Hide file tree
Showing 911 changed files with 116,401 additions and 14,460 deletions.
2 changes: 1 addition & 1 deletion ACL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ project(ACL LANGUAGES CXX)
include(../build/BuildDefaults.cmake)

add_subdirectory("src")
acsdk_add_test_subdirectory_if_allowed()
add_subdirectory("test")
86 changes: 35 additions & 51 deletions ACL/include/ACL/AVSConnectionManager.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2016-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand All @@ -22,10 +22,11 @@
#include <string>
#include <unordered_set>

#include <AVSCommon/AVS/AbstractConnection.h>
#include <AVSCommon/AVS/AbstractAVSConnectionManager.h>
#include <AVSCommon/AVS/MessageRequest.h>
#include <AVSCommon/SDKInterfaces/AVSEndpointAssignerInterface.h>
#include <AVSCommon/SDKInterfaces/ConnectionStatusObserverInterface.h>
#include <AVSCommon/SDKInterfaces/InternetConnectionMonitorInterface.h>
#include <AVSCommon/SDKInterfaces/MessageObserverInterface.h>
#include <AVSCommon/SDKInterfaces/MessageSenderInterface.h>
#include <AVSCommon/Utils/RequiresShutdown.h>
Expand Down Expand Up @@ -67,11 +68,13 @@ namespace acl {
* changes, and when messages are received from AVS. These observer objects are optional.
*/
class AVSConnectionManager
: public avsCommon::avs::AbstractConnection
: public avsCommon::avs::AbstractAVSConnectionManager
, public avsCommon::sdkInterfaces::MessageSenderInterface
, public avsCommon::sdkInterfaces::AVSEndpointAssignerInterface
, public MessageRouterObserverInterface
, public avsCommon::utils::RequiresShutdown {
, public avsCommon::sdkInterfaces::InternetConnectionObserverInterface
, public avsCommon::utils::RequiresShutdown
, public std::enable_shared_from_this<AVSConnectionManager> {
public:
/**
* A factory function that creates an AVSConnectionManager object.
Expand All @@ -91,52 +94,20 @@ class AVSConnectionManager
connectionStatusObservers =
std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::ConnectionStatusObserverInterface>>(),
std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::MessageObserverInterface>> messageObservers =
std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::MessageObserverInterface>>());

/**
* Enable the AVSConnectionManager object to make connections to AVS. Once enabled, the object will attempt to
* create a connection to AVS. If the object is already connected, this function will do nothing.
*/
void enable();

/**
* Disable the AVSConnectionManager object. If the object is currently connected to AVS, then calling this
* function will cause the connection to be closed. If the object is not connected, then calling this function
* will do nothing.
*/
void disable();

/**
* Returns if the object is enabled for making connections to AVS.
*
* @return Whether this Connection object is enabled to make connections.
*/
bool isEnabled();

/**
* This function causes the object, if enabled, to create new connection to AVS. If the object is already
* connected, then that connection will be closed and a new one created. If the object is not connected, but
* perhaps in the process of waiting for its next connection attempt, then its waiting policy will be reset and
* it will attempt to create a new connection immediately.
* If the object is disabled, then this function will do nothing.
*/
void reconnect();

std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::MessageObserverInterface>>(),
std::shared_ptr<avsCommon::sdkInterfaces::InternetConnectionMonitorInterface> internetConnectionMonitor =
nullptr);

/// @name AVSConnectionManagerInterface method overrides.
/// @{
void enable() override;
void disable() override;
bool isEnabled() override;
void reconnect() override;
bool isConnected() const override;

/**
* Adds an observer to be notified of message receptions.
*
* @param observer The observer object to add.
*/
void addMessageObserver(std::shared_ptr<avsCommon::sdkInterfaces::MessageObserverInterface> observer);

/**
* Removes an observer from being notified of message receptions.
*
* @param observer The observer object to remove.
*/
void removeMessageObserver(std::shared_ptr<avsCommon::sdkInterfaces::MessageObserverInterface> observer);
void addMessageObserver(std::shared_ptr<avsCommon::sdkInterfaces::MessageObserverInterface> observer) override;
void removeMessageObserver(std::shared_ptr<avsCommon::sdkInterfaces::MessageObserverInterface> observer) override;
/// @}

void sendMessage(std::shared_ptr<avsCommon::avs::MessageRequest> request) override;

Expand All @@ -146,6 +117,11 @@ class AVSConnectionManager
*/
void setAVSEndpoint(const std::string& avsEndpoint) override;

/// @name InternetConnectionObserverInterface method overrides.
/// @{
void onConnectionStatusChanged(bool connected) override;
/// @}

private:
/**
* AVSConnectionManager constructor.
Expand All @@ -161,7 +137,9 @@ class AVSConnectionManager
connectionStatusObservers =
std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::ConnectionStatusObserverInterface>>(),
std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::MessageObserverInterface>> messageObserver =
std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::MessageObserverInterface>>());
std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::MessageObserverInterface>>(),
std::shared_ptr<avsCommon::sdkInterfaces::InternetConnectionMonitorInterface> internetConnectionMonitor =
nullptr);

void doShutdown() override;

Expand All @@ -171,8 +149,11 @@ class AVSConnectionManager

void receive(const std::string& contextId, const std::string& message) override;

/// Mutex to serialize access to @c m_isEnabled
std::mutex m_isEnabledMutex;

/// Internal state to indicate if the Connection object is enabled for making an AVS connection.
std::atomic<bool> m_isEnabled;
bool m_isEnabled;

/// Client-provided message listener, which will receive all messages sent from AVS.
std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::MessageObserverInterface>> m_messageObservers;
Expand All @@ -182,6 +163,9 @@ class AVSConnectionManager

/// Internal object that manages the actual connection to AVS.
std::shared_ptr<MessageRouterInterface> m_messageRouter;

/// Object providing notification of gaining and losing internet connectivity.
std::shared_ptr<avsCommon::sdkInterfaces::InternetConnectionMonitorInterface> m_internetConnectionMonitor;
};

} // namespace acl
Expand Down
84 changes: 84 additions & 0 deletions ACL/include/ACL/Transport/DownchannelHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* 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.
*/

#ifndef ALEXA_CLIENT_SDK_ACL_INCLUDE_ACL_TRANSPORT_DOWNCHANNELHANDLER_H_
#define ALEXA_CLIENT_SDK_ACL_INCLUDE_ACL_TRANSPORT_DOWNCHANNELHANDLER_H_

#include <memory>

#include <AVSCommon/AVS/Attachment/AttachmentManager.h>
#include <AVSCommon/Utils/HTTP2/HTTP2RequestSourceInterface.h>

#include "ACL/Transport/ExchangeHandler.h"
#include "ACL/Transport/MessageConsumerInterface.h"
#include "ACL/Transport/MimeResponseStatusHandlerInterface.h"

namespace alexaClientSDK {
namespace acl {

class DownchannelHandler;

/**
* Handle the HTTP2 request and response that establishes and services the downchannel of an connection to AVS.
*/
class DownchannelHandler
: public ExchangeHandler
, public avsCommon::utils::http2::HTTP2RequestSourceInterface
, public MimeResponseStatusHandlerInterface
, public std::enable_shared_from_this<DownchannelHandler> {
public:
/**
* Create a DownchannelHandler, and send the downchannel request.
*
* @param context The ExchangeContext in which this MessageRequest handler will operate.
* @param authToken The token to use to authorize the request.
* @param messageConsumer Object to send decoded messages to.
* @param attachmentManager Object with which to get attachments to write to.
* @return The new DownchannelHandler or nullptr if the operation failed.
*/
static std::shared_ptr<DownchannelHandler> create(
std::shared_ptr<ExchangeHandlerContextInterface> context,
const std::string& authToken,
std::shared_ptr<MessageConsumerInterface> messageConsumer,
std::shared_ptr<avsCommon::avs::attachment::AttachmentManager> attachmentManager);

private:
/**
* Constructor.
*
* @param context The ExchangeContext in which this MessageRequest handler will operate.
* @param authToken The token to use to authorize the request.
*/
DownchannelHandler(std::shared_ptr<ExchangeHandlerContextInterface> context, const std::string& authToken);

/// @name HTTP2RequestSourceInterface methods
/// @{
std::vector<std::string> getRequestHeaderLines() override;
avsCommon::utils::http2::HTTP2SendDataResult onSendData(char* bytes, size_t size) override;
/// @}

/// @name MimeResponseStatusHandlerInterface
/// @{
void onActivity() override;
bool onReceiveResponseCode(long responseCode) override;
void onResponseFinished(avsCommon::utils::http2::HTTP2ResponseFinishedStatus status, const std::string& nonMimeBody)
override;
/// @}
};

} // namespace acl
} // namespace alexaClientSDK

#endif // ALEXA_CLIENT_SDK_ACL_INCLUDE_ACL_TRANSPORT_DOWNCHANNELHANDLER_H_
60 changes: 60 additions & 0 deletions ACL/include/ACL/Transport/ExchangeHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* 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.
*/

#ifndef ALEXA_CLIENT_SDK_ACL_INCLUDE_ACL_TRANSPORT_EXCHANGEHANDLER_H_
#define ALEXA_CLIENT_SDK_ACL_INCLUDE_ACL_TRANSPORT_EXCHANGEHANDLER_H_

#include <memory>

#include "ACL/Transport/ExchangeHandlerContextInterface.h"

namespace alexaClientSDK {
namespace acl {

class HTTP2Transport;

/**
* Common base class for HTTP2 request / response exchanges with AVS.
*/
class ExchangeHandler {
public:
/**
* Constructor.
*
* @param context The context in which this HTTP2 request / reply exchange will be performed.
* @param authToken The authorization token to send in the request.
*/
ExchangeHandler(std::shared_ptr<ExchangeHandlerContextInterface> context, const std::string& authToken);

/**
* Destructor
*/
virtual ~ExchangeHandler() = default;

protected:
/// The @c HTTP2Transport instance for which this exchange is to be performed.
std::shared_ptr<ExchangeHandlerContextInterface> m_context;

/// The auth token used to make the request.
const std::string m_authToken;

/// The AVS authorization header to send in the request.
const std::string m_authHeader;
};

} // namespace acl
} // namespace alexaClientSDK

#endif // ALEXA_CLIENT_SDK_ACL_INCLUDE_ACL_TRANSPORT_EXCHANGEHANDLER_H_
Loading

0 comments on commit f68087c

Please sign in to comment.