Skip to content

Commit

Permalink
Merge pull request alexa#6 from dfollent/xmos_v1.6
Browse files Browse the repository at this point in the history
avs-device-sdk v1.6
  • Loading branch information
Peter Hedinger authored Jul 13, 2018
2 parents 4def446 + 2f2db36 commit e5ffae4
Show file tree
Hide file tree
Showing 659 changed files with 156,143 additions and 16,017 deletions.
102 changes: 102 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
Language: Cpp
BasedOnStyle: Google
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
#AlignConsecutiveAssignments: false
#AlignConsecutiveDeclarations: false
#AlignEscapedNewlines: Left
#AlignOperands: true
#AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
#AllowShortBlocksOnASingleLine: false
#AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
#AllowShortIfStatementsOnASingleLine: true
#AllowShortLoopsOnASingleLine: true
#AlwaysBreakAfterDefinitionReturnType: None
#AlwaysBreakAfterReturnType: None
#AlwaysBreakBeforeMultilineStrings: true
#AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
#BraceWrapping:
# AfterClass: false
# AfterControlStatement: false
# AfterEnum: false
# AfterFunction: false
# AfterNamespace: false
# AfterObjCDeclaration: false
# AfterStruct: false
# AfterUnion: false
# BeforeCatch: false
# BeforeElse: false
# IndentBraces: false
# SplitEmptyFunctionBody: true
#BreakBeforeBinaryOperators: None
#BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: true
#BreakBeforeTernaryOperators: true
#BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: AfterColon
#BreakAfterJavaFieldAnnotations: false
#BreakStringLiterals: true
ColumnLimit: 120
#CommentPragmas: '^ IWYU pragma:'
#CompactNamespaces: false
#ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 8
#ContinuationIndentWidth: 4
#Cpp11BracedListStyle: true
DerivePointerAlignment: false
#DisableFormat: false
#ExperimentalAutoDetectBinPacking: false
#FixNamespaceComments: true
#ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
#IncludeCategories:
# - Regex: '^<.*\.h>'
# Priority: 1
# - Regex: '^<.*'
# Priority: 2
# - Regex: '.*'
# Priority: 3
#IncludeIsMainRegex: '([-_](test|unittest))?$'
#IndentCaseLabels: true
IndentWidth: 4
#IndentWrappedFunctionNames: false
#JavaScriptQuotes: Leave
#JavaScriptWrapImports: true
#KeepEmptyLinesAtTheStartOfBlocks: false
#MacroBlockBegin: ''
#MacroBlockEnd: ''
#MaxEmptyLinesToKeep: 1
#NamespaceIndentation: None
#ObjCBlockIndentWidth: 2
#ObjCSpaceAfterProperty: false
#ObjCSpaceBeforeProtocolList: false
#PenaltyBreakAssignment: 2
#PenaltyBreakBeforeFirstCallParameter: 1
#PenaltyBreakComment: 300
#PenaltyBreakFirstLessLess: 120
#PenaltyBreakString: 1000
#PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 20000
#PointerAlignment: Left
#ReflowComments: true
SortIncludes: false
#SpaceAfterCStyleCast: false
#SpaceAfterTemplateKeyword: true
#SpaceBeforeAssignmentOperators: true
#SpaceBeforeParens: ControlStatements
#SpaceInEmptyParentheses: false
#SpacesBeforeTrailingComments: 2
#SpacesInAngles: false
#SpacesInContainerLiterals: true
#SpacesInCStyleCastParentheses: false
#SpacesInParentheses: false
#SpacesInSquareBrackets: false
#Standard: Auto
#TabWidth: 8
#UseTab: Never
...

7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#CLion project files
.idea
#config file required for SDK integration tests. Each user will configure this differently, so it is preferable that git not show this file as
#'untracked' when printing the status.
Integration/AuthDelegate.config
#macOS specific files
.DS_Store
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")
add_subdirectory("test")
acsdk_add_test_subdirectory_if_allowed()
108 changes: 31 additions & 77 deletions ACL/include/ACL/AVSConnectionManager.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* AVSConnectionManager.h
*
* Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2016-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.
Expand All @@ -15,21 +13,21 @@
* permissions and limitations under the License.
*/

#ifndef ALEXA_CLIENT_SDK_ACL_INCLUDE_ACL_AVS_CONNECTION_MANAGER_H_
#define ALEXA_CLIENT_SDK_ACL_INCLUDE_ACL_AVS_CONNECTION_MANAGER_H_
#ifndef ALEXA_CLIENT_SDK_ACL_INCLUDE_ACL_AVSCONNECTIONMANAGER_H_
#define ALEXA_CLIENT_SDK_ACL_INCLUDE_ACL_AVSCONNECTIONMANAGER_H_

#include <atomic>
#include <memory>
#include <mutex>
#include <string>
#include <unordered_set>

#include <AVSCommon/AVS/AbstractConnection.h>
#include <AVSCommon/AVS/MessageRequest.h>
#include <AVSCommon/SDKInterfaces/AVSEndpointAssignerInterface.h>
#include <AVSCommon/SDKInterfaces/ConnectionStatusObserverInterface.h>
#include <AVSCommon/SDKInterfaces/MessageObserverInterface.h>
#include <AVSCommon/SDKInterfaces/MessageSenderInterface.h>
#include <AVSCommon/SDKInterfaces/StateSynchronizerObserverInterface.h>
#include <AVSCommon/Utils/RequiresShutdown.h>

#include "ACL/Transport/MessageRouterInterface.h"
Expand Down Expand Up @@ -68,13 +66,12 @@ namespace acl {
* This SDK also provides observer interfaces for classes that may be notified when the connection status
* changes, and when messages are received from AVS. These observer objects are optional.
*/
class AVSConnectionManager :
public avsCommon::sdkInterfaces::MessageSenderInterface,
public avsCommon::sdkInterfaces::AVSEndpointAssignerInterface,
/* TODO: ACSDK-421: Remove the implementation of StateSynchronizerObserverInterface */
public avsCommon::sdkInterfaces::StateSynchronizerObserverInterface,
public MessageRouterObserverInterface,
public avsCommon::utils::RequiresShutdown {
class AVSConnectionManager
: public avsCommon::avs::AbstractConnection
, public avsCommon::sdkInterfaces::MessageSenderInterface
, public avsCommon::sdkInterfaces::AVSEndpointAssignerInterface
, public MessageRouterObserverInterface
, public avsCommon::utils::RequiresShutdown {
public:
/**
* A factory function that creates an AVSConnectionManager object.
Expand All @@ -88,14 +85,13 @@ class AVSConnectionManager :
* @return The created AVSConnectionManager object.
*/
static std::shared_ptr<AVSConnectionManager> create(
std::shared_ptr<MessageRouterInterface> messageRouter,
bool isEnabled = true,
std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::ConnectionStatusObserverInterface>>
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>>());
std::shared_ptr<MessageRouterInterface> messageRouter,
bool isEnabled = true,
std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::ConnectionStatusObserverInterface>>
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
Expand Down Expand Up @@ -126,29 +122,7 @@ class AVSConnectionManager :
*/
void reconnect();

/**
* Returns whether the AVS connection is established. If the connection is pending, @c false will be returned.
*
* @return Whether the AVS connection is established.
*/
bool isConnected() const;

/**
* Adds an observer to be notified of connection stauts changes. The observer will be notified of the current
* connection status before this function returns.
*
* @param observer The observer object to add.
*/
void addConnectionStatusObserver(
std::shared_ptr<avsCommon::sdkInterfaces::ConnectionStatusObserverInterface> observer);

/**
* Removes an observer from being notified of connection status changes.
*
* @param observer The observer object to remove.
*/
void removeConnectionStatusObserver(
std::shared_ptr<avsCommon::sdkInterfaces::ConnectionStatusObserverInterface> observer);
bool isConnected() const override;

/**
* Adds an observer to be notified of message receptions.
Expand All @@ -166,17 +140,13 @@ class AVSConnectionManager :

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

/* TODO: ACSDK-421: Remove the implementation of StateSynchronizerObserverInterface */
void onStateChanged(avsCommon::sdkInterfaces::StateSynchronizerObserverInterface::State newState) override;

/**
* @note Set the URL endpoint for the AVS connection. Calling this function with a new value will cause the
* current active connection to be closed, and a new one opened to the new endpoint.
*/
void setAVSEndpoint(const std::string& avsEndpoint) override;

private:

/**
* AVSConnectionManager constructor.
*
Expand All @@ -186,51 +156,35 @@ class AVSConnectionManager :
* @param messageObserver An optional observer which will be sent messages that arrive from AVS.
*/
AVSConnectionManager(
std::shared_ptr<MessageRouterInterface> messageRouter,
std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::ConnectionStatusObserverInterface>>
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::shared_ptr<MessageRouterInterface> messageRouter,
std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::ConnectionStatusObserverInterface>>
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>>());

void doShutdown() override;

void onConnectionStatusChanged(
const avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::Status status,
const avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::ChangedReason reason) override;
const avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::Status status,
const avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::ChangedReason reason) override;

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

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

/* TODO: ACSDK-421: Remove the implementation of StateSynchronizerObserverInterface */
/// Internal object that flags if @c StateSynchronizer had sent the initial event successfully.
bool m_isSynchronized;

/// Mutex to protect @c m_isSynchronized.
std::mutex m_synchronizationMutex;

/// Set of observers to notify when the connection status changes. @c m_connectionStatusObserverMutex must be
/// acquired before access.
std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::ConnectionStatusObserverInterface>>
m_connectionStatusObservers;

/// Mutex for connection status observers.
std::mutex m_connectionStatusObserverMutex;

/// Client-provided message listener, which will receive all messages sent from AVS.
std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::MessageObserverInterface>> m_messageObservers;

/// Mutex for message observers.
std::mutex m_messageOberverMutex;
std::mutex m_messageObserverMutex;

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

} // namespace acl
} // namespace alexaClientSDK
} // namespace acl
} // namespace alexaClientSDK

#endif // ALEXA_CLIENT_SDK_ACL_INCLUDE_ACL_AVS_CONNECTION_MANAGER_H_
#endif // ALEXA_CLIENT_SDK_ACL_INCLUDE_ACL_AVSCONNECTIONMANAGER_H_
36 changes: 17 additions & 19 deletions ACL/include/ACL/Transport/HTTP2MessageRouter.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* HTTP2MessageRouter.h
*
* Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2017-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.
Expand All @@ -15,8 +13,8 @@
* permissions and limitations under the License.
*/

#ifndef ALEXACLIENTSDK_ACL_INCLUDE_ACL_TRANSPORT_HTTP2_MESSAGE_ROUTER_H_
#define ALEXACLIENTSDK_ACL_INCLUDE_ACL_TRANSPORT_HTTP2_MESSAGE_ROUTER_H_
#ifndef ALEXA_CLIENT_SDK_ACL_INCLUDE_ACL_TRANSPORT_HTTP2MESSAGEROUTER_H_
#define ALEXA_CLIENT_SDK_ACL_INCLUDE_ACL_TRANSPORT_HTTP2MESSAGEROUTER_H_

#include <memory>
#include <string>
Expand All @@ -26,26 +24,26 @@
#include "ACL/Transport/MessageRouter.h"
#include "ACL/Transport/MessageConsumerInterface.h"


namespace alexaClientSDK {
namespace acl {

/**
* An HTTP2MessageRouter routes request messages to the Alexa Voice Service, and response messages to the client. It
* uses an HTTP2 connection with AVS.
*/
class HTTP2MessageRouter: public MessageRouter {
class HTTP2MessageRouter : public MessageRouter {
public:
/**
* Constructor.
*
* @param authDelegate The AuthDelegate implementation.
* @param avsEndpoint The URL for the AVS endpoint of this object.
* @param avsEndpoint The URL for the AVS endpoint to connect to. If empty the "endpoint" value of the "acl"
* configuration will be used. If there no such configuration value a default value will be used instead.
*/
HTTP2MessageRouter(
std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface> authDelegate,
std::shared_ptr<avsCommon::avs::attachment::AttachmentManager> attachmentManager,
const std::string& avsEndpoint = "https://avs-alexa-na.amazon.com");
std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface> authDelegate,
std::shared_ptr<avsCommon::avs::attachment::AttachmentManager> attachmentManager,
const std::string& avsEndpoint = "");

/**
* Destructor.
Expand All @@ -54,14 +52,14 @@ class HTTP2MessageRouter: public MessageRouter {

private:
std::shared_ptr<TransportInterface> createTransport(
std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface> authDelegate,
std::shared_ptr<avsCommon::avs::attachment::AttachmentManager> attachmentManager,
const std::string& avsEndpoint,
MessageConsumerInterface* messageConsumerInterface,
TransportObserverInterface* transportObserverInterface) override;
std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface> authDelegate,
std::shared_ptr<avsCommon::avs::attachment::AttachmentManager> attachmentManager,
const std::string& avsEndpoint,
std::shared_ptr<MessageConsumerInterface> messageConsumerInterface,
std::shared_ptr<TransportObserverInterface> transportObserverInterface) override;
};

} // acl
} // alexaClientSDK
} // namespace acl
} // namespace alexaClientSDK

#endif // ALEXACLIENTSDK_ACL_INCLUDE_ACL_TRANSPORT_HTTP2_MESSAGE_ROUTER_H_
#endif // ALEXA_CLIENT_SDK_ACL_INCLUDE_ACL_TRANSPORT_HTTP2MESSAGEROUTER_H_
Loading

0 comments on commit e5ffae4

Please sign in to comment.