2017-02-10 23:39:10 +00:00
|
|
|
/*
|
|
|
|
* ObservableMessageRequest.cpp
|
|
|
|
*
|
|
|
|
* Copyright 2016-2017 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.
|
|
|
|
*/
|
|
|
|
|
2017-06-23 23:26:34 +00:00
|
|
|
#include <AVSCommon/Utils/Logger/Logger.h>
|
|
|
|
|
2017-02-10 23:39:10 +00:00
|
|
|
#include "Integration/ObservableMessageRequest.h"
|
|
|
|
|
2017-05-26 23:06:14 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2017-02-10 23:39:10 +00:00
|
|
|
namespace alexaClientSDK {
|
|
|
|
namespace integration {
|
|
|
|
|
2017-06-23 23:26:34 +00:00
|
|
|
/// String to identify log entries originating from this file.
|
|
|
|
static const std::string TAG("ObservableMessageRequest");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a LogEntry using this file's TAG and the specified event string.
|
|
|
|
*
|
|
|
|
* @param The event string for this @c LogEntry.
|
|
|
|
*/
|
|
|
|
#define LX(event) alexaClientSDK::avsCommon::utils::logger::LogEntry(TAG, event)
|
|
|
|
|
2017-05-26 23:06:14 +00:00
|
|
|
using namespace avsCommon::avs;
|
|
|
|
using namespace avsCommon::avs::attachment;
|
|
|
|
|
2017-05-18 05:02:48 +00:00
|
|
|
ObservableMessageRequest::ObservableMessageRequest(
|
|
|
|
const std::string & jsonContent,
|
2017-05-26 23:06:14 +00:00
|
|
|
std::shared_ptr<AttachmentReader> attachmentReader) :
|
|
|
|
MessageRequest{jsonContent, attachmentReader}, m_sendMessageStatus(MessageRequest::Status::PENDING) {
|
2017-02-10 23:39:10 +00:00
|
|
|
}
|
|
|
|
|
2017-05-26 23:06:14 +00:00
|
|
|
void ObservableMessageRequest::onSendCompleted(MessageRequest::Status sendMessageStatus) {
|
2017-05-18 05:02:48 +00:00
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
2017-06-23 23:26:34 +00:00
|
|
|
ACSDK_DEBUG(LX("onSendCompleted").d("status", MessageRequest::statusToString(sendMessageStatus)));
|
2017-05-26 23:06:14 +00:00
|
|
|
m_sendMessageStatus = sendMessageStatus;
|
2017-02-10 23:39:10 +00:00
|
|
|
m_wakeTrigger.notify_all();
|
|
|
|
}
|
|
|
|
|
2017-05-26 23:06:14 +00:00
|
|
|
MessageRequest::Status ObservableMessageRequest::getSendMessageStatus() const {
|
2017-05-18 05:02:48 +00:00
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
2017-05-26 23:06:14 +00:00
|
|
|
return m_sendMessageStatus;
|
2017-02-10 23:39:10 +00:00
|
|
|
}
|
|
|
|
|
2017-05-26 23:06:14 +00:00
|
|
|
bool ObservableMessageRequest::waitFor(
|
|
|
|
const MessageRequest::Status sendMessageStatus, const std::chrono::seconds duration) {
|
2017-02-10 23:39:10 +00:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
2017-05-26 23:06:14 +00:00
|
|
|
return m_wakeTrigger.wait_for(lock, duration, [this, sendMessageStatus]() {
|
|
|
|
return sendMessageStatus == m_sendMessageStatus;
|
2017-02-10 23:39:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-26 23:06:14 +00:00
|
|
|
void ObservableMessageRequest::onExceptionReceived(const std::string & exceptionMessage) {
|
2017-06-23 23:26:34 +00:00
|
|
|
ACSDK_DEBUG(LX("onExceptionReceived").d("status", exceptionMessage));
|
2017-05-26 23:06:14 +00:00
|
|
|
}
|
|
|
|
|
2017-02-10 23:39:10 +00:00
|
|
|
} // namespace integration
|
|
|
|
} // namespace alexaClientSDK
|