Build examples now with travis-ci to ensure new changes don't break existing code. Fixed warnings as a result of lambda captures.

This commit is contained in:
zerodefect 2018-01-30 10:07:27 +00:00
parent c287382770
commit 4b2c423896
13 changed files with 216 additions and 63 deletions

View File

@ -1,5 +1,5 @@
################
# project config
# Config
################
# C++ project
@ -11,7 +11,14 @@ group: edge
################
# build matrix
# Services
################
services:
- docker
################
# Build matrix
################
matrix:
@ -22,61 +29,63 @@ matrix:
################
- os: linux
compiler: gcc
env: COMPILER=g++-5
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-5', 'ninja-build']
env:
- COMPILER_PACKAGE=g++-6
- C_COMPILER=gcc-6
- CXX_COMPILER=g++-6
- os: linux
compiler: gcc
env: COMPILER=g++-6
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-6', 'ninja-build']
- os: linux
compiler: gcc
env: COMPILER=g++-7
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-7', 'ninja-build']
env:
- COMPILER_PACKAGE=g++-7
- C_COMPILER=gcc-7
- CXX_COMPILER=g++-7
################
# Linux / Clang
################
- os: linux
compiler: clang
env: COMPILER=clang++-4.0
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0']
packages: ['clang-4.0', 'ninja-build']
env:
- COMPILER_PACKAGE=clang-4.0
- C_COMPILER=clang-4.0
- CXX_COMPILER=clang++-4.0
- os: linux
compiler: clang
env: COMPILER=clang++-5.0
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-5.0']
packages: ['clang-5.0', 'ninja-build']
env:
- COMPILER_PACKAGE=clang-5.0
- C_COMPILER=clang-5.0
- CXX_COMPILER=clang++-5.0
before_install:
# Show OS/compiler version (this may not be the same OS as the Docker container)
- uname -a
# Use an artful container - gives us access to latest compilers.
- docker run -d --name ubuntu-test-container -v $(pwd):/travis ubuntu:artful tail -f /dev/null
- docker ps
install:
# Create our container
- docker exec -t ubuntu-test-container bash -c "apt-get update -y &&
apt-get --no-install-recommends install -y software-properties-common cmake
ninja-build libboost-all-dev libev-dev libuv1-dev ninja-build $COMPILER_PACKAGE &&
apt-get -y clean && rm -rf /var/lib/apt/lists/*"
################
# build / test
# Build / Test
################
script:
# show OS/compiler version
- uname -a
- $CXX --version
# compile and execute unit tests
- mkdir -p build.release && cd build.release
- cmake .. ${CMAKE_OPTIONS} -GNinja && cmake --build . --config Release
- cd ..
# Run the container that we created and build the code
- docker exec -t ubuntu-test-container bash -c "cd /travis &&
export CC=/usr/bin/$C_COMPILER &&
export CXX=/usr/bin/$CXX_COMPILER &&
mkdir build.release && cd build.release &&
cmake .. ${CMAKE_OPTIONS} -DAMQP-CPP_BUILD_EXAMPLES=ON -DAMQP-CPP_LINUX_TCP=ON -GNinja &&
cmake --build . --config Release &&
cd .."

View File

@ -18,6 +18,7 @@ project(amqpcpp)
# build options
option(AMQP-CPP_BUILD_SHARED "Build shared library. If off, build will be static." OFF)
option(AMQP-CPP_LINUX_TCP "Build linux sockets implementation." OFF)
option(AMQP-CPP_BUILD_EXAMPLES "Build amqpcpp examples" OFF)
# ensure c++11 on all compilers
set (CMAKE_CXX_STANDARD 11)
@ -91,6 +92,11 @@ else()
ARCHIVE DESTINATION lib
)
endif()
if(AMQP-CPP_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# copy header files
install(DIRECTORY include/amqpcpp/ DESTINATION include/amqpcpp
FILES_MATCHING PATTERN "*.h")

View File

@ -1,6 +1,8 @@
AMQP-CPP
========
[![Build Status](https://travis-ci.org/CopernicaMarketingSoftware/AMQP-CPP.svg?branch=master)](https://travis-ci.org/CopernicaMarketingSoftware/AMQP-CPP)
AMQP-CPP is a C++ library for communicating with a RabbitMQ message broker. The
library can be used to parse incoming data from a RabbitMQ server, and to
generate frames that can be sent to a RabbitMQ server.

32
examples/CMakeLists.txt Normal file
View File

@ -0,0 +1,32 @@
###################################
# Boost
###################################
add_executable(amqpcpp_boost_example libboostasio.cpp)
add_dependencies(amqpcpp_boost_example amqpcpp)
target_link_libraries(amqpcpp_boost_example amqpcpp boost_system pthread)
###################################
# Libev
###################################
add_executable(amqpcpp_libev_example libev.cpp)
add_dependencies(amqpcpp_libev_example amqpcpp)
target_link_libraries(amqpcpp_libev_example amqpcpp ev pthread)
###################################
# Libuv
###################################
add_executable(amqpcpp_libuv_example libuv.cpp)
add_dependencies(amqpcpp_libuv_example amqpcpp)
target_link_libraries(amqpcpp_libuv_example amqpcpp uv pthread)

View File

@ -24,9 +24,12 @@
#include <boost/asio/strand.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/posix/stream_descriptor.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include "amqpcpp/linux_tcp.h"
// C++17 has 'weak_from_this()' support.
#if __cplusplus >= 201701L
#define PTR_FROM_THIS weak_from_this
@ -60,11 +63,13 @@ private:
*/
boost::asio::io_service & _ioservice;
typedef std::weak_ptr<boost::asio::io_service::strand> strand_weak_ptr;
/**
* The boost asio io_service::strand managed pointer.
* @var class std::shared_ptr<boost::asio::io_service>
*/
std::weak_ptr<boost::asio::io_service::strand> _strand;
strand_weak_ptr _wpstrand;
/**
* The boost tcp socket.
@ -108,15 +113,17 @@ private:
*/
handler_cb get_dispatch_wrapper(io_handler fn)
{
return [fn, strand = _strand](const boost::system::error_code &ec, const std::size_t bytes_transferred)
const strand_weak_ptr wpstrand = _wpstrand;
return [fn, wpstrand](const boost::system::error_code &ec, const std::size_t bytes_transferred)
{
const std::shared_ptr<boost::asio::io_service::strand> apStrand = strand.lock();
if (!apStrand)
const strand_shared_ptr strand = wpstrand.lock();
if (!strand)
{
fn(boost::system::errc::make_error_code(boost::system::errc::operation_canceled), std::size_t{0});
return;
}
apStrand->dispatch(boost::bind(fn, ec, bytes_transferred));
strand->dispatch(boost::bind(fn, ec, bytes_transferred));
};
}
@ -229,14 +236,14 @@ private:
* Constructor- initialises the watcher and assigns the filedescriptor to
* a boost socket for monitoring.
* @param io_service The boost io_service
* @param strand A weak pointer to a io_service::strand instance.
* @param wpstrand A weak pointer to a io_service::strand instance.
* @param fd The filedescriptor being watched
*/
Watcher(boost::asio::io_service &io_service,
const std::weak_ptr<boost::asio::io_service::strand> strand,
const strand_weak_ptr wpstrand,
const int fd) :
_ioservice(io_service),
_strand(strand),
_wpstrand(wpstrand),
_socket(_ioservice)
{
_socket.assign(fd);
@ -309,11 +316,13 @@ private:
*/
boost::asio::io_service & _ioservice;
typedef std::weak_ptr<boost::asio::io_service::strand> strand_weak_ptr;
/**
* The boost asio io_service::strand managed pointer.
* @var class std::shared_ptr<boost::asio::io_service>
*/
std::weak_ptr<boost::asio::io_service::strand> _strand;
strand_weak_ptr _wpstrand;
/**
* The boost asynchronous deadline timer.
@ -330,21 +339,24 @@ private:
*/
handler_fn get_handler(TcpConnection *const connection, const uint16_t timeout)
{
auto fn = boost::bind(&Timer::timeout,
const auto fn = boost::bind(&Timer::timeout,
this,
_1,
PTR_FROM_THIS(),
connection,
timeout);
return [fn, strand = _strand](const boost::system::error_code &ec)
const strand_weak_ptr wpstrand = _wpstrand;
return [fn, wpstrand](const boost::system::error_code &ec)
{
const std::shared_ptr<boost::asio::io_service::strand> apStrand = strand.lock();
if (!apStrand)
const strand_shared_ptr strand = wpstrand.lock();
if (!strand)
{
fn(boost::system::errc::make_error_code(boost::system::errc::operation_canceled));
return;
}
apStrand->dispatch(boost::bind(fn, ec));
strand->dispatch(boost::bind(fn, ec));
};
}
@ -394,13 +406,13 @@ private:
/**
* Constructor
* @param io_service The boost asio io_service.
* @param strand A weak pointer to a io_service::strand instance.
* @param wpstrand A weak pointer to a io_service::strand instance.
*/
Timer(boost::asio::io_service &io_service,
const std::weak_ptr<boost::asio::io_service::strand> strand) :
_ioservice(io_service),
_strand(strand),
_timer(_ioservice)
const strand_weak_ptr wpstrand) :
_ioservice(io_service),
_wpstrand(wpstrand),
_timer(_ioservice)
{
}
@ -446,11 +458,13 @@ private:
*/
boost::asio::io_service & _ioservice;
typedef std::shared_ptr<boost::asio::io_service::strand> strand_shared_ptr;
/**
* The boost asio io_service::strand managed pointer.
* @var class std::shared_ptr<boost::asio::io_service>
*/
std::shared_ptr<boost::asio::io_service::strand> _strand;
strand_shared_ptr _strand;
/**

View File

@ -21,6 +21,8 @@
*/
#include <ev.h>
#include "amqpcpp/linux_tcp.h"
/**
* Set up namespace
*/

View File

@ -21,6 +21,8 @@
*/
#include <uv.h>
#include "amqpcpp/linux_tcp.h"
/**
* Set up namespace
*/

View File

@ -1,14 +1,91 @@
add_sources(
array.cpp
basicackframe.h
basiccancelframe.h
basiccancelokframe.h
basicconsumeframe.h
basicconsumeokframe.h
basicdeliverframe.h
basicframe.h
basicgetemptyframe.h
basicgetframe.h
basicgetokframe.h
basicheaderframe.h
basicnackframe.h
basicpublishframe.h
basicqosframe.h
basicqosokframe.h
basicrecoverasyncframe.h
basicrecoverframe.h
basicrecoverokframe.h
basicrejectframe.h
basicreturnframe.h
bodyframe.h
channelcloseframe.h
channelcloseokframe.h
channelflowframe.h
channelflowokframe.h
channelframe.h
channelimpl.cpp
channelopenframe.h
channelopenokframe.h
connectioncloseframe.h
connectioncloseokframe.h
connectionframe.h
connectionimpl.cpp
connectionopenframe.h
connectionopenokframe.h
connectionsecureframe.h
connectionsecureokframe.h
connectionstartframe.h
connectionstartokframe.h
connectiontuneframe.h
connectiontuneokframe.h
consumedmessage.h
deferredcancel.cpp
deferredconsumer.cpp
deferredconsumerbase.cpp
deferredget.cpp
exchangebindframe.h
exchangebindokframe.h
exchangedeclareframe.h
exchangedeclareokframe.h
exchangedeleteframe.h
exchangedeleteokframe.h
exchangeframe.h
exchangeunbindframe.h
exchangeunbindokframe.h
extframe.h
field.cpp
flags.cpp
framecheck.h
headerframe.h
heartbeatframe.h
includes.h
methodframe.h
passthroughbuffer.h
protocolheaderframe.h
queuebindframe.h
queuebindokframe.h
queuedeclareframe.h
queuedeclareokframe.h
queuedeleteframe.h
queuedeleteokframe.h
queueframe.h
queuepurgeframe.h
queuepurgeokframe.h
queueunbindframe.h
queueunbindokframe.h
receivedframe.cpp
reducedbuffer.h
returnedmessage.h
table.cpp
transactioncommitframe.h
transactioncommitokframe.h
transactionframe.h
transactionrollbackframe.h
transactionrollbackokframe.h
transactionselectframe.h
transactionselectokframe.h
watchable.cpp
)

View File

@ -1,3 +1,12 @@
add_sources(
addressinfo.h
includes.h
pipe.h
tcpclosed.h
tcpconnected.h
tcpconnection.cpp
tcpinbuffer.h
tcpoutbuffer.h
tcpresolver.h
tcpstate.h
)