Commit e0b1fe64680a6023bc821d9ac2288f980de2c559

Authored by Peter M. Groen
1 parent 7ecdab62

Fixed script.

CMakeLists.txt
@@ -13,10 +13,10 @@ endif() @@ -13,10 +13,10 @@ endif()
13 13
14 # ============================================================================== 14 # ==============================================================================
15 # Check to see if there is versioning information available 15 # Check to see if there is versioning information available
16 -if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/osdev_versioning/cmake)  
17 - LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/osdev_versioning/cmake)  
18 -elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../osdev_versioning/cmake)  
19 - LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../osdev_versioning/cmake) 16 +if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/versioning)
  17 + LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/versioning/cmake)
  18 +elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../versioning)
  19 + LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../versioning/cmake)
20 else() 20 else()
21 message( FATAL_ERROR "No ${CURRENT_SOURCE_DIR}/osdev_versioning directory found. Did you run the submodules script?" ) 21 message( FATAL_ERROR "No ${CURRENT_SOURCE_DIR}/osdev_versioning directory found. Did you run the submodules script?" )
22 endif() 22 endif()
README.md
  1 +MQTT-CPP
  2 +========
  3 +
  4 +Modern, asynchronous and fast C++ client for paho-mqtt ( paho-c ).
  5 +
  6 +**Features:**
  7 +* Simple and clean A-synchronous API. ( Connect, publish, subscribe ).
  8 +* Thread-safe. Use multiple topics in multiple threads..
  9 +* Callbacks can be lambdas, class methods, bind expressions, or any [std::function]
  10 +* Fully autonomous reconnecting
  11 +
  12 +# Dependencies
  13 +The only dependency is to libpaho-mqtt3a.so. CHanges are there is a version for your platform ( Debian, Fedora, CentOS ).
  14 +Just check your package manager for the correct package-name.
  15 +
  16 +# Tutorial
  17 +* Clone this repository :
  18 + ```
  19 + git clone http://gitlab.osdev.nl/open_source/mqtt-cpp.git
  20 + ```
  21 + * Change to the repo and run the submodules script :
  22 + ```
  23 + $ cd mqtt-cpp
  24 + $ scripts/setup_submodules -i
  25 + ```
  26 + This will add the cmake directory and versioning.
  27 + * Create a build directory and start the build.
  28 + ```
  29 + $ mkdir build
  30 + $ cd build
  31 + $ cmake ../
  32 + $ gmake
  33 + ```
  34 +And you're all set. In build/bin there are two examples, test_mqtt_pu and test_mqtt_sub. Have a broker running,
  35 +like mosquitto or flashmq capable of accepting anonymous connections. Start the "sub" part and couple of moments
  36 +later the "pub" part. If all went well, you should see two screens in sync running.
  37 +One is sending, the other is receiveing.
scripts/setup_submodules
1 -#!/bin/bash 1 +#!/bin/bash -x
2 # ================= 2 # =================
3 # = Do not chenge. 3 # = Do not chenge.
4 # ================= 4 # =================
5 GIT_URL_SUBS="http://gitlab.osdev.nl/open_source" 5 GIT_URL_SUBS="http://gitlab.osdev.nl/open_source"
6 -TOP_REPO="-1" 6 +FUNC_RESULT=""
7 7
8 -function print_usage_exit() { 8 +function print_usage_exit()
  9 +{
9 echo "Usage $0 -i|--install|-u|--update" 10 echo "Usage $0 -i|--install|-u|--update"
10 echo " -i or --install Install the submodules mentioned in the submodules.list" 11 echo " -i or --install Install the submodules mentioned in the submodules.list"
11 echo " -u or --update Update the submodules mentioned in the submodules.list" 12 echo " -u or --update Update the submodules mentioned in the submodules.list"
@@ -13,45 +14,55 @@ function print_usage_exit() { @@ -13,45 +14,55 @@ function print_usage_exit() {
13 exit 1 14 exit 1
14 } 15 }
15 16
16 -function check_top_or_sub() { 17 +function check_top_or_sub()
  18 +{
17 # This function checks if we're the top-repository. 19 # This function checks if we're the top-repository.
18 # In that case we need the submodules.. If we're already a submodule, 20 # In that case we need the submodules.. If we're already a submodule,
19 # we simply exit this script with a message 21 # we simply exit this script with a message
20 - if [ -d ./.git ]; then  
21 - return 1  
22 - elif [ -d ../.git ]; then  
23 - if [ -f ../.submodules ]; then 22 + if [ -e ./.git ]; then
  23 + FUNC_RESULT="1"
  24 + return
  25 + elif [ -e ../.git ]; then
  26 + if [ -e ../.submodules ]; then
24 echo "Seems like we're already a submodule. Nothing to do here." 27 echo "Seems like we're already a submodule. Nothing to do here."
25 - return 0 28 + FUNC_RESULT="0"
  29 + return
26 fi 30 fi
27 fi 31 fi
28 - return 0 32 + FUNC_RESULT="0"
  33 + return
29 } 34 }
30 35
31 -function check_working_dir() { 36 +function check_working_dir()
  37 +{
32 # Check if we're in the top-level directory of our repository. 38 # Check if we're in the top-level directory of our repository.
33 if [ -f ./scripts/submodules.list ]; then 39 if [ -f ./scripts/submodules.list ]; then
34 # We're good to go 40 # We're good to go
35 - return 1 41 + FUNC_RESULT="1"
  42 + return
36 fi 43 fi
37 - return 0 44 + FUNC_RESULT="0"
  45 + return
38 } 46 }
39 47
40 -function read_submodules() { 48 +function read_submodules()
  49 +{
41 if [ -e ./scripts/submodules.list ]; then 50 if [ -e ./scripts/submodules.list ]; then
42 source ./scripts/submodules.list 51 source ./scripts/submodules.list
43 fi 52 fi
44 } 53 }
45 54
46 -function add_submodules() { 55 +function add_submodules()
  56 +{
47 for SUB_MODULE in ${SUB_MODULES} 57 for SUB_MODULE in ${SUB_MODULES}
48 do 58 do
49 - git submodule add -f ${GIT_URL_SUBS}/${SUB_MODULE} ${SUB_MODULE}  
50 - git config submodule.${SUB_MODULE}.url ${GIT_URL_SUBS}/${SUB_MODULE} 59 + git submodule add -f ${GIT_URL_SUBS}/${SUB_MODULE}.git ${SUB_MODULE}
  60 + git config submodule.${SUB_MODULE}.url ${GIT_URL_SUBS}/${SUB_MODULE}.git
51 done 61 done
52 } 62 }
53 63
54 -function get_submodules() { 64 +function get_submodules()
  65 +{
55 git submodule update --init --recursive 66 git submodule update --init --recursive
56 } 67 }
57 68
@@ -62,14 +73,14 @@ function update_submodules() { @@ -62,14 +73,14 @@ function update_submodules() {
62 # ============================================================================= 73 # =============================================================================
63 # == T H E M A I N E N T R Y O F T H I S S C R I P T == 74 # == T H E M A I N E N T R Y O F T H I S S C R I P T ==
64 # ============================================================================= 75 # =============================================================================
65 -RESULT=check_top_or_sub()  
66 -if [ $RESULT -eq 0 ]; then 76 +check_top_or_sub
  77 +if [ "${FUNC_RESULT}" == "0" ]; then
67 echo "Seems like we're a submodule already or not part of a repository." 78 echo "Seems like we're a submodule already or not part of a repository."
68 exit 0 79 exit 0
69 fi 80 fi
70 81
71 -RESULT=check_working_dir()  
72 -if [ $RESULT -eq 0 ]; then 82 +check_working_dir
  83 +if [ "${FUNC_RESULT}" == "0" ]; then
73 echo "Go to the top of this repository and type : scripts/setup_submodules [-i|--install]" 84 echo "Go to the top of this repository and type : scripts/setup_submodules [-i|--install]"
74 exit 0 85 exit 0
75 fi 86 fi
scripts/submodules.list
1 -SUB_MODULES="osdev_versioning 1 +SUB_MODULES="versioning
2 cmake" 2 cmake"
src/CMakeLists.txt
1 cmake_minimum_required(VERSION 3.12) 1 cmake_minimum_required(VERSION 3.12)
2 -LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) 2 +# ==============================================================================
  3 +# Check to see if we're a submodule or top-repo.
  4 +if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
  5 + message( STATUS "Looks like we're a single module" )
  6 + LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
  7 +elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake)
  8 + message( STATUS "Looks like we're a submodule" )
  9 + LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake)
  10 +else()
  11 + message( FATAL_ERROR "No cmake directory found. Did you run the submodules script?" )
  12 +endif()
  13 +
  14 +# ==============================================================================
  15 +# Check to see if there is versioning information available
  16 +if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../versioning)
  17 + LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../versioning/cmake)
  18 +elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../versioning)
  19 + LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../versioning/cmake)
  20 +else()
  21 + message( FATAL_ERROR "No ${CURRENT_SOURCE_DIR}/osdev_versioning directory found. Did you run the submodules script?" )
  22 +endif()
  23 +# ==============================================================================
3 include(projectheader) 24 include(projectheader)
  25 +
4 project_header(mqtt) 26 project_header(mqtt)
5 27
6 find_package( Boost REQUIRED COMPONENTS regex ) 28 find_package( Boost REQUIRED COMPONENTS regex )