Merge pull request #173 from zerodefect/build-example-ci

Build examples now with travis-ci to ensure new changes
This commit is contained in:
Emiel Bruijntjes 2018-01-30 14:53:43 +01:00 committed by GitHub
commit 0cdb1fe500
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 217 additions and 66 deletions

View File

@ -1,5 +1,5 @@
################ ################
# project config # Config
################ ################
# C++ project # C++ project
@ -11,7 +11,14 @@ group: edge
################ ################
# build matrix # Services
################
services:
- docker
################
# Build matrix
################ ################
matrix: matrix:
@ -22,61 +29,63 @@ matrix:
################ ################
- os: linux - os: linux
compiler: gcc env:
env: COMPILER=g++-5 - COMPILER_PACKAGE=g++-6
addons: - C_COMPILER=gcc-6
apt: - CXX_COMPILER=g++-6
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-5', 'ninja-build']
- os: linux - os: linux
compiler: gcc compiler: gcc
env: COMPILER=g++-6 env:
addons: - COMPILER_PACKAGE=g++-7
apt: - C_COMPILER=gcc-7
sources: ['ubuntu-toolchain-r-test'] - CXX_COMPILER=g++-7
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']
################ ################
# Linux / Clang # Linux / Clang
################ ################
- os: linux - os: linux
compiler: clang env:
env: COMPILER=clang++-4.0 - COMPILER_PACKAGE=clang-4.0
addons: - C_COMPILER=clang-4.0
apt: - CXX_COMPILER=clang++-4.0
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0']
packages: ['clang-4.0', 'ninja-build']
- os: linux - os: linux
compiler: clang env:
env: COMPILER=clang++-5.0 - COMPILER_PACKAGE=clang-5.0
addons: - C_COMPILER=clang-5.0
apt: - CXX_COMPILER=clang++-5.0
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-5.0']
packages: ['clang-5.0', 'ninja-build'] 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: script:
# show OS/compiler version # Run the container that we created and build the code
- uname -a - docker exec -t ubuntu-test-container bash -c "cd /travis &&
- $CXX --version export CC=/usr/bin/$C_COMPILER &&
export CXX=/usr/bin/$CXX_COMPILER &&
# compile and execute unit tests mkdir build.release && cd build.release &&
- mkdir -p build.release && cd build.release cmake .. ${CMAKE_OPTIONS} -DAMQP-CPP_BUILD_EXAMPLES=ON -DAMQP-CPP_LINUX_TCP=ON -GNinja &&
- cmake .. ${CMAKE_OPTIONS} -GNinja && cmake --build . --config Release cmake --build . --config Release &&
- cd .. cd .."

View File

@ -18,6 +18,7 @@ project(amqpcpp)
# build options # build options
option(AMQP-CPP_BUILD_SHARED "Build shared library. If off, build will be static." OFF) 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_LINUX_TCP "Build linux sockets implementation." OFF)
option(AMQP-CPP_BUILD_EXAMPLES "Build amqpcpp examples" OFF)
# ensure c++11 on all compilers # ensure c++11 on all compilers
set (CMAKE_CXX_STANDARD 11) set (CMAKE_CXX_STANDARD 11)
@ -51,6 +52,11 @@ if(AMQP-CPP_LINUX_TCP)
add_subdirectory(src/linux_tcp) add_subdirectory(src/linux_tcp)
endif() endif()
# potentially build the examples
if(AMQP-CPP_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# settings for specific compilers # settings for specific compilers
# ------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------
@ -91,6 +97,7 @@ else()
ARCHIVE DESTINATION lib ARCHIVE DESTINATION lib
) )
endif() endif()
# copy header files # copy header files
install(DIRECTORY include/amqpcpp/ DESTINATION include/amqpcpp install(DIRECTORY include/amqpcpp/ DESTINATION include/amqpcpp
FILES_MATCHING PATTERN "*.h") FILES_MATCHING PATTERN "*.h")

View File

@ -1,6 +1,8 @@
AMQP-CPP 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 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 library can be used to parse incoming data from a RabbitMQ server, and to
generate frames that can be sent to a RabbitMQ server. 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

@ -80,7 +80,5 @@
#include "amqpcpp/connection.h" #include "amqpcpp/connection.h"
// tcp level includes // tcp level includes
#include "amqpcpp/tcphandler.h" #include "amqpcpp/linux_tcp.h"
#include "amqpcpp/tcpconnection.h"
#include "amqpcpp/tcpchannel.h"

View File

@ -27,6 +27,8 @@
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/function.hpp> #include <boost/function.hpp>
#include "amqpcpp/linux_tcp.h"
// C++17 has 'weak_from_this()' support. // C++17 has 'weak_from_this()' support.
#if __cplusplus >= 201701L #if __cplusplus >= 201701L
#define PTR_FROM_THIS weak_from_this #define PTR_FROM_THIS weak_from_this
@ -60,11 +62,13 @@ private:
*/ */
boost::asio::io_service & _ioservice; 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. * The boost asio io_service::strand managed pointer.
* @var class std::shared_ptr<boost::asio::io_service> * @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. * The boost tcp socket.
@ -108,15 +112,17 @@ private:
*/ */
handler_cb get_dispatch_wrapper(io_handler fn) 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(); const strand_shared_ptr strand = wpstrand.lock();
if (!apStrand) if (!strand)
{ {
fn(boost::system::errc::make_error_code(boost::system::errc::operation_canceled), std::size_t{0}); fn(boost::system::errc::make_error_code(boost::system::errc::operation_canceled), std::size_t{0});
return; return;
} }
apStrand->dispatch(boost::bind(fn, ec, bytes_transferred)); strand->dispatch(boost::bind(fn, ec, bytes_transferred));
}; };
} }
@ -229,14 +235,14 @@ private:
* Constructor- initialises the watcher and assigns the filedescriptor to * Constructor- initialises the watcher and assigns the filedescriptor to
* a boost socket for monitoring. * a boost socket for monitoring.
* @param io_service The boost io_service * @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 * @param fd The filedescriptor being watched
*/ */
Watcher(boost::asio::io_service &io_service, 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) : const int fd) :
_ioservice(io_service), _ioservice(io_service),
_strand(strand), _wpstrand(wpstrand),
_socket(_ioservice) _socket(_ioservice)
{ {
_socket.assign(fd); _socket.assign(fd);
@ -309,11 +315,13 @@ private:
*/ */
boost::asio::io_service & _ioservice; 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. * The boost asio io_service::strand managed pointer.
* @var class std::shared_ptr<boost::asio::io_service> * @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. * The boost asynchronous deadline timer.
@ -330,21 +338,24 @@ private:
*/ */
handler_fn get_handler(TcpConnection *const connection, const uint16_t timeout) 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, this,
_1, _1,
PTR_FROM_THIS(), PTR_FROM_THIS(),
connection, connection,
timeout); 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(); const strand_shared_ptr strand = wpstrand.lock();
if (!apStrand) if (!strand)
{ {
fn(boost::system::errc::make_error_code(boost::system::errc::operation_canceled)); fn(boost::system::errc::make_error_code(boost::system::errc::operation_canceled));
return; return;
} }
apStrand->dispatch(boost::bind(fn, ec)); strand->dispatch(boost::bind(fn, ec));
}; };
} }
@ -394,13 +405,13 @@ private:
/** /**
* Constructor * Constructor
* @param io_service The boost asio io_service. * @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, Timer(boost::asio::io_service &io_service,
const std::weak_ptr<boost::asio::io_service::strand> strand) : const strand_weak_ptr wpstrand) :
_ioservice(io_service), _ioservice(io_service),
_strand(strand), _wpstrand(wpstrand),
_timer(_ioservice) _timer(_ioservice)
{ {
} }
@ -446,11 +457,13 @@ private:
*/ */
boost::asio::io_service & _ioservice; 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. * The boost asio io_service::strand managed pointer.
* @var class std::shared_ptr<boost::asio::io_service> * @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 <ev.h>
#include "amqpcpp/linux_tcp.h"
/** /**
* Set up namespace * Set up namespace
*/ */

View File

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

View File

@ -1,14 +1,91 @@
add_sources( add_sources(
array.cpp 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 channelimpl.cpp
channelopenframe.h
channelopenokframe.h
connectioncloseframe.h
connectioncloseokframe.h
connectionframe.h
connectionimpl.cpp connectionimpl.cpp
connectionopenframe.h
connectionopenokframe.h
connectionsecureframe.h
connectionsecureokframe.h
connectionstartframe.h
connectionstartokframe.h
connectiontuneframe.h
connectiontuneokframe.h
consumedmessage.h
deferredcancel.cpp deferredcancel.cpp
deferredconsumer.cpp deferredconsumer.cpp
deferredconsumerbase.cpp deferredconsumerbase.cpp
deferredget.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 field.cpp
flags.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 receivedframe.cpp
reducedbuffer.h
returnedmessage.h
table.cpp table.cpp
transactioncommitframe.h
transactioncommitokframe.h
transactionframe.h
transactionrollbackframe.h
transactionrollbackokframe.h
transactionselectframe.h
transactionselectokframe.h
watchable.cpp watchable.cpp
) )

View File

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