diff --git a/CMakeLists.txt b/CMakeLists.txt index 2fccb8c..38cff83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,10 +13,10 @@ endif() # ============================================================================== # Check to see if there is versioning information available -if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/osdev_versioning/cmake) - LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/osdev_versioning/cmake) -elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../osdev_versioning/cmake) - LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../osdev_versioning/cmake) +if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/versioning) + LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/versioning/cmake) +elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../versioning) + LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../versioning/cmake) else() message( FATAL_ERROR "No ${CURRENT_SOURCE_DIR}/osdev_versioning directory found. Did you run the submodules script?" ) endif() diff --git a/README.md b/README.md index e69de29..9647e78 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,37 @@ +MQTT-CPP +======== + +Modern, asynchronous and fast C++ client for paho-mqtt ( paho-c ). + +**Features:** +* Simple and clean A-synchronous API. ( Connect, publish, subscribe ). +* Thread-safe. Use multiple topics in multiple threads.. +* Callbacks can be lambdas, class methods, bind expressions, or any [std::function] +* Fully autonomous reconnecting + +# Dependencies +The only dependency is to libpaho-mqtt3a.so. CHanges are there is a version for your platform ( Debian, Fedora, CentOS ). +Just check your package manager for the correct package-name. + +# Tutorial +* Clone this repository : + ``` + git clone http://gitlab.osdev.nl/open_source/mqtt-cpp.git + ``` + * Change to the repo and run the submodules script : + ``` + $ cd mqtt-cpp + $ scripts/setup_submodules -i + ``` + This will add the cmake directory and versioning. + * Create a build directory and start the build. + ``` + $ mkdir build + $ cd build + $ cmake ../ + $ gmake + ``` +And you're all set. In build/bin there are two examples, test_mqtt_pu and test_mqtt_sub. Have a broker running, +like mosquitto or flashmq capable of accepting anonymous connections. Start the "sub" part and couple of moments +later the "pub" part. If all went well, you should see two screens in sync running. +One is sending, the other is receiveing. diff --git a/scripts/setup_submodules b/scripts/setup_submodules index 52e7155..45effbd 100755 --- a/scripts/setup_submodules +++ b/scripts/setup_submodules @@ -1,11 +1,12 @@ -#!/bin/bash +#!/bin/bash -x # ================= # = Do not chenge. # ================= GIT_URL_SUBS="http://gitlab.osdev.nl/open_source" -TOP_REPO="-1" +FUNC_RESULT="" -function print_usage_exit() { +function print_usage_exit() +{ echo "Usage $0 -i|--install|-u|--update" echo " -i or --install Install the submodules mentioned in the submodules.list" echo " -u or --update Update the submodules mentioned in the submodules.list" @@ -13,45 +14,55 @@ function print_usage_exit() { exit 1 } -function check_top_or_sub() { +function check_top_or_sub() +{ # This function checks if we're the top-repository. # In that case we need the submodules.. If we're already a submodule, # we simply exit this script with a message - if [ -d ./.git ]; then - return 1 - elif [ -d ../.git ]; then - if [ -f ../.submodules ]; then + if [ -e ./.git ]; then + FUNC_RESULT="1" + return + elif [ -e ../.git ]; then + if [ -e ../.submodules ]; then echo "Seems like we're already a submodule. Nothing to do here." - return 0 + FUNC_RESULT="0" + return fi fi - return 0 + FUNC_RESULT="0" + return } -function check_working_dir() { +function check_working_dir() +{ # Check if we're in the top-level directory of our repository. if [ -f ./scripts/submodules.list ]; then # We're good to go - return 1 + FUNC_RESULT="1" + return fi - return 0 + FUNC_RESULT="0" + return } -function read_submodules() { +function read_submodules() +{ if [ -e ./scripts/submodules.list ]; then source ./scripts/submodules.list fi } -function add_submodules() { +function add_submodules() +{ for SUB_MODULE in ${SUB_MODULES} do - git submodule add -f ${GIT_URL_SUBS}/${SUB_MODULE} ${SUB_MODULE} - git config submodule.${SUB_MODULE}.url ${GIT_URL_SUBS}/${SUB_MODULE} + git submodule add -f ${GIT_URL_SUBS}/${SUB_MODULE}.git ${SUB_MODULE} + git config submodule.${SUB_MODULE}.url ${GIT_URL_SUBS}/${SUB_MODULE}.git done } -function get_submodules() { +function get_submodules() +{ git submodule update --init --recursive } @@ -62,14 +73,14 @@ function update_submodules() { # ============================================================================= # == T H E M A I N E N T R Y O F T H I S S C R I P T == # ============================================================================= -RESULT=check_top_or_sub() -if [ $RESULT -eq 0 ]; then +check_top_or_sub +if [ "${FUNC_RESULT}" == "0" ]; then echo "Seems like we're a submodule already or not part of a repository." exit 0 fi -RESULT=check_working_dir() -if [ $RESULT -eq 0 ]; then +check_working_dir +if [ "${FUNC_RESULT}" == "0" ]; then echo "Go to the top of this repository and type : scripts/setup_submodules [-i|--install]" exit 0 fi diff --git a/scripts/submodules.list b/scripts/submodules.list index 0f00651..109e69b 100644 --- a/scripts/submodules.list +++ b/scripts/submodules.list @@ -1,2 +1,2 @@ -SUB_MODULES="osdev_versioning +SUB_MODULES="versioning cmake" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f6c58b3..543ce86 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,28 @@ cmake_minimum_required(VERSION 3.12) -LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) +# ============================================================================== +# Check to see if we're a submodule or top-repo. +if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) + message( STATUS "Looks like we're a single module" ) + LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) +elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake) + message( STATUS "Looks like we're a submodule" ) + LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake) +else() + message( FATAL_ERROR "No cmake directory found. Did you run the submodules script?" ) +endif() + +# ============================================================================== +# Check to see if there is versioning information available +if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../versioning) + LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../versioning/cmake) +elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../versioning) + LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../versioning/cmake) +else() + message( FATAL_ERROR "No ${CURRENT_SOURCE_DIR}/osdev_versioning directory found. Did you run the submodules script?" ) +endif() +# ============================================================================== include(projectheader) + project_header(mqtt) find_package( Boost REQUIRED COMPONENTS regex )