Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
Version 3.0.0 alexa-client-sdk
Browse files Browse the repository at this point in the history
Changes in this update:

Feature enhancements, updates, and resolved issues from all releases are available on the [Amazon developer portal](https://developer.amazon.com/docs/alexa/avs-device-sdk/release-notes.html)
  • Loading branch information
VaruPan committed Sep 29, 2022
1 parent 7f9b5b7 commit b32be0a
Show file tree
Hide file tree
Showing 1,909 changed files with 255,921 additions and 33,966 deletions.
4 changes: 2 additions & 2 deletions ACL/include/ACL/Transport/MessageRequestHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class MessageRequestHandler
* Record a stream metric once when a specific threshold of bytes have been read from the stream.
* The stream metric name and threshold will be specified in the MessageRequest.
*/
void recordStreamMetric(int bytes);
void recordStreamMetric(std::size_t bytes);

/**
* Record the metric that specifics the start of sending the Message Event to the cloud.
Expand Down Expand Up @@ -159,7 +159,7 @@ class MessageRequestHandler
avsCommon::sdkInterfaces::MessageRequestObserverInterface::Status m_resultStatus;

/// The number of bytes that have been read from the stream.
unsigned int m_streamBytesRead;
std::size_t m_streamBytesRead;

/// If the stream metric has already been recorded.
bool m_recordedStreamMetric;
Expand Down
1 change: 0 additions & 1 deletion ACL/include/ACL/Transport/MessageRouterFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
namespace alexaClientSDK {
namespace acl {

using namespace alexaClientSDK::acl;
using namespace avsCommon::sdkInterfaces;
using namespace avsCommon::avs::attachment;

Expand Down
1 change: 0 additions & 1 deletion ACL/include/ACL/Transport/MessageRouterFactoryInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
namespace alexaClientSDK {
namespace acl {

using namespace alexaClientSDK::acl;
using namespace avsCommon::sdkInterfaces;
using namespace avsCommon::avs::attachment;

Expand Down
2 changes: 1 addition & 1 deletion ACL/src/AVSConnectionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace acl {
using namespace alexaClientSDK::avsCommon::sdkInterfaces;

/// String to identify log entries originating from this file.
static const std::string TAG("AVSConnectionManager");
#define TAG "AVSConnectionManager"

/**
* Create a LogEntry using this file's TAG and the specified event string.
Expand Down
2 changes: 1 addition & 1 deletion ACL/src/Transport/DownchannelHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static const std::string DOWNCHANNEL_ID_PREFIX = "AVSDownChannel-";
static const std::chrono::seconds ESTABLISH_CONNECTION_TIMEOUT = std::chrono::seconds(60);

/// String to identify log entries originating from this file.
static const std::string TAG("DownchannelHandler");
#define TAG "DownchannelHandler"

/// String to identify the metric source prefix for @c DownChannelHandler.
static const std::string METRIC_SOURCE_PREFIX = "DOWNCHANNEL_HANDLER-";
Expand Down
2 changes: 1 addition & 1 deletion ACL/src/Transport/ExchangeHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace acl {
static const std::string AUTHORIZATION_HEADER = "Authorization: Bearer ";

/// String to identify log entries originating from this file.
static const std::string TAG("ExchangeHandler");
#define TAG "ExchangeHandler"

/**
* Create a LogEntry using this file's TAG and the specified event string.
Expand Down
8 changes: 5 additions & 3 deletions ACL/src/Transport/HTTP2Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ using namespace avsCommon::utils::metrics;
using namespace avsCommon::utils::power;

/// String to identify log entries originating from this file.
static const std::string TAG("HTTP2Transport");
#define TAG "HTTP2Transport"

/**
* Create a LogEntry using this file's TAG and the specified event string.
Expand Down Expand Up @@ -288,10 +288,10 @@ HTTP2Transport::HTTP2Transport(
m_disconnectReason{ConnectionStatusObserverInterface::ChangedReason::NONE} {
m_observers.insert(transportObserver);

m_mainLoopPowerResource = PowerMonitor::getInstance()->createLocalPowerResource(TAG + "_mainLoop");
m_mainLoopPowerResource = PowerMonitor::getInstance()->createLocalPowerResource(TAG "_mainLoop");

m_requestActivityPowerResource =
PowerMonitor::getInstance()->createLocalPowerResource(TAG + "_requestActivityResource");
PowerMonitor::getInstance()->createLocalPowerResource(TAG "_requestActivityResource");

if (m_mainLoopPowerResource) {
m_mainLoopPowerResource->acquire();
Expand Down Expand Up @@ -772,6 +772,8 @@ HTTP2Transport::State HTTP2Transport::handlePostConnecting() {
}
}

ACSDK_INFO(LX_P("handlePostConnecting").m("completing"));

return sendMessagesAndPings(State::POST_CONNECTING, m_requestQueue);
}

Expand Down
2 changes: 1 addition & 1 deletion ACL/src/Transport/HTTP2TransportFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using namespace avsCommon::sdkInterfaces;
using namespace avsCommon::avs::attachment;

/// String to identify log entries originating from this file.
static const std::string TAG("HTTP2TransportFactory");
#define TAG "HTTP2TransportFactory"

/**
* Create a LogEntry using this file's TAG and the specified event string.
Expand Down
48 changes: 38 additions & 10 deletions ACL/src/Transport/MessageRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
namespace alexaClientSDK {
namespace acl {

using namespace avsCommon::avs;
using namespace avsCommon::avs::attachment;
using namespace avsCommon::sdkInterfaces;
using namespace avsCommon::utils::http;
Expand Down Expand Up @@ -66,7 +67,7 @@ static const std::string ATTACHMENT_CONTENT_TYPE = "Content-Type: application/oc
static const std::string MESSAGEREQUEST_ID_PREFIX = "AVSEvent-";

/// String to identify log entries originating from this file.
static const std::string TAG("MessageRequestHandler");
#define TAG "MessageRequestHandler"

/// Prefix used to identify metrics published by this module.
static const std::string ACL_METRIC_SOURCE_PREFIX = "ACL-";
Expand All @@ -92,9 +93,18 @@ static const std::string SEND_COMPLETED = "SEND_COMPLETED";
/// Metric identifier for message send error.
static const std::string MESSAGE_SEND_ERROR = "ERROR.MESSAGE_SEND_FAILED";

// Key value separator for HTTP headers
/// Key value separator for HTTP headers
static const std::string HTTP_KEY_VALUE_SEPARATOR = ": ";

/// Event header key for the namespace field.
static const std::string EVENT_HEADER_NAMESPACE = "namespace";

/// Event header key for the name field.
static const std::string EVENT_HEADER_NAME = "name";

/// Event header missing.
static const std::string EVENT_HEADER_MISSING = "EVENT_HEADER_MISSING";

/**
* Create a LogEntry using this file's TAG and the specified event string.
*
Expand Down Expand Up @@ -131,10 +141,12 @@ static void collectSendDataResultMetric(
*
* @param metricRecorder The metric recorder object.
* @param status The @c MessageRequestObserverInterface::Status of the message.
* @param messageRequest The @c MessageRequest object.
*/
static void submitMessageSendErrorMetric(
const std::shared_ptr<MetricRecorderInterface>& metricRecorder,
MessageRequestObserverInterface::Status status) {
MessageRequestObserverInterface::Status status,
const std::shared_ptr<MessageRequest>& messageRequest) {
if (!metricRecorder) {
return;
}
Expand All @@ -155,11 +167,27 @@ static void submitMessageSendErrorMetric(
return;
}

auto metricEvent = MetricEventBuilder{}
.setActivityName(ACL_METRIC_SOURCE_PREFIX + MESSAGE_SEND_ERROR)
.addDataPoint(DataPointCounterBuilder{}.setName(ss.str()).increment(1).build())
.build();

auto metricEventBuilder = MetricEventBuilder{}
.setActivityName(ACL_METRIC_SOURCE_PREFIX + MESSAGE_SEND_ERROR)
.addDataPoint(DataPointCounterBuilder{}.setName(ss.str()).increment(1).build());
if (messageRequest) {
auto eventHeaders = messageRequest->retrieveEventHeaders();
if (!eventHeaders.eventNamespace.empty()) {
metricEventBuilder.addDataPoint(
DataPointStringBuilder{}.setName(EVENT_HEADER_NAMESPACE).setValue(eventHeaders.eventNamespace).build());
} else {
metricEventBuilder.addDataPoint(
DataPointStringBuilder{}.setName(EVENT_HEADER_NAMESPACE).setValue(EVENT_HEADER_MISSING).build());
}
if (!eventHeaders.eventName.empty()) {
metricEventBuilder.addDataPoint(
DataPointStringBuilder{}.setName(EVENT_HEADER_NAME).setValue(eventHeaders.eventName).build());
} else {
metricEventBuilder.addDataPoint(
DataPointStringBuilder{}.setName(EVENT_HEADER_NAME).setValue(EVENT_HEADER_MISSING).build());
}
}
auto metricEvent = metricEventBuilder.build();
if (!metricEvent) {
ACSDK_ERROR(LX("submitErrorMetricFailed").d("reason", "invalid metric event"));
return;
Expand All @@ -168,7 +196,7 @@ static void submitMessageSendErrorMetric(
recordMetric(metricRecorder, metricEvent);
}

void MessageRequestHandler::recordStreamMetric(int bytes) {
void MessageRequestHandler::recordStreamMetric(std::size_t bytes) {
if (m_messageRequest == nullptr) {
return;
}
Expand Down Expand Up @@ -506,7 +534,7 @@ void MessageRequestHandler::onResponseFinished(HTTP2ResponseFinishedStatus statu

m_messageRequest->sendCompleted(m_resultStatus);

submitMessageSendErrorMetric(m_metricRecorder, m_resultStatus);
submitMessageSendErrorMetric(m_metricRecorder, m_resultStatus, m_messageRequest);
}

} // namespace acl
Expand Down
2 changes: 1 addition & 1 deletion ACL/src/Transport/MessageRequestQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace acl {
using namespace avsCommon::avs;

/// String to identify log entries originating from this file.
static const std::string TAG("MessageRequestQueue");
#define TAG "MessageRequestQueue"

/**
* Create a LogEntry using this file's TAG and the specified event string.
Expand Down
10 changes: 5 additions & 5 deletions ACL/src/Transport/MessageRouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ using namespace avsCommon::avs::attachment;
using namespace avsCommon::avs;

/// String to identify log entries originating from this file.
static const std::string TAG("MessageRouter");
#define TAG "MessageRouter"

/// String for logging purpose as the key for the size of m_transports.
static constexpr const char* KEY_SIZEOF_TRANSPORTS = "sizeOf m_transports";
Expand Down Expand Up @@ -316,7 +316,7 @@ void MessageRouter::notifyObserverOnConnectionStatusChanged(
m_serverSideDisconnectNotificationPending = true;
m_serverSideDisconnectTimer.start(m_serverSideReconnectGracePeriod, [this]() {
ACSDK_DEBUG0(LX("serverSideDisconectTimerPredicate"));
m_executor.submit([this]() {
m_executor.execute([this]() {
ACSDK_DEBUG0(
LX("serverSideDisconectTimerHandler")
.d("m_serverSideDisconnectNotificationPending", m_serverSideDisconnectNotificationPending));
Expand All @@ -335,7 +335,7 @@ void MessageRouter::notifyObserverOnConnectionStatusChanged(
handleNotifyObserverOnConnectionStatusChanged(status, reason);
}
};
m_executor.submit(task);
m_executor.execute(task);
}

void MessageRouter::handleNotifyObserverOnConnectionStatusChanged(
Expand All @@ -360,7 +360,7 @@ void MessageRouter::notifyObserverOnReceive(const std::string& contextId, const
temp->receive(contextId, message);
}
};
m_executor.submit(task);
m_executor.execute(task);
}

void MessageRouter::createActiveTransportLocked() {
Expand Down Expand Up @@ -428,7 +428,7 @@ void MessageRouter::safelyResetActiveTransportLocked() {
void MessageRouter::safelyReleaseTransport(std::shared_ptr<TransportInterface> transport) {
if (transport) {
auto task = [transport]() { transport->shutdown(); };
m_executor.submit(task);
m_executor.execute(task);
}
}

Expand Down
1 change: 0 additions & 1 deletion ACL/src/Transport/MessageRouterFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
namespace alexaClientSDK {
namespace acl {

using namespace alexaClientSDK::acl;
using namespace avsCommon::sdkInterfaces;
using namespace avsCommon::avs::attachment;

Expand Down
2 changes: 1 addition & 1 deletion ACL/src/Transport/MimeResponseSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static const std::string MIME_OCTET_STREAM_CONTENT_TYPE = "application/octet-str
static const size_t NON_MIME_BODY_MAX_SIZE = 4096;

/// String to identify log entries originating from this file.
static const std::string TAG("MimeResponseSink");
#define TAG "MimeResponseSink"

/**
* Create a LogEntry using this file's TAG and the specified event string.
Expand Down
2 changes: 1 addition & 1 deletion ACL/src/Transport/PingHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static const uint8_t PING_PRIORITY = 200;
static const std::string PING_ID_PREFIX = "AVSPing-";

/// String to identify log entries originating from this file.
static const std::string TAG("PingHandler");
#define TAG "PingHandler"

/**
* Create a LogEntry using this file's TAG and the specified event string.
Expand Down
18 changes: 9 additions & 9 deletions ACL/src/Transport/PostConnectSequencer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using namespace avsCommon::utils::error;
using namespace avsCommon::utils::power;

/// String to identify log entries originating form this file.
static const std::string TAG("PostConnectSequencer");
#define TAG "PostConnectSequencer"

/**
* Create a LogEntry using this file's TAG and the specified event string.
Expand All @@ -50,24 +50,24 @@ std::shared_ptr<PostConnectSequencer> PostConnectSequencer::create(
PostConnectSequencer::PostConnectSequencer(const PostConnectOperationsSet& postConnectOperations) :
m_isStopping{false},
m_postConnectOperations{postConnectOperations} {
ACSDK_DEBUG5(LX("init"));
ACSDK_INFO(LX("init"));

m_mainLoopPowerResource = PowerMonitor::getInstance()->createLocalPowerResource(TAG + "_mainLoop");
m_mainLoopPowerResource = PowerMonitor::getInstance()->createLocalPowerResource(TAG "_mainLoop");

if (m_mainLoopPowerResource) {
m_mainLoopPowerResource->acquire();
}
}

PostConnectSequencer::~PostConnectSequencer() {
ACSDK_DEBUG5(LX("destroy"));
ACSDK_INFO(LX("destroy"));
stop();
}

bool PostConnectSequencer::doPostConnect(
std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> postConnectSender,
std::shared_ptr<PostConnectObserverInterface> postConnectObserver) {
ACSDK_DEBUG5(LX("doPostConnect"));
ACSDK_INFO(LX("doPostConnect"));

if (!postConnectSender) {
ACSDK_ERROR(LX("doPostConnectFailed").d("reason", "nullPostConnectSender"));
Expand All @@ -94,7 +94,7 @@ bool PostConnectSequencer::doPostConnect(
void PostConnectSequencer::mainLoop(
std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> postConnectSender,
std::shared_ptr<PostConnectObserverInterface> postConnectObserver) {
ACSDK_DEBUG5(LX("mainLoop"));
ACSDK_INFO(LX("mainLoop"));

PowerMonitor::getInstance()->assignThreadPowerResource(m_mainLoopPowerResource);

Expand Down Expand Up @@ -144,11 +144,11 @@ void PostConnectSequencer::mainLoop(
postConnectObserver->onPostConnected();
}

ACSDK_DEBUG5(LX("mainLoopReturning"));
ACSDK_INFO(LX("mainLoopReturning"));
}

void PostConnectSequencer::onDisconnect() {
ACSDK_DEBUG5(LX("onDisconnect"));
ACSDK_INFO(LX("onDisconnect"));
stop();
}

Expand All @@ -163,7 +163,7 @@ bool PostConnectSequencer::isStopping() {
}

void PostConnectSequencer::stop() {
ACSDK_DEBUG5(LX("stop"));
ACSDK_INFO(LX("stop"));
{
std::lock_guard<std::mutex> lock{m_mutex};
if (m_isStopping) {
Expand Down
2 changes: 1 addition & 1 deletion ACL/src/Transport/PostConnectSequencerFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using namespace avsCommon::sdkInterfaces;
using namespace acsdkPostConnectOperationProviderRegistrarInterfaces;

/// String to identify log entries originating from this file.
static const std::string TAG("PostConnectSequencerFactory");
#define TAG "PostConnectSequencerFactory"

/**
* Create a LogEntry using this file's TAG and the specified event string.
Expand Down
2 changes: 1 addition & 1 deletion ACL/src/Transport/SynchronizedMessageRequestQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace acl {
using namespace avsCommon::avs;

/// String to identify log entries originating from this file.
static const std::string TAG("SynchronizedMessageRequestQueue");
#define TAG "SynchronizedMessageRequestQueue"

/**
* Create a LogEntry using this file's TAG and the specified event string.
Expand Down
6 changes: 3 additions & 3 deletions ACL/test/Transport/Common/MockHTTP2Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ std::shared_ptr<HTTP2RequestInterface> MockHTTP2Connection::createAndSendRequest

if (request->getRequestType() == HTTP2RequestType::POST) {
// Parse POST HTTP2 Requests.
std::lock_guard<std::mutex> lock(m_postRequestMutex);
std::lock_guard<std::mutex> innerLock(m_postRequestMutex);
m_postRequestQueue.push_back(request);
if (m_postResponseCode != HTTPResponseCode::HTTP_RESPONSE_CODE_UNDEFINED) {
request->getSink()->onReceiveResponseCode(responseCodeToInt(m_postResponseCode));
Expand All @@ -66,12 +66,12 @@ std::shared_ptr<HTTP2RequestInterface> MockHTTP2Connection::createAndSendRequest
m_requestPostCv.notify_one();
} else if (m_downchannelURL == request->getUrl()) {
// Push downchannel requests to its queue.
std::lock_guard<std::mutex> lock(m_downchannelRequestMutex);
std::lock_guard<std::mutex> innerLock(m_downchannelRequestMutex);
m_downchannelRequestQueue.push_back(request);
m_downchannelRequestCv.notify_all();
} else if (m_pingURL == request->getUrl()) {
// Push ping requests to its queue.
std::lock_guard<std::mutex> lock(m_pingRequestMutex);
std::lock_guard<std::mutex> innerLock(m_pingRequestMutex);
m_pingRequestQueue.push_back(request);
m_pingRequestCv.notify_one();
}
Expand Down
Loading

0 comments on commit b32be0a

Please sign in to comment.