From 0f27607da91a0836d949b6aac37d7e75f99e49ca Mon Sep 17 00:00:00 2001 From: Manuel Weichselbaumer Date: Thu, 12 Dec 2024 11:48:57 +0100 Subject: [PATCH] Prepare for 1.0.0 Release --- .gitmodules | 3 - CMakeLists.txt | 41 ++--- README.md | 24 +-- cmake/CPM.cmake | 24 +++ common/CMakeLists.txt | 6 +- common/include/common/ble/Converter.h | 8 - common/src/ble/Converter.cpp | 59 ------- cornrowd/CMakeLists.txt | 1 - cornrowd/src/audio/CMakeLists.txt | 2 + cornrowd/src/bluetooth/Controller.cpp | 77 --------- cornrowd/src/bluetooth/Controller.h | 6 - debian/cornrowd-rpi.install | 2 - debian/cornrowd-rpi.postinst | 1 - debian/cornrowd-rpi.postrm | 1 - debian/{cornrowd.install => install} | 0 debian/{cornrowd.postinst => postinst} | 0 debian/{cornrowd.postrm => postrm} | 0 net/CMakeLists.txt | 63 ------- net/include/QtZeroProps/QZeroPropsClient.h | 114 ------------- net/include/QtZeroProps/QZeroPropsServer.h | 60 ------- net/include/QtZeroProps/QZeroPropsService.h | 98 ----------- net/include/QtZeroProps/QZeroPropsTypes.h | 35 ---- net/net.pro | 40 ----- net/src/BleClientSession.cpp | 152 ----------------- net/src/BleClientSession.h | 68 -------- net/src/BleServer.cpp | 59 ------- net/src/BleServer.h | 58 ------- net/src/BleServerSession.cpp | 83 --------- net/src/BleServerSession.h | 50 ------ net/src/QZeroPropsBleClient.cpp | 135 --------------- net/src/QZeroPropsBleClient.h | 67 -------- net/src/QZeroPropsBleService.h | 80 --------- net/src/QZeroPropsClient.cpp | 172 ------------------- net/src/QZeroPropsServer.cpp | 49 ------ net/src/QZeroPropsServerPrivate.cpp | 38 ----- net/src/QZeroPropsServerPrivate.h | 45 ----- net/src/QZeroPropsService.cpp | 85 --------- net/src/QZeroPropsServicePrivate.cpp | 53 ------ net/src/QZeroPropsServicePrivate.h | 57 ------- net/src/QZeroPropsWsServer.cpp | 73 -------- net/src/QZeroPropsWsServer.h | 44 ----- net/src/QZeroPropsWsService.cpp | 180 -------------------- net/src/QZeroPropsWsService.h | 53 ------ net/tests/CMakeLists.txt | 19 --- net/tests/centraltest.cpp | 18 -- net/tests/peripheraltest.cpp | 100 ----------- thirdparty/libcornrow | 1 - 47 files changed, 52 insertions(+), 2352 deletions(-) create mode 100644 cmake/CPM.cmake delete mode 100644 debian/cornrowd-rpi.install delete mode 120000 debian/cornrowd-rpi.postinst delete mode 120000 debian/cornrowd-rpi.postrm rename debian/{cornrowd.install => install} (100%) rename debian/{cornrowd.postinst => postinst} (100%) rename debian/{cornrowd.postrm => postrm} (100%) delete mode 100644 net/CMakeLists.txt delete mode 100644 net/include/QtZeroProps/QZeroPropsClient.h delete mode 100644 net/include/QtZeroProps/QZeroPropsServer.h delete mode 100644 net/include/QtZeroProps/QZeroPropsService.h delete mode 100644 net/include/QtZeroProps/QZeroPropsTypes.h delete mode 100644 net/net.pro delete mode 100644 net/src/BleClientSession.cpp delete mode 100644 net/src/BleClientSession.h delete mode 100644 net/src/BleServer.cpp delete mode 100644 net/src/BleServer.h delete mode 100644 net/src/BleServerSession.cpp delete mode 100644 net/src/BleServerSession.h delete mode 100644 net/src/QZeroPropsBleClient.cpp delete mode 100644 net/src/QZeroPropsBleClient.h delete mode 100644 net/src/QZeroPropsBleService.h delete mode 100644 net/src/QZeroPropsClient.cpp delete mode 100644 net/src/QZeroPropsServer.cpp delete mode 100644 net/src/QZeroPropsServerPrivate.cpp delete mode 100644 net/src/QZeroPropsServerPrivate.h delete mode 100644 net/src/QZeroPropsService.cpp delete mode 100644 net/src/QZeroPropsServicePrivate.cpp delete mode 100644 net/src/QZeroPropsServicePrivate.h delete mode 100644 net/src/QZeroPropsWsServer.cpp delete mode 100644 net/src/QZeroPropsWsServer.h delete mode 100644 net/src/QZeroPropsWsService.cpp delete mode 100644 net/src/QZeroPropsWsService.h delete mode 100644 net/tests/CMakeLists.txt delete mode 100644 net/tests/centraltest.cpp delete mode 100644 net/tests/peripheraltest.cpp delete mode 160000 thirdparty/libcornrow diff --git a/.gitmodules b/.gitmodules index 07e190d..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "thirdparty/libcornrow"] - path = thirdparty/libcornrow - url = https://github.com/mincequi/libcornrow diff --git a/CMakeLists.txt b/CMakeLists.txt index c35bec2..a9d9a0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.7) project(cornrow) -include(ExternalProject) +include(cmake/CPM.cmake) set(CMAKE_AUTOMOC ON) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ @@ -12,41 +12,22 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ -Wno-deprecated-declarations \ -Wno-zero-as-null-pointer-constant") set(CMAKE_CXX_STANDARD 17) -# -Werror \ find_package(Qt5 REQUIRED COMPONENTS Core Network) -# Add thirdparty libs -add_subdirectory(thirdparty/libcornrow) -#add_subdirectory(thirdparty/qtzeroprops) - # Add internal libs add_subdirectory(common) add_subdirectory(cornrowd) -#add_subdirectory(net) -#add_subdirectory(bluebricated) -# Mandatory debian variables -SET(CPACK_GENERATOR "DEB") -SET(CPACK_PACKAGE_CONTACT "mincequi@web.de") -SET(CPACK_PACKAGE_VERSION "0.9.0") +install(TARGETS cornrowd DESTINATION bin) +install(FILES ${PROJECT_SOURCE_DIR}/debian/cornrowd.service DESTINATION /usr/lib/systemd/system) + +set(CPACK_GENERATOR "DEB") +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Manuel Weichselbaumer ") #required +set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) +set(CPACK_DEBIAN_PACKAGE_DEPENDS adduser) SET(CPACK_PACKAGE_DESCRIPTION "Bluetooth audio player") SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "This daemon accepts and plays audio from any Bluetooth source and turns your linux PC into a Bluetooth speaker.") -#CPACK_SYSTEM_NAME -> CMAKE_SYSTEM_NAME -##CPACK_DEBIAN_PACKAGE_NAME -> CPACK_PACKAGE_NAME -> project name -#CPACK_DEBIAN_FILE_NAME -> CPACK_PACKAGE_FILE_NAME -> ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME} -#CPACK_DEBIAN_PACKAGE_VERSION -> CPACK_PACKAGE_VERSION -#CPACK_DEBIAN_PACKAGE_RELEASE -#CPACK_DEBIAN_PACKAGE_ARCHITECTURE -#CPACK_DEBIAN_PACKAGE_MAINTAINER -> CPACK_PACKAGE_CONTACT -#CPACK_DEBIAN_PACKAGE_DESCRIPTION -> CPACK_PACKAGE_DESCRIPTION_SUMMARY -#CPACK_DEBIAN_COMPRESSION_TYPE -#CPACK_DEBIAN_PACKAGE_PRIORITY - -# DEBIAN OPTIONS -#SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Manuel Weichselbaumer ") -#SET(CPACK_DEBIAN_PACKAGE_SECTION "Sound") -#SET(CPACK_DEBIAN_PACKAGE_DEPENDS "${OSG_PACKAGE_DEPENDS}") -#SET(CPACK_DEBIAN_PACKAGE_CONFLICTS "${OSG_PACKAGE_CONFLICTS}") -#SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${OpenSceneGraph_SOURCE_DIR}/debian/postinst;") -#SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${OpenSceneGraph_SOURCE_DIR}/debian/conffiles;") +SET(CPACK_PACKAGE_VERSION "1.0.0") +set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${PROJECT_SOURCE_DIR}/debian/postinst;${PROJECT_SOURCE_DIR}/debian/postrm;${PROJECT_SOURCE_DIR}/debian/install") +include(CPack) diff --git a/README.md b/README.md index c514cf2..d98e17f 100644 --- a/README.md +++ b/README.md @@ -3,17 +3,18 @@ Cornrow is an audio sink daemon for Bluetooth and Airplay streams. It is designed for low-powered boards like the Raspberry Pi, but can also be used for SBCs/VMs with a Bluetooth dongle instead of a built-in module (first Bluetooth adapter found will be used). It is made for Debian based environments and compatible with Ubuntu and Debian. This means that this service runs as a dedicated user and can be cleanly installed and removed using Debian package management. -**Note:** for Debian Buster and Ubuntu Bionic (18.04) please use cornrow **v0.8.0**. -For Debian Bullseye and Ubuntu Focal (20.04) and later, please use cornrow **v0.8.1**. +**Note:** +For Debian Bullseye and Ubuntu 20.04 (Focal) and later, please use cornrow **v0.8.1**. For Debian Bookworm and later, please use cornrow **v0.9.0**. +For Debian Trixie and Ubuntu 24.10 (Oracular) and later, please use cornrow **v1.0.0**. ## Installation (binary) -Compiled debian/ubuntu packages are available for [armhf](https://github.com/mincequi/cornrow/releases/download/v0.8.1/cornrowd_0.8.1_armhf.deb) and [amd64](https://github.com/mincequi/cornrow/releases/download/v0.6.0/cornrowd_0.6.0_amd64.deb). +Compiled debian/ubuntu packages are available for [armhf](https://github.com/mincequi/cornrow/releases/download/v1.0.0/cornrow_1.0.0_armhf.deb). ``` -wget https://github.com/mincequi/cornrow/releases/download/v0.9.0/cornrowd_0.9.0_arm64.deb +wget https://github.com/mincequi/cornrow/releases/download/v1.0.0/cornrow_1.0.0_armhf.deb sudo apt update -sudo apt install ./cornrowd_0.9.0_arm64.deb +sudo apt install ./cornrow_1.0.0_armhf.deb sudo systemctl unmask cornrowd.service # unmask service sudo systemctl start cornrowd.service # start-up service. You should now be able to connect any bluetooth audio device. sudo systemctl enable cornrowd.service # start-up service on each reboot. @@ -40,12 +41,15 @@ sudo apt install \ libssl-dev \ qtconnectivity5-dev \ libqt5websockets5-dev -wget https://github.com/mincequi/cornrow/archive/refs/tags/v0.9.0.tar.gz -tar xf cornrowd-0.9.0.tar.xz +wget https://github.com/mincequi/cornrow/archive/refs/tags/v1.0.0.tar.gz +tar xf cornrowd-1.0.0.tar.xz cd cornrow -dpkg-buildpackage -us -uc -nc # build unsigned debian package +mkdir build +cd build +cmake -DCMAKE_BUILD_TYPE=Release .. +cpack # build debian package cd .. -sudo apt install ./cornrowd_0.9.0_.deb # install package +sudo apt install ./cornrow_1.0.0_.deb # install package sudo systemctl unmask cornrowd.service # unmask service sudo systemctl start cornrowd.service # start-up service. You should now be able to connect any bluetooth audio device. sudo systemctl enable cornrowd.service # start-up service on each reboot. @@ -54,7 +58,7 @@ sudo systemctl enable cornrowd.service # start-up service on each r ### Arbitrary distro Get the dependencies. Basically, these are ffmpeg (libav*), qt5bluetooth, qt5websockets ``` -git clone --recursive https://github.com/mincequi/cornrow +git clone https://github.com/mincequi/cornrow cd cornrow mkdir build cd build diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake new file mode 100644 index 0000000..baf2d8c --- /dev/null +++ b/cmake/CPM.cmake @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: MIT +# +# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors + +set(CPM_DOWNLOAD_VERSION 0.40.2) +set(CPM_HASH_SUM "c8cdc32c03816538ce22781ed72964dc864b2a34a310d3b7104812a5ca2d835d") + +if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +endif() + +# Expand relative path. This is important if the provided path contains a tilde (~) +get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) + +file(DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} +) + +include(${CPM_DOWNLOAD_LOCATION}) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 6b0f74a..1c85b72 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -6,14 +6,10 @@ add_library(common STATIC target_include_directories(common PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/include $ $ PRIVATE include/common include/common/ble ) - -# @TODO(mawe): remove qt dependency -target_link_libraries(common - Qt5::Core -) diff --git a/common/include/common/ble/Converter.h b/common/include/common/ble/Converter.h index 93c92aa..aff7a1e 100644 --- a/common/include/common/ble/Converter.h +++ b/common/include/common/ble/Converter.h @@ -3,8 +3,6 @@ #include #include -class QByteArray; - namespace common { namespace ble @@ -16,12 +14,6 @@ class Converter Converter(); virtual ~Converter(); - virtual QByteArray toBle(const std::vector& interfaces) const; - virtual std::vector fromBle(const QByteArray& bytes) const; - - virtual QByteArray filtersToBle(const std::vector& filters) const; - virtual std::vector filtersFromBle(const QByteArray& array) const; - protected: virtual uint8_t fToBle(float f) const; virtual float fFromBle(uint8_t i) const; diff --git a/common/src/ble/Converter.cpp b/common/src/ble/Converter.cpp index b88d456..21fbea6 100644 --- a/common/src/ble/Converter.cpp +++ b/common/src/ble/Converter.cpp @@ -2,8 +2,6 @@ #include -#include - namespace common { namespace ble @@ -17,63 +15,6 @@ Converter::~Converter() { } -QByteArray Converter::toBle(const std::vector& interfaces) const -{ - QByteArray value; - value.reserve(interfaces.size()); - - for (const auto& interface : interfaces) { - value.append(*reinterpret_cast(&interface)); - } - - return value; -} - -std::vector Converter::fromBle(const QByteArray& bytes) const -{ - std::vector interfaces; - interfaces.reserve(bytes.size()); - - for (const auto& c : bytes) { - auto interface = *reinterpret_cast(&c); - interfaces.push_back(interface); - } - - return interfaces; -} - -QByteArray Converter::filtersToBle(const std::vector& filters) const -{ - QByteArray value; - value.reserve(filters.size()*4); - - for (const auto& filter : filters) { - value.append(static_cast(filter.type)); - value.append(fToBle(filter.f)); - value.append(gToBle(filter.g)); - value.append(qToBle(filter.q)); - } - - return value; -} - -std::vector Converter::filtersFromBle(const QByteArray& array) const -{ - if (array.size()%4 != 0) { - return {}; - } - - std::vector filters; - filters.reserve(array.size()/4); - for (int i = 0; i < array.size(); i+=4) { - filters.push_back( { static_cast(array.at(i)), - fFromBle(array.at(i+1)), - gFromBle(array.at(i+2)), - qFromBle(array.at(i+3)) } ); - } - return filters; -} - uint8_t Converter::fToBle(float f) const { uint8_t i = 0; diff --git a/cornrowd/CMakeLists.txt b/cornrowd/CMakeLists.txt index 5a225a4..0380ed3 100644 --- a/cornrowd/CMakeLists.txt +++ b/cornrowd/CMakeLists.txt @@ -19,7 +19,6 @@ target_link_libraries(${PROJECT_NAME} audio bluetooth config - #qtzeroprops ) install(TARGETS ${PROJECT_NAME} diff --git a/cornrowd/src/audio/CMakeLists.txt b/cornrowd/src/audio/CMakeLists.txt index ac47489..9373a69 100644 --- a/cornrowd/src/audio/CMakeLists.txt +++ b/cornrowd/src/audio/CMakeLists.txt @@ -1,3 +1,5 @@ +CPMAddPackage(gh:mincequi/libcornrow@0.1.1) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLOGURU_WITH_STREAMS") add_library(audio STATIC diff --git a/cornrowd/src/bluetooth/Controller.cpp b/cornrowd/src/bluetooth/Controller.cpp index bc3db5d..770878c 100644 --- a/cornrowd/src/bluetooth/Controller.cpp +++ b/cornrowd/src/bluetooth/Controller.cpp @@ -96,8 +96,6 @@ Controller::Controller(QObject *parent) adapter->setDiscoverable(true); adapter->setPairable(true); } - - initBle(); } Controller::~Controller() @@ -121,37 +119,6 @@ void Controller::setReadIoConfCallback(ReadIoConfCallback callback) m_readIoConfCallback = callback; } -void Controller::initBle() -{ - if (!m_manager->usableAdapter() || !m_manager->usableAdapter()->leAdvertisingManager()) { - LOG_F(WARNING, "No BLE adapter present"); - return; - } - - m_advertisement = new LEAdvertisement({QStringLiteral("ad100000-d901-11e8-9f8b-f2801f1b9fd1")}, this); - m_manager->usableAdapter()->leAdvertisingManager()->registerAdvertisement(m_advertisement); - - m_application = new GattApplication(this); - auto service = new GattService(QStringLiteral("ad100000-d901-11e8-9f8b-f2801f1b9fd1"), true, m_application); - - auto peqCharc = new GattCharacteristic(QStringLiteral("ad10e100-d901-11e8-9f8b-f2801f1b9fd1"), service); - peqCharc->setReadCallback(std::bind(&Controller::onReadPeqFilters, this)); - connect(peqCharc, &GattCharacteristic::valueWritten, std::bind(&Controller::onWriteFilters, this, common::ble::CharacteristicType::Peq, _1)); - - auto auxCharc = new GattCharacteristic(QStringLiteral("ad10a100-d901-11e8-9f8b-f2801f1b9fd1"), service); - auxCharc->setReadCallback(std::bind(&Controller::onReadAuxFilters, this)); - connect(auxCharc, &GattCharacteristic::valueWritten, std::bind(&Controller::onWriteFilters, this, common::ble::CharacteristicType::Aux, _1)); - - auto ioCapsCharc = new GattCharacteristic(QString::fromStdString(common::ble::ioCapsCharacteristicUuid), service); - ioCapsCharc->setReadCallback(std::bind(&Controller::onReadIoCaps, this)); - - auto ioConfCharc = new GattCharacteristic(QString::fromStdString(common::ble::ioConfCharacteristicUuid), service); - ioConfCharc->setReadCallback(std::bind(&Controller::onReadIoConf, this)); - connect(ioConfCharc, &GattCharacteristic::valueWritten, this, &Controller::onWriteIoConf); - - m_manager->usableAdapter()->gattManager()->registerApplication(m_application); -} - void Controller::onTransportChanged(MediaTransportPtr transport) { if (m_transport == transport) { @@ -215,48 +182,4 @@ void Controller::onTransportVolumeChanged(uint16_t volume) emit volumeChanged(pow(10.0f, (volume-127)/(factor*20.0f))); } -QByteArray Controller::onReadPeqFilters() -{ - return m_converter.filtersToBle(m_readFiltersCallback(common::ble::CharacteristicType::Peq)); -} - -QByteArray Controller::onReadAuxFilters() -{ - return m_converter.filtersToBle(m_readFiltersCallback(common::ble::CharacteristicType::Aux)); -} - -QByteArray Controller::onReadIoCaps() -{ - return m_converter.toBle(m_readIoCapsCallback()); -} - -QByteArray Controller::onReadIoConf() -{ - return m_converter.toBle(m_readIoConfCallback()); -} - -void Controller::onWriteFilters(common::ble::CharacteristicType group, const QByteArray& value) -{ - emit filtersWritten(group, m_converter.filtersFromBle(value)); -} - -void Controller::onWriteIoConf(const QByteArray& value) -{ - auto interfaces = m_converter.fromBle(value); - - common::IoInterface input; - common::IoInterface output; - - for (const auto& interface : interfaces) { - if (interface.isOutput) { - output = interface; - } else { - input = interface; - } - } - - emit inputSet(input); - emit outputSet(output); -} - } // namespace bluetooth diff --git a/cornrowd/src/bluetooth/Controller.h b/cornrowd/src/bluetooth/Controller.h index 2866b79..141a13b 100644 --- a/cornrowd/src/bluetooth/Controller.h +++ b/cornrowd/src/bluetooth/Controller.h @@ -64,15 +64,9 @@ class Controller : public QObject void outputSet(common::IoInterface output); private: - void initBle(); - void onTransportChanged(BluezQt::MediaTransportPtr transport); void onTransportStateChanged(BluezQt::MediaTransport::State state); void onTransportVolumeChanged(uint16_t volume); - QByteArray onReadPeqFilters(); - QByteArray onReadAuxFilters(); - QByteArray onReadIoCaps(); - QByteArray onReadIoConf(); void onWriteFilters(common::ble::CharacteristicType group, const QByteArray& value); void onWriteIoConf(const QByteArray& value); diff --git a/debian/cornrowd-rpi.install b/debian/cornrowd-rpi.install deleted file mode 100644 index fb9a11c..0000000 --- a/debian/cornrowd-rpi.install +++ /dev/null @@ -1,2 +0,0 @@ -debian/cornrowd.service /lib/systemd/system -debian/tmp-rpi/usr/bin/cornrowd usr/bin diff --git a/debian/cornrowd-rpi.postinst b/debian/cornrowd-rpi.postinst deleted file mode 120000 index 2cc1d97..0000000 --- a/debian/cornrowd-rpi.postinst +++ /dev/null @@ -1 +0,0 @@ -cornrowd.postinst \ No newline at end of file diff --git a/debian/cornrowd-rpi.postrm b/debian/cornrowd-rpi.postrm deleted file mode 120000 index 3511fb5..0000000 --- a/debian/cornrowd-rpi.postrm +++ /dev/null @@ -1 +0,0 @@ -cornrowd.postrm \ No newline at end of file diff --git a/debian/cornrowd.install b/debian/install similarity index 100% rename from debian/cornrowd.install rename to debian/install diff --git a/debian/cornrowd.postinst b/debian/postinst similarity index 100% rename from debian/cornrowd.postinst rename to debian/postinst diff --git a/debian/cornrowd.postrm b/debian/postrm similarity index 100% rename from debian/cornrowd.postrm rename to debian/postrm diff --git a/net/CMakeLists.txt b/net/CMakeLists.txt deleted file mode 100644 index 842292f..0000000 --- a/net/CMakeLists.txt +++ /dev/null @@ -1,63 +0,0 @@ -add_definitions(-DQZEROCONF_STATIC) - -add_library(net STATIC - include/QtZeroProps/QZeroPropsServer.h - include/QtZeroProps/QZeroPropsService.h - - #src/QZeroPropsClient.cpp - src/QZeroPropsServer.cpp - src/QZeroPropsServerPrivate.cpp - src/QZeroPropsService.cpp - src/QZeroPropsServicePrivate.cpp - src/QZeroPropsWsServer.h - src/QZeroPropsWsServer.cpp - src/QZeroPropsWsService.h - src/QZeroPropsWsService.cpp - - ../thirdparty/QtZeroConf/qzeroconf.h - ../thirdparty/QtZeroConf/avahi-qt/qt-watch.h - ../thirdparty/QtZeroConf/avahi-qt/qt-watch_p.h - - ../thirdparty/QtZeroConf/avahi-qt/qt-watch.cpp - ../thirdparty/QtZeroConf/avahiclient.cpp - ../thirdparty/QtZeroConf/avahi-qt/qt-watch.cpp - - ../thirdparty/qmsgpack/src/msgpack.cpp - ../thirdparty/qmsgpack/src/msgpackcommon.cpp - ../thirdparty/qmsgpack/src/msgpackstream.cpp - ../thirdparty/qmsgpack/src/private/pack_p.cpp - ../thirdparty/qmsgpack/src/private/unpack_p.cpp - ../thirdparty/qmsgpack/src/private/qt_types_p.cpp - ../thirdparty/qmsgpack/src/stream/time.cpp - ../thirdparty/qmsgpack/src/stream/geometry.cpp - - ../thirdparty/qmsgpack/src/msgpack.h - ../thirdparty/qmsgpack/src/endianhelper.h - ../thirdparty/qmsgpack/src/msgpackcommon.h - ../thirdparty/qmsgpack/src/msgpack_export.h - ../thirdparty/qmsgpack/src/msgpackstream.h - ../thirdparty/qmsgpack/src/private/pack_p.h - ../thirdparty/qmsgpack/src/private/unpack_p.h - ../thirdparty/qmsgpack/src/private/qt_types_p.h - ../thirdparty/qmsgpack/src/stream/time.h - ../thirdparty/qmsgpack/src/stream/geometry.h -) - -target_include_directories(net -PUBLIC - $ - $ - src # @TODO(mawe): temporary hack -PRIVATE - include/net - ../thirdparty/QtZeroConf - ../thirdparty/qmsgpack/src -) - -target_link_libraries(net - avahi-common - avahi-client - common - cornrow - Qt5::WebSockets -) diff --git a/net/include/QtZeroProps/QZeroPropsClient.h b/net/include/QtZeroProps/QZeroPropsClient.h deleted file mode 100644 index 6d00567..0000000 --- a/net/include/QtZeroProps/QZeroPropsClient.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2020 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include - -#include - -namespace QtZeroProps -{ -class QZeroPropsService; - -/// Discovers and connects to a remote QZeroPropsServer. -class QZeroPropsClient : public QObject -{ - Q_OBJECT - - /// Returns a list of all discovered services. - Q_PROPERTY(QList discoveredServices READ discoveredServices NOTIFY servicesChanged) - -public: - /// This enum describes the different states in which a client can be. - enum class State : uint8_t { - Idle, ///< The client is idle. We also enter this state when Discovering times out. - Discovering, ///< The client is disovering services. - Connecting, ///< The client is connecting to a service. - Connected, ///< The client is connected to a service. - Disconnected, ///< The connection has been interrupted. - Error ///< This indicated that an error occured. - }; - Q_ENUM(State) - - /// Constructs a new QZeroPropsClient with parent. - explicit QZeroPropsClient(QObject* parent = nullptr); - - /// Destroys this QZeroPropsClient. - ~QZeroPropsClient(); - - //ServiceTypes supportedServiceTypes() const; - - /// Sets the maximum search time for QZeroPropsServers in milliseconds. - /// If timeout is 0 the discovery runs until stopDiscovery() is called. - /// - /// The timeout ensures that the discovery is stopped after timeout - /// milliseconds. It is still possible to manually abort the discovery by - /// calling stopDiscovery(). - /// - /// The new timeout value does not take effect until the discovery is - /// restarted. - void setDiscoveryTimeout(int msTimeout); - - /// Returns a list of all discovered services. See QZeroPropsService for - /// object details. - /// - /// When a new discovery is started, all previously returned - /// QZeroPropsServices are invalid. - QObjectList discoveredServices() const; - -public slots: - /// Starts QZeroProps service discovery. If it was previously started, it - /// will be stopped and started again. Any previously returned - /// QZeroPropsService will be invalid. - /// - /// The Discovering state is emitted once the discovery is started. When it - /// finishes, the Idle state is emitted. - /// - /// The configuration defines the Bluetooth Low Energy and WebSocket - /// services we are looking for. If the appropriate fields are empty or - /// undefined, they are not discovered. - void startDiscovery(const ServiceConfiguration& config); - - /// Stops QZeroProps service discovery. - /// - /// The Idle state is emitted once the discovery is stopped. - void stopDiscovery(); - - /// Connect to a QZeroPropsService that has previously been discovered. - void connectToService(QZeroPropsService* device); - - /// Disconnect from currently connected QZeroPropsService. - void disconnectFromService(); - -signals: - /// This signal is emitted whenever QZeroPropsClient's state changes. - /// - /// The state parameter is the new state. - /// The errorString is additionally provided in case an Error state occured. - void stateChanged(State state, const QString& errorString = QString()); - - /// This signal is emitted whenever discovered services changed during - /// Discovering state. It is also emitted when a new discovery is started - /// and all previously discovered services are cleared. - void servicesChanged(); - -private: - class QZeroPropsClientPrivate* const d; -}; - -} // namespace QZeroProps diff --git a/net/include/QtZeroProps/QZeroPropsServer.h b/net/include/QtZeroProps/QZeroPropsServer.h deleted file mode 100644 index 4415f24..0000000 --- a/net/include/QtZeroProps/QZeroPropsServer.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2020 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include - -namespace QtZeroProps -{ -class QZeroPropsService; -struct ServiceConfiguration; - -/// QZeroPropsServer creates, starts and announces QZeroPropsServices which can -/// be connected to from remote QZeroPropsClients. -class QZeroPropsServer : public QObject -{ - Q_OBJECT - -public: - /// Constructs a new QZeroPropsServer with parent. - explicit QZeroPropsServer(QObject* parent = nullptr); - - /// Destroys this QZeroPropsServer. - ~QZeroPropsServer(); - - //ServiceTypes supportedServiceTypes() const; - - /// Create, start and announce a QZeroPropsService represented by - /// configuration. - /// - /// Any QZeroPropsService instance that resulted from previous call to this - /// function is invalidated. - /// - /// The configuration defines the Bluetooth Low Energy and WebSocket - /// services we are providing. If the appropriate fields are empty or - /// undefined, the corresponding backend is not started. - QZeroPropsService* startService(const ServiceConfiguration& configuration); - - /// Stops current QZeroProps service. - void stopService(); - -private: - class QZeroPropsServerPrivate* const d; -}; - -} // namespace QZeroProps diff --git a/net/include/QtZeroProps/QZeroPropsService.h b/net/include/QtZeroProps/QZeroPropsService.h deleted file mode 100644 index 33736b1..0000000 --- a/net/include/QtZeroProps/QZeroPropsService.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2020 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include - -namespace QtZeroProps -{ - -/// QZeroPropsService provides access to the properties of a service instance. -/// The class permits modifying of the contained data and notifies about remote -/// changes. -/// -/// Instances are created either from QZeroPropsClient or QZeroPropsServer and -/// behave slighty different dependent on their role (client or server). -class QZeroPropsService : public QObject -{ - Q_OBJECT - - /// This property holds the host/device name the service is running on. - Q_PROPERTY(QString name READ name) - /// This property holds the type of this service. - Q_PROPERTY(ServiceType type READ type) - -public: - enum class ServiceType : uint8_t { - Invalid = 0, - BluetoothLe = 0x1, - WebSocket = 0x2, - All = BluetoothLe | WebSocket - }; - Q_ENUM(ServiceType) - - /// Destroys this QZeroPropsService. - virtual ~QZeroPropsService(); - - /// Returns the host/device name the service is running on. - QString name() const; - - /// Returns the type of this service. - ServiceType type() const; - - /// This property holds the debounce time in milliseconds that is applied to - /// any call to setProperty(). - /// - /// If this object is created on server side, the default value is 0, which - /// means a changed value will immediatly be sent. On client side this value - /// defaults to 200 milliseconds. - int debounceTime() const; - void setDebounceTime(int msec); - - /// Set property values and emit to remote QZeroPropsService object. Calling - /// this function does not trigger the a propertyChanged() signal unless the - /// remote QZeroPropsService itself changes the value again afterwards. - /// Values can be set and identified using QUuids and quint32. - /// - /// If we are using the BluetoothLe backend all properties set with quint32 - /// are extended to a QUuid using the base Uuid from this service. - void setProperty(quint32 id, const QByteArray& value); - void setProperty(const QUuid& uuid, const QByteArray& value); - -signals: - /// This signal is emitted when the value of a property is changed remotely. - /// - /// Each property is uniquely identified by the uuid parameter, which can - /// carry a quint32 or QUuid, depending which method was used on remote side - /// to change the property's value. - /// The value parameter contains the updated value of the property. - void propertyChanged(const QVariant& uuid, const QByteArray& value); - -private: - QZeroPropsService(QObject* parent = nullptr); - - // make non-const to later add custom impl - class QZeroPropsServicePrivate* d; - - friend class QZeroPropsClient; - friend class QZeroPropsClientPrivate; - friend class QZeroPropsServer; - friend class QZeroPropsServerPrivate; -}; - -} // namespace QZeroProps diff --git a/net/include/QtZeroProps/QZeroPropsTypes.h b/net/include/QtZeroProps/QZeroPropsTypes.h deleted file mode 100644 index 4e95cbd..0000000 --- a/net/include/QtZeroProps/QZeroPropsTypes.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2020 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include - -namespace QtZeroProps -{ - -/// ServiceConfiguration struct for QZeroPropsServer and QZeroPropsClient. -/// -/// Provide a valid zeroConfType for using the WebSocket backend (e.g. _raop._tcp). -/// Provide a valid bleUuid for using the Bluetooth Low Energy backend. -struct ServiceConfiguration -{ - QString zeroConfType; ///< ZeroConf (WebSocket) service type to announce/discover - QUuid bleUuid; ///< BluetoothLe service uuid to announce/discover -}; - -} // namespace QZeroProps diff --git a/net/net.pro b/net/net.pro deleted file mode 100644 index 3da0630..0000000 --- a/net/net.pro +++ /dev/null @@ -1,40 +0,0 @@ -TEMPLATE = lib -QT -= gui -QT += bluetooth websockets -CONFIG += staticlib create_prl - -QMAKE_CXXFLAGS += -Werror - -DEFINES += QZEROCONF_STATIC MSGPACK_NO_PACKTYPES -include(../thirdparty/QtZeroConf/qtzeroconf.pri) -include(../thirdparty/qmsgpack/qmsgpack.pri) - -SOURCES += \ - src/BleClientSession.cpp \ - src/BleServer.cpp \ - src/BleServerSession.cpp \ - src/QZeroPropsBleClient.cpp \ - src/QZeroPropsClient.cpp \ - src/QZeroPropsServer.cpp \ - src/QZeroPropsServerPrivate.cpp \ - src/QZeroPropsService.cpp \ - src/QZeroPropsServicePrivate.cpp \ - src/QZeroPropsWsService.cpp \ - src/QZeroPropsWsServer.cpp - -HEADERS += \ - include/QtZeroProps/QZeroPropsTypes.h \ - include/QtZeroProps/QZeroPropsClient.h \ - include/QtZeroProps/QZeroPropsServer.h \ - include/QtZeroProps/QZeroPropsService.h \ - src/BleClientSession.h \ - src/BleServerSession.h \ - src/QZeroPropsBleClient.h \ - src/QZeroPropsBleService.h \ - src/QZeroPropsServerPrivate.h \ - src/QZeroPropsServicePrivate.h \ - src/QZeroPropsWsService.h \ - src/QZeroPropsWsServer.h - -INCLUDEPATH += \ - include diff --git a/net/src/BleClientSession.cpp b/net/src/BleClientSession.cpp deleted file mode 100644 index f4ceb66..0000000 --- a/net/src/BleClientSession.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (C) 2020 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "BleClientSession.h" - -#include - -#include "QZeroPropsBleClient.h" -#include "QZeroPropsServicePrivate.h" - -namespace QtZeroProps -{ - -BleClientSession::BleClientSession(QZeroPropsServicePrivate* _q) - : q(_q) -{ -} - -BleClientSession::~BleClientSession() -{ -} - -void BleClientSession::connectToDevice(const QBluetoothDeviceInfo& device, const QUuid& serviceUuid) -{ - disconnectFromDevice(); - - qDebug() << "Connecting device: " << device.name(); - - m_serviceUuid = serviceUuid; - - // @TODO(mawe): handle multiple devices - m_control = new QLowEnergyController(device, this); - m_control->setRemoteAddressType(QLowEnergyController::PublicAddress); - - // Connect to device - //q->setStatus(BleClient::Status::Connecting, "Connecting " + m_control->remoteName()); - - connect(m_control, &QLowEnergyController::connected, this, &BleClientSession::onDeviceConnected); - connect(m_control, &QLowEnergyController::disconnected, this, &BleClientSession::onDeviceDisconnected); - m_control->connectToDevice(); - - // Discover services after device has been connected - connect(m_control, &QLowEnergyController::serviceDiscovered, this, &BleClientSession::onServiceDiscovered); - connect(m_control, QOverload::of(&QLowEnergyController::error), this, &BleClientSession::onServiceDiscoveryError); - connect(m_control, &QLowEnergyController::discoveryFinished, this, &BleClientSession::onServiceDiscoveryFinished); -} - -void BleClientSession::disconnectFromDevice() -{ - // Disconnect - if (m_control) { - m_control->disconnectFromDevice(); - delete m_control; - m_control = nullptr; - } -} - -void BleClientSession::onDeviceConnected() -{ - qDebug() << "Device connected. Discovering services..."; - - m_control->discoverServices(); -} - -void BleClientSession::onDeviceDisconnected() -{ - qDebug() << __func__; - - q->disconnect(); - emit q->stateChanged(QZeroPropsClient::State::Disconnected); -} - -void BleClientSession::onServiceDiscovered(const QBluetoothUuid& serviceUuid) -{ - qDebug() << __func__ << "Service discovered:" << serviceUuid; -} - -void BleClientSession::onServiceDiscoveryError(QLowEnergyController::Error /*error*/) -{ - qDebug() << __func__; - - emit q->stateChanged(QZeroPropsClient::State::Error, m_control->errorString()); -} - -void BleClientSession::onServiceDiscoveryFinished() -{ - qDebug() << __func__; - - if (!m_control->services().contains(m_serviceUuid)) { - emit q->stateChanged(QZeroPropsClient::State::Error, "Could not find cornrow service on device " + m_control->remoteName()); - return; - } - m_service = m_control->createServiceObject(m_serviceUuid, this); - connect(m_service, &QLowEnergyService::stateChanged, this, &BleClientSession::onServiceStateChanged); - connect(m_service, &QLowEnergyService::characteristicRead, this, &BleClientSession::onCharacteristicRead); - connect(m_service, QOverload::of(&QLowEnergyService::error), this, &BleClientSession::onServiceError); - - // We cannot access characteristics here, but we have to wait for appropriate state change. - // discoverDetails() will trigger those state changes. - m_service->discoverDetails(); - //q->setStatus(BleClient::Status::Connecting, "Reading settings from " + m_control->remoteName()); -} - -void BleClientSession::onServiceStateChanged(QLowEnergyService::ServiceState s) -{ - switch (s) { - case QLowEnergyService::ServiceDiscovered: - for (const auto& charc : m_service->characteristics()) { - m_service->readCharacteristic(charc); - } - break; - case QLowEnergyService::InvalidService: - qDebug() << __func__; - emit q->stateChanged(QZeroPropsClient::State::Disconnected); - break; - case QLowEnergyService::DiscoveryRequired: - // Rename DiscoveringServices -> DiscoveringDetails or DiscoveringService - case QLowEnergyService::DiscoveringServices: // discoverDetails() called and running - case QLowEnergyService::LocalService: // Only in peripheral role - break; - } -} - -void BleClientSession::onServiceError(QLowEnergyService::ServiceError /*error*/) -{ - qDebug() << __func__; - - emit q->stateChanged(QZeroPropsClient::State::Error, "Service error"); -} - -void BleClientSession::onCharacteristicRead(const QLowEnergyCharacteristic& characteristic, const QByteArray& value) -{ - qDebug() << __func__ << "> " << characteristic.uuid(); - emit q->stateChanged(QZeroPropsClient::State::Connected); - emit characteristicChanged(characteristic.uuid().toString(QUuid::StringFormat::WithoutBraces).toStdString().c_str(), value); -} - -} // namespace QZeroProps diff --git a/net/src/BleClientSession.h b/net/src/BleClientSession.h deleted file mode 100644 index 5b06ad3..0000000 --- a/net/src/BleClientSession.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2020 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include - -#include - -namespace QtZeroProps -{ -class QZeroPropsServicePrivate; - -class BleClientSession : public QObject -{ - Q_OBJECT - -public: - BleClientSession(QZeroPropsServicePrivate* _q); - ~BleClientSession(); - - void setDiscoveryTimeout(int msTimeout); - void startDiscovery(const QUuid& uuid); - void stopDiscovery(); - - void connectToDevice(const QBluetoothDeviceInfo& device, const QUuid& serviceUuid); - void disconnectFromDevice(); - -signals: - // Emits remotely changed values - void characteristicChanged(const QUuid& uuid, const QByteArray& value); - -private: - // QLowEnergyController - void onDeviceConnected(); - void onDeviceDisconnected(); - void onServiceDiscovered(const QBluetoothUuid&); - void onServiceDiscoveryError(QLowEnergyController::Error); - void onServiceDiscoveryFinished(); - - // QLowEnergyService - void onServiceStateChanged(QLowEnergyService::ServiceState s); - void onServiceError(QLowEnergyService::ServiceError error); - void onCharacteristicRead(const QLowEnergyCharacteristic& characteristic, const QByteArray& value); - - QZeroPropsServicePrivate* q; - QUuid m_serviceUuid; - QLowEnergyController* m_control = nullptr; - QLowEnergyService* m_service = nullptr; - - friend class QZeroPropsBleService; -}; - -} // namespace QZeroProps diff --git a/net/src/BleServer.cpp b/net/src/BleServer.cpp deleted file mode 100644 index d513f66..0000000 --- a/net/src/BleServer.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2018 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "BleServer.h" - -#include "BleServerSession.h" - -#include -#include -#include -#include - -#include - -namespace QtZeroProps -{ - -BleServer::BleServer(QObject *parent) - : QObject(parent) -{ -} - -BleServer::~BleServer() -{ -} - -void BleServer::init(const QUuid& uuid, CharcsProvider charcsProvider) -{ - m_charcsProvider = charcsProvider; - - startPublishing(uuid); -} - -void BleServer::startPublishing(const QUuid& uuid) -{ - if (m_session) { - delete m_session; - m_session = nullptr; - } - - // Publish service - m_session = new BleServerSession(uuid, this, m_charcsProvider()); -} - -} // namespace QZeroProps diff --git a/net/src/BleServer.h b/net/src/BleServer.h deleted file mode 100644 index 5af9d27..0000000 --- a/net/src/BleServer.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2018 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include - -#include -#include - -class QLowEnergyCharacteristic; - -namespace QtZeroProps -{ - -class BleServer : public QObject -{ - Q_OBJECT - -public: - explicit BleServer(QObject *parent = nullptr); - ~BleServer(); - -signals: - // Signals, that a client has changed a characteristic - void characteristicChanged(const QLowEnergyCharacteristic& characteristic, const QByteArray& newValue); - // Signals, that a device disconnected. Used to trigger persistence. - void deviceDisconnected(); - -private: - // Adapter should set initial values of characteristics - using CharcsProvider = std::function()>; - void init(const QUuid& uuid, CharcsProvider); - - void startPublishing(const QUuid& uuid); - - CharcsProvider m_charcsProvider = nullptr; - - class BleServerSession* m_session = nullptr; - friend class BleServerAdapter; - friend class BleServerSession; -}; - -} // namespace QZeroProps diff --git a/net/src/BleServerSession.cpp b/net/src/BleServerSession.cpp deleted file mode 100644 index 6c1047a..0000000 --- a/net/src/BleServerSession.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2020 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "BleServerSession.h" - -#include "BleServer.h" - -namespace QtZeroProps -{ - -BleServerSession::BleServerSession(const QUuid& serviceUuid, BleServer* server, const std::map& characteristicsMap) - : m_serviceUuid(serviceUuid), - m_server(server) -{ - // Service data - serviceData.setType(QLowEnergyServiceData::ServiceTypePrimary); - serviceData.setUuid(m_serviceUuid); - - QList characteristics; - for (const auto& kv : characteristicsMap) { - QLowEnergyCharacteristicData characteristicData; - characteristicData.setUuid(kv.first); - characteristicData.setValue(kv.second); - characteristicData.setProperties(QLowEnergyCharacteristic::Read | QLowEnergyCharacteristic::Write); - characteristics << characteristicData; - } - serviceData.setCharacteristics(characteristics); - - // Peripheral - peripheral = QLowEnergyController::createPeripheral(this); - service = peripheral->addService(serviceData); - connect(service, &QLowEnergyService::characteristicChanged, m_server, &BleServer::characteristicChanged); - connect(service, QOverload::of(&QLowEnergyService::error), this, &BleServerSession::onError); - - // Advertising will stop once a client connects, so re-advertise once disconnected. - connect(peripheral, &QLowEnergyController::disconnected, this, &BleServerSession::onDisconnected); - connect(peripheral, QOverload::of(&QLowEnergyController::error), this, &BleServerSession::onError); - // This has to be connected last, since it destroys the previous ServerSession object - connect(peripheral, &QLowEnergyController::disconnected, [this]() { - m_server->startPublishing(m_serviceUuid); - }); - - // Advertising data - advertisingData.setDiscoverability(QLowEnergyAdvertisingData::DiscoverabilityGeneral); - advertisingData.setServices({m_serviceUuid}); - peripheral->startAdvertising(QLowEnergyAdvertisingParameters(), advertisingData/*, advertisingData*/); -} - -BleServerSession::~BleServerSession() -{ - peripheral->stopAdvertising(); - peripheral->disconnectFromDevice(); -} - -void BleServerSession::onError() -{ - qDebug() << __func__; - - emit m_server->deviceDisconnected(); -} - -void BleServerSession::onDisconnected() -{ - qDebug() << __func__; - - emit m_server->deviceDisconnected(); -} - -} // namespace QZeroProps diff --git a/net/src/BleServerSession.h b/net/src/BleServerSession.h deleted file mode 100644 index 41bdb8d..0000000 --- a/net/src/BleServerSession.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2020 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include -#include -#include - -namespace QtZeroProps -{ -class BleServer; - -class BleServerSession : public QObject -{ - Q_OBJECT - -public: - explicit BleServerSession(const QUuid& serviceUuid, BleServer* server, const std::map& characteristicsMap); - ~BleServerSession(); - - QLowEnergyController* peripheral; - QLowEnergyService* service; - QLowEnergyAdvertisingData advertisingData; - QLowEnergyServiceData serviceData; - -private: - void onError(); - void onDisconnected(); - - const QUuid m_serviceUuid; - BleServer* m_server = nullptr; -}; - -} // namespace QZeroProps diff --git a/net/src/QZeroPropsBleClient.cpp b/net/src/QZeroPropsBleClient.cpp deleted file mode 100644 index 2211f74..0000000 --- a/net/src/QZeroPropsBleClient.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (C) 2018 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "QZeroPropsBleClient.h" - -#include "BleClientSession.h" - -#include -#include -#include - -#include "QZeroPropsBleService.h" - -namespace QtZeroProps -{ - -QZeroPropsBleClient::QZeroPropsBleClient(QObject* parent) - : QObject(parent) -{ -} - -QZeroPropsBleClient::~QZeroPropsBleClient() -{ - //delete m_clientSession; -} - -void QZeroPropsBleClient::setDiscoveryTimeout(int msTimeout) -{ - m_msTimeout = msTimeout; -} - -void QZeroPropsBleClient::startDiscovery(const QUuid& uuid) -{ - stopDiscovery(); - - m_serviceUuid = uuid; - m_discoverer = new QBluetoothDeviceDiscoveryAgent(this); - connect(m_discoverer, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &QZeroPropsBleClient::onDeviceDiscovered); - connect(m_discoverer, QOverload::of(&QBluetoothDeviceDiscoveryAgent::error), this, &QZeroPropsBleClient::onDeviceDiscoveryError); - connect(m_discoverer, &QBluetoothDeviceDiscoveryAgent::finished, this, &QZeroPropsBleClient::onDeviceDiscoveryFinished); - - m_discoverer->setLowEnergyDiscoveryTimeout(m_msTimeout); - m_discoverer->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod); -} - -void QZeroPropsBleClient::stopDiscovery() -{ - if (m_discoverer) { - m_discoverer->stop(); - m_discoverer->deleteLater(); - m_discoverer = nullptr; - } -} - -void QZeroPropsBleClient::setStatus(QZeroPropsClient::State _error, const QString& errorString) -{ - qDebug() << "Status:" << static_cast(_error) << "error:" << errorString; - emit stateChanged(_error, errorString); -} - -void QZeroPropsBleClient::onDeviceDiscovered(const QBluetoothDeviceInfo& device) -{ - // Only check LE devices - if (!(device.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration)) { - return; - } - - // Check if service is already discovered - auto serviceUuids = device.serviceUuids(); - if (serviceUuids.contains(m_serviceUuid)) { - qDebug() << __func__ << ": found cornrow device:" << device.name(); - emit serviceDiscovered(device, m_serviceUuid); - return; - } - - // We have to do a full discovery - // @TODO(mawe): this causes crashed. To be fixed. Currently, we rely on services provided from device discovery instead of doing a full discovery. - //discoverServices(device); -} - -void QZeroPropsBleClient::onDeviceDiscoveryError(QBluetoothDeviceDiscoveryAgent::Error error) -{ - qDebug() << __func__ << "error:" << error << "string:" << m_discoverer->errorString(); - - setStatus(QZeroPropsClient::State::Error, m_discoverer->errorString()); -} - -void QZeroPropsBleClient::onDeviceDiscoveryFinished() -{ - qDebug() << __func__; - - setStatus(QZeroPropsClient::State::Idle); -} - -void QZeroPropsBleClient::discoverServices(const QBluetoothDeviceInfo& device) -{ - qDebug() << "Connecting device: " << device.name(); - - m_controller = new QLowEnergyController(device, this); - m_controller->setRemoteAddressType(QLowEnergyController::PublicAddress); - - connect(m_controller, &QLowEnergyController::connected, [&]() { - connect(m_controller, &QLowEnergyController::serviceDiscovered, [&] (const QBluetoothUuid& newService) { - if (newService == m_serviceUuid) { - emit serviceDiscovered(device, m_serviceUuid); - m_controller->disconnectFromDevice(); - } - }); - connect(m_controller, &QLowEnergyController::discoveryFinished, [this] () { - m_controller->disconnectFromDevice(); - }); - - m_controller->discoverServices(); - }); - connect(m_controller, &QLowEnergyController::disconnected, [this]() { - m_controller->deleteLater(); - }); - m_controller->connectToDevice(); -} - -} // namespace QZeroProps diff --git a/net/src/QZeroPropsBleClient.h b/net/src/QZeroPropsBleClient.h deleted file mode 100644 index 063d5a6..0000000 --- a/net/src/QZeroPropsBleClient.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2018 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include - -#include - -class QBluetoothDeviceInfo; -class QLowEnergyController; - -namespace QtZeroProps -{ -class QZeroPropsService; - -class QZeroPropsBleClient : public QObject -{ - Q_OBJECT - -public: - explicit QZeroPropsBleClient(QObject *parent = nullptr); - ~QZeroPropsBleClient(); - - void setDiscoveryTimeout(int msTimeout); - void startDiscovery(const QUuid& uuid); - void stopDiscovery(); - -signals: - void stateChanged(QZeroPropsClient::State state, const QString& errorString = QString()); - void serviceDiscovered(const QBluetoothDeviceInfo& device, const QUuid& serviceUuid); - -private: - void setStatus(QZeroPropsClient::State state, const QString& errorString = QString()); - - void onDeviceDiscovered(const QBluetoothDeviceInfo& device); - void onDeviceDiscoveryError(QBluetoothDeviceDiscoveryAgent::Error error); - void onDeviceDiscoveryFinished(); - - void discoverServices(const QBluetoothDeviceInfo& device); - - QUuid m_serviceUuid; - QBluetoothDeviceDiscoveryAgent* m_discoverer = nullptr; - QLowEnergyController* m_controller; - - friend class BleClientSession; - friend class QZeroPropsBleService; - friend class QZeroPropsClientPrivate; - - int m_msTimeout = 8000; -}; - -} // namespace QZeroProps diff --git a/net/src/QZeroPropsBleService.h b/net/src/QZeroPropsBleService.h deleted file mode 100644 index a1c912d..0000000 --- a/net/src/QZeroPropsBleService.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2020 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include "QZeroPropsServicePrivate.h" -#include "QZeroPropsBleClient.h" -#include "BleClientSession.h" -#include - -namespace QtZeroProps -{ - -class QZeroPropsBleService : public QZeroPropsServicePrivate -{ -public: - QZeroPropsBleService(QZeroPropsService* _q) - : QZeroPropsServicePrivate(_q), - session(new BleClientSession(this)) - { - QObject::connect(session, &BleClientSession::characteristicChanged, [this](const QUuid& uuid, const QByteArray& value) { - onReceive(uuid, value); - }); - } - - ~QZeroPropsBleService() override { - delete session; - } - - void connect() override { - emit stateChanged(QZeroPropsClient::State::Connecting, "Connecting " + q->name()); - session->connectToDevice(bluetoothDeviceInfo, serviceUuid); - } - - void disconnect() override { - session->disconnectFromDevice(); - } - - void doSend(const QVariant& uuid, const QByteArray& value) override { - if (!session || !session->m_service) { - qWarning() << __func__ << "> No BLE device connected"; - return; - } - - const auto characteristic = session->m_service->characteristic(uuid.toUuid()); - if (!characteristic.isValid()) { - qDebug() << __func__ << "> Characteristic invalid:" << characteristic.uuid(); - return; - } - session->m_service->writeCharacteristic(characteristic, value); - } - - void onReceive(const QUuid& uuid, const QByteArray& value) { - properties.insert(uuid, value); - emit q->propertyChanged(uuid, value); - } - - // Event handlers from socket - void onStateChanged(QAbstractSocket::SocketState state); - - QBluetoothDeviceInfo bluetoothDeviceInfo; - QUuid serviceUuid; - BleClientSession* session = nullptr; -}; - -} // namespace QZeroProps diff --git a/net/src/QZeroPropsClient.cpp b/net/src/QZeroPropsClient.cpp deleted file mode 100644 index da4f73a..0000000 --- a/net/src/QZeroPropsClient.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (C) 2020 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include - -#include "QZeroPropsBleClient.h" -#include "QZeroPropsBleService.h" -#include "QZeroPropsWsService.h" - -#include - -#include -#include - -namespace QtZeroProps -{ -using QZeroPropsServicePtr = QSharedPointer; - -class QZeroPropsClientPrivate -{ -public: - QZeroPropsClientPrivate(QZeroPropsClient* _q) - : q(_q) - { - // Setup zeroconf - QObject::connect(&zeroConf, &QZeroConf::serviceAdded, [this](QZeroConfService service) { - onServiceDiscovered(service); - }); - - QObject::connect(&bleClient, &QtZeroProps::QZeroPropsBleClient::serviceDiscovered, [this](const QBluetoothDeviceInfo& service, const QUuid& serviceUuid) { - onServiceDiscovered(service, serviceUuid); - }); - QObject::connect(&bleClient, &QZeroPropsBleClient::stateChanged, [this](QZeroPropsClient::State state, const QString& errorString) { - if (state == QZeroPropsClient::State::Idle) { - q->stopDiscovery(); - return; - } - emit q->stateChanged(state, errorString); - }); - } - - void onServiceDiscovered(QZeroConfService service) - { - // Create impl and attach to base class - QZeroPropsServicePtr device(new QZeroPropsService); - auto impl = new QZeroPropsWsService(device.data()); - impl->name = service->name(); - impl->type = ServiceType::WebSocket; - impl->address = service->ip(); - impl->port = service->port(); - device->d = impl; - - services.push_back(device); - emit q->servicesChanged(); - } - - void onServiceDiscovered(const QBluetoothDeviceInfo& info, const QUuid& serviceUuid) - { - QZeroPropsServicePtr device(new QZeroPropsService); - QString name = info.name(); - if (name.isEmpty()) { - name = ""; - } - auto impl = new QZeroPropsBleService(device.data()); - impl->name = name; - impl->type = ServiceType::BluetoothLe; - impl->bluetoothDeviceInfo = info; - impl->serviceUuid = serviceUuid; - device->d = impl; - - services.push_back(device); - emit q->servicesChanged(); - } - - QZeroPropsClient* const q; - - // ZeroConf members - QZeroConf zeroConf; - QZeroPropsBleClient bleClient; - - QList services; - QZeroPropsService* currentService = nullptr; -}; - -QZeroPropsClient::QZeroPropsClient(QObject* parent) - : QObject(parent), - d(new QZeroPropsClientPrivate(this)) -{ -} - -QZeroPropsClient::~QZeroPropsClient() -{ -} - -void QZeroPropsClient::setDiscoveryTimeout(int msTimeout) -{ - d->bleClient.setDiscoveryTimeout(msTimeout); -} - -QObjectList QZeroPropsClient::discoveredServices() const -{ - QObjectList _devices; - for (const auto& device : d->services) { - _devices.push_back(device.get()); - } - return _devices; -} - -void QZeroPropsClient::startDiscovery(const ServiceConfiguration& config) -{ - // Clear previous services - d->services.clear(); - emit servicesChanged(); - emit stateChanged(State::Discovering); - - if (!config.zeroConfType.isEmpty()) { - d->zeroConf.startBrowser(config.zeroConfType); - } - - if (!config.bleUuid.isNull()) { - d->bleClient.startDiscovery(config.bleUuid); - } -} - -void QZeroPropsClient::stopDiscovery() -{ - d->zeroConf.stopBrowser(); - d->bleClient.stopDiscovery(); - - emit stateChanged(State::Idle); -} - -void QZeroPropsClient::connectToService(QZeroPropsService* service) -{ - disconnectFromService(); - - if (!service) { - return; - } - - stopDiscovery(); - emit stateChanged(State::Connecting, "Connecting " + service->name()); - - d->currentService = service; - connect(d->currentService->d, &QZeroPropsServicePrivate::stateChanged, this, &QZeroPropsClient::stateChanged); - d->currentService->d->connect(); -} - -void QZeroPropsClient::disconnectFromService() -{ - if (d->currentService) { - //d->currentService->d->disconnect(); - d->currentService = nullptr; - } -} - -} // namespace QZeroProps diff --git a/net/src/QZeroPropsServer.cpp b/net/src/QZeroPropsServer.cpp deleted file mode 100644 index d8d82d4..0000000 --- a/net/src/QZeroPropsServer.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2020 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include - -#include -#include "QZeroPropsWsServer.h" -#include "QZeroPropsWsService.h" - -namespace QtZeroProps -{ - -QZeroPropsServer::QZeroPropsServer(QObject* parent) : - QObject(parent), - d(new QZeroPropsWsServer(this)) -{ -} - -QZeroPropsServer::~QZeroPropsServer() -{ -} - -QZeroPropsService* QZeroPropsServer::startService(const ServiceConfiguration& configuration) -{ - d->stopService(); - - return d->startPublishing(configuration); -} - -void QZeroPropsServer::stopService() -{ - d->stopService(); -} - -} // namespace QZeroProps diff --git a/net/src/QZeroPropsServerPrivate.cpp b/net/src/QZeroPropsServerPrivate.cpp deleted file mode 100644 index bf6a0a1..0000000 --- a/net/src/QZeroPropsServerPrivate.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "QZeroPropsServerPrivate.h" - -#include "QZeroPropsServicePrivate.h" -#include - -namespace QtZeroProps -{ - -QZeroPropsServerPrivate::QZeroPropsServerPrivate(QObject *parent) : - QObject(parent) -{ -} - -QZeroPropsServerPrivate::~QZeroPropsServerPrivate() -{ -} - -QZeroPropsService* QZeroPropsServerPrivate::startPublishing(const ServiceConfiguration& config) -{ - m_currentService = new QZeroPropsService; - auto temp = createService(config); - m_currentService->d = temp; - m_currentService->setDebounceTime(0); - - return m_currentService; -} - -void QZeroPropsServerPrivate::stopService() -{ - if (!m_currentService) { - return; - } - - m_currentService->d->disconnect(); - m_currentService = nullptr; -} - -} // namespace QtZeroProps diff --git a/net/src/QZeroPropsServerPrivate.h b/net/src/QZeroPropsServerPrivate.h deleted file mode 100644 index 6f98e4a..0000000 --- a/net/src/QZeroPropsServerPrivate.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2018 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include - -namespace QtZeroProps -{ -class QZeroPropsService; -class QZeroPropsServicePrivate; -struct ServiceConfiguration; - -class QZeroPropsServerPrivate : public QObject -{ - Q_OBJECT -public: - explicit QZeroPropsServerPrivate(QObject *parent = nullptr); - ~QZeroPropsServerPrivate(); - - // @TODO(mawe): rename - QZeroPropsService* startPublishing(const ServiceConfiguration& config); - virtual void stopService(); - -protected: - virtual QZeroPropsServicePrivate* createService(const ServiceConfiguration& config) = 0; - - QZeroPropsService* m_currentService = nullptr; -}; - -} // namespace QtZeroProps diff --git a/net/src/QZeroPropsService.cpp b/net/src/QZeroPropsService.cpp deleted file mode 100644 index f832a22..0000000 --- a/net/src/QZeroPropsService.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2020 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include - -#include "QZeroPropsWsService.h" - -#include -#include - -uint qHash(const QVariant& var) -{ - switch (var.type()) { - case QVariant::Uuid: - return qHash(var.toUuid()); - case QVariant::UInt: - return qHash(var.toUInt()); - default: - return 0; - } -} - -namespace QtZeroProps -{ - -QZeroPropsService::QZeroPropsService(QObject* parent) - : QObject(parent) -{ -} - -QZeroPropsService::~QZeroPropsService() -{ - delete d; -} - -QString QZeroPropsService::name() const -{ - return d->name; -} - -ServiceType QZeroPropsService::type() const -{ - return d->type; -} - -void QZeroPropsService::setDebounceTime(int msec) -{ - d->timer.setInterval(msec); -} - -void QZeroPropsService::setProperty(quint32 uuid, const QByteArray& value) -{ - d->properties.insert(uuid, value); - - d->dirtyProperties.insert(uuid); - if (!d->timer.isActive()) { - d->timer.start(); - } -} - -void QZeroPropsService::setProperty(const QUuid& uuid, const QByteArray& value) -{ - d->properties.insert(uuid, value); - - d->dirtyProperties.insert(uuid); - if (!d->timer.isActive()) { - d->timer.start(); - } -} - -} // namespace QZeroProps diff --git a/net/src/QZeroPropsServicePrivate.cpp b/net/src/QZeroPropsServicePrivate.cpp deleted file mode 100644 index a1a4d6b..0000000 --- a/net/src/QZeroPropsServicePrivate.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2020 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "QZeroPropsServicePrivate.h" - -#include - -namespace QtZeroProps -{ - -QZeroPropsServicePrivate::QZeroPropsServicePrivate(QZeroPropsService* _q) - : q(_q) -{ - // Setup timer - timer.setInterval(200); - timer.setSingleShot(true); - QTimer::connect(&timer, &QTimer::timeout, [this]() { - onTimeout(); - }); -} - -QZeroPropsServicePrivate::~QZeroPropsServicePrivate() -{ -} - -void QZeroPropsServicePrivate::onTimeout() -{ - // Iterate dirty properties and send them - for (const auto& key : dirtyProperties) { - const auto& value = properties[key]; - qDebug() << "Send property:" << key << ", value size:" << value.size(); - doSend(key, value); - } - - // Clear dirty propertiers - dirtyProperties.clear(); -} - -} // namespace QZeroProps diff --git a/net/src/QZeroPropsServicePrivate.h b/net/src/QZeroPropsServicePrivate.h deleted file mode 100644 index 24af9f1..0000000 --- a/net/src/QZeroPropsServicePrivate.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2020 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include - -#include -#include -#include - -namespace QtZeroProps -{ - -class QZeroPropsServicePrivate : public QObject -{ - Q_OBJECT - -public: - QZeroPropsServicePrivate(QZeroPropsService* _q); - virtual ~QZeroPropsServicePrivate(); - - virtual void connect() = 0; - virtual void disconnect() = 0; - - void onTimeout(); - virtual void doSend(const QVariant& uuid, const QByteArray& value) = 0; - - QTimer timer; - QSet dirtyProperties; - QMap properties; - - QString name; - ServiceType type = ServiceType::Invalid; - - class QZeroPropsService* const q; - -signals: - void stateChanged(QZeroPropsClient::State state, const QString& errorString = QString()); -}; - -} // namespace QZeroProps diff --git a/net/src/QZeroPropsWsServer.cpp b/net/src/QZeroPropsWsServer.cpp deleted file mode 100644 index f04347e..0000000 --- a/net/src/QZeroPropsWsServer.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2020 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "QZeroPropsWsServer.h" - -#include "QZeroPropsWsService.h" - -#include -#include -#include - -#include - -namespace QtZeroProps -{ - -QZeroPropsWsServer::QZeroPropsWsServer(QObject *parent) - : QtZeroProps::QZeroPropsServerPrivate(parent), - m_server("", QWebSocketServer::SslMode::NonSecureMode) -{ -} - -QZeroPropsWsServer::~QZeroPropsWsServer() -{ -} - -QZeroPropsServicePrivate* QZeroPropsWsServer::createService(const QtZeroProps::ServiceConfiguration& config) -{ - // Open socket - m_server.close(); - if (!m_server.listen(QHostAddress::AnyIPv4)) { - qWarning("Error starting NetService."); - return nullptr; - } - - m_service = new QZeroPropsWsService(m_currentService); - m_service->name = config.zeroConfType; - m_service->type = ServiceType::WebSocket; - connect(&m_server, &QWebSocketServer::newConnection, [this]() { - m_service->onClientConnected(m_server.nextPendingConnection()); - }); - - // Publish service - QZeroConf* zeroConf = new QZeroConf(this); - connect(zeroConf, &QZeroConf::servicePublished, [&]() { - qDebug("TCP server published at port: %i", m_server.serverPort()); - }); - connect(zeroConf, &QZeroConf::error, [](QZeroConf::error_t error) { - qWarning("Error publishing service: %i", error); - }); - zeroConf->startServicePublish(QHostInfo::localHostName().toStdString().c_str(), - config.zeroConfType.toStdString().c_str(), - nullptr, - m_server.serverPort()); - - return m_service; -} - -} // namespace net diff --git a/net/src/QZeroPropsWsServer.h b/net/src/QZeroPropsWsServer.h deleted file mode 100644 index 76546e1..0000000 --- a/net/src/QZeroPropsWsServer.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2020 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include "QZeroPropsServerPrivate.h" - -namespace QtZeroProps -{ -class QZeroPropsWsService; - -class QZeroPropsWsServer : public QtZeroProps::QZeroPropsServerPrivate -{ - Q_OBJECT - -public: - explicit QZeroPropsWsServer(QObject *parent = nullptr); - ~QZeroPropsWsServer() override; - -private: - virtual QZeroPropsServicePrivate* createService(const ServiceConfiguration& config) override; - - QWebSocketServer m_server; - QZeroPropsWsService* m_service = nullptr; - - friend class QZeroPropsServer; -}; - -} // namespace net diff --git a/net/src/QZeroPropsWsService.cpp b/net/src/QZeroPropsWsService.cpp deleted file mode 100644 index 27c5d42..0000000 --- a/net/src/QZeroPropsWsService.cpp +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (C) 2020 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "QZeroPropsWsService.h" - -#include - -#include - -namespace QtZeroProps -{ - -QZeroPropsWsService::QZeroPropsWsService(QZeroPropsService* _q) - : QZeroPropsServicePrivate(_q) -{ - MsgPack::registerPacker(QVariant::Type::Uuid, QVariant::Type::Uuid, [](const QVariant& variant) -> QByteArray { - return variant.toUuid().toRfc4122(); - }); - MsgPack::registerUnpacker(QVariant::Type::Uuid, [](const QByteArray& buffer) -> QVariant { - return QUuid::fromRfc4122(buffer); - }); -} - -QZeroPropsWsService::~QZeroPropsWsService() -{ - disconnect(); -} - -void QZeroPropsWsService::connect() -{ - emit stateChanged(QZeroPropsClient::State::Connecting, "Connecting " + q->name()); - - if (socket) { - socket->disconnect(); - socket->deleteLater(); - } - - socket = new QWebSocket(QString(), QWebSocketProtocol::VersionLatest, this); - - // Setup socket - QObject::connect(socket, &QWebSocket::binaryMessageReceived, [this](const QByteArray &message) { - onReceive(message); - }); - QObject::connect(socket, &QWebSocket::connected, [this]() { - emit stateChanged(QZeroPropsClient::State::Connected); - }); - QObject::connect(socket, &QWebSocket::disconnected, [this]() { - emit stateChanged(QZeroPropsClient::State::Disconnected); - }); - QObject::connect(socket, QOverload::of(&QWebSocket::error), [this](QAbstractSocket::SocketError) { - emit stateChanged(QZeroPropsClient::State::Error, socket->errorString()); - }); - QObject::connect(socket, &QWebSocket::pong, [](quint64 elapsedTime, const QByteArray &payload) { - qDebug() << "pong> elapsedTime:" << elapsedTime << ", payload.size: " << payload.size(); - }); - QObject::connect(socket, &QWebSocket::stateChanged, [this](QAbstractSocket::SocketState state) { - onStateChanged(state); - }); - - QUrl url; - url.setScheme("ws"); - url.setHost(address.toString()); - url.setPort(port); - socket->open(url); -} - -void QZeroPropsWsService::disconnect() -{ - if (socket) { - socket->disconnect(); - socket->abort(); - socket->deleteLater(); - socket = nullptr; - } -} - -void QZeroPropsWsService::onClientConnected(QWebSocket* _socket) -{ - if (socket) { - qDebug("Another client already connected"); - return; - } - - // Open socket - socket = _socket; - - QObject::connect(socket, &QWebSocket::binaryMessageReceived, this, &QZeroPropsWsService::onReceive); - QObject::connect(socket, &QWebSocket::disconnected, this, &QZeroPropsWsService::disconnect); - - // Iterate dirty properties and send them - qDebug("New connection. Send properties:"); - for (const auto& kv : properties.toStdMap()) { - const auto& key = kv.first; - const auto& value = kv.second; - qDebug("%s: %i", key.toByteArray().toStdString().c_str(), value.size()); - - QByteArray block; - block += static_cast(0x81); // Map with one element - block += MsgPack::pack(key); - block += MsgPack::pack(value); - const auto bytes = socket->sendBinaryMessage(block); - qDebug("Wrote %lld bytes", bytes); - } - socket->flush(); -} - -void QZeroPropsWsService::onStateChanged(QAbstractSocket::SocketState state) -{ - switch (state) { - case QAbstractSocket::UnconnectedState: - break; - case QAbstractSocket::HostLookupState: - case QAbstractSocket::ConnectingState: - emit stateChanged(QZeroPropsClient::State::Connecting); - break; - case QAbstractSocket::ConnectedState: - emit stateChanged(QZeroPropsClient::State::Connected); - break; - case QAbstractSocket::BoundState: - case QAbstractSocket::ClosingState: - break; - default: - break; - } -} - -void QZeroPropsWsService::onReceive(const QByteArray& message) -{ - if (message.front() != static_cast(0x81)) { - qWarning() << "XXXIllegal data:" << message.front(); - return; - } - - QVariantList vlist = MsgPack::unpack(message.mid(1)).toList(); - if (vlist.size() != 2 || - (vlist.at(0).type() != QVariant::Type::UInt && vlist.at(0).type() != QVariant::Type::Uuid) || - vlist.at(1).type() != QVariant::Type::ByteArray) { - qWarning() << "YYYIllegal data:" << vlist; - return; - } - - auto value = vlist.last().toByteArray(); - - properties.insert(vlist.first(), value); - emit q->propertyChanged(vlist.first(), value); -} - -void QZeroPropsWsService::doSend(const QVariant& uuid, const QByteArray& value) -{ - // If we are not connected, we do not send - if (!socket || socket->state() != QAbstractSocket::ConnectedState) { - qDebug() << "Socket not connected"; - return; - } - - QByteArray block; - block += static_cast(0x81); // Map with one element - block += MsgPack::pack(uuid); - block += MsgPack::pack(value); - const auto bytes = socket->sendBinaryMessage(block); - qDebug() << "Sent" << bytes << "bytes"; - - socket->flush(); -} - -} // namespace QZeroProps diff --git a/net/src/QZeroPropsWsService.h b/net/src/QZeroPropsWsService.h deleted file mode 100644 index 4842ae0..0000000 --- a/net/src/QZeroPropsWsService.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2020 Manuel Weichselbaumer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include "QZeroPropsServicePrivate.h" - -#include - -namespace QtZeroProps -{ - -class QZeroPropsWsService : public QZeroPropsServicePrivate -{ -public: - QZeroPropsWsService(QZeroPropsService* _q); - ~QZeroPropsWsService() override; - -private: - void connect() override; - void disconnect() override; - void doSend(const QVariant& uuid, const QByteArray& value) override; - - // Event handlers from socket/server - void onClientConnected(QWebSocket* socket); - void onStateChanged(QAbstractSocket::SocketState state); - void onReceive(const QByteArray& message); - - QHostAddress address; - uint16_t port = 0; - - QWebSocket* socket = nullptr; - - friend class QZeroPropsClientPrivate; - friend class QZeroPropsServer; - friend class QZeroPropsWsServer; -}; - -} // namespace QZeroProps diff --git a/net/tests/CMakeLists.txt b/net/tests/CMakeLists.txt deleted file mode 100644 index 35e98b2..0000000 --- a/net/tests/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -macro(ble_tests) - foreach(_testname ${ARGN}) - add_executable(${_testname} ${_testname}.cpp) - target_link_libraries(${_testname} ble) - endforeach(_testname) -endmacro() - -ble_tests( - centraltest - #peripheraltest -) - -find_package(Qt5 CONFIG REQUIRED Core DBus) -add_executable(peripheraltest peripheraltest.cpp) -target_link_libraries(peripheraltest - ble - KF5BluezQt - Qt5::DBus -) diff --git a/net/tests/centraltest.cpp b/net/tests/centraltest.cpp deleted file mode 100644 index b1f12f6..0000000 --- a/net/tests/centraltest.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -#include - -#include - -int main(int argc, char** argv) -{ - QCoreApplication app(argc, argv); - - auto central = new ble::Client(); - QObject::connect(central, &ble::Client::characteristicRead, [](const std::string& charc, const QByteArray &value) { - qDebug() << "charc:" << QString::fromStdString(charc) << ", value:" << value.toHex(); - }); - central->startDiscovering(); - - return app.exec(); -} diff --git a/net/tests/peripheraltest.cpp b/net/tests/peripheraltest.cpp deleted file mode 100644 index d262268..0000000 --- a/net/tests/peripheraltest.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace BluezQt; -using namespace std::placeholders; - -class Controller : public QObject -{ -public: - explicit Controller(QObject *parent = nullptr) - { - // Init BluezQt - m_manager = new Manager(this); - InitManagerJob *initJob = m_manager->init(); - initJob->exec(); - if (initJob->error()) { - qWarning() << "Error initializing bluetooth manager:" << initJob->errorText(); - return; - } - - m_advertisement = new LEAdvertisement({QStringLiteral("ad100000-d901-11e8-9f8b-f2801f1b9fd1")}, this); - m_manager->usableAdapter()->leAdvertisingManager()->registerAdvertisement(m_advertisement); - - m_application = new GattApplication(this); - auto service = new GattService(QStringLiteral("ad100000-d901-11e8-9f8b-f2801f1b9fd1"), true, m_application); - - auto peqCharc = new GattCharacteristic(QStringLiteral("ad10e100-d901-11e8-9f8b-f2801f1b9fd1"), service); - peqCharc->setReadCallback(std::bind(&Controller::onReadFilters, this, common::ble::CharacteristicType::Peq)); - connect(peqCharc, &GattCharacteristic::valueWritten, std::bind(&Controller::onWriteFilters, this, common::ble::CharacteristicType::Peq, _1)); - m_charcs[common::ble::CharacteristicType::Peq] = peqCharc; - - auto auxCharc = new GattCharacteristic(QStringLiteral("ad10a100-d901-11e8-9f8b-f2801f1b9fd1"), service); - auxCharc->setReadCallback(std::bind(&Controller::onReadFilters, this, common::ble::CharacteristicType::Aux)); - connect(auxCharc, &GattCharacteristic::valueWritten, std::bind(&Controller::onWriteFilters, this, common::ble::CharacteristicType::Aux, _1)); - m_charcs[common::ble::CharacteristicType::Aux] = auxCharc; - - m_manager->usableAdapter()->gattManager()->registerApplication(m_application); - } - ~Controller() - { - m_manager->usableAdapter()->leAdvertisingManager()->unregisterAdvertisement(m_advertisement); - m_manager->usableAdapter()->gattManager()->unregisterApplication(m_application); - } - -private: - QByteArray onReadFilters(common::ble::CharacteristicType group) - { - switch (group) { - case common::ble::CharacteristicType::Aux: - return m_converter.filtersToBle({{common::FilterType::Crossover, 3000.0}}); - case common::ble::CharacteristicType::Peq: - return m_converter.filtersToBle( { { common::FilterType::Peak, 2335.0, -3.7, 0.7 }, - { common::FilterType::LowPass, 12222.0, 1.4, 0.5 }, - { common::FilterType::HighPass, 47.0, -3.3, 0.8 } }); - default: - return QByteArray(); - } - return QByteArray(); - } - - void onWriteFilters(common::ble::CharacteristicType group, const QByteArray& value) - { - auto filters = m_converter.filtersFromBle(value); - for (const auto& filter : filters) { - qDebug() << "t:" << static_cast(filter.type) - << "f:" << filter.f - << "g:" << filter.g - << "q:" << filter.q; - } - qDebug() << ""; - } - - BluezQt::Manager* m_manager = nullptr; - std::map m_charcs; - BluezQt::GattApplication* m_application = nullptr; - BluezQt::LEAdvertisement* m_advertisement = nullptr; - common::ble::Converter m_converter; -}; - - -int main(int argc, char** argv) -{ - QCoreApplication app(argc, argv); - - new Controller(); - - return app.exec(); -} diff --git a/thirdparty/libcornrow b/thirdparty/libcornrow deleted file mode 160000 index e99329e..0000000 --- a/thirdparty/libcornrow +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e99329e28fdbeec692a177d7ad298a2c3b136d4f