diff --git a/.travis.yml b/.travis.yml index 06f69b0..d3be12c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 .." diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c8fddb..9bcb914 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -51,6 +52,11 @@ if(AMQP-CPP_LINUX_TCP) add_subdirectory(src/linux_tcp) endif() +# potentially build the examples +if(AMQP-CPP_BUILD_EXAMPLES) + add_subdirectory(examples) +endif() + # settings for specific compilers # ------------------------------------------------------------------------------------------------------ @@ -91,6 +97,7 @@ else() ARCHIVE DESTINATION lib ) endif() + # copy header files install(DIRECTORY include/amqpcpp/ DESTINATION include/amqpcpp FILES_MATCHING PATTERN "*.h") diff --git a/README.md b/README.md index f38e941..ef0178e 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..beee70e --- /dev/null +++ b/examples/CMakeLists.txt @@ -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) \ No newline at end of file diff --git a/tests/libboostasio.cpp b/examples/libboostasio.cpp similarity index 100% rename from tests/libboostasio.cpp rename to examples/libboostasio.cpp diff --git a/tests/libev.cpp b/examples/libev.cpp similarity index 100% rename from tests/libev.cpp rename to examples/libev.cpp diff --git a/tests/libevent.cpp b/examples/libevent.cpp similarity index 100% rename from tests/libevent.cpp rename to examples/libevent.cpp diff --git a/tests/libuv.cpp b/examples/libuv.cpp similarity index 100% rename from tests/libuv.cpp rename to examples/libuv.cpp diff --git a/include/amqpcpp.h b/include/amqpcpp.h index f002eae..4d7735a 100644 --- a/include/amqpcpp.h +++ b/include/amqpcpp.h @@ -80,7 +80,5 @@ #include "amqpcpp/connection.h" // tcp level includes -#include "amqpcpp/tcphandler.h" -#include "amqpcpp/tcpconnection.h" -#include "amqpcpp/tcpchannel.h" +#include "amqpcpp/linux_tcp.h" diff --git a/include/amqpcpp/libboostasio.h b/include/amqpcpp/libboostasio.h index 5937286..18b2a10 100644 --- a/include/amqpcpp/libboostasio.h +++ b/include/amqpcpp/libboostasio.h @@ -27,6 +27,8 @@ #include #include +#include "amqpcpp/linux_tcp.h" + // C++17 has 'weak_from_this()' support. #if __cplusplus >= 201701L #define PTR_FROM_THIS weak_from_this @@ -60,11 +62,13 @@ private: */ boost::asio::io_service & _ioservice; + typedef std::weak_ptr strand_weak_ptr; + /** * The boost asio io_service::strand managed pointer. * @var class std::shared_ptr */ - std::weak_ptr _strand; + strand_weak_ptr _wpstrand; /** * The boost tcp socket. @@ -108,15 +112,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 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 +235,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 strand, + const strand_weak_ptr wpstrand, const int fd) : _ioservice(io_service), - _strand(strand), + _wpstrand(wpstrand), _socket(_ioservice) { _socket.assign(fd); @@ -309,11 +315,13 @@ private: */ boost::asio::io_service & _ioservice; + typedef std::weak_ptr strand_weak_ptr; + /** * The boost asio io_service::strand managed pointer. * @var class std::shared_ptr */ - std::weak_ptr _strand; + strand_weak_ptr _wpstrand; /** * The boost asynchronous deadline timer. @@ -330,21 +338,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 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 +405,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 strand) : - _ioservice(io_service), - _strand(strand), - _timer(_ioservice) + const strand_weak_ptr wpstrand) : + _ioservice(io_service), + _wpstrand(wpstrand), + _timer(_ioservice) { } @@ -446,11 +457,13 @@ private: */ boost::asio::io_service & _ioservice; + typedef std::shared_ptr strand_shared_ptr; + /** * The boost asio io_service::strand managed pointer. * @var class std::shared_ptr */ - std::shared_ptr _strand; + strand_shared_ptr _strand; /** diff --git a/include/amqpcpp/libev.h b/include/amqpcpp/libev.h index d14a3b6..1fc1f32 100644 --- a/include/amqpcpp/libev.h +++ b/include/amqpcpp/libev.h @@ -21,6 +21,8 @@ */ #include +#include "amqpcpp/linux_tcp.h" + /** * Set up namespace */ diff --git a/include/amqpcpp/libuv.h b/include/amqpcpp/libuv.h index d48303f..eebf204 100644 --- a/include/amqpcpp/libuv.h +++ b/include/amqpcpp/libuv.h @@ -21,6 +21,8 @@ */ #include +#include "amqpcpp/linux_tcp.h" + /** * Set up namespace */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d61b3e0..6cc8e1a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 ) diff --git a/src/linux_tcp/CMakeLists.txt b/src/linux_tcp/CMakeLists.txt index d5cb67f..55d0e16 100644 --- a/src/linux_tcp/CMakeLists.txt +++ b/src/linux_tcp/CMakeLists.txt @@ -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 )