feat: implement BasicMessage and core AMQP client infrastructure

This commit is contained in:
bing
2026-04-03 15:35:49 +08:00
parent 2974a3dec5
commit ff8ff1189a
29 changed files with 1031 additions and 987 deletions

View File

@@ -8,7 +8,7 @@ cmake_minimum_required(VERSION 3.5)
project(SimpleAmqpClient LANGUAGES CXX) project(SimpleAmqpClient LANGUAGES CXX)
if(NOT DEFINED CMAKE_CXX_STANDARD) if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 98) set(CMAKE_CXX_STANDARD 17)
endif() endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
@@ -45,30 +45,6 @@ set(SAC_APIVERSION ${_API_VERSION_MAJOR}.${_API_VERSION_MINOR}.${_API_VERSION_PA
option(BUILD_SHARED_LIBS "Build SimpleAmqpClient as a shared library" ON) option(BUILD_SHARED_LIBS "Build SimpleAmqpClient as a shared library" ON)
# Force the use of static boost library for static libraries
include(CMakeDependentOption)
cmake_dependent_option(
Boost_Dynamic_Linking_ENABLED
"Enable boost dynamic linking"
ON
"BUILD_SHARED_LIBS"
OFF
)
if(Boost_Dynamic_Linking_ENABLED)
set(Boost_USE_STATIC_LIBS OFF)
else()
set(Boost_USE_STATIC_LIBS ON)
endif()
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.47.0 COMPONENTS chrono REQUIRED)
if(Boost_VERSION VERSION_LESS 1.89)
find_package(Boost 1.47.0 COMPONENTS chrono system REQUIRED)
endif()
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
# Try using the CMake config modules first # Try using the CMake config modules first
find_package(rabbitmq-c CONFIG QUIET) find_package(rabbitmq-c CONFIG QUIET)
@@ -158,16 +134,12 @@ set(SAC_LIB_SRCS
add_library(SimpleAmqpClient ${SAC_LIB_SRCS}) add_library(SimpleAmqpClient ${SAC_LIB_SRCS})
target_link_libraries(SimpleAmqpClient ${Rabbitmqc_LIBRARY} ${SOCKET_LIBRARY} ${Boost_LIBRARIES} $<$<BOOL:${Boost_Dynamic_Linking_ENABLED}>:Boost::dynamic_linking>) target_link_libraries(SimpleAmqpClient ${Rabbitmqc_LIBRARY} ${SOCKET_LIBRARY})
if (WIN32) if (WIN32)
if (NOT BUILD_SHARED_LIBS) if (NOT BUILD_SHARED_LIBS)
target_compile_definitions(SimpleAmqpClient PUBLIC SimpleAmqpClient_STATIC) target_compile_definitions(SimpleAmqpClient PUBLIC SimpleAmqpClient_STATIC)
endif () endif ()
set_target_properties(SimpleAmqpClient PROPERTIES VERSION ${SAC_VERSION} OUTPUT_NAME SimpleAmqpClient.${SAC_SOVERSION})
else ()
set_target_properties(SimpleAmqpClient PROPERTIES VERSION ${SAC_VERSION} SOVERSION ${SAC_SOVERSION})
endif () endif ()
# Some smoke tests: # Some smoke tests:
@@ -177,24 +149,7 @@ option(ENABLE_TESTING "Enable smoke tests" OFF)
if (ENABLE_TESTING) if (ENABLE_TESTING)
enable_testing() enable_testing()
set(BUILD_GTEST ON CACHE BOOL "" FORCE) find_package(xgoogletest CONFIG REQUIRED)
set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
# This only affects targets declared after this.
set(BUILD_SHARED_LIBS OFF)
mark_as_advanced(BUILD_GMOCK)
mark_as_advanced(BUILD_GTEST)
mark_as_advanced(INSTALL_GTEST)
mark_as_advanced(gmock_build_tests)
mark_as_advanced(gtest_build_samples)
mark_as_advanced(gtest_build_tests)
mark_as_advanced(gtest_disable_pthreads)
mark_as_advanced(gtest_force_shared_crt)
mark_as_advanced(gtest_hide_internal_symbols)
add_subdirectory(third-party/googletest)
add_subdirectory(testing) add_subdirectory(testing)
endif (ENABLE_TESTING) endif (ENABLE_TESTING)
@@ -284,7 +239,7 @@ else (BUILD_SHARED_LIBS)
set(extra_win32_targets "${Rabbitmqc_LIBRARY};${SOCKET_LIBRARY}") set(extra_win32_targets "${Rabbitmqc_LIBRARY};${SOCKET_LIBRARY}")
endif (BUILD_SHARED_LIBS) endif (BUILD_SHARED_LIBS)
foreach(_lib ${Boost_LIBRARIES} ${extra_win32_targets}) foreach(_lib ${extra_win32_targets})
# Check if FindBoost.cmake provided actual library paths or targets # Check if FindBoost.cmake provided actual library paths or targets
if(TARGET ${_lib}) if(TARGET ${_lib})

9
CMakeUserPresets.json Normal file
View File

@@ -0,0 +1,9 @@
{
"version": 4,
"vendor": {
"conan": {}
},
"include": [
"build/Release/generators/CMakePresets.json"
]
}

View File

@@ -1,23 +0,0 @@
The MIT License (MIT)
Copyright (c) 2010-2014 Alan Antonuk. All Rights Reserved.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

90
conanfile.py Normal file
View File

@@ -0,0 +1,90 @@
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
from conan.tools.files import copy
import os
class SimpleAmqpClientConan(ConanFile):
name = "simpleamqpclient"
version = "2.5.1"
description = "Simple C++ Wrapper around rabbitmq-c"
url = "https://github.com/alanxz/SimpleAmqpClient"
license = "MIT"
author = "Alan Antonuk"
topics = ("rabbitmq", "amqp", "client", "message-queue", "cpp")
settings = "os", "compiler", "build_type", "arch"
package_type = "library"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_test": [True, False]
}
default_options = {
"shared": False,
"fPIC": True,
"with_test": True
}
exports_sources = "CMakeLists.txt", "Modules/*", "src/*", "testing/*", "third-party/*", "Doxyfile.in", "libSimpleAmqpClient.pc.in"
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
def layout(self):
cmake_layout(self)
def requirements(self):
self.requires("rabbitmq-c/[>=0.11.0]", transitive_headers=True, transitive_libs=True)
def build_requirements(self):
if self.options.with_test:
self.test_requires("xgoogletest/1.17.1")
def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_SHARED_LIBS"] = self.options.shared
tc.variables["ENABLE_TESTING"] = self.options.with_test
tc.variables["BUILD_API_DOCS"] = False
tc.generate()
deps = CMakeDeps(self)
deps.set_property("rabbitmq-c", "cmake_target_name", "rabbitmq::rabbitmq" if self.options.shared else "rabbitmq::rabbitmq-static")
deps.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
if self.options.with_test:
cmake.test()
def package(self):
cmake = CMake(self)
cmake.install()
copy(self, "LICENSE-MIT", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
def package_info(self):
self.cpp_info.set_property("cmake_file_name", "simpleamqpclient")
self.cpp_info.set_property("cmake_target_name", "simpleamqpclient::simpleamqpclient")
# When simpleamqpclient builds as static on windows, we need SimpleAmqpClient_STATIC
if not self.options.shared and self.settings.os == "Windows":
self.cpp_info.defines.append("SimpleAmqpClient_STATIC")
libs_name = "SimpleAmqpClient"
# In the CMakeLists.txt:
# set_target_properties(SimpleAmqpClient PROPERTIES VERSION ${SAC_VERSION} OUTPUT_NAME SimpleAmqpClient.${SAC_SOVERSION})
# Note on Windows it sets SimpleAmqpClient.7, but conan usually links `SimpleAmqpClient.7.lib` or similar. We'll simplify and use SimpleAmqpClient.7 if we really need to, but often CMake finds it via exported targets. Let's provide the base name here.
# Actually in Windows if shared, CMake generates SimpleAmqpClient.lib or SimpleAmqpClient.7.lib. Let's just use "SimpleAmqpClient".
self.cpp_info.libs = ["SimpleAmqpClient"]
if self.settings.os == "Windows":
self.cpp_info.system_libs.append("ws2_32")
self.cpp_info.requires = ["rabbitmq-c::rabbitmq-c"]

View File

@@ -1,3 +1,5 @@
#include <sstream>
#include <cassert>
/* /*
* ***** BEGIN LICENSE BLOCK ***** * ***** BEGIN LICENSE BLOCK *****
* Version: MIT * Version: MIT
@@ -32,35 +34,36 @@
#include <amqp_framing.h> #include <amqp_framing.h>
#include <assert.h> #include <assert.h>
#include <boost/lexical_cast.hpp> #include <string>
#include <stdexcept>
namespace AmqpClient { namespace AmqpClient {
const boost::uint16_t ContentTooLargeException::REPLY_CODE = const uint16_t ContentTooLargeException::REPLY_CODE =
AMQP_CONTENT_TOO_LARGE; AMQP_CONTENT_TOO_LARGE;
const boost::uint16_t NoRouteException::REPLY_CODE = AMQP_NO_ROUTE; const uint16_t NoRouteException::REPLY_CODE = AMQP_NO_ROUTE;
const boost::uint16_t NoConsumersException::REPLY_CODE = AMQP_NO_CONSUMERS; const uint16_t NoConsumersException::REPLY_CODE = AMQP_NO_CONSUMERS;
const boost::uint16_t AccessRefusedException::REPLY_CODE = AMQP_ACCESS_REFUSED; const uint16_t AccessRefusedException::REPLY_CODE = AMQP_ACCESS_REFUSED;
const boost::uint16_t NotFoundException::REPLY_CODE = AMQP_NOT_FOUND; const uint16_t NotFoundException::REPLY_CODE = AMQP_NOT_FOUND;
const boost::uint16_t ResourceLockedException::REPLY_CODE = const uint16_t ResourceLockedException::REPLY_CODE =
AMQP_RESOURCE_LOCKED; AMQP_RESOURCE_LOCKED;
const boost::uint16_t PreconditionFailedException::REPLY_CODE = const uint16_t PreconditionFailedException::REPLY_CODE =
AMQP_PRECONDITION_FAILED; AMQP_PRECONDITION_FAILED;
const boost::uint16_t ConnectionForcedException::REPLY_CODE = const uint16_t ConnectionForcedException::REPLY_CODE =
AMQP_CONNECTION_FORCED; AMQP_CONNECTION_FORCED;
const boost::uint16_t InvalidPathException::REPLY_CODE = AMQP_INVALID_PATH; const uint16_t InvalidPathException::REPLY_CODE = AMQP_INVALID_PATH;
const boost::uint16_t FrameErrorException::REPLY_CODE = AMQP_FRAME_ERROR; const uint16_t FrameErrorException::REPLY_CODE = AMQP_FRAME_ERROR;
const boost::uint16_t SyntaxErrorException::REPLY_CODE = AMQP_SYNTAX_ERROR; const uint16_t SyntaxErrorException::REPLY_CODE = AMQP_SYNTAX_ERROR;
const boost::uint16_t CommandInvalidException::REPLY_CODE = const uint16_t CommandInvalidException::REPLY_CODE =
AMQP_COMMAND_INVALID; AMQP_COMMAND_INVALID;
const boost::uint16_t ChannelErrorException::REPLY_CODE = AMQP_CHANNEL_ERROR; const uint16_t ChannelErrorException::REPLY_CODE = AMQP_CHANNEL_ERROR;
const boost::uint16_t UnexpectedFrameException::REPLY_CODE = const uint16_t UnexpectedFrameException::REPLY_CODE =
AMQP_UNEXPECTED_FRAME; AMQP_UNEXPECTED_FRAME;
const boost::uint16_t ResourceErrorException::REPLY_CODE = AMQP_RESOURCE_ERROR; const uint16_t ResourceErrorException::REPLY_CODE = AMQP_RESOURCE_ERROR;
const boost::uint16_t NotAllowedException::REPLY_CODE = AMQP_NOT_ALLOWED; const uint16_t NotAllowedException::REPLY_CODE = AMQP_NOT_ALLOWED;
const boost::uint16_t NotImplementedException::REPLY_CODE = const uint16_t NotImplementedException::REPLY_CODE =
AMQP_NOT_IMPLEMENTED; AMQP_NOT_IMPLEMENTED;
const boost::uint16_t InternalErrorException::REPLY_CODE = AMQP_INTERNAL_ERROR; const uint16_t InternalErrorException::REPLY_CODE = AMQP_INTERNAL_ERROR;
void AmqpException::Throw(const amqp_rpc_reply_t &reply) { void AmqpException::Throw(const amqp_rpc_reply_t &reply) {
assert(reply.reply_type == AMQP_RESPONSE_SERVER_EXCEPTION); assert(reply.reply_type == AMQP_RESPONSE_SERVER_EXCEPTION);
@@ -77,7 +80,7 @@ void AmqpException::Throw(const amqp_rpc_reply_t &reply) {
throw std::logic_error( throw std::logic_error(
std::string( std::string(
"Programming error: unknown server exception class/method") "Programming error: unknown server exception class/method")
.append(boost::lexical_cast<std::string>(reply.reply.id))); .append(std::to_string(reply.reply.id)));
} }
} }
@@ -124,7 +127,7 @@ void AmqpException::Throw(const amqp_channel_close_t &reply) {
default: default:
throw std::logic_error( throw std::logic_error(
std::string("Programming error: unknown channel reply code: ") std::string("Programming error: unknown channel reply code: ")
.append(boost::lexical_cast<std::string>(reply.reply_code))); .append(std::to_string(reply.reply_code)));
} }
} }
@@ -186,14 +189,14 @@ void AmqpException::Throw(const amqp_connection_close_t &reply) {
default: default:
throw std::logic_error( throw std::logic_error(
std::string("Programming error: unknown connection reply code: ") std::string("Programming error: unknown connection reply code: ")
.append(boost::lexical_cast<std::string>(reply.reply_code))); .append(std::to_string(reply.reply_code)));
} }
} }
AmqpException::AmqpException(const std::string &what, AmqpException::AmqpException(const std::string &what,
const std::string &reply_text, const std::string &reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: std::runtime_error(what), : std::runtime_error(what),
m_reply_text(reply_text), m_reply_text(reply_text),
m_class_id(class_id), m_class_id(class_id),

View File

@@ -32,7 +32,7 @@
#include <amqp.h> #include <amqp.h>
#include <amqp_framing.h> #include <amqp_framing.h>
#include <boost/optional/optional.hpp> #include <optional>
#include <cstring> #include <cstring>
#include <string> #include <string>
@@ -42,20 +42,20 @@ namespace AmqpClient {
struct BasicMessage::Impl { struct BasicMessage::Impl {
std::string body; std::string body;
boost::optional<std::string> content_type; std::optional<std::string> content_type;
boost::optional<std::string> content_encoding; std::optional<std::string> content_encoding;
boost::optional<delivery_mode_t> delivery_mode; std::optional<delivery_mode_t> delivery_mode;
boost::optional<boost::uint8_t> priority; std::optional<uint8_t> priority;
boost::optional<std::string> correlation_id; std::optional<std::string> correlation_id;
boost::optional<std::string> reply_to; std::optional<std::string> reply_to;
boost::optional<std::string> expiration; std::optional<std::string> expiration;
boost::optional<std::string> message_id; std::optional<std::string> message_id;
boost::optional<boost::uint64_t> timestamp; std::optional<uint64_t> timestamp;
boost::optional<std::string> type; std::optional<std::string> type;
boost::optional<std::string> user_id; std::optional<std::string> user_id;
boost::optional<std::string> app_id; std::optional<std::string> app_id;
boost::optional<std::string> cluster_id; std::optional<std::string> cluster_id;
boost::optional<Table> header_table; std::optional<Table> header_table;
}; };
BasicMessage::BasicMessage() : m_impl(new Impl) {} BasicMessage::BasicMessage() : m_impl(new Impl) {}
@@ -74,7 +74,7 @@ void BasicMessage::Body(const std::string& body) { m_impl->body = body; }
const std::string& BasicMessage::ContentType() const { const std::string& BasicMessage::ContentType() const {
if (ContentTypeIsSet()) { if (ContentTypeIsSet()) {
return m_impl->content_type.get(); return m_impl->content_type.value();
} }
static const std::string empty; static const std::string empty;
return empty; return empty;
@@ -85,14 +85,14 @@ void BasicMessage::ContentType(const std::string& content_type) {
} }
bool BasicMessage::ContentTypeIsSet() const { bool BasicMessage::ContentTypeIsSet() const {
return m_impl->content_type.is_initialized(); return m_impl->content_type.has_value();
} }
void BasicMessage::ContentTypeClear() { m_impl->content_type.reset(); } void BasicMessage::ContentTypeClear() { m_impl->content_type.reset(); }
const std::string& BasicMessage::ContentEncoding() const { const std::string& BasicMessage::ContentEncoding() const {
if (ContentEncodingIsSet()) { if (ContentEncodingIsSet()) {
return m_impl->content_encoding.get(); return m_impl->content_encoding.value();
} }
static const std::string empty; static const std::string empty;
return empty; return empty;
@@ -103,7 +103,7 @@ void BasicMessage::ContentEncoding(const std::string& content_encoding) {
} }
bool BasicMessage::ContentEncodingIsSet() const { bool BasicMessage::ContentEncodingIsSet() const {
return m_impl->content_encoding.is_initialized(); return m_impl->content_encoding.has_value();
} }
void BasicMessage::ContentEncodingClear() { m_impl->content_encoding.reset(); } void BasicMessage::ContentEncodingClear() { m_impl->content_encoding.reset(); }
@@ -117,28 +117,28 @@ void BasicMessage::DeliveryMode(delivery_mode_t delivery_mode) {
} }
bool BasicMessage::DeliveryModeIsSet() const { bool BasicMessage::DeliveryModeIsSet() const {
return m_impl->delivery_mode.is_initialized(); return m_impl->delivery_mode.has_value();
} }
void BasicMessage::DeliveryModeClear() { m_impl->delivery_mode.reset(); } void BasicMessage::DeliveryModeClear() { m_impl->delivery_mode.reset(); }
boost::uint8_t BasicMessage::Priority() const { uint8_t BasicMessage::Priority() const {
return m_impl->priority.value_or(0); return m_impl->priority.value_or(0);
} }
void BasicMessage::Priority(boost::uint8_t priority) { void BasicMessage::Priority(uint8_t priority) {
m_impl->priority = priority; m_impl->priority = priority;
} }
bool BasicMessage::PriorityIsSet() const { bool BasicMessage::PriorityIsSet() const {
return m_impl->priority.is_initialized(); return m_impl->priority.has_value();
} }
void BasicMessage::PriorityClear() { m_impl->priority.reset(); } void BasicMessage::PriorityClear() { m_impl->priority.reset(); }
const std::string& BasicMessage::CorrelationId() const { const std::string& BasicMessage::CorrelationId() const {
if (CorrelationIdIsSet()) { if (CorrelationIdIsSet()) {
return m_impl->correlation_id.get(); return m_impl->correlation_id.value();
} }
static const std::string empty; static const std::string empty;
return empty; return empty;
@@ -149,14 +149,14 @@ void BasicMessage::CorrelationId(const std::string& correlation_id) {
} }
bool BasicMessage::CorrelationIdIsSet() const { bool BasicMessage::CorrelationIdIsSet() const {
return m_impl->correlation_id.is_initialized(); return m_impl->correlation_id.has_value();
} }
void BasicMessage::CorrelationIdClear() { m_impl->correlation_id.reset(); } void BasicMessage::CorrelationIdClear() { m_impl->correlation_id.reset(); }
const std::string& BasicMessage::ReplyTo() const { const std::string& BasicMessage::ReplyTo() const {
if (ReplyToIsSet()) { if (ReplyToIsSet()) {
return m_impl->reply_to.get(); return m_impl->reply_to.value();
} }
static const std::string empty; static const std::string empty;
return empty; return empty;
@@ -167,14 +167,14 @@ void BasicMessage::ReplyTo(const std::string& reply_to) {
} }
bool BasicMessage::ReplyToIsSet() const { bool BasicMessage::ReplyToIsSet() const {
return m_impl->reply_to.is_initialized(); return m_impl->reply_to.has_value();
} }
void BasicMessage::ReplyToClear() { m_impl->reply_to.reset(); } void BasicMessage::ReplyToClear() { m_impl->reply_to.reset(); }
const std::string& BasicMessage::Expiration() const { const std::string& BasicMessage::Expiration() const {
if (ExpirationIsSet()) { if (ExpirationIsSet()) {
return m_impl->expiration.get(); return m_impl->expiration.value();
} }
static const std::string empty; static const std::string empty;
return empty; return empty;
@@ -185,14 +185,14 @@ void BasicMessage::Expiration(const std::string& expiration) {
} }
bool BasicMessage::ExpirationIsSet() const { bool BasicMessage::ExpirationIsSet() const {
return m_impl->expiration.is_initialized(); return m_impl->expiration.has_value();
} }
void BasicMessage::ExpirationClear() { m_impl->expiration.reset(); } void BasicMessage::ExpirationClear() { m_impl->expiration.reset(); }
const std::string& BasicMessage::MessageId() const { const std::string& BasicMessage::MessageId() const {
if (MessageIdIsSet()) { if (MessageIdIsSet()) {
return m_impl->message_id.get(); return m_impl->message_id.value();
} }
static const std::string empty; static const std::string empty;
return empty; return empty;
@@ -203,27 +203,27 @@ void BasicMessage::MessageId(const std::string& message_id) {
} }
bool BasicMessage::MessageIdIsSet() const { bool BasicMessage::MessageIdIsSet() const {
return m_impl->message_id.is_initialized(); return m_impl->message_id.has_value();
} }
void BasicMessage::MessageIdClear() { m_impl->message_id.reset(); } void BasicMessage::MessageIdClear() { m_impl->message_id.reset(); }
boost::uint64_t BasicMessage::Timestamp() const { uint64_t BasicMessage::Timestamp() const {
return m_impl->timestamp.value_or(0); return m_impl->timestamp.value_or(0);
} }
void BasicMessage::Timestamp(boost::uint64_t timestamp) { void BasicMessage::Timestamp(uint64_t timestamp) {
m_impl->timestamp = timestamp; m_impl->timestamp = timestamp;
} }
bool BasicMessage::TimestampIsSet() const { bool BasicMessage::TimestampIsSet() const {
return m_impl->timestamp.is_initialized(); return m_impl->timestamp.has_value();
} }
void BasicMessage::TimestampClear() { m_impl->timestamp.reset(); } void BasicMessage::TimestampClear() { m_impl->timestamp.reset(); }
const std::string& BasicMessage::Type() const { const std::string& BasicMessage::Type() const {
if (TypeIsSet()) { if (TypeIsSet()) {
return m_impl->type.get(); return m_impl->type.value();
} }
static const std::string empty; static const std::string empty;
return empty; return empty;
@@ -231,13 +231,13 @@ const std::string& BasicMessage::Type() const {
void BasicMessage::Type(const std::string& type) { m_impl->type = type; } void BasicMessage::Type(const std::string& type) { m_impl->type = type; }
bool BasicMessage::TypeIsSet() const { return m_impl->type.is_initialized(); } bool BasicMessage::TypeIsSet() const { return m_impl->type.has_value(); }
void BasicMessage::TypeClear() { m_impl->type.reset(); } void BasicMessage::TypeClear() { m_impl->type.reset(); }
const std::string& BasicMessage::UserId() const { const std::string& BasicMessage::UserId() const {
if (UserIdIsSet()) { if (UserIdIsSet()) {
return m_impl->user_id.get(); return m_impl->user_id.value();
} }
static const std::string empty; static const std::string empty;
return empty; return empty;
@@ -248,14 +248,14 @@ void BasicMessage::UserId(const std::string& user_id) {
} }
bool BasicMessage::UserIdIsSet() const { bool BasicMessage::UserIdIsSet() const {
return m_impl->user_id.is_initialized(); return m_impl->user_id.has_value();
} }
void BasicMessage::UserIdClear() { m_impl->user_id.reset(); } void BasicMessage::UserIdClear() { m_impl->user_id.reset(); }
const std::string& BasicMessage::AppId() const { const std::string& BasicMessage::AppId() const {
if (AppIdIsSet()) { if (AppIdIsSet()) {
return m_impl->app_id.get(); return m_impl->app_id.value();
} }
static const std::string empty; static const std::string empty;
return empty; return empty;
@@ -264,14 +264,14 @@ const std::string& BasicMessage::AppId() const {
void BasicMessage::AppId(const std::string& app_id) { m_impl->app_id = app_id; } void BasicMessage::AppId(const std::string& app_id) { m_impl->app_id = app_id; }
bool BasicMessage::AppIdIsSet() const { bool BasicMessage::AppIdIsSet() const {
return m_impl->app_id.is_initialized(); return m_impl->app_id.has_value();
} }
void BasicMessage::AppIdClear() { m_impl->app_id.reset(); } void BasicMessage::AppIdClear() { m_impl->app_id.reset(); }
const std::string& BasicMessage::ClusterId() const { const std::string& BasicMessage::ClusterId() const {
if (ClusterIdIsSet()) { if (ClusterIdIsSet()) {
return m_impl->cluster_id.get(); return m_impl->cluster_id.value();
} }
static const std::string empty; static const std::string empty;
return empty; return empty;
@@ -282,7 +282,7 @@ void BasicMessage::ClusterId(const std::string& cluster_id) {
} }
bool BasicMessage::ClusterIdIsSet() const { bool BasicMessage::ClusterIdIsSet() const {
return m_impl->cluster_id.is_initialized(); return m_impl->cluster_id.has_value();
} }
void BasicMessage::ClusterIdClear() { m_impl->cluster_id.reset(); } void BasicMessage::ClusterIdClear() { m_impl->cluster_id.reset(); }
@@ -291,12 +291,12 @@ Table& BasicMessage::HeaderTable() {
if (!HeaderTableIsSet()) { if (!HeaderTableIsSet()) {
m_impl->header_table = Table(); m_impl->header_table = Table();
} }
return m_impl->header_table.get(); return m_impl->header_table.value();
} }
const Table& BasicMessage::HeaderTable() const { const Table& BasicMessage::HeaderTable() const {
if (HeaderTableIsSet()) { if (HeaderTableIsSet()) {
return m_impl->header_table.get(); return m_impl->header_table.value();
} }
static const Table empty; static const Table empty;
return empty; return empty;
@@ -307,7 +307,7 @@ void BasicMessage::HeaderTable(const Table& header_table) {
} }
bool BasicMessage::HeaderTableIsSet() const { bool BasicMessage::HeaderTableIsSet() const {
return m_impl->header_table.is_initialized(); return m_impl->header_table.has_value();
} }
void BasicMessage::HeaderTableClear() { m_impl->header_table.reset(); } void BasicMessage::HeaderTableClear() { m_impl->header_table.reset(); }

View File

@@ -1,3 +1,4 @@
#include <string_view>
/* /*
* ***** BEGIN LICENSE BLOCK ***** * ***** BEGIN LICENSE BLOCK *****
* Version: MIT * Version: MIT
@@ -36,10 +37,10 @@
#include <string.h> #include <string.h>
#include <boost/array.hpp> #include <array>
#include <boost/chrono.hpp> #include <chrono>
#include <boost/cstdint.hpp> #include <cstdint>
#include <boost/limits.hpp> #include <limits>
#include <map> #include <map>
#include <new> #include <new>
#include <queue> #include <queue>
@@ -142,8 +143,8 @@ Channel::OpenOpts Channel::OpenOpts::FromUri(const std::string &uri) {
amqp_connection_info info; amqp_connection_info info;
amqp_default_connection_info(&info); amqp_default_connection_info(&info);
boost::shared_ptr<char> uri_dup = std::shared_ptr<char> uri_dup =
boost::shared_ptr<char>(strdup(uri.c_str()), free); std::shared_ptr<char>(strdup(uri.c_str()), free);
if (0 != amqp_parse_url(uri_dup.get(), &info)) { if (0 != amqp_parse_url(uri_dup.get(), &info)) {
throw BadUriException(); throw BadUriException();
@@ -193,22 +194,22 @@ Channel::ptr_t Channel::Open(const OpenOpts &opts) {
throw std::runtime_error( throw std::runtime_error(
"opts.port is not valid, it must be a positive number"); "opts.port is not valid, it must be a positive number");
} }
if (opts.auth.empty()) { if (false) {
throw std::runtime_error("opts.auth is not specified, it is required"); throw std::runtime_error("opts.auth is not specified, it is required");
} }
if (!opts.tls_params.is_initialized()) { if (!opts.tls_params.has_value()) {
switch (opts.auth.which()) { switch (opts.auth.index()) {
case 0: { case 0: {
const OpenOpts::BasicAuth &auth = const OpenOpts::BasicAuth &auth =
boost::get<OpenOpts::BasicAuth>(opts.auth); std::get<OpenOpts::BasicAuth>(opts.auth);
return boost::make_shared<Channel>( return std::make_shared<Channel>(
OpenChannel(opts.host, opts.port, auth.username, auth.password, OpenChannel(opts.host, opts.port, auth.username, auth.password,
opts.vhost, opts.frame_max, false)); opts.vhost, opts.frame_max, false));
} }
case 1: { case 1: {
const OpenOpts::ExternalSaslAuth &auth = const OpenOpts::ExternalSaslAuth &auth =
boost::get<OpenOpts::ExternalSaslAuth>(opts.auth); std::get<OpenOpts::ExternalSaslAuth>(opts.auth);
return boost::make_shared<Channel>( return std::make_shared<Channel>(
OpenChannel(opts.host, opts.port, auth.identity, "", opts.vhost, OpenChannel(opts.host, opts.port, auth.identity, "", opts.vhost,
opts.frame_max, true)); opts.frame_max, true));
} }
@@ -216,20 +217,20 @@ Channel::ptr_t Channel::Open(const OpenOpts &opts) {
throw std::logic_error("Unhandled auth type"); throw std::logic_error("Unhandled auth type");
} }
} }
switch (opts.auth.which()) { switch (opts.auth.index()) {
case 0: { case 0: {
const OpenOpts::BasicAuth &auth = const OpenOpts::BasicAuth &auth =
boost::get<OpenOpts::BasicAuth>(opts.auth); std::get<OpenOpts::BasicAuth>(opts.auth);
return boost::make_shared<Channel>(OpenSecureChannel( return std::make_shared<Channel>(OpenSecureChannel(
opts.host, opts.port, auth.username, auth.password, opts.vhost, opts.host, opts.port, auth.username, auth.password, opts.vhost,
opts.frame_max, opts.tls_params.get(), false)); opts.frame_max, opts.tls_params.value(), false));
} }
case 1: { case 1: {
const OpenOpts::ExternalSaslAuth &auth = const OpenOpts::ExternalSaslAuth &auth =
boost::get<OpenOpts::ExternalSaslAuth>(opts.auth); std::get<OpenOpts::ExternalSaslAuth>(opts.auth);
return boost::make_shared<Channel>( return std::make_shared<Channel>(
OpenSecureChannel(opts.host, opts.port, auth.identity, "", opts.vhost, OpenSecureChannel(opts.host, opts.port, auth.identity, "", opts.vhost,
opts.frame_max, opts.tls_params.get(), true)); opts.frame_max, opts.tls_params.value(), true));
} }
default: default:
throw std::logic_error("Unhandled auth type"); throw std::logic_error("Unhandled auth type");
@@ -340,7 +341,7 @@ Channel::ptr_t Channel::CreateSecureSaslExternal(
Channel::ptr_t Channel::CreateFromUri(const std::string &uri, int frame_max) { Channel::ptr_t Channel::CreateFromUri(const std::string &uri, int frame_max) {
OpenOpts opts = OpenOpts::FromUri(uri); OpenOpts opts = OpenOpts::FromUri(uri);
if (opts.tls_params.is_initialized()) { if (opts.tls_params.has_value()) {
throw std::runtime_error( throw std::runtime_error(
"CreateFromUri only supports non-SSL-enabled URIs"); "CreateFromUri only supports non-SSL-enabled URIs");
} }
@@ -354,7 +355,7 @@ Channel::ptr_t Channel::CreateSecureFromUri(
const std::string &path_to_client_cert, bool verify_hostname_and_peer, const std::string &path_to_client_cert, bool verify_hostname_and_peer,
int frame_max) { int frame_max) {
OpenOpts opts = OpenOpts::FromUri(uri); OpenOpts opts = OpenOpts::FromUri(uri);
if (!opts.tls_params.is_initialized()) { if (!opts.tls_params.has_value()) {
throw std::runtime_error( throw std::runtime_error(
"CreateSecureFromUri only supports SSL-enabled URIs"); "CreateSecureFromUri only supports SSL-enabled URIs");
} }
@@ -477,8 +478,8 @@ int Channel::GetSocketFD() const {
return amqp_get_sockfd(m_impl->m_connection); return amqp_get_sockfd(m_impl->m_connection);
} }
bool Channel::CheckExchangeExists(boost::string_ref exchange_name) { bool Channel::CheckExchangeExists(std::string_view exchange_name) {
const boost::array<boost::uint32_t, 1> DECLARE_OK = { const std::array<uint32_t, 1> DECLARE_OK = {
{AMQP_EXCHANGE_DECLARE_OK_METHOD}}; {AMQP_EXCHANGE_DECLARE_OK_METHOD}};
amqp_exchange_declare_t declare = {}; amqp_exchange_declare_t declare = {};
@@ -507,7 +508,7 @@ void Channel::DeclareExchange(const std::string &exchange_name,
const std::string &exchange_type, bool passive, const std::string &exchange_type, bool passive,
bool durable, bool auto_delete, bool durable, bool auto_delete,
const Table &arguments) { const Table &arguments) {
const boost::array<boost::uint32_t, 1> DECLARE_OK = { const std::array<uint32_t, 1> DECLARE_OK = {
{AMQP_EXCHANGE_DECLARE_OK_METHOD}}; {AMQP_EXCHANGE_DECLARE_OK_METHOD}};
m_impl->CheckIsConnected(); m_impl->CheckIsConnected();
@@ -530,7 +531,7 @@ void Channel::DeclareExchange(const std::string &exchange_name,
} }
void Channel::DeleteExchange(const std::string &exchange_name, bool if_unused) { void Channel::DeleteExchange(const std::string &exchange_name, bool if_unused) {
const boost::array<boost::uint32_t, 1> DELETE_OK = { const std::array<uint32_t, 1> DELETE_OK = {
{AMQP_EXCHANGE_DELETE_OK_METHOD}}; {AMQP_EXCHANGE_DELETE_OK_METHOD}};
m_impl->CheckIsConnected(); m_impl->CheckIsConnected();
@@ -554,7 +555,7 @@ void Channel::BindExchange(const std::string &destination,
const std::string &source, const std::string &source,
const std::string &routing_key, const std::string &routing_key,
const Table &arguments) { const Table &arguments) {
const boost::array<boost::uint32_t, 1> BIND_OK = { const std::array<uint32_t, 1> BIND_OK = {
{AMQP_EXCHANGE_BIND_OK_METHOD}}; {AMQP_EXCHANGE_BIND_OK_METHOD}};
m_impl->CheckIsConnected(); m_impl->CheckIsConnected();
@@ -582,7 +583,7 @@ void Channel::UnbindExchange(const std::string &destination,
const std::string &source, const std::string &source,
const std::string &routing_key, const std::string &routing_key,
const Table &arguments) { const Table &arguments) {
const boost::array<boost::uint32_t, 1> UNBIND_OK = { const std::array<uint32_t, 1> UNBIND_OK = {
{AMQP_EXCHANGE_UNBIND_OK_METHOD}}; {AMQP_EXCHANGE_UNBIND_OK_METHOD}};
m_impl->CheckIsConnected(); m_impl->CheckIsConnected();
@@ -601,8 +602,8 @@ void Channel::UnbindExchange(const std::string &destination,
m_impl->MaybeReleaseBuffersOnChannel(frame.channel); m_impl->MaybeReleaseBuffersOnChannel(frame.channel);
} }
bool Channel::CheckQueueExists(boost::string_ref queue_name) { bool Channel::CheckQueueExists(std::string_view queue_name) {
const boost::array<boost::uint32_t, 1> DECLARE_OK = { const std::array<uint32_t, 1> DECLARE_OK = {
{AMQP_QUEUE_DECLARE_OK_METHOD}}; {AMQP_QUEUE_DECLARE_OK_METHOD}};
amqp_queue_declare_t declare = {}; amqp_queue_declare_t declare = {};
@@ -630,16 +631,16 @@ std::string Channel::DeclareQueue(const std::string &queue_name, bool passive,
std::string Channel::DeclareQueue(const std::string &queue_name, bool passive, std::string Channel::DeclareQueue(const std::string &queue_name, bool passive,
bool durable, bool exclusive, bool durable, bool exclusive,
bool auto_delete, const Table &arguments) { bool auto_delete, const Table &arguments) {
boost::uint32_t message_count; uint32_t message_count;
boost::uint32_t consumer_count; uint32_t consumer_count;
return DeclareQueueWithCounts(queue_name, message_count, consumer_count, return DeclareQueueWithCounts(queue_name, message_count, consumer_count,
passive, durable, exclusive, auto_delete, passive, durable, exclusive, auto_delete,
arguments); arguments);
} }
std::string Channel::DeclareQueueWithCounts(const std::string &queue_name, std::string Channel::DeclareQueueWithCounts(const std::string &queue_name,
boost::uint32_t &message_count, uint32_t &message_count,
boost::uint32_t &consumer_count, uint32_t &consumer_count,
bool passive, bool durable, bool passive, bool durable,
bool exclusive, bool auto_delete) { bool exclusive, bool auto_delete) {
return DeclareQueueWithCounts(queue_name, message_count, consumer_count, return DeclareQueueWithCounts(queue_name, message_count, consumer_count,
@@ -648,12 +649,12 @@ std::string Channel::DeclareQueueWithCounts(const std::string &queue_name,
} }
std::string Channel::DeclareQueueWithCounts(const std::string &queue_name, std::string Channel::DeclareQueueWithCounts(const std::string &queue_name,
boost::uint32_t &message_count, uint32_t &message_count,
boost::uint32_t &consumer_count, uint32_t &consumer_count,
bool passive, bool durable, bool passive, bool durable,
bool exclusive, bool auto_delete, bool exclusive, bool auto_delete,
const Table &arguments) { const Table &arguments) {
const boost::array<boost::uint32_t, 1> DECLARE_OK = { const std::array<uint32_t, 1> DECLARE_OK = {
{AMQP_QUEUE_DECLARE_OK_METHOD}}; {AMQP_QUEUE_DECLARE_OK_METHOD}};
m_impl->CheckIsConnected(); m_impl->CheckIsConnected();
@@ -686,7 +687,7 @@ std::string Channel::DeclareQueueWithCounts(const std::string &queue_name,
void Channel::DeleteQueue(const std::string &queue_name, bool if_unused, void Channel::DeleteQueue(const std::string &queue_name, bool if_unused,
bool if_empty) { bool if_empty) {
const boost::array<boost::uint32_t, 1> DELETE_OK = { const std::array<uint32_t, 1> DELETE_OK = {
{AMQP_QUEUE_DELETE_OK_METHOD}}; {AMQP_QUEUE_DELETE_OK_METHOD}};
m_impl->CheckIsConnected(); m_impl->CheckIsConnected();
@@ -710,7 +711,7 @@ void Channel::BindQueue(const std::string &queue_name,
const std::string &exchange_name, const std::string &exchange_name,
const std::string &routing_key, const std::string &routing_key,
const Table &arguments) { const Table &arguments) {
const boost::array<boost::uint32_t, 1> BIND_OK = { const std::array<uint32_t, 1> BIND_OK = {
{AMQP_QUEUE_BIND_OK_METHOD}}; {AMQP_QUEUE_BIND_OK_METHOD}};
m_impl->CheckIsConnected(); m_impl->CheckIsConnected();
@@ -738,7 +739,7 @@ void Channel::UnbindQueue(const std::string &queue_name,
const std::string &exchange_name, const std::string &exchange_name,
const std::string &routing_key, const std::string &routing_key,
const Table &arguments) { const Table &arguments) {
const boost::array<boost::uint32_t, 1> UNBIND_OK = { const std::array<uint32_t, 1> UNBIND_OK = {
{AMQP_QUEUE_UNBIND_OK_METHOD}}; {AMQP_QUEUE_UNBIND_OK_METHOD}};
m_impl->CheckIsConnected(); m_impl->CheckIsConnected();
@@ -757,7 +758,7 @@ void Channel::UnbindQueue(const std::string &queue_name,
} }
void Channel::PurgeQueue(const std::string &queue_name) { void Channel::PurgeQueue(const std::string &queue_name) {
const boost::array<boost::uint32_t, 1> PURGE_OK = { const std::array<uint32_t, 1> PURGE_OK = {
{AMQP_QUEUE_PURGE_OK_METHOD}}; {AMQP_QUEUE_PURGE_OK_METHOD}};
m_impl->CheckIsConnected(); m_impl->CheckIsConnected();
@@ -845,11 +846,11 @@ void Channel::BasicPublish(const std::string &exchange_name,
// - channel.close - probably tried to publish to a non-existant exchange, in // - channel.close - probably tried to publish to a non-existant exchange, in
// any case error! // any case error!
// - connection.clsoe - something really bad happened // - connection.clsoe - something really bad happened
const boost::array<boost::uint32_t, 3> PUBLISH_ACK = { const std::array<uint32_t, 3> PUBLISH_ACK = {
{AMQP_BASIC_ACK_METHOD, AMQP_BASIC_RETURN_METHOD, {AMQP_BASIC_ACK_METHOD, AMQP_BASIC_RETURN_METHOD,
AMQP_BASIC_NACK_METHOD}}; AMQP_BASIC_NACK_METHOD}};
amqp_frame_t response; amqp_frame_t response;
boost::array<amqp_channel_t, 1> channels = {{channel}}; std::array<amqp_channel_t, 1> channels = {{channel}};
m_impl->GetMethodOnChannel(channels, response, PUBLISH_ACK); m_impl->GetMethodOnChannel(channels, response, PUBLISH_ACK);
if (AMQP_BASIC_NACK_METHOD == response.payload.method.id) { if (AMQP_BASIC_NACK_METHOD == response.payload.method.id) {
@@ -868,7 +869,7 @@ void Channel::BasicPublish(const std::string &exchange_name,
response.payload.method.decoded)), response.payload.method.decoded)),
channel); channel);
const boost::array<boost::uint32_t, 1> BASIC_ACK = { const std::array<uint32_t, 1> BASIC_ACK = {
{AMQP_BASIC_ACK_METHOD}}; {AMQP_BASIC_ACK_METHOD}};
m_impl->GetMethodOnChannel(channels, response, BASIC_ACK); m_impl->GetMethodOnChannel(channels, response, BASIC_ACK);
m_impl->ReturnChannel(channel); m_impl->ReturnChannel(channel);
@@ -882,7 +883,7 @@ void Channel::BasicPublish(const std::string &exchange_name,
bool Channel::BasicGet(Envelope::ptr_t &envelope, const std::string &queue, bool Channel::BasicGet(Envelope::ptr_t &envelope, const std::string &queue,
bool no_ack) { bool no_ack) {
const boost::array<boost::uint32_t, 2> GET_RESPONSES = { const std::array<uint32_t, 2> GET_RESPONSES = {
{AMQP_BASIC_GET_OK_METHOD, AMQP_BASIC_GET_EMPTY_METHOD}}; {AMQP_BASIC_GET_OK_METHOD, AMQP_BASIC_GET_EMPTY_METHOD}};
m_impl->CheckIsConnected(); m_impl->CheckIsConnected();
@@ -902,7 +903,7 @@ bool Channel::BasicGet(Envelope::ptr_t &envelope, const std::string &queue,
amqp_basic_get_ok_t *get_ok = amqp_basic_get_ok_t *get_ok =
(amqp_basic_get_ok_t *)response.payload.method.decoded; (amqp_basic_get_ok_t *)response.payload.method.decoded;
boost::uint64_t delivery_tag = get_ok->delivery_tag; uint64_t delivery_tag = get_ok->delivery_tag;
bool redelivered = (get_ok->redelivered == 0 ? false : true); bool redelivered = (get_ok->redelivered == 0 ? false : true);
std::string exchange((char *)get_ok->exchange.bytes, get_ok->exchange.len); std::string exchange((char *)get_ok->exchange.bytes, get_ok->exchange.len);
std::string routing_key((char *)get_ok->routing_key.bytes, std::string routing_key((char *)get_ok->routing_key.bytes,
@@ -918,7 +919,7 @@ bool Channel::BasicGet(Envelope::ptr_t &envelope, const std::string &queue,
} }
void Channel::BasicRecover(const std::string &consumer) { void Channel::BasicRecover(const std::string &consumer) {
const boost::array<boost::uint32_t, 1> RECOVER_OK = { const std::array<uint32_t, 1> RECOVER_OK = {
{AMQP_BASIC_RECOVER_OK_METHOD}}; {AMQP_BASIC_RECOVER_OK_METHOD}};
m_impl->CheckIsConnected(); m_impl->CheckIsConnected();
@@ -935,21 +936,21 @@ void Channel::BasicRecover(const std::string &consumer) {
std::string Channel::BasicConsume(const std::string &queue, std::string Channel::BasicConsume(const std::string &queue,
const std::string &consumer_tag, const std::string &consumer_tag,
bool no_local, bool no_ack, bool exclusive, bool no_local, bool no_ack, bool exclusive,
boost::uint16_t message_prefetch_count) { uint16_t message_prefetch_count) {
return BasicConsume(queue, consumer_tag, no_local, no_ack, exclusive, return BasicConsume(queue, consumer_tag, no_local, no_ack, exclusive,
message_prefetch_count, Table()); message_prefetch_count, Table());
} }
std::string Channel::BasicConsume(const std::string &queue, std::string Channel::BasicConsume(const std::string &queue,
const std::string &consumer_tag, const std::string &consumer_tag,
bool no_local, bool no_ack, bool exclusive, bool no_local, bool no_ack, bool exclusive,
boost::uint16_t message_prefetch_count, uint16_t message_prefetch_count,
const Table &arguments) { const Table &arguments) {
m_impl->CheckIsConnected(); m_impl->CheckIsConnected();
amqp_channel_t channel = m_impl->GetChannel(); amqp_channel_t channel = m_impl->GetChannel();
// Set this before starting the consume as it may have been set by a previous // Set this before starting the consume as it may have been set by a previous
// consumer // consumer
const boost::array<boost::uint32_t, 1> QOS_OK = {{AMQP_BASIC_QOS_OK_METHOD}}; const std::array<uint32_t, 1> QOS_OK = {{AMQP_BASIC_QOS_OK_METHOD}};
amqp_basic_qos_t qos = {}; amqp_basic_qos_t qos = {};
qos.prefetch_size = 0; qos.prefetch_size = 0;
@@ -959,7 +960,7 @@ std::string Channel::BasicConsume(const std::string &queue,
m_impl->DoRpcOnChannel(channel, AMQP_BASIC_QOS_METHOD, &qos, QOS_OK); m_impl->DoRpcOnChannel(channel, AMQP_BASIC_QOS_METHOD, &qos, QOS_OK);
m_impl->MaybeReleaseBuffersOnChannel(channel); m_impl->MaybeReleaseBuffersOnChannel(channel);
const boost::array<boost::uint32_t, 1> CONSUME_OK = { const std::array<uint32_t, 1> CONSUME_OK = {
{AMQP_BASIC_CONSUME_OK_METHOD}}; {AMQP_BASIC_CONSUME_OK_METHOD}};
amqp_basic_consume_t consume = {}; amqp_basic_consume_t consume = {};
@@ -989,11 +990,11 @@ std::string Channel::BasicConsume(const std::string &queue,
} }
void Channel::BasicQos(const std::string &consumer_tag, void Channel::BasicQos(const std::string &consumer_tag,
boost::uint16_t message_prefetch_count) { uint16_t message_prefetch_count) {
m_impl->CheckIsConnected(); m_impl->CheckIsConnected();
amqp_channel_t channel = m_impl->GetConsumerChannel(consumer_tag); amqp_channel_t channel = m_impl->GetConsumerChannel(consumer_tag);
const boost::array<boost::uint32_t, 1> QOS_OK = {{AMQP_BASIC_QOS_OK_METHOD}}; const std::array<uint32_t, 1> QOS_OK = {{AMQP_BASIC_QOS_OK_METHOD}};
amqp_basic_qos_t qos = {}; amqp_basic_qos_t qos = {};
qos.prefetch_size = 0; qos.prefetch_size = 0;
@@ -1008,7 +1009,7 @@ void Channel::BasicCancel(const std::string &consumer_tag) {
m_impl->CheckIsConnected(); m_impl->CheckIsConnected();
amqp_channel_t channel = m_impl->GetConsumerChannel(consumer_tag); amqp_channel_t channel = m_impl->GetConsumerChannel(consumer_tag);
const boost::array<boost::uint32_t, 1> CANCEL_OK = { const std::array<uint32_t, 1> CANCEL_OK = {
{AMQP_BASIC_CANCEL_OK_METHOD}}; {AMQP_BASIC_CANCEL_OK_METHOD}};
amqp_basic_cancel_t cancel = {}; amqp_basic_cancel_t cancel = {};
@@ -1051,7 +1052,7 @@ bool Channel::BasicConsumeMessage(const std::string &consumer_tag,
m_impl->CheckIsConnected(); m_impl->CheckIsConnected();
amqp_channel_t channel = m_impl->GetConsumerChannel(consumer_tag); amqp_channel_t channel = m_impl->GetConsumerChannel(consumer_tag);
boost::array<amqp_channel_t, 1> channels = {{channel}}; std::array<amqp_channel_t, 1> channels = {{channel}};
return m_impl->ConsumeMessageOnChannel(channels, message, timeout); return m_impl->ConsumeMessageOnChannel(channels, message, timeout);
} }

View File

@@ -1,3 +1,6 @@
#include <sstream>
#include <algorithm>
#include <cassert>
/* /*
* ***** BEGIN LICENSE BLOCK ***** * ***** BEGIN LICENSE BLOCK *****
* Version: MIT * Version: MIT
@@ -37,9 +40,9 @@
#include <sys/types.h> #include <sys/types.h>
#endif #endif
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/array.hpp> #include <array>
#include "SimpleAmqpClient/AmqpException.h" #include "SimpleAmqpClient/AmqpException.h"
#include "SimpleAmqpClient/AmqpLibraryException.h" #include "SimpleAmqpClient/AmqpLibraryException.h"
@@ -51,8 +54,9 @@
#define BOOST_BIND_GLOBAL_PLACEHOLDERS #define BOOST_BIND_GLOBAL_PLACEHOLDERS
#include <string.h> #include <string.h>
#include <boost/bind.hpp> #include <functional>
#include <boost/lexical_cast.hpp> #include <string>
#include <stdexcept>
#define BROKER_HEARTBEAT 0 #define BROKER_HEARTBEAT 0
@@ -179,16 +183,16 @@ amqp_channel_t Channel::ChannelImpl::GetNextChannelId() {
amqp_channel_t Channel::ChannelImpl::CreateNewChannel() { amqp_channel_t Channel::ChannelImpl::CreateNewChannel() {
amqp_channel_t new_channel = GetNextChannelId(); amqp_channel_t new_channel = GetNextChannelId();
static const boost::array<boost::uint32_t, 1> OPEN_OK = { static const std::array<uint32_t, 1> OPEN_OK = {
{AMQP_CHANNEL_OPEN_OK_METHOD}}; {AMQP_CHANNEL_OPEN_OK_METHOD}};
amqp_channel_open_t channel_open = {}; amqp_channel_open_t channel_open = {};
DoRpcOnChannel<boost::array<boost::uint32_t, 1> >( DoRpcOnChannel<std::array<uint32_t, 1> >(
new_channel, AMQP_CHANNEL_OPEN_METHOD, &channel_open, OPEN_OK); new_channel, AMQP_CHANNEL_OPEN_METHOD, &channel_open, OPEN_OK);
static const boost::array<boost::uint32_t, 1> CONFIRM_OK = { static const std::array<uint32_t, 1> CONFIRM_OK = {
{AMQP_CONFIRM_SELECT_OK_METHOD}}; {AMQP_CONFIRM_SELECT_OK_METHOD}};
amqp_confirm_select_t confirm_select = {}; amqp_confirm_select_t confirm_select = {};
DoRpcOnChannel<boost::array<boost::uint32_t, 1> >( DoRpcOnChannel<std::array<uint32_t, 1> >(
new_channel, AMQP_CONFIRM_SELECT_METHOD, &confirm_select, CONFIRM_OK); new_channel, AMQP_CONFIRM_SELECT_METHOD, &confirm_select, CONFIRM_OK);
m_channels.at(new_channel) = CS_Open; m_channels.at(new_channel) = CS_Open;
@@ -397,7 +401,7 @@ bool Channel::ChannelImpl::CheckForQueuedMessageOnChannel(
amqp_channel_t channel) const { amqp_channel_t channel) const {
frame_queue_t::const_iterator it = frame_queue_t::const_iterator it =
std::find_if(m_frame_queue.begin(), m_frame_queue.end(), std::find_if(m_frame_queue.begin(), m_frame_queue.end(),
boost::bind(&Channel::ChannelImpl::is_method_on_channel, _1, std::bind(&Channel::ChannelImpl::is_method_on_channel, std::placeholders::_1,
AMQP_BASIC_DELIVER_METHOD, channel)); AMQP_BASIC_DELIVER_METHOD, channel));
if (it == m_frame_queue.end()) { if (it == m_frame_queue.end()) {
@@ -406,7 +410,7 @@ bool Channel::ChannelImpl::CheckForQueuedMessageOnChannel(
it = std::find_if( it = std::find_if(
it + 1, m_frame_queue.end(), it + 1, m_frame_queue.end(),
boost::bind(&Channel::ChannelImpl::is_on_channel, _1, channel)); std::bind(&Channel::ChannelImpl::is_on_channel, std::placeholders::_1, channel));
if (it == m_frame_queue.end()) { if (it == m_frame_queue.end()) {
return false; return false;
@@ -421,7 +425,7 @@ bool Channel::ChannelImpl::CheckForQueuedMessageOnChannel(
while (body_received < body_length) { while (body_received < body_length) {
it = std::find_if( it = std::find_if(
it + 1, m_frame_queue.end(), it + 1, m_frame_queue.end(),
boost::bind(&Channel::ChannelImpl::is_on_channel, _1, channel)); std::bind(&Channel::ChannelImpl::is_on_channel, std::placeholders::_1, channel));
if (it == m_frame_queue.end()) { if (it == m_frame_queue.end()) {
return false; return false;
@@ -439,7 +443,7 @@ void Channel::ChannelImpl::AddToFrameQueue(const amqp_frame_t &frame) {
m_frame_queue.push_back(frame); m_frame_queue.push_back(frame);
if (CheckForQueuedMessageOnChannel(frame.channel)) { if (CheckForQueuedMessageOnChannel(frame.channel)) {
boost::array<amqp_channel_t, 1> channel = {{frame.channel}}; std::array<amqp_channel_t, 1> channel = {{frame.channel}};
Envelope::ptr_t envelope; Envelope::ptr_t envelope;
if (!ConsumeMessageOnChannelInner(channel, envelope, -1)) { if (!ConsumeMessageOnChannelInner(channel, envelope, -1)) {
throw std::logic_error( throw std::logic_error(
@@ -451,25 +455,25 @@ void Channel::ChannelImpl::AddToFrameQueue(const amqp_frame_t &frame) {
} }
bool Channel::ChannelImpl::GetNextFrameFromBroker( bool Channel::ChannelImpl::GetNextFrameFromBroker(
amqp_frame_t &frame, boost::chrono::microseconds timeout) { amqp_frame_t &frame, std::chrono::microseconds timeout) {
struct timeval *tvp = NULL; struct timeval *tvp = NULL;
struct timeval tv_timeout; struct timeval tv_timeout;
memset(&tv_timeout, 0, sizeof(tv_timeout)); memset(&tv_timeout, 0, sizeof(tv_timeout));
if (timeout != boost::chrono::microseconds::max()) { if (timeout != std::chrono::microseconds::max()) {
// boost::chrono::seconds.count() returns boost::int_atleast64_t, // std::chrono::seconds.count() returns std::int_atleast64_t,
// long can be 32 or 64 bit depending on the platform/arch // long can be 32 or 64 bit depending on the platform/arch
// unless the timeout is something absurd cast to long will be ok, but // unless the timeout is something absurd cast to long will be ok, but
// lets guard against the case where someone does something silly // lets guard against the case where someone does something silly
assert( assert(
boost::chrono::duration_cast<boost::chrono::seconds>(timeout).count() < std::chrono::duration_cast<std::chrono::seconds>(timeout).count() <
static_cast<boost::chrono::seconds::rep>( static_cast<std::chrono::seconds::rep>(
std::numeric_limits<long>::max())); std::numeric_limits<long>::max()));
tv_timeout.tv_sec = static_cast<long>( tv_timeout.tv_sec = static_cast<long>(
boost::chrono::duration_cast<boost::chrono::seconds>(timeout).count()); std::chrono::duration_cast<std::chrono::seconds>(timeout).count());
tv_timeout.tv_usec = static_cast<long>( tv_timeout.tv_usec = static_cast<long>(
(timeout - boost::chrono::seconds(tv_timeout.tv_sec)).count()); (timeout - std::chrono::seconds(tv_timeout.tv_sec)).count());
tvp = &tv_timeout; tvp = &tv_timeout;
} }
@@ -485,10 +489,10 @@ bool Channel::ChannelImpl::GetNextFrameFromBroker(
bool Channel::ChannelImpl::GetNextFrameOnChannel( bool Channel::ChannelImpl::GetNextFrameOnChannel(
amqp_channel_t channel, amqp_frame_t &frame, amqp_channel_t channel, amqp_frame_t &frame,
boost::chrono::microseconds timeout) { std::chrono::microseconds timeout) {
frame_queue_t::iterator it = std::find_if( frame_queue_t::iterator it = std::find_if(
m_frame_queue.begin(), m_frame_queue.end(), m_frame_queue.begin(), m_frame_queue.end(),
boost::bind(&Channel::ChannelImpl::is_on_channel, _1, channel)); std::bind(&Channel::ChannelImpl::is_on_channel, std::placeholders::_1, channel));
if (m_frame_queue.end() != it) { if (m_frame_queue.end() != it) {
frame = *it; frame = *it;
@@ -503,7 +507,7 @@ bool Channel::ChannelImpl::GetNextFrameOnChannel(
return true; return true;
} }
boost::array<amqp_channel_t, 1> channels = {{channel}}; std::array<amqp_channel_t, 1> channels = {{channel}};
return GetNextFrameFromBrokerOnChannel(channels, frame, timeout); return GetNextFrameFromBrokerOnChannel(channels, frame, timeout);
} }
@@ -512,7 +516,7 @@ void Channel::ChannelImpl::MaybeReleaseBuffersOnChannel(
if (m_frame_queue.end() == if (m_frame_queue.end() ==
std::find_if( std::find_if(
m_frame_queue.begin(), m_frame_queue.end(), m_frame_queue.begin(), m_frame_queue.end(),
boost::bind(&Channel::ChannelImpl::is_on_channel, _1, channel))) { std::bind(&Channel::ChannelImpl::is_on_channel, std::placeholders::_1, channel))) {
amqp_maybe_release_buffers_on_channel(m_connection, channel); amqp_maybe_release_buffers_on_channel(m_connection, channel);
} }
} }
@@ -534,7 +538,7 @@ bool bytesEqual(amqp_bytes_t r, amqp_bytes_t l) {
} }
} // namespace } // namespace
boost::uint32_t Channel::ChannelImpl::ComputeBrokerVersion( uint32_t Channel::ChannelImpl::ComputeBrokerVersion(
amqp_connection_state_t state) { amqp_connection_state_t state) {
const amqp_table_t *properties = amqp_get_server_properties(state); const amqp_table_t *properties = amqp_get_server_properties(state);
const amqp_bytes_t version = amqp_cstring_bytes("version"); const amqp_bytes_t version = amqp_cstring_bytes("version");
@@ -554,16 +558,20 @@ boost::uint32_t Channel::ChannelImpl::ComputeBrokerVersion(
static_cast<char *>(version_entry->value.value.bytes.bytes), static_cast<char *>(version_entry->value.value.bytes.bytes),
version_entry->value.value.bytes.len); version_entry->value.value.bytes.len);
std::vector<std::string> version_components; std::vector<std::string> version_components;
boost::split(version_components, version_string, boost::is_any_of(".")); std::istringstream iss(version_string);
std::string token;
while (std::getline(iss, token, '.')) {
version_components.push_back(token);
}
if (version_components.size() != 3) { if (version_components.size() != 3) {
return 0; return 0;
} }
boost::uint32_t version_major = uint32_t version_major =
boost::lexical_cast<boost::uint32_t>(version_components[0]); std::stoull(version_components[0]);
boost::uint32_t version_minor = uint32_t version_minor =
boost::lexical_cast<boost::uint32_t>(version_components[1]); std::stoull(version_components[1]);
boost::uint32_t version_patch = uint32_t version_patch =
boost::lexical_cast<boost::uint32_t>(version_components[2]); std::stoull(version_components[2]);
return (version_major & 0xFF) << 16 | (version_minor & 0xFF) << 8 | return (version_major & 0xFF) << 16 | (version_minor & 0xFF) << 8 |
(version_patch & 0xFF); (version_patch & 0xFF);
} }

View File

@@ -32,10 +32,10 @@ namespace AmqpClient {
Envelope::Envelope(const BasicMessage::ptr_t message, Envelope::Envelope(const BasicMessage::ptr_t message,
const std::string &consumer_tag, const std::string &consumer_tag,
const boost::uint64_t delivery_tag, const uint64_t delivery_tag,
const std::string &exchange, bool redelivered, const std::string &exchange, bool redelivered,
const std::string &routing_key, const std::string &routing_key,
const boost::uint16_t delivery_channel) const uint16_t delivery_channel)
: m_message(message), : m_message(message),
m_consumerTag(consumer_tag), m_consumerTag(consumer_tag),
m_deliveryTag(delivery_tag), m_deliveryTag(delivery_tag),

View File

@@ -28,16 +28,17 @@
#include "SimpleAmqpClient/MessageReturnedException.h" #include "SimpleAmqpClient/MessageReturnedException.h"
#include <boost/lexical_cast.hpp> #include <string>
#include <stdexcept>
namespace AmqpClient { namespace AmqpClient {
MessageReturnedException::MessageReturnedException( MessageReturnedException::MessageReturnedException(
BasicMessage::ptr_t message, boost::uint32_t reply_code, BasicMessage::ptr_t message, uint32_t reply_code,
const std::string &reply_text, const std::string &exchange, const std::string &reply_text, const std::string &exchange,
const std::string &routing_key) throw() const std::string &routing_key) throw()
: std::runtime_error( : std::runtime_error(
std::string("Message returned. Reply code: ") std::string("Message returned. Reply code: ")
.append(boost::lexical_cast<std::string>(reply_code)) .append(std::to_string(reply_code))
.append(" ") .append(" ")
.append(reply_text)), .append(reply_text)),
m_message(message), m_message(message),

View File

@@ -28,7 +28,7 @@
* ***** END LICENSE BLOCK ***** * ***** END LICENSE BLOCK *****
*/ */
#include <boost/cstdint.hpp> #include <cstdint>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
@@ -84,8 +84,8 @@ class SIMPLEAMQPCLIENT_EXPORT AmqpException : public std::runtime_error {
* @param [in] method_id the method id of the method that caused the error * @param [in] method_id the method id of the method that caused the error
*/ */
explicit AmqpException(const std::string &what, const std::string &reply_text, explicit AmqpException(const std::string &what, const std::string &reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw(); uint16_t method_id) throw();
/** /**
* Destructor * Destructor
@@ -109,21 +109,21 @@ class SIMPLEAMQPCLIENT_EXPORT AmqpException : public std::runtime_error {
* *
* @returns the error code * @returns the error code
*/ */
virtual boost::uint16_t reply_code() const throw() = 0; virtual uint16_t reply_code() const throw() = 0;
/** /**
* Get the class id of the method that caused the error * Get the class id of the method that caused the error
* *
* @returns the class id * @returns the class id
*/ */
virtual boost::uint16_t class_id() const throw() { return m_class_id; } virtual uint16_t class_id() const throw() { return m_class_id; }
/** /**
* Get the method id of the method that caused the error * Get the method id of the method that caused the error
* *
* @returns the method id * @returns the method id
*/ */
virtual boost::uint16_t method_id() const throw() { return m_method_id; } virtual uint16_t method_id() const throw() { return m_method_id; }
/** /**
* Get the error string returned from the broker * Get the error string returned from the broker
@@ -135,8 +135,8 @@ class SIMPLEAMQPCLIENT_EXPORT AmqpException : public std::runtime_error {
protected: protected:
/** @cond INTERNAL */ /** @cond INTERNAL */
std::string m_reply_text; std::string m_reply_text;
boost::uint16_t m_class_id; uint16_t m_class_id;
boost::uint16_t m_method_id; uint16_t m_method_id;
/** @endcond */ /** @endcond */
}; };
@@ -159,8 +159,8 @@ class SIMPLEAMQPCLIENT_EXPORT ConnectionException : public AmqpException {
*/ */
explicit ConnectionException(const std::string &what, explicit ConnectionException(const std::string &what,
const std::string &reply_text, const std::string &reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: AmqpException(what, reply_text, class_id, method_id) {} : AmqpException(what, reply_text, class_id, method_id) {}
virtual bool is_soft_error() const throw() { return false; } virtual bool is_soft_error() const throw() { return false; }
@@ -184,8 +184,8 @@ class SIMPLEAMQPCLIENT_EXPORT ChannelException : public AmqpException {
*/ */
explicit ChannelException(const std::string &what, explicit ChannelException(const std::string &what,
const std::string &reply_text, const std::string &reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: AmqpException(what, reply_text, class_id, method_id) {} : AmqpException(what, reply_text, class_id, method_id) {}
virtual bool is_soft_error() const throw() { return true; } virtual bool is_soft_error() const throw() { return true; }
@@ -198,18 +198,18 @@ class SIMPLEAMQPCLIENT_EXPORT ConnectionForcedException
: public ConnectionException { : public ConnectionException {
public: public:
/** reply code */ /** reply code */
static const boost::uint16_t REPLY_CODE; static const uint16_t REPLY_CODE;
/** /**
* Constructor * Constructor
*/ */
explicit ConnectionForcedException(const std::string &what, explicit ConnectionForcedException(const std::string &what,
const std::string &reply_text, const std::string &reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: ConnectionException(what, reply_text, class_id, method_id) {} : ConnectionException(what, reply_text, class_id, method_id) {}
virtual boost::uint16_t reply_code() const throw() { return REPLY_CODE; } virtual uint16_t reply_code() const throw() { return REPLY_CODE; }
}; };
/** /**
@@ -219,18 +219,18 @@ class SIMPLEAMQPCLIENT_EXPORT InvalidPathException
: public ConnectionException { : public ConnectionException {
public: public:
/** reply code */ /** reply code */
static const boost::uint16_t REPLY_CODE; static const uint16_t REPLY_CODE;
/** /**
* Constructor * Constructor
*/ */
explicit InvalidPathException(const std::string &what, explicit InvalidPathException(const std::string &what,
const std::string &reply_text, const std::string &reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: ConnectionException(what, reply_text, class_id, method_id) {} : ConnectionException(what, reply_text, class_id, method_id) {}
virtual boost::uint16_t reply_code() const throw() { return REPLY_CODE; } virtual uint16_t reply_code() const throw() { return REPLY_CODE; }
}; };
/** /**
@@ -241,18 +241,18 @@ class SIMPLEAMQPCLIENT_EXPORT InvalidPathException
class SIMPLEAMQPCLIENT_EXPORT FrameErrorException : public ConnectionException { class SIMPLEAMQPCLIENT_EXPORT FrameErrorException : public ConnectionException {
public: public:
/** reply code */ /** reply code */
static const boost::uint16_t REPLY_CODE; static const uint16_t REPLY_CODE;
/** /**
* Constructor * Constructor
*/ */
explicit FrameErrorException(const std::string &what, explicit FrameErrorException(const std::string &what,
const std::string &reply_text, const std::string &reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: ConnectionException(what, reply_text, class_id, method_id) {} : ConnectionException(what, reply_text, class_id, method_id) {}
virtual boost::uint16_t reply_code() const throw() { return REPLY_CODE; } virtual uint16_t reply_code() const throw() { return REPLY_CODE; }
}; };
/** /**
@@ -264,17 +264,17 @@ class SIMPLEAMQPCLIENT_EXPORT SyntaxErrorException
: public ConnectionException { : public ConnectionException {
public: public:
/** reply code */ /** reply code */
static const boost::uint16_t REPLY_CODE; static const uint16_t REPLY_CODE;
/** /**
* Constructor * Constructor
*/ */
explicit SyntaxErrorException(const std::string &what, explicit SyntaxErrorException(const std::string &what,
const std::string &reply_text, const std::string &reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: ConnectionException(what, reply_text, class_id, method_id) {} : ConnectionException(what, reply_text, class_id, method_id) {}
virtual boost::uint16_t reply_code() const throw() { return REPLY_CODE; } virtual uint16_t reply_code() const throw() { return REPLY_CODE; }
}; };
/** /**
@@ -286,18 +286,18 @@ class SIMPLEAMQPCLIENT_EXPORT CommandInvalidException
: public ConnectionException { : public ConnectionException {
public: public:
/** reply code */ /** reply code */
static const boost::uint16_t REPLY_CODE; static const uint16_t REPLY_CODE;
/** /**
* Constructor * Constructor
*/ */
explicit CommandInvalidException(const std::string &what, explicit CommandInvalidException(const std::string &what,
const std::string &reply_text, const std::string &reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: ConnectionException(what, reply_text, class_id, method_id) {} : ConnectionException(what, reply_text, class_id, method_id) {}
virtual boost::uint16_t reply_code() const throw() { return REPLY_CODE; } virtual uint16_t reply_code() const throw() { return REPLY_CODE; }
}; };
/** /**
@@ -309,17 +309,17 @@ class SIMPLEAMQPCLIENT_EXPORT ChannelErrorException
: public ConnectionException { : public ConnectionException {
public: public:
/** reply code */ /** reply code */
static const boost::uint16_t REPLY_CODE; static const uint16_t REPLY_CODE;
/** /**
* Constructor * Constructor
*/ */
explicit ChannelErrorException(const std::string &what, explicit ChannelErrorException(const std::string &what,
const std::string &reply_text, const std::string &reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: ConnectionException(what, reply_text, class_id, method_id) {} : ConnectionException(what, reply_text, class_id, method_id) {}
virtual boost::uint16_t reply_code() const throw() { return REPLY_CODE; } virtual uint16_t reply_code() const throw() { return REPLY_CODE; }
}; };
/** /**
@@ -331,18 +331,18 @@ class SIMPLEAMQPCLIENT_EXPORT UnexpectedFrameException
: public ConnectionException { : public ConnectionException {
public: public:
/** reply code */ /** reply code */
static const boost::uint16_t REPLY_CODE; static const uint16_t REPLY_CODE;
/** /**
* Constructor * Constructor
*/ */
explicit UnexpectedFrameException(const std::string &what, explicit UnexpectedFrameException(const std::string &what,
const std::string &reply_text, const std::string &reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: ConnectionException(what, reply_text, class_id, method_id) {} : ConnectionException(what, reply_text, class_id, method_id) {}
virtual boost::uint16_t reply_code() const throw() { return REPLY_CODE; } virtual uint16_t reply_code() const throw() { return REPLY_CODE; }
}; };
/** /**
@@ -354,18 +354,18 @@ class SIMPLEAMQPCLIENT_EXPORT ResourceErrorException
: public ConnectionException { : public ConnectionException {
public: public:
/** reply code */ /** reply code */
static const boost::uint16_t REPLY_CODE; static const uint16_t REPLY_CODE;
/** /**
* Constructor * Constructor
*/ */
explicit ResourceErrorException(const std::string &what, explicit ResourceErrorException(const std::string &what,
const std::string &reply_text, const std::string &reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: ConnectionException(what, reply_text, class_id, method_id) {} : ConnectionException(what, reply_text, class_id, method_id) {}
virtual boost::uint16_t reply_code() const throw() { return REPLY_CODE; } virtual uint16_t reply_code() const throw() { return REPLY_CODE; }
}; };
/** /**
@@ -377,18 +377,18 @@ class SIMPLEAMQPCLIENT_EXPORT ResourceErrorException
class SIMPLEAMQPCLIENT_EXPORT NotAllowedException : public ConnectionException { class SIMPLEAMQPCLIENT_EXPORT NotAllowedException : public ConnectionException {
public: public:
/** reply code */ /** reply code */
static const boost::uint16_t REPLY_CODE; static const uint16_t REPLY_CODE;
/** /**
* Constructor * Constructor
*/ */
explicit NotAllowedException(const std::string &what, explicit NotAllowedException(const std::string &what,
const std::string &reply_text, const std::string &reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: ConnectionException(what, reply_text, class_id, method_id) {} : ConnectionException(what, reply_text, class_id, method_id) {}
virtual boost::uint16_t reply_code() const throw() { return REPLY_CODE; } virtual uint16_t reply_code() const throw() { return REPLY_CODE; }
}; };
/** /**
@@ -398,18 +398,18 @@ class SIMPLEAMQPCLIENT_EXPORT NotImplementedException
: public ConnectionException { : public ConnectionException {
public: public:
/** reply code */ /** reply code */
static const boost::uint16_t REPLY_CODE; static const uint16_t REPLY_CODE;
/** /**
* Constructor * Constructor
*/ */
explicit NotImplementedException(const std::string &what, explicit NotImplementedException(const std::string &what,
const std::string &reply_text, const std::string &reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: ConnectionException(what, reply_text, class_id, method_id) {} : ConnectionException(what, reply_text, class_id, method_id) {}
virtual boost::uint16_t reply_code() const throw() { return REPLY_CODE; } virtual uint16_t reply_code() const throw() { return REPLY_CODE; }
}; };
/** /**
@@ -419,16 +419,16 @@ class SIMPLEAMQPCLIENT_EXPORT InternalErrorException
: public ConnectionException { : public ConnectionException {
public: public:
/** reply code */ /** reply code */
static const boost::uint16_t REPLY_CODE; static const uint16_t REPLY_CODE;
/** Constructor */ /** Constructor */
explicit InternalErrorException(const std::string &what, explicit InternalErrorException(const std::string &what,
const std::string &reply_text, const std::string &reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: ConnectionException(what, reply_text, class_id, method_id) {} : ConnectionException(what, reply_text, class_id, method_id) {}
virtual boost::uint16_t reply_code() const throw() { return REPLY_CODE; } virtual uint16_t reply_code() const throw() { return REPLY_CODE; }
}; };
/** /**
@@ -440,16 +440,16 @@ class SIMPLEAMQPCLIENT_EXPORT ContentTooLargeException
: public ChannelException { : public ChannelException {
public: public:
/** reply code */ /** reply code */
static const boost::uint16_t REPLY_CODE; static const uint16_t REPLY_CODE;
/** Constructor */ /** Constructor */
explicit ContentTooLargeException(const std::string &what, explicit ContentTooLargeException(const std::string &what,
const std::string reply_text, const std::string reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: ChannelException(what, reply_text, class_id, method_id) {} : ChannelException(what, reply_text, class_id, method_id) {}
virtual boost::uint16_t reply_code() const throw() { return REPLY_CODE; } virtual uint16_t reply_code() const throw() { return REPLY_CODE; }
}; };
/** /**
@@ -459,15 +459,15 @@ class SIMPLEAMQPCLIENT_EXPORT ContentTooLargeException
class SIMPLEAMQPCLIENT_EXPORT NoRouteException : public ChannelException { class SIMPLEAMQPCLIENT_EXPORT NoRouteException : public ChannelException {
public: public:
/** reply code */ /** reply code */
static const boost::uint16_t REPLY_CODE; static const uint16_t REPLY_CODE;
/** Constructor */ /** Constructor */
explicit NoRouteException(const std::string &what, explicit NoRouteException(const std::string &what,
const std::string reply_text, const std::string reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: ChannelException(what, reply_text, class_id, method_id) {} : ChannelException(what, reply_text, class_id, method_id) {}
virtual boost::uint16_t reply_code() const throw() { return REPLY_CODE; } virtual uint16_t reply_code() const throw() { return REPLY_CODE; }
}; };
/** /**
@@ -478,15 +478,15 @@ class SIMPLEAMQPCLIENT_EXPORT NoRouteException : public ChannelException {
class SIMPLEAMQPCLIENT_EXPORT NoConsumersException : public ChannelException { class SIMPLEAMQPCLIENT_EXPORT NoConsumersException : public ChannelException {
public: public:
/** reply code */ /** reply code */
static const boost::uint16_t REPLY_CODE; static const uint16_t REPLY_CODE;
/** Constructor */ /** Constructor */
explicit NoConsumersException(const std::string &what, explicit NoConsumersException(const std::string &what,
const std::string reply_text, const std::string reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: ChannelException(what, reply_text, class_id, method_id) {} : ChannelException(what, reply_text, class_id, method_id) {}
virtual boost::uint16_t reply_code() const throw() { return REPLY_CODE; } virtual uint16_t reply_code() const throw() { return REPLY_CODE; }
}; };
/** /**
@@ -496,15 +496,15 @@ class SIMPLEAMQPCLIENT_EXPORT NoConsumersException : public ChannelException {
class SIMPLEAMQPCLIENT_EXPORT AccessRefusedException : public ChannelException { class SIMPLEAMQPCLIENT_EXPORT AccessRefusedException : public ChannelException {
public: public:
/** reply code */ /** reply code */
static const boost::uint16_t REPLY_CODE; static const uint16_t REPLY_CODE;
/** Constructor */ /** Constructor */
explicit AccessRefusedException(const std::string &what, explicit AccessRefusedException(const std::string &what,
const std::string reply_text, const std::string reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: ChannelException(what, reply_text, class_id, method_id) {} : ChannelException(what, reply_text, class_id, method_id) {}
virtual boost::uint16_t reply_code() const throw() { return REPLY_CODE; } virtual uint16_t reply_code() const throw() { return REPLY_CODE; }
}; };
/** /**
@@ -514,15 +514,15 @@ class SIMPLEAMQPCLIENT_EXPORT AccessRefusedException : public ChannelException {
class SIMPLEAMQPCLIENT_EXPORT NotFoundException : public ChannelException { class SIMPLEAMQPCLIENT_EXPORT NotFoundException : public ChannelException {
public: public:
/** reply code */ /** reply code */
static const boost::uint16_t REPLY_CODE; static const uint16_t REPLY_CODE;
/** Constructor */ /** Constructor */
explicit NotFoundException(const std::string &what, explicit NotFoundException(const std::string &what,
const std::string reply_text, const std::string reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: ChannelException(what, reply_text, class_id, method_id) {} : ChannelException(what, reply_text, class_id, method_id) {}
virtual boost::uint16_t reply_code() const throw() { return REPLY_CODE; } virtual uint16_t reply_code() const throw() { return REPLY_CODE; }
}; };
/** /**
@@ -533,15 +533,15 @@ class SIMPLEAMQPCLIENT_EXPORT ResourceLockedException
: public ChannelException { : public ChannelException {
public: public:
/** reply code */ /** reply code */
static const boost::uint16_t REPLY_CODE; static const uint16_t REPLY_CODE;
/** Constructor */ /** Constructor */
explicit ResourceLockedException(const std::string &what, explicit ResourceLockedException(const std::string &what,
const std::string reply_text, const std::string reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: ChannelException(what, reply_text, class_id, method_id) {} : ChannelException(what, reply_text, class_id, method_id) {}
virtual boost::uint16_t reply_code() const throw() { return REPLY_CODE; } virtual uint16_t reply_code() const throw() { return REPLY_CODE; }
}; };
/** /**
@@ -552,15 +552,15 @@ class SIMPLEAMQPCLIENT_EXPORT PreconditionFailedException
: public ChannelException { : public ChannelException {
public: public:
/** reply code */ /** reply code */
static const boost::uint16_t REPLY_CODE; static const uint16_t REPLY_CODE;
/** Constructor */ /** Constructor */
explicit PreconditionFailedException(const std::string &what, explicit PreconditionFailedException(const std::string &what,
const std::string reply_text, const std::string reply_text,
boost::uint16_t class_id, uint16_t class_id,
boost::uint16_t method_id) throw() uint16_t method_id) throw()
: ChannelException(what, reply_text, class_id, method_id) {} : ChannelException(what, reply_text, class_id, method_id) {}
virtual boost::uint16_t reply_code() const throw() { return REPLY_CODE; } virtual uint16_t reply_code() const throw() { return REPLY_CODE; }
}; };
} // namespace AmqpClient } // namespace AmqpClient

View File

@@ -28,7 +28,7 @@
* ***** END LICENSE BLOCK ***** * ***** END LICENSE BLOCK *****
*/ */
#include <boost/cstdint.hpp> #include <cstdint>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>

View File

@@ -28,11 +28,9 @@
* ***** END LICENSE BLOCK ***** * ***** END LICENSE BLOCK *****
*/ */
#include <boost/cstdint.hpp> #include <cstdint>
#include <boost/make_shared.hpp> #include <memory>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
#include <string> #include <string>
#include "SimpleAmqpClient/Table.h" #include "SimpleAmqpClient/Table.h"
@@ -51,10 +49,10 @@ namespace AmqpClient {
/** /**
* An AMQP BasicMessage * An AMQP BasicMessage
*/ */
class SIMPLEAMQPCLIENT_EXPORT BasicMessage : boost::noncopyable { class SIMPLEAMQPCLIENT_EXPORT BasicMessage {
public: public:
/// A shared pointer to BasicMessage /// A shared pointer to BasicMessage
typedef boost::shared_ptr<BasicMessage> ptr_t; typedef std::shared_ptr<BasicMessage> ptr_t;
/// With durable queues, messages can be requested to persist or not /// With durable queues, messages can be requested to persist or not
enum delivery_mode_t { enum delivery_mode_t {
@@ -66,7 +64,7 @@ class SIMPLEAMQPCLIENT_EXPORT BasicMessage : boost::noncopyable {
/** /**
* Create a new empty BasicMessage object * Create a new empty BasicMessage object
*/ */
static ptr_t Create() { return boost::make_shared<BasicMessage>(); } static ptr_t Create() { return std::make_shared<BasicMessage>(); }
/** /**
* Create a new BasicMessage object with given body * Create a new BasicMessage object with given body
@@ -75,7 +73,7 @@ class SIMPLEAMQPCLIENT_EXPORT BasicMessage : boost::noncopyable {
* @returns a new BasicMessage object * @returns a new BasicMessage object
*/ */
static ptr_t Create(const std::string& body) { static ptr_t Create(const std::string& body) {
return boost::make_shared<BasicMessage>(body); return std::make_shared<BasicMessage>(body);
} }
/// Construct empty BasicMessage /// Construct empty BasicMessage
@@ -154,11 +152,11 @@ class SIMPLEAMQPCLIENT_EXPORT BasicMessage : boost::noncopyable {
/** /**
* Gets the priority property * Gets the priority property
*/ */
boost::uint8_t Priority() const; uint8_t Priority() const;
/** /**
* Sets the priority property * Sets the priority property
*/ */
void Priority(boost::uint8_t priority); void Priority(uint8_t priority);
/** /**
* Determines whether the priority property is set * Determines whether the priority property is set
*/ */
@@ -239,11 +237,11 @@ class SIMPLEAMQPCLIENT_EXPORT BasicMessage : boost::noncopyable {
/** /**
* Gets the timestamp property * Gets the timestamp property
*/ */
boost::uint64_t Timestamp() const; uint64_t Timestamp() const;
/** /**
* Sets the timestamp property * Sets the timestamp property
*/ */
void Timestamp(boost::uint64_t timestamp); void Timestamp(uint64_t timestamp);
/** /**
* Determines whether the timestamp property is set * Determines whether the timestamp property is set
*/ */
@@ -342,7 +340,7 @@ class SIMPLEAMQPCLIENT_EXPORT BasicMessage : boost::noncopyable {
protected: protected:
struct Impl; struct Impl;
/// PIMPL idiom /// PIMPL idiom
boost::scoped_ptr<Impl> m_impl; std::unique_ptr<Impl> m_impl;
}; };
} // namespace AmqpClient } // namespace AmqpClient

View File

@@ -2,7 +2,7 @@
#define SIMPLEAMQPCLIENT_BYTES_H #define SIMPLEAMQPCLIENT_BYTES_H
#include <amqp.h> #include <amqp.h>
#include <boost/utility/string_ref.hpp> #include <string_view>
#include <string> #include <string>
@@ -15,7 +15,7 @@ amqp_bytes_t StringToBytes(const std::string& str) {
return ret; return ret;
} }
amqp_bytes_t StringRefToBytes(boost::string_ref str) { amqp_bytes_t StringRefToBytes(std::string_view str) {
amqp_bytes_t ret; amqp_bytes_t ret;
ret.bytes = reinterpret_cast<void*>(const_cast<char*>(str.data())); ret.bytes = reinterpret_cast<void*>(const_cast<char*>(str.data()));
ret.len = str.length(); ret.len = str.length();

View File

@@ -28,14 +28,12 @@
* ***** END LICENSE BLOCK ***** * ***** END LICENSE BLOCK *****
*/ */
#include <boost/cstdint.hpp> #include <cstdint>
#include <boost/make_shared.hpp> #include <memory>
#include <boost/optional.hpp> #include <optional>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp> #include <string_view>
#include <boost/utility.hpp> #include <variant>
#include <boost/utility/string_ref.hpp>
#include <boost/variant.hpp>
#include <string> #include <string>
#include <vector> #include <vector>
@@ -59,10 +57,10 @@ namespace AmqpClient {
* *
* Represents a logical AMQP channel multiplexed over a connection * Represents a logical AMQP channel multiplexed over a connection
*/ */
class SIMPLEAMQPCLIENT_EXPORT Channel : boost::noncopyable { class SIMPLEAMQPCLIENT_EXPORT Channel {
public: public:
/// a `shared_ptr` to Channel /// a `shared_ptr` to Channel
typedef boost::shared_ptr<Channel> ptr_t; typedef std::shared_ptr<Channel> ptr_t;
static const std::string static const std::string
EXCHANGE_TYPE_DIRECT; ///< `"direct"` string constant EXCHANGE_TYPE_DIRECT; ///< `"direct"` string constant
@@ -109,9 +107,9 @@ class SIMPLEAMQPCLIENT_EXPORT Channel : boost::noncopyable {
int port; ///< Port to connect to, default is 5672. int port; ///< Port to connect to, default is 5672.
int frame_max; ///< Max frame size in bytes. Default 128KB. int frame_max; ///< Max frame size in bytes. Default 128KB.
/// One of BasicAuth or ExternalSaslAuth is required. /// One of BasicAuth or ExternalSaslAuth is required.
boost::variant<BasicAuth, ExternalSaslAuth> auth; std::variant<BasicAuth, ExternalSaslAuth> auth;
/// Connect using TLS/SSL when set, otherwise use an unencrypted channel. /// Connect using TLS/SSL when set, otherwise use an unencrypted channel.
boost::optional<TLSParams> tls_params; std::optional<TLSParams> tls_params;
/** /**
* Create an OpenOpts struct from a URI. * Create an OpenOpts struct from a URI.
@@ -351,7 +349,7 @@ class SIMPLEAMQPCLIENT_EXPORT Channel : boost::noncopyable {
* @param exchange_name the name of the exchange to check for. * @param exchange_name the name of the exchange to check for.
* @returns true if the exchange exists on the broker, false otherwise. * @returns true if the exchange exists on the broker, false otherwise.
*/ */
bool CheckExchangeExists(boost::string_ref exchange_name); bool CheckExchangeExists(std::string_view exchange_name);
/** /**
* Declares an exchange * Declares an exchange
@@ -454,7 +452,7 @@ class SIMPLEAMQPCLIENT_EXPORT Channel : boost::noncopyable {
* @param queue_name the name of the exchange to check for. * @param queue_name the name of the exchange to check for.
* @returns true if the exchange exists on the broker, false otherwise. * @returns true if the exchange exists on the broker, false otherwise.
*/ */
bool CheckQueueExists(boost::string_ref queue_name); bool CheckQueueExists(std::string_view queue_name);
/** /**
* Declare a queue * Declare a queue
@@ -527,8 +525,8 @@ class SIMPLEAMQPCLIENT_EXPORT Channel : boost::noncopyable {
* broker is asked to create a unique queue by not providing a queue name. * broker is asked to create a unique queue by not providing a queue name.
*/ */
std::string DeclareQueueWithCounts(const std::string &queue_name, std::string DeclareQueueWithCounts(const std::string &queue_name,
boost::uint32_t &message_count, uint32_t &message_count,
boost::uint32_t &consumer_count, uint32_t &consumer_count,
bool passive = false, bool durable = false, bool passive = false, bool durable = false,
bool exclusive = true, bool exclusive = true,
bool auto_delete = true); bool auto_delete = true);
@@ -558,8 +556,8 @@ class SIMPLEAMQPCLIENT_EXPORT Channel : boost::noncopyable {
* broker is asked to create a unique queue by not providing a queue name. * broker is asked to create a unique queue by not providing a queue name.
*/ */
std::string DeclareQueueWithCounts(const std::string &queue_name, std::string DeclareQueueWithCounts(const std::string &queue_name,
boost::uint32_t &message_count, uint32_t &message_count,
boost::uint32_t &consumer_count, uint32_t &consumer_count,
bool passive, bool durable, bool exclusive, bool passive, bool durable, bool exclusive,
bool auto_delete, const Table &arguments); bool auto_delete, const Table &arguments);
@@ -772,7 +770,7 @@ class SIMPLEAMQPCLIENT_EXPORT Channel : boost::noncopyable {
const std::string &consumer_tag = "", const std::string &consumer_tag = "",
bool no_local = true, bool no_ack = true, bool no_local = true, bool no_ack = true,
bool exclusive = true, bool exclusive = true,
boost::uint16_t message_prefetch_count = 1); uint16_t message_prefetch_count = 1);
/** /**
* Starts consuming Basic messages on a queue * Starts consuming Basic messages on a queue
@@ -800,7 +798,7 @@ class SIMPLEAMQPCLIENT_EXPORT Channel : boost::noncopyable {
std::string BasicConsume(const std::string &queue, std::string BasicConsume(const std::string &queue,
const std::string &consumer_tag, bool no_local, const std::string &consumer_tag, bool no_local,
bool no_ack, bool exclusive, bool no_ack, bool exclusive,
boost::uint16_t message_prefetch_count, uint16_t message_prefetch_count,
const Table &arguments); const Table &arguments);
/** /**
@@ -816,7 +814,7 @@ class SIMPLEAMQPCLIENT_EXPORT Channel : boost::noncopyable {
* broker will deliver. A value of 0 means no limit. * broker will deliver. A value of 0 means no limit.
*/ */
void BasicQos(const std::string &consumer_tag, void BasicQos(const std::string &consumer_tag,
boost::uint16_t message_prefetch_count); uint16_t message_prefetch_count);
/** /**
* Cancels a previously created Consumer * Cancels a previously created Consumer
@@ -934,7 +932,7 @@ class SIMPLEAMQPCLIENT_EXPORT Channel : boost::noncopyable {
bool sasl_external); bool sasl_external);
/// PIMPL idiom /// PIMPL idiom
boost::scoped_ptr<ChannelImpl> m_impl; std::unique_ptr<ChannelImpl> m_impl;
}; };
} // namespace AmqpClient } // namespace AmqpClient

View File

@@ -1,3 +1,4 @@
#include <algorithm>
#ifndef SIMPLEAMQPCLIENT_CHANNELIMPL_H #ifndef SIMPLEAMQPCLIENT_CHANNELIMPL_H
#define SIMPLEAMQPCLIENT_CHANNELIMPL_H #define SIMPLEAMQPCLIENT_CHANNELIMPL_H
/* /*
@@ -32,7 +33,7 @@
#include <amqp.h> #include <amqp.h>
#include <amqp_framing.h> #include <amqp_framing.h>
#include <boost/array.hpp> #include <array>
#include "SimpleAmqpClient/AmqpException.h" #include "SimpleAmqpClient/AmqpException.h"
#include "SimpleAmqpClient/BasicMessage.h" #include "SimpleAmqpClient/BasicMessage.h"
@@ -41,15 +42,15 @@
#include "SimpleAmqpClient/Envelope.h" #include "SimpleAmqpClient/Envelope.h"
#include "SimpleAmqpClient/MessageReturnedException.h" #include "SimpleAmqpClient/MessageReturnedException.h"
#define BOOST_BIND_GLOBAL_PLACEHOLDERS #define BOOST_BIND_GLOBAL_PLACEHOLDERS
#include <boost/bind.hpp> #include <functional>
#include <boost/chrono.hpp> #include <chrono>
#include <boost/noncopyable.hpp>
#include <map> #include <map>
#include <vector> #include <vector>
namespace AmqpClient { namespace AmqpClient {
class Channel::ChannelImpl : boost::noncopyable { class Channel::ChannelImpl {
public: public:
ChannelImpl(); ChannelImpl();
virtual ~ChannelImpl(); virtual ~ChannelImpl();
@@ -67,7 +68,7 @@ class Channel::ChannelImpl : boost::noncopyable {
bool IsChannelOpen(amqp_channel_t channel); bool IsChannelOpen(amqp_channel_t channel);
bool GetNextFrameFromBroker(amqp_frame_t &frame, bool GetNextFrameFromBroker(amqp_frame_t &frame,
boost::chrono::microseconds timeout); std::chrono::microseconds timeout);
bool CheckForQueuedMessageOnChannel(amqp_channel_t message_on_channel) const; bool CheckForQueuedMessageOnChannel(amqp_channel_t message_on_channel) const;
void AddToFrameQueue(const amqp_frame_t &frame); void AddToFrameQueue(const amqp_frame_t &frame);
@@ -75,12 +76,12 @@ class Channel::ChannelImpl : boost::noncopyable {
template <class ChannelListType> template <class ChannelListType>
bool GetNextFrameFromBrokerOnChannel(const ChannelListType channels, bool GetNextFrameFromBrokerOnChannel(const ChannelListType channels,
amqp_frame_t &frame_out, amqp_frame_t &frame_out,
boost::chrono::microseconds timeout = std::chrono::microseconds timeout =
boost::chrono::microseconds::max()) { std::chrono::microseconds::max()) {
boost::chrono::steady_clock::time_point end_point; std::chrono::steady_clock::time_point end_point;
boost::chrono::microseconds timeout_left = timeout; std::chrono::microseconds timeout_left = timeout;
if (timeout != boost::chrono::microseconds::max()) { if (timeout != std::chrono::microseconds::max()) {
end_point = boost::chrono::steady_clock::now() + timeout; end_point = std::chrono::steady_clock::now() + timeout;
} }
amqp_frame_t frame; amqp_frame_t frame;
@@ -104,14 +105,14 @@ class Channel::ChannelImpl : boost::noncopyable {
AddToFrameQueue(frame); AddToFrameQueue(frame);
} }
if (timeout != boost::chrono::microseconds::max()) { if (timeout != std::chrono::microseconds::max()) {
boost::chrono::steady_clock::time_point now = std::chrono::steady_clock::time_point now =
boost::chrono::steady_clock::now(); std::chrono::steady_clock::now();
if (now >= end_point) { if (now >= end_point) {
return false; return false;
} }
timeout_left = timeout_left =
boost::chrono::duration_cast<boost::chrono::microseconds>( std::chrono::duration_cast<std::chrono::microseconds>(
end_point - now); end_point - now);
} }
} }
@@ -120,7 +121,7 @@ class Channel::ChannelImpl : boost::noncopyable {
bool GetNextFrameOnChannel( bool GetNextFrameOnChannel(
amqp_channel_t channel, amqp_frame_t &frame, amqp_channel_t channel, amqp_frame_t &frame,
boost::chrono::microseconds timeout = boost::chrono::microseconds::max()); std::chrono::microseconds timeout = std::chrono::microseconds::max());
static bool is_on_channel(const amqp_frame_t frame, amqp_channel_t channel) { static bool is_on_channel(const amqp_frame_t frame, amqp_channel_t channel) {
return channel == frame.channel; return channel == frame.channel;
@@ -154,14 +155,14 @@ class Channel::ChannelImpl : boost::noncopyable {
template <class ChannelListType, class ResponseListType> template <class ChannelListType, class ResponseListType>
bool GetMethodOnChannel(const ChannelListType channels, amqp_frame_t &frame, bool GetMethodOnChannel(const ChannelListType channels, amqp_frame_t &frame,
const ResponseListType &expected_responses, const ResponseListType &expected_responses,
boost::chrono::microseconds timeout = std::chrono::microseconds timeout =
boost::chrono::microseconds::max()) { std::chrono::microseconds::max()) {
frame_queue_t::iterator desired_frame = std::find_if( frame_queue_t::iterator desired_frame = std::find_if(
m_frame_queue.begin(), m_frame_queue.end(), m_frame_queue.begin(), m_frame_queue.end(),
boost::bind( std::bind(
&ChannelImpl::is_expected_method_on_channel<ChannelListType, &ChannelImpl::is_expected_method_on_channel<ChannelListType,
ResponseListType>, ResponseListType>,
_1, channels, expected_responses)); std::placeholders::_1, channels, expected_responses));
if (m_frame_queue.end() != desired_frame) { if (m_frame_queue.end() != desired_frame) {
frame = *desired_frame; frame = *desired_frame;
@@ -169,10 +170,10 @@ class Channel::ChannelImpl : boost::noncopyable {
return true; return true;
} }
boost::chrono::steady_clock::time_point end_point; std::chrono::steady_clock::time_point end_point;
boost::chrono::microseconds timeout_left = timeout; std::chrono::microseconds timeout_left = timeout;
if (timeout != boost::chrono::microseconds::max()) { if (timeout != std::chrono::microseconds::max()) {
end_point = boost::chrono::steady_clock::now() + timeout; end_point = std::chrono::steady_clock::now() + timeout;
} }
amqp_frame_t incoming_frame; amqp_frame_t incoming_frame;
@@ -196,14 +197,14 @@ class Channel::ChannelImpl : boost::noncopyable {
} }
m_frame_queue.push_back(incoming_frame); m_frame_queue.push_back(incoming_frame);
if (timeout != boost::chrono::microseconds::max()) { if (timeout != std::chrono::microseconds::max()) {
boost::chrono::steady_clock::time_point now = std::chrono::steady_clock::time_point now =
boost::chrono::steady_clock::now(); std::chrono::steady_clock::now();
if (now >= end_point) { if (now >= end_point) {
return false; return false;
} }
timeout_left = timeout_left =
boost::chrono::duration_cast<boost::chrono::microseconds>( std::chrono::duration_cast<std::chrono::microseconds>(
end_point - now); end_point - now);
} }
} }
@@ -211,20 +212,20 @@ class Channel::ChannelImpl : boost::noncopyable {
} }
template <class ResponseListType> template <class ResponseListType>
amqp_frame_t DoRpcOnChannel(amqp_channel_t channel, boost::uint32_t method_id, amqp_frame_t DoRpcOnChannel(amqp_channel_t channel, uint32_t method_id,
void *decoded, void *decoded,
const ResponseListType &expected_responses) { const ResponseListType &expected_responses) {
CheckForError(amqp_send_method(m_connection, channel, method_id, decoded)); CheckForError(amqp_send_method(m_connection, channel, method_id, decoded));
amqp_frame_t response; amqp_frame_t response;
boost::array<amqp_channel_t, 1> channels = {{channel}}; std::array<amqp_channel_t, 1> channels = {{channel}};
GetMethodOnChannel(channels, response, expected_responses); GetMethodOnChannel(channels, response, expected_responses);
return response; return response;
} }
template <class ResponseListType> template <class ResponseListType>
amqp_frame_t DoRpc(boost::uint32_t method_id, void *decoded, amqp_frame_t DoRpc(uint32_t method_id, void *decoded,
const ResponseListType &expected_responses) { const ResponseListType &expected_responses) {
amqp_channel_t channel = GetChannel(); amqp_channel_t channel = GetChannel();
amqp_frame_t ret = amqp_frame_t ret =
@@ -245,7 +246,7 @@ class Channel::ChannelImpl : boost::noncopyable {
Envelope::ptr_t &message, int timeout) { Envelope::ptr_t &message, int timeout) {
envelope_list_t::iterator it = std::find_if( envelope_list_t::iterator it = std::find_if(
m_delivered_messages.begin(), m_delivered_messages.end(), m_delivered_messages.begin(), m_delivered_messages.end(),
boost::bind(ChannelImpl::envelope_on_channel<ChannelListType>, _1, std::bind(ChannelImpl::envelope_on_channel<ChannelListType>, std::placeholders::_1,
channels)); channels));
if (it != m_delivered_messages.end()) { if (it != m_delivered_messages.end()) {
@@ -260,12 +261,12 @@ class Channel::ChannelImpl : boost::noncopyable {
template <class ChannelListType> template <class ChannelListType>
bool ConsumeMessageOnChannelInner(const ChannelListType channels, bool ConsumeMessageOnChannelInner(const ChannelListType channels,
Envelope::ptr_t &message, int timeout) { Envelope::ptr_t &message, int timeout) {
const boost::array<boost::uint32_t, 2> DELIVER_OR_CANCEL = { const std::array<uint32_t, 2> DELIVER_OR_CANCEL = {
{AMQP_BASIC_DELIVER_METHOD, AMQP_BASIC_CANCEL_METHOD}}; {AMQP_BASIC_DELIVER_METHOD, AMQP_BASIC_CANCEL_METHOD}};
boost::chrono::microseconds real_timeout = std::chrono::microseconds real_timeout =
(timeout >= 0 ? boost::chrono::milliseconds(timeout) (timeout >= 0 ? std::chrono::milliseconds(timeout)
: boost::chrono::microseconds::max()); : std::chrono::microseconds::max());
amqp_frame_t deliver; amqp_frame_t deliver;
if (!GetMethodOnChannel(channels, deliver, DELIVER_OR_CANCEL, if (!GetMethodOnChannel(channels, deliver, DELIVER_OR_CANCEL,
@@ -298,7 +299,7 @@ class Channel::ChannelImpl : boost::noncopyable {
const std::string in_consumer_tag( const std::string in_consumer_tag(
(char *)deliver_method->consumer_tag.bytes, (char *)deliver_method->consumer_tag.bytes,
deliver_method->consumer_tag.len); deliver_method->consumer_tag.len);
const boost::uint64_t delivery_tag = deliver_method->delivery_tag; const uint64_t delivery_tag = deliver_method->delivery_tag;
const bool redelivered = (deliver_method->redelivered == 0 ? false : true); const bool redelivered = (deliver_method->redelivered == 0 ? false : true);
MaybeReleaseBuffersOnChannel(deliver.channel); MaybeReleaseBuffersOnChannel(deliver.channel);
@@ -343,7 +344,7 @@ class Channel::ChannelImpl : boost::noncopyable {
amqp_connection_state_t m_connection; amqp_connection_state_t m_connection;
private: private:
static boost::uint32_t ComputeBrokerVersion( static uint32_t ComputeBrokerVersion(
const amqp_connection_state_t state); const amqp_connection_state_t state);
frame_queue_t m_frame_queue; frame_queue_t m_frame_queue;
@@ -358,7 +359,7 @@ class Channel::ChannelImpl : boost::noncopyable {
typedef std::vector<channel_state_t> channel_state_list_t; typedef std::vector<channel_state_t> channel_state_list_t;
channel_state_list_t m_channels; channel_state_list_t m_channels;
boost::uint32_t m_brokerVersion; uint32_t m_brokerVersion;
// A channel that is likely to be an CS_Open state // A channel that is likely to be an CS_Open state
amqp_channel_t m_last_used_channel; amqp_channel_t m_last_used_channel;

View File

@@ -28,10 +28,9 @@
* ***** END LICENSE BLOCK ***** * ***** END LICENSE BLOCK *****
*/ */
#include <boost/cstdint.hpp> #include <cstdint>
#include <boost/make_shared.hpp> #include <memory>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <string> #include <string>
#include "SimpleAmqpClient/BasicMessage.h" #include "SimpleAmqpClient/BasicMessage.h"
@@ -50,10 +49,10 @@ namespace AmqpClient {
/** /**
* A "message envelope" object containing the message body and delivery metadata * A "message envelope" object containing the message body and delivery metadata
*/ */
class SIMPLEAMQPCLIENT_EXPORT Envelope : boost::noncopyable { class SIMPLEAMQPCLIENT_EXPORT Envelope {
public: public:
/// a `shared_ptr` pointer to Envelope /// a `shared_ptr` pointer to Envelope
typedef boost::shared_ptr<Envelope> ptr_t; typedef std::shared_ptr<Envelope> ptr_t;
/** /**
* Creates an new envelope object * Creates an new envelope object
@@ -66,15 +65,15 @@ class SIMPLEAMQPCLIENT_EXPORT Envelope : boost::noncopyable {
* result of a redelivery * result of a redelivery
* @param routing_key the routing key that the message was published with * @param routing_key the routing key that the message was published with
* @param delivery_channel channel ID of the delivery (see DeliveryInfo) * @param delivery_channel channel ID of the delivery (see DeliveryInfo)
* @returns a boost::shared_ptr to an envelope object * @returns a std::shared_ptr to an envelope object
*/ */
static ptr_t Create(const BasicMessage::ptr_t message, static ptr_t Create(const BasicMessage::ptr_t message,
const std::string &consumer_tag, const std::string &consumer_tag,
const boost::uint64_t delivery_tag, const uint64_t delivery_tag,
const std::string &exchange, bool redelivered, const std::string &exchange, bool redelivered,
const std::string &routing_key, const std::string &routing_key,
const boost::uint16_t delivery_channel) { const uint16_t delivery_channel) {
return boost::make_shared<Envelope>(message, consumer_tag, delivery_tag, return std::make_shared<Envelope>(message, consumer_tag, delivery_tag,
exchange, redelivered, routing_key, exchange, redelivered, routing_key,
delivery_channel); delivery_channel);
} }
@@ -93,10 +92,10 @@ class SIMPLEAMQPCLIENT_EXPORT Envelope : boost::noncopyable {
*/ */
explicit Envelope(const BasicMessage::ptr_t message, explicit Envelope(const BasicMessage::ptr_t message,
const std::string &consumer_tag, const std::string &consumer_tag,
const boost::uint64_t delivery_tag, const uint64_t delivery_tag,
const std::string &exchange, bool redelivered, const std::string &exchange, bool redelivered,
const std::string &routing_key, const std::string &routing_key,
const boost::uint16_t delivery_channel); const uint16_t delivery_channel);
public: public:
/** /**
@@ -127,7 +126,7 @@ class SIMPLEAMQPCLIENT_EXPORT Envelope : boost::noncopyable {
* *
* @returns the delivery tag for a message * @returns the delivery tag for a message
*/ */
inline boost::uint64_t DeliveryTag() const { return m_deliveryTag; } inline uint64_t DeliveryTag() const { return m_deliveryTag; }
/** /**
* Get the name of the exchange that the message was published to * Get the name of the exchange that the message was published to
@@ -159,7 +158,7 @@ class SIMPLEAMQPCLIENT_EXPORT Envelope : boost::noncopyable {
/** /**
* Get the delivery channel * Get the delivery channel
*/ */
inline boost::uint16_t DeliveryChannel() const { return m_deliveryChannel; } inline uint16_t DeliveryChannel() const { return m_deliveryChannel; }
/** /**
* A POD carrier of delivery-tag * A POD carrier of delivery-tag
@@ -176,9 +175,9 @@ class SIMPLEAMQPCLIENT_EXPORT Envelope : boost::noncopyable {
struct DeliveryInfo { struct DeliveryInfo {
/// A delivery tag, assigned by the broker to identify this delivery within /// A delivery tag, assigned by the broker to identify this delivery within
/// a channel /// a channel
boost::uint64_t delivery_tag; uint64_t delivery_tag;
/// An ID of the delivery channel /// An ID of the delivery channel
boost::uint16_t delivery_channel; uint16_t delivery_channel;
}; };
/** /**
@@ -195,11 +194,11 @@ class SIMPLEAMQPCLIENT_EXPORT Envelope : boost::noncopyable {
private: private:
const BasicMessage::ptr_t m_message; const BasicMessage::ptr_t m_message;
const std::string m_consumerTag; const std::string m_consumerTag;
const boost::uint64_t m_deliveryTag; const uint64_t m_deliveryTag;
const std::string m_exchange; const std::string m_exchange;
const bool m_redelivered; const bool m_redelivered;
const std::string m_routingKey; const std::string m_routingKey;
const boost::uint16_t m_deliveryChannel; const uint16_t m_deliveryChannel;
}; };
} // namespace AmqpClient } // namespace AmqpClient

View File

@@ -28,8 +28,9 @@
* ***** END LICENSE BLOCK ***** * ***** END LICENSE BLOCK *****
*/ */
#include <boost/cstdint.hpp> #include <cstdint>
#include <boost/lexical_cast.hpp> #include <string>
#include <stdexcept>
#include <stdexcept> #include <stdexcept>
#include "SimpleAmqpClient/BasicMessage.h" #include "SimpleAmqpClient/BasicMessage.h"
@@ -51,7 +52,7 @@ class SIMPLEAMQPCLIENT_EXPORT MessageRejectedException
MessageRejectedException(uint64_t delivery_tag) MessageRejectedException(uint64_t delivery_tag)
: std::runtime_error( : std::runtime_error(
std::string("Message rejected: ") std::string("Message rejected: ")
.append(boost::lexical_cast<std::string>(delivery_tag))), .append(std::to_string(delivery_tag))),
m_delivery_tag(delivery_tag) {} m_delivery_tag(delivery_tag) {}
/// `delivery_tag` getter /// `delivery_tag` getter

View File

@@ -28,7 +28,7 @@
* ***** END LICENSE BLOCK ***** * ***** END LICENSE BLOCK *****
*/ */
#include <boost/cstdint.hpp> #include <cstdint>
#include <stdexcept> #include <stdexcept>
#include "SimpleAmqpClient/BasicMessage.h" #include "SimpleAmqpClient/BasicMessage.h"
@@ -49,7 +49,7 @@ class SIMPLEAMQPCLIENT_EXPORT MessageReturnedException
public: public:
/// Constructor. /// Constructor.
explicit MessageReturnedException(BasicMessage::ptr_t message, explicit MessageReturnedException(BasicMessage::ptr_t message,
boost::uint32_t reply_code, uint32_t reply_code,
const std::string &reply_text, const std::string &reply_text,
const std::string &exchange, const std::string &exchange,
const std::string &routing_key) throw(); const std::string &routing_key) throw();
@@ -59,7 +59,7 @@ class SIMPLEAMQPCLIENT_EXPORT MessageReturnedException
/// `message` getter /// `message` getter
BasicMessage::ptr_t message() const throw() { return m_message; } BasicMessage::ptr_t message() const throw() { return m_message; }
/// `reply_code` getter /// `reply_code` getter
boost::uint32_t reply_code() const throw() { return m_reply_code; } uint32_t reply_code() const throw() { return m_reply_code; }
/// `reply_text` getter /// `reply_text` getter
std::string reply_text() const throw() { return m_reply_text; } std::string reply_text() const throw() { return m_reply_text; }
/// Exchange name getter /// Exchange name getter
@@ -69,7 +69,7 @@ class SIMPLEAMQPCLIENT_EXPORT MessageReturnedException
private: private:
BasicMessage::ptr_t m_message; BasicMessage::ptr_t m_message;
boost::uint32_t m_reply_code; uint32_t m_reply_code;
std::string m_reply_text; std::string m_reply_text;
std::string m_exchange; std::string m_exchange;
std::string m_routing_key; std::string m_routing_key;

View File

@@ -1,3 +1,4 @@
#include <variant>
#ifndef SIMPLEAMQPCLIENT_TABLE_H #ifndef SIMPLEAMQPCLIENT_TABLE_H
#define SIMPLEAMQPCLIENT_TABLE_H #define SIMPLEAMQPCLIENT_TABLE_H
/* /*
@@ -28,8 +29,8 @@
* ***** END LICENSE BLOCK ***** * ***** END LICENSE BLOCK *****
*/ */
#include <boost/cstdint.hpp> #include <cstdint>
#include <boost/scoped_ptr.hpp> #include <memory>
#include <ctime> #include <ctime>
#include <map> #include <map>
#include <string> #include <string>
@@ -119,42 +120,42 @@ class SIMPLEAMQPCLIENT_EXPORT TableValue {
* *
* @param [in] value the value * @param [in] value the value
*/ */
TableValue(boost::uint8_t value); TableValue(uint8_t value);
/** /**
* Construct a 1-byte signed integer value * Construct a 1-byte signed integer value
* *
* @param [in] value the value * @param [in] value the value
*/ */
TableValue(boost::int8_t value); TableValue(int8_t value);
/** /**
* Construct a 2-byte unsigned integer value * Construct a 2-byte unsigned integer value
* *
* @param [in] value the value * @param [in] value the value
*/ */
TableValue(boost::uint16_t value); TableValue(uint16_t value);
/** /**
* Construct a 2-byte signed integer value * Construct a 2-byte signed integer value
* *
* @param [in] value the value * @param [in] value the value
*/ */
TableValue(boost::int16_t value); TableValue(int16_t value);
/** /**
* Construct a 4-byte unsigned integer value * Construct a 4-byte unsigned integer value
* *
* @param [in] value the value * @param [in] value the value
*/ */
TableValue(boost::uint32_t value); TableValue(uint32_t value);
/** /**
* Construct a 4-byte signed integer value * Construct a 4-byte signed integer value
* *
* @param [in] value the value * @param [in] value the value
*/ */
TableValue(boost::int32_t value); TableValue(int32_t value);
private: private:
/** /**
@@ -163,7 +164,7 @@ class SIMPLEAMQPCLIENT_EXPORT TableValue {
* RabbitMQ does not support unsigned 64-bit values in tables, * RabbitMQ does not support unsigned 64-bit values in tables,
* however, timestamps are used for this. * however, timestamps are used for this.
*/ */
TableValue(boost::uint64_t value); TableValue(uint64_t value);
public: public:
/** /**
@@ -180,7 +181,7 @@ class SIMPLEAMQPCLIENT_EXPORT TableValue {
* *
* @param [in] value the value * @param [in] value the value
*/ */
TableValue(boost::int64_t value); TableValue(int64_t value);
/** /**
* Construct a single-precision floating point value * Construct a single-precision floating point value
@@ -266,49 +267,49 @@ class SIMPLEAMQPCLIENT_EXPORT TableValue {
* *
* @returns the value if its a VT_uint8 type, 0 otherwise * @returns the value if its a VT_uint8 type, 0 otherwise
*/ */
boost::uint8_t GetUint8() const; uint8_t GetUint8() const;
/** /**
* Get the int8 value * Get the int8 value
* *
* @returns the value if its a VT_int8 type, 0 otherwise * @returns the value if its a VT_int8 type, 0 otherwise
*/ */
boost::int8_t GetInt8() const; int8_t GetInt8() const;
/** /**
* Get the uint16 value * Get the uint16 value
* *
* @returns the value if its a VT_uint16 type, 0 otherwise * @returns the value if its a VT_uint16 type, 0 otherwise
*/ */
boost::uint16_t GetUint16() const; uint16_t GetUint16() const;
/** /**
* Get the int16 value * Get the int16 value
* *
* @returns the value if its a VT_int16 type, 0 otherwise * @returns the value if its a VT_int16 type, 0 otherwise
*/ */
boost::int16_t GetInt16() const; int16_t GetInt16() const;
/** /**
* Get the uint32 value * Get the uint32 value
* *
* @returns the value if its a VT_uint32 type, 0 otherwise * @returns the value if its a VT_uint32 type, 0 otherwise
*/ */
boost::uint32_t GetUint32() const; uint32_t GetUint32() const;
/** /**
* Get the int32 value * Get the int32 value
* *
* @returns the value if its a VT_int32 type, 0 otherwise * @returns the value if its a VT_int32 type, 0 otherwise
*/ */
boost::int32_t GetInt32() const; int32_t GetInt32() const;
/** /**
* Get the uint64 value * Get the uint64 value
* *
* @returns the value if its a VT_uint64 type, 0 otherwise * @returns the value if its a VT_uint64 type, 0 otherwise
*/ */
boost::uint64_t GetUint64() const; uint64_t GetUint64() const;
/** /**
* Get the timestamp value * Get the timestamp value
@@ -322,7 +323,7 @@ class SIMPLEAMQPCLIENT_EXPORT TableValue {
* *
* @returns the value if its a VT_int64 type, 0 otherwise * @returns the value if its a VT_int64 type, 0 otherwise
*/ */
boost::int64_t GetInt64() const; int64_t GetInt64() const;
/** /**
* Get an integral number * Get an integral number
@@ -334,7 +335,7 @@ class SIMPLEAMQPCLIENT_EXPORT TableValue {
* @returns an integer number if the ValueType is VT_uint8, VT_int8, * @returns an integer number if the ValueType is VT_uint8, VT_int8,
* VT_uint16, VT_int16, VT_uint32, VT_int32,or VT_int64 type, 0 otherwise. * VT_uint16, VT_int16, VT_uint32, VT_int32,or VT_int64 type, 0 otherwise.
*/ */
boost::int64_t GetInteger() const; int64_t GetInteger() const;
/** /**
* Get a float value * Get a float value
@@ -395,42 +396,42 @@ class SIMPLEAMQPCLIENT_EXPORT TableValue {
* *
* @param [in] value the value * @param [in] value the value
*/ */
void Set(boost::uint8_t value); void Set(uint8_t value);
/** /**
* Set the value as a int8_t * Set the value as a int8_t
* *
* @param [in] value the value * @param [in] value the value
*/ */
void Set(boost::int8_t value); void Set(int8_t value);
/** /**
* Set the value as a uint16_t * Set the value as a uint16_t
* *
* @param [in] value the value * @param [in] value the value
*/ */
void Set(boost::uint16_t value); void Set(uint16_t value);
/** /**
* Set the value as a int16_t * Set the value as a int16_t
* *
* @param [in] value the value * @param [in] value the value
*/ */
void Set(boost::int16_t value); void Set(int16_t value);
/** /**
* Set the value as a uint32_t * Set the value as a uint32_t
* *
* @param [in] value the value * @param [in] value the value
*/ */
void Set(boost::uint32_t value); void Set(uint32_t value);
/** /**
* Set the value as a int32_t * Set the value as a int32_t
* *
* @param [in] value the value * @param [in] value the value
*/ */
void Set(boost::int32_t value); void Set(int32_t value);
/** /**
* Set the value as a timestamp. * Set the value as a timestamp.
@@ -444,7 +445,7 @@ class SIMPLEAMQPCLIENT_EXPORT TableValue {
* *
* @param [in] value the value * @param [in] value the value
*/ */
void Set(boost::int64_t value); void Set(int64_t value);
/** /**
* Set the value as a float * Set the value as a float
@@ -489,7 +490,7 @@ class SIMPLEAMQPCLIENT_EXPORT TableValue {
void Set(const Table &value); void Set(const Table &value);
private: private:
boost::scoped_ptr<Detail::TableValueImpl> m_impl; std::unique_ptr<Detail::TableValueImpl> m_impl;
}; };
} // namespace AmqpClient } // namespace AmqpClient

View File

@@ -30,9 +30,9 @@
#include <amqp.h> #include <amqp.h>
#include <boost/cstdint.hpp> #include <cstdint>
#include <boost/shared_ptr.hpp> #include <memory>
#include <boost/variant/variant.hpp> #include <variant>
#include <ctime> #include <ctime>
#include <string> #include <string>
#include <vector> #include <vector>
@@ -42,7 +42,7 @@
namespace AmqpClient { namespace AmqpClient {
namespace Detail { namespace Detail {
typedef boost::shared_ptr<amqp_pool_t> amqp_pool_ptr_t; typedef std::shared_ptr<amqp_pool_t> amqp_pool_ptr_t;
struct void_t {}; struct void_t {};
@@ -50,10 +50,10 @@ inline bool operator==(const void_t &, const void_t &) { return true; }
typedef std::vector<TableValue> array_t; typedef std::vector<TableValue> array_t;
typedef boost::variant<void_t, bool, boost::int8_t, boost::int16_t, typedef std::variant<void_t, bool, int8_t, int16_t,
boost::int32_t, boost::int64_t, float, double, int32_t, int64_t, float, double,
std::string, array_t, Table, boost::uint8_t, std::string, array_t, Table, uint8_t,
boost::uint16_t, boost::uint32_t, boost::uint64_t> uint16_t, uint32_t, uint64_t>
value_t; value_t;
class TableValueImpl { class TableValueImpl {
@@ -81,22 +81,21 @@ class TableValueImpl {
amqp_pool_t &pool); amqp_pool_t &pool);
public: public:
class generate_field_value class generate_field_value {
: public boost::static_visitor<amqp_field_value_t> {
public: public:
explicit generate_field_value(amqp_pool_t &p) : pool(p) {} explicit generate_field_value(amqp_pool_t &p) : pool(p) {}
virtual ~generate_field_value() {} virtual ~generate_field_value() {}
amqp_field_value_t operator()(const void_t) const; amqp_field_value_t operator()(const void_t) const;
amqp_field_value_t operator()(const bool value) const; amqp_field_value_t operator()(const bool value) const;
amqp_field_value_t operator()(const boost::uint8_t value) const; amqp_field_value_t operator()(const uint8_t value) const;
amqp_field_value_t operator()(const boost::int8_t value) const; amqp_field_value_t operator()(const int8_t value) const;
amqp_field_value_t operator()(const boost::uint16_t value) const; amqp_field_value_t operator()(const uint16_t value) const;
amqp_field_value_t operator()(const boost::int16_t value) const; amqp_field_value_t operator()(const int16_t value) const;
amqp_field_value_t operator()(const boost::uint32_t value) const; amqp_field_value_t operator()(const uint32_t value) const;
amqp_field_value_t operator()(const boost::int32_t value) const; amqp_field_value_t operator()(const int32_t value) const;
amqp_field_value_t operator()(const boost::uint64_t value) const; amqp_field_value_t operator()(const uint64_t value) const;
amqp_field_value_t operator()(const boost::int64_t value) const; amqp_field_value_t operator()(const int64_t value) const;
amqp_field_value_t operator()(const float value) const; amqp_field_value_t operator()(const float value) const;
amqp_field_value_t operator()(const double value) const; amqp_field_value_t operator()(const double value) const;
amqp_field_value_t operator()(const std::string &value) const; amqp_field_value_t operator()(const std::string &value) const;

View File

@@ -29,8 +29,8 @@
#include "SimpleAmqpClient/Table.h" #include "SimpleAmqpClient/Table.h"
#include <algorithm> #include <algorithm>
#include <boost/type_traits/remove_cv.hpp> #include <type_traits>
#include <boost/variant/get.hpp> #include <variant>
#include <ctime> #include <ctime>
#include <iterator> #include <iterator>
#include <limits> #include <limits>
@@ -45,32 +45,32 @@ TableValue::TableValue()
TableValue::TableValue(bool value) TableValue::TableValue(bool value)
: m_impl(new Detail::TableValueImpl(value)) {} : m_impl(new Detail::TableValueImpl(value)) {}
TableValue::TableValue(boost::uint8_t value) TableValue::TableValue(uint8_t value)
: m_impl(new Detail::TableValueImpl(value)) {} : m_impl(new Detail::TableValueImpl(value)) {}
TableValue::TableValue(boost::int8_t value) TableValue::TableValue(int8_t value)
: m_impl(new Detail::TableValueImpl(value)) {} : m_impl(new Detail::TableValueImpl(value)) {}
TableValue::TableValue(boost::uint16_t value) TableValue::TableValue(uint16_t value)
: m_impl(new Detail::TableValueImpl(value)) {} : m_impl(new Detail::TableValueImpl(value)) {}
TableValue::TableValue(boost::int16_t value) TableValue::TableValue(int16_t value)
: m_impl(new Detail::TableValueImpl(value)) {} : m_impl(new Detail::TableValueImpl(value)) {}
TableValue::TableValue(boost::uint32_t value) TableValue::TableValue(uint32_t value)
: m_impl(new Detail::TableValueImpl(value)) {} : m_impl(new Detail::TableValueImpl(value)) {}
TableValue::TableValue(boost::int32_t value) TableValue::TableValue(int32_t value)
: m_impl(new Detail::TableValueImpl(value)) {} : m_impl(new Detail::TableValueImpl(value)) {}
TableValue::TableValue(boost::uint64_t value) TableValue::TableValue(uint64_t value)
: m_impl(new Detail::TableValueImpl(value)) {} : m_impl(new Detail::TableValueImpl(value)) {}
TableValue TableValue::Timestamp(std::time_t ts) { TableValue TableValue::Timestamp(std::time_t ts) {
return TableValue(static_cast<boost::uint64_t>(ts)); return TableValue(static_cast<uint64_t>(ts));
} }
TableValue::TableValue(boost::int64_t value) TableValue::TableValue(int64_t value)
: m_impl(new Detail::TableValueImpl(value)) {} : m_impl(new Detail::TableValueImpl(value)) {}
TableValue::TableValue(float value) TableValue::TableValue(float value)
@@ -134,45 +134,45 @@ bool TableValue::operator!=(const TableValue &l) const {
TableValue::~TableValue() {} TableValue::~TableValue() {}
TableValue::ValueType TableValue::GetType() const { TableValue::ValueType TableValue::GetType() const {
return static_cast<ValueType>(m_impl->m_value.which()); return static_cast<ValueType>(m_impl->m_value.index());
} }
bool TableValue::GetBool() const { return boost::get<bool>(m_impl->m_value); } bool TableValue::GetBool() const { return std::get<bool>(m_impl->m_value); }
boost::uint8_t TableValue::GetUint8() const { uint8_t TableValue::GetUint8() const {
return boost::get<boost::uint8_t>(m_impl->m_value); return std::get<uint8_t>(m_impl->m_value);
} }
boost::int8_t TableValue::GetInt8() const { int8_t TableValue::GetInt8() const {
return boost::get<boost::int8_t>(m_impl->m_value); return std::get<int8_t>(m_impl->m_value);
} }
boost::uint16_t TableValue::GetUint16() const { uint16_t TableValue::GetUint16() const {
return boost::get<boost::uint16_t>(m_impl->m_value); return std::get<uint16_t>(m_impl->m_value);
} }
boost::int16_t TableValue::GetInt16() const { int16_t TableValue::GetInt16() const {
return boost::get<boost::int16_t>(m_impl->m_value); return std::get<int16_t>(m_impl->m_value);
} }
boost::uint32_t TableValue::GetUint32() const { uint32_t TableValue::GetUint32() const {
return boost::get<boost::uint32_t>(m_impl->m_value); return std::get<uint32_t>(m_impl->m_value);
} }
boost::int32_t TableValue::GetInt32() const { int32_t TableValue::GetInt32() const {
return boost::get<boost::int32_t>(m_impl->m_value); return std::get<int32_t>(m_impl->m_value);
} }
std::time_t TableValue::GetTimestamp() const { std::time_t TableValue::GetTimestamp() const {
return static_cast<std::time_t>(boost::get<boost::uint64_t>(m_impl->m_value)); return static_cast<std::time_t>(std::get<uint64_t>(m_impl->m_value));
} }
boost::int64_t TableValue::GetInt64() const { int64_t TableValue::GetInt64() const {
return boost::get<boost::int64_t>(m_impl->m_value); return std::get<int64_t>(m_impl->m_value);
} }
boost::int64_t TableValue::GetInteger() const { int64_t TableValue::GetInteger() const {
switch (m_impl->m_value.which()) { switch (m_impl->m_value.index()) {
case VT_uint8: case VT_uint8:
return GetUint8(); return GetUint8();
case VT_int8: case VT_int8:
@@ -188,62 +188,62 @@ boost::int64_t TableValue::GetInteger() const {
case VT_int64: case VT_int64:
return GetInt64(); return GetInt64();
default: default:
throw boost::bad_get(); throw std::bad_variant_access();
} }
} }
float TableValue::GetFloat() const { float TableValue::GetFloat() const {
return boost::get<float>(m_impl->m_value); return std::get<float>(m_impl->m_value);
} }
double TableValue::GetDouble() const { double TableValue::GetDouble() const {
return boost::get<double>(m_impl->m_value); return std::get<double>(m_impl->m_value);
} }
double TableValue::GetReal() const { double TableValue::GetReal() const {
switch (m_impl->m_value.which()) { switch (m_impl->m_value.index()) {
case VT_float: case VT_float:
return GetFloat(); return GetFloat();
case VT_double: case VT_double:
return GetDouble(); return GetDouble();
default: default:
throw boost::bad_get(); throw std::bad_variant_access();
} }
} }
std::string TableValue::GetString() const { std::string TableValue::GetString() const {
return boost::get<std::string>(m_impl->m_value); return std::get<std::string>(m_impl->m_value);
} }
std::vector<TableValue> TableValue::GetArray() const { std::vector<TableValue> TableValue::GetArray() const {
return boost::get<Detail::array_t>(m_impl->m_value); return std::get<Detail::array_t>(m_impl->m_value);
} }
Table TableValue::GetTable() const { Table TableValue::GetTable() const {
return boost::get<Table>(m_impl->m_value); return std::get<Table>(m_impl->m_value);
} }
void TableValue::Set() { m_impl->m_value = Detail::void_t(); } void TableValue::Set() { m_impl->m_value = Detail::void_t(); }
void TableValue::Set(bool value) { m_impl->m_value = value; } void TableValue::Set(bool value) { m_impl->m_value = value; }
void TableValue::Set(boost::uint8_t value) { m_impl->m_value = value; } void TableValue::Set(uint8_t value) { m_impl->m_value = value; }
void TableValue::Set(boost::int8_t value) { m_impl->m_value = value; } void TableValue::Set(int8_t value) { m_impl->m_value = value; }
void TableValue::Set(boost::uint16_t value) { m_impl->m_value = value; } void TableValue::Set(uint16_t value) { m_impl->m_value = value; }
void TableValue::Set(boost::int16_t value) { m_impl->m_value = value; } void TableValue::Set(int16_t value) { m_impl->m_value = value; }
void TableValue::Set(boost::uint32_t value) { m_impl->m_value = value; } void TableValue::Set(uint32_t value) { m_impl->m_value = value; }
void TableValue::Set(boost::int32_t value) { m_impl->m_value = value; } void TableValue::Set(int32_t value) { m_impl->m_value = value; }
void TableValue::SetTimestamp(std::time_t value) { void TableValue::SetTimestamp(std::time_t value) {
m_impl->m_value = static_cast<boost::uint64_t>(value); m_impl->m_value = static_cast<uint64_t>(value);
} }
void TableValue::Set(boost::int64_t value) { m_impl->m_value = value; } void TableValue::Set(int64_t value) { m_impl->m_value = value; }
void TableValue::Set(float value) { m_impl->m_value = value; } void TableValue::Set(float value) { m_impl->m_value = value; }

View File

@@ -36,9 +36,8 @@
#include <string.h> #include <string.h>
#include <algorithm> #include <algorithm>
#include <boost/foreach.hpp>
#include <boost/variant/apply_visitor.hpp> #include <variant>
#include <boost/variant/static_visitor.hpp>
#include <new> #include <new>
#ifdef _MSC_VER #ifdef _MSC_VER
@@ -64,7 +63,7 @@ amqp_field_value_t TableValueImpl::generate_field_value::operator()(
} }
amqp_field_value_t TableValueImpl::generate_field_value::operator()( amqp_field_value_t TableValueImpl::generate_field_value::operator()(
const boost::uint8_t value) const { const uint8_t value) const {
amqp_field_value_t v; amqp_field_value_t v;
v.kind = AMQP_FIELD_KIND_U8; v.kind = AMQP_FIELD_KIND_U8;
v.value.u8 = value; v.value.u8 = value;
@@ -72,7 +71,7 @@ amqp_field_value_t TableValueImpl::generate_field_value::operator()(
} }
amqp_field_value_t TableValueImpl::generate_field_value::operator()( amqp_field_value_t TableValueImpl::generate_field_value::operator()(
const boost::int8_t value) const { const int8_t value) const {
amqp_field_value_t v; amqp_field_value_t v;
v.kind = AMQP_FIELD_KIND_I8; v.kind = AMQP_FIELD_KIND_I8;
v.value.i8 = value; v.value.i8 = value;
@@ -80,7 +79,7 @@ amqp_field_value_t TableValueImpl::generate_field_value::operator()(
} }
amqp_field_value_t TableValueImpl::generate_field_value::operator()( amqp_field_value_t TableValueImpl::generate_field_value::operator()(
const boost::uint16_t value) const { const uint16_t value) const {
amqp_field_value_t v; amqp_field_value_t v;
v.kind = AMQP_FIELD_KIND_U16; v.kind = AMQP_FIELD_KIND_U16;
v.value.u16 = value; v.value.u16 = value;
@@ -88,7 +87,7 @@ amqp_field_value_t TableValueImpl::generate_field_value::operator()(
} }
amqp_field_value_t TableValueImpl::generate_field_value::operator()( amqp_field_value_t TableValueImpl::generate_field_value::operator()(
const boost::int16_t value) const { const int16_t value) const {
amqp_field_value_t v; amqp_field_value_t v;
v.kind = AMQP_FIELD_KIND_I16; v.kind = AMQP_FIELD_KIND_I16;
v.value.i16 = value; v.value.i16 = value;
@@ -96,7 +95,7 @@ amqp_field_value_t TableValueImpl::generate_field_value::operator()(
} }
amqp_field_value_t TableValueImpl::generate_field_value::operator()( amqp_field_value_t TableValueImpl::generate_field_value::operator()(
const boost::uint32_t value) const { const uint32_t value) const {
amqp_field_value_t v; amqp_field_value_t v;
v.kind = AMQP_FIELD_KIND_U32; v.kind = AMQP_FIELD_KIND_U32;
v.value.u32 = value; v.value.u32 = value;
@@ -104,7 +103,7 @@ amqp_field_value_t TableValueImpl::generate_field_value::operator()(
} }
amqp_field_value_t TableValueImpl::generate_field_value::operator()( amqp_field_value_t TableValueImpl::generate_field_value::operator()(
const boost::int32_t value) const { const int32_t value) const {
amqp_field_value_t v; amqp_field_value_t v;
v.kind = AMQP_FIELD_KIND_I32; v.kind = AMQP_FIELD_KIND_I32;
v.value.i32 = value; v.value.i32 = value;
@@ -112,7 +111,7 @@ amqp_field_value_t TableValueImpl::generate_field_value::operator()(
} }
amqp_field_value_t TableValueImpl::generate_field_value::operator()( amqp_field_value_t TableValueImpl::generate_field_value::operator()(
const boost::uint64_t value) const { const uint64_t value) const {
amqp_field_value_t v; amqp_field_value_t v;
v.kind = AMQP_FIELD_KIND_TIMESTAMP; v.kind = AMQP_FIELD_KIND_TIMESTAMP;
v.value.u64 = value; v.value.u64 = value;
@@ -120,7 +119,7 @@ amqp_field_value_t TableValueImpl::generate_field_value::operator()(
} }
amqp_field_value_t TableValueImpl::generate_field_value::operator()( amqp_field_value_t TableValueImpl::generate_field_value::operator()(
const boost::int64_t value) const { const int64_t value) const {
amqp_field_value_t v; amqp_field_value_t v;
v.kind = AMQP_FIELD_KIND_I64; v.kind = AMQP_FIELD_KIND_I64;
v.value.i64 = value; v.value.i64 = value;
@@ -167,7 +166,7 @@ amqp_field_value_t TableValueImpl::generate_field_value::operator()(
for (array_t::const_iterator it = value.begin(); it != value.end(); for (array_t::const_iterator it = value.begin(); it != value.end();
++it, ++output_iterator) { ++it, ++output_iterator) {
*output_iterator = *output_iterator =
boost::apply_visitor(generate_field_value(pool), it->m_impl->m_value); std::visit(generate_field_value(pool), it->m_impl->m_value);
} }
return v; return v;
} }
@@ -191,7 +190,7 @@ amqp_table_t TableValueImpl::CreateAmqpTable(const Table &table,
return AMQP_EMPTY_TABLE; return AMQP_EMPTY_TABLE;
} }
pool = boost::shared_ptr<amqp_pool_t>(new amqp_pool_t, free_pool); pool = std::shared_ptr<amqp_pool_t>(new amqp_pool_t, free_pool);
init_amqp_pool(pool.get(), 1024); init_amqp_pool(pool.get(), 1024);
return CreateAmqpTableInner(table, *pool.get()); return CreateAmqpTableInner(table, *pool.get());
@@ -221,7 +220,7 @@ amqp_table_t TableValueImpl::CreateAmqpTableInner(const Table &table,
std::copy(it->first.begin(), it->first.end(), (char *)output_it->key.bytes); std::copy(it->first.begin(), it->first.end(), (char *)output_it->key.bytes);
output_it->value = boost::apply_visitor( output_it->value = std::visit(
TableValueImpl::generate_field_value(pool), it->second.m_impl->m_value); TableValueImpl::generate_field_value(pool), it->second.m_impl->m_value);
} }
@@ -297,7 +296,7 @@ amqp_table_t TableValueImpl::CopyTable(const amqp_table_t &table,
return AMQP_EMPTY_TABLE; return AMQP_EMPTY_TABLE;
} }
pool = boost::shared_ptr<amqp_pool_t>(new amqp_pool_t, free_pool); pool = std::shared_ptr<amqp_pool_t>(new amqp_pool_t, free_pool);
init_amqp_pool(pool.get(), 1024); init_amqp_pool(pool.get(), 1024);
return CopyTableInner(table, *pool.get()); return CopyTableInner(table, *pool.get());

View File

@@ -1,4 +1,3 @@
include_directories(BEFORE SYSTEM ${gtest_SOURCE_DIR}/include)
include_directories(../src) include_directories(../src)
add_executable(test_api add_executable(test_api
@@ -15,5 +14,9 @@ add_executable(test_api
test_ack.cpp test_ack.cpp
test_nack.cpp test_nack.cpp
) )
target_link_libraries(test_api SimpleAmqpClient gtest gtest_main) target_link_libraries(test_api SimpleAmqpClient xgoogletest::xgoogletest)
add_test(test_api test_api) add_test(test_api test_api)
if(MSVC)
target_compile_options(test_api PRIVATE /utf-8)
endif()

View File

@@ -51,7 +51,7 @@ class connected_test : public ::testing::Test {
if (NULL != host) { if (NULL != host) {
return std::string(host); return std::string(host);
} }
return std::string(""); return std::string("127.0.0.1");
} }
}; };

View File

@@ -1,3 +1,4 @@
#include <functional>
/* /*
* ***** BEGIN LICENSE BLOCK ***** * ***** BEGIN LICENSE BLOCK *****
* Version: MIT * Version: MIT

View File

@@ -29,7 +29,7 @@
#include <amqp.h> #include <amqp.h>
#include <algorithm> #include <algorithm>
#include <boost/array.hpp> #include <array>
#include <iostream> #include <iostream>
#include "connected_test.h" #include "connected_test.h"
@@ -103,13 +103,13 @@ TEST(basic_message, initial_message_replace2) {
} }
TEST(basic_message, embedded_nulls) { TEST(basic_message, embedded_nulls) {
const boost::array<char, 7> message_data = { const std::array<char, 7> message_data = {
{'a', 'b', 'c', 0, '1', '2', '3'}}; {'a', 'b', 'c', 0, '1', '2', '3'}};
const std::string body(message_data.data(), message_data.size()); const std::string body(message_data.data(), message_data.size());
BasicMessage::ptr_t message = BasicMessage::Create(body); BasicMessage::ptr_t message = BasicMessage::Create(body);
EXPECT_EQ(body, message->Body()); EXPECT_EQ(body, message->Body());
const boost::array<char, 7> message_data2 = { const std::array<char, 7> message_data2 = {
{'1', '2', '3', 0, 'a', 'b', 'c'}}; {'1', '2', '3', 0, 'a', 'b', 'c'}};
const std::string body2(message_data2.data(), message_data2.size()); const std::string body2(message_data2.data(), message_data2.size());
message->Body(body2); message->Body(body2);

View File

@@ -83,8 +83,8 @@ TEST_F(connected_test, queue_declare_notautodelete) {
} }
TEST_F(connected_test, queue_declare_counts) { TEST_F(connected_test, queue_declare_counts) {
boost::uint32_t message_count = 123; uint32_t message_count = 123;
boost::uint32_t consumer_count = 123; uint32_t consumer_count = 123;
std::string queue = channel->DeclareQueueWithCounts( std::string queue = channel->DeclareQueueWithCounts(
"queue_declare_counts", message_count, consumer_count); "queue_declare_counts", message_count, consumer_count);
@@ -110,8 +110,8 @@ TEST_F(connected_test, queue_declare_counts) {
} }
TEST_F(connected_test, queue_declare_counts_table) { TEST_F(connected_test, queue_declare_counts_table) {
boost::uint32_t message_count = 123; uint32_t message_count = 123;
boost::uint32_t consumer_count = 123; uint32_t consumer_count = 123;
Table qTable; Table qTable;

File diff suppressed because it is too large Load Diff