From af416f81b14a3bee682e300b165a6efdb9739d54 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 23 Nov 2018 16:41:24 +0100 Subject: o Trying to improve compatibility with some feature checks. o Misc nits. --- .idea/codeStyles/codeStyleConfig.xml | 1 + README.md | 12 +++++++ apps/apps.cpp | 11 ++++--- apps/ble-inspect-device.cpp | 3 +- apps/ble-read-characteristic.cpp | 2 +- ble/BluetoothImpl.h | 3 -- include/ble/Bluetooth.h | 4 --- include/ble/att.h | 6 ++-- include/ble/compiler-support.h | 62 ++++++++++++++++++++++++++++++++++++ include/ble/misc.h | 4 +-- 10 files changed, 89 insertions(+), 19 deletions(-) create mode 100644 include/ble/compiler-support.h diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml index 79ee123..6e6eec1 100644 --- a/.idea/codeStyles/codeStyleConfig.xml +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -1,5 +1,6 @@ \ No newline at end of file diff --git a/README.md b/README.md index 5b5f5b1..1ddaa1a 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,18 @@ Building: This will build a Debug release by default. Add `-DCMAKE_BUILD_TYPE=Release` to build a release build. +## Required packages + +For Debian-based systems (Debian, Ubuntu, Armbian, etc): + + * cmake + * libmosquitto-dev + * libpqxx-dev + * libbluetooth-dev + * libboost-all-dev + * liblog4cplus-dev + * ninja-build # optional + # CMake notes Header files are added as sources so the IDEs will search/index them properly. diff --git a/apps/apps.cpp b/apps/apps.cpp index 56abc7b..ef0a7fc 100644 --- a/apps/apps.cpp +++ b/apps/apps.cpp @@ -53,12 +53,12 @@ const po::options_description logging_options() { return desc; } -void setup_logging(string app_name) { +void setup_logging(const string &app_name) { Appender *console = new ConsoleAppender(true, true); string pattern = "%-5p %D{%Y-%m-%d %H:%M:%S} " + app_name + "/%-20c %m%n"; // add %M (function name) - PatternLayout *layout = new PatternLayout(LOG4CPLUS_TEXT(pattern)); + auto *layout = new PatternLayout(LOG4CPLUS_TEXT(pattern)); console->setLayout(auto_ptr(layout)); Hierarchy &h = Logger::getDefaultHierarchy(); @@ -90,7 +90,7 @@ int launch_app(app *app, int argc, const char *argv[]) { return EXIT_FAILURE; } - if (unrecognized.size()) { + if (!unrecognized.empty()) { cerr << "Unrecognized option: " << unrecognized.at(0) << "\n"; return EXIT_FAILURE; } @@ -123,5 +123,6 @@ int real_main(app *app, int argc, const char *argv[]) { return launch_app(app, argc, argv); } -} -} + +} // namespace apps +} // namespace trygvis diff --git a/apps/ble-inspect-device.cpp b/apps/ble-inspect-device.cpp index a6665b3..cb8cf0f 100644 --- a/apps/ble-inspect-device.cpp +++ b/apps/ble-inspect-device.cpp @@ -44,8 +44,7 @@ public: << endl; for (auto &c : characteristics) { - cout << "Characteristic: UUID: " << c->getUuid() << ", properties: " << (uint16_t) c->getProperties() - << endl; + cout << "Characteristic: UUID: " << c->getUuid() << ", properties: " << (uint16_t) c->getProperties() << endl; } } } diff --git a/apps/ble-read-characteristic.cpp b/apps/ble-read-characteristic.cpp index ecdb471..3ef3c70 100644 --- a/apps/ble-read-characteristic.cpp +++ b/apps/ble-read-characteristic.cpp @@ -117,7 +117,7 @@ public: } while(std::chrono::system_clock::now() < end); } } else { - cout << "Unsupported op mode." << endl; + cout << "Unsupported op mode: " << op_mode << endl; } return EXIT_SUCCESS; diff --git a/ble/BluetoothImpl.h b/ble/BluetoothImpl.h index c41712c..92f71d3 100644 --- a/ble/BluetoothImpl.h +++ b/ble/BluetoothImpl.h @@ -289,9 +289,6 @@ protected: BluetoothAdapterPtr getAdapterImpl(string name); -template struct overloaded : Ts... { using Ts::operator()...; }; -template overloaded(Ts...) -> overloaded; - } // namespace bluetooth } // namespace trygvis diff --git a/include/ble/Bluetooth.h b/include/ble/Bluetooth.h index 5f7cd17..28e2794 100644 --- a/include/ble/Bluetooth.h +++ b/include/ble/Bluetooth.h @@ -1,7 +1,6 @@ #ifndef BLUETOOTH_H #define BLUETOOTH_H -#include #include #include #include @@ -23,9 +22,6 @@ using std::vector; using std::map; using std::runtime_error; -template -using o = std::optional; - class BluetoothAdapter; class BluetoothDevice; class BluetoothGatt; diff --git a/include/ble/att.h b/include/ble/att.h index 152a779..7b77812 100644 --- a/include/ble/att.h +++ b/include/ble/att.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include "ble/ByteBuffer.h" @@ -9,6 +8,9 @@ namespace trygvis { namespace bluetooth { +using ::trygvis::compiler::variant; +using ::trygvis::compiler::monostate; + /** * BLUETOOTH SPECIFICATION Version 4.0 [Vol 3] - Attribute Protocol (ATT) - 3.4.8 Attribute Opcode Summary * Table 3.37 @@ -144,7 +146,7 @@ struct HandleValueIndication { ByteBuffer data; }; -using AttVariant = std::variant) +# include +# define have_optional 1 +# elif __has_include() +# include +# define have_optional 1 +# define have_experimental_optional 1 +# else +# define have_optional 0 +# endif + +# if __has_include() +# include +# define have_variant 1 +# elif __has_include() +# include +# define have_variant 1 +# define have_experimental_variant 1 +# else +# define have_variant 0 +# endif + +#endif + +namespace trygvis { +namespace compiler { + +#if have_experimental_optional + +template +using o = std::experimental::optional; + +#elif have_optional + +template +using o = std::optional; + +#endif + +#if have_experimental_variant + +template +using variant = std::experimental::variant; +using monostate = std::experimental::monostate; + +#elif have_variant + +template +using variant = std::variant; +using monostate = std::monostate; + +#endif + +} // namespace compiler +} // namespace trygvis + + +#endif diff --git a/include/ble/misc.h b/include/ble/misc.h index 563d039..aa0ba2e 100644 --- a/include/ble/misc.h +++ b/include/ble/misc.h @@ -1,5 +1,6 @@ #pragma once +#include "ble/compiler-support.h" #include "ByteBuffer.h" #include @@ -10,8 +11,7 @@ namespace trygvis { namespace bluetooth { -template -using o = std::optional; +using ::trygvis::compiler::o; class BluetoothAdapter; class BluetoothDevice; -- cgit v1.2.3