diff --git a/.github/workflows/push-master.yml b/.github/workflows/push-master.yml index d0972b5e8..98b9ac17c 100644 --- a/.github/workflows/push-master.yml +++ b/.github/workflows/push-master.yml @@ -4,7 +4,7 @@ on: [push] env: USE_CACHE: "1" - RESET_CACHE: "0" + RESET_CACHE: "1" jobs: diff --git a/.gitmodules b/.gitmodules index abe2e392f..47d8fa807 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,10 +6,6 @@ path = dependencies/external/flatbuffers url = https://github.com/google/flatbuffers branch = master -[submodule "dependencies/external/protobuf"] - path = dependencies/external/protobuf - url = https://github.com/protocolbuffers/protobuf.git - branch = 3.14.x [submodule "dependencies/external/mbedtls"] path = dependencies/external/mbedtls url = https://github.com/ARMmbed/mbedtls diff --git a/CMakeLists.txt b/CMakeLists.txt index 75d6364ec..8beb16e71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -267,9 +267,6 @@ message(STATUS "ENABLE_CEC = ${ENABLE_CEC}") SET ( FLATBUFFERS_INSTALL_BIN_DIR ${CMAKE_BINARY_DIR}/flatbuf ) SET ( FLATBUFFERS_INSTALL_LIB_DIR ${CMAKE_BINARY_DIR}/flatbuf ) -SET ( PROTOBUF_INSTALL_BIN_DIR ${CMAKE_BINARY_DIR}/proto ) -SET ( PROTOBUF_INSTALL_LIB_DIR ${CMAKE_BINARY_DIR}/proto ) - find_package(GitVersion) # configure a header file to pass some of the CMake settings diff --git a/assets/webconfig/js/network.js b/assets/webconfig/js/network.js index d7e255156..db2a7812b 100644 --- a/assets/webconfig/js/network.js +++ b/assets/webconfig/js/network.js @@ -6,7 +6,6 @@ $(document).ready( function() { var conf_editor = null; var conf_editor_net = null; var conf_editor_json = null; - var conf_editor_proto = null; var conf_editor_fbs = null; var conf_editor_bobl = null; var conf_editor_forw = null; @@ -27,10 +26,6 @@ $(document).ready( function() { $('#conf_cont').append(createOptPanel('fa-sitemap', $.i18n("edt_conf_fbs_heading_title"), 'editor_container_fbserver', 'btn_submit_fbserver')); $('#conf_cont').append(createHelpTable(window.schema.flatbufServer.properties, $.i18n("edt_conf_fbs_heading_title"))); - //protoserver - $('#conf_cont').append(createOptPanel('fa-sitemap', $.i18n("edt_conf_pbs_heading_title"), 'editor_container_protoserver', 'btn_submit_protoserver')); - $('#conf_cont').append(createHelpTable(window.schema.protoServer.properties, $.i18n("edt_conf_pbs_heading_title"))); - //boblight if (BOBLIGHT_ENABLED) { @@ -104,19 +99,6 @@ $(document).ready( function() { requestWriteConfig(conf_editor_fbs.getValue()); }); - //protobuffer - conf_editor_proto = createJsonEditor('editor_container_protoserver', { - protoServer : window.schema.protoServer - }, true, true); - - conf_editor_proto.on('change',function() { - conf_editor_proto.validate().length || window.readOnlyMode ? $('#btn_submit_protoserver').attr('disabled', true) : $('#btn_submit_protoserver').attr('disabled', false); - }); - - $('#btn_submit_protoserver').off().on('click',function() { - requestWriteConfig(conf_editor_proto.getValue()); - }); - //boblight if (BOBLIGHT_ENABLED) { @@ -156,7 +138,6 @@ $(document).ready( function() { createHint("intro", $.i18n('conf_network_net_intro'), "editor_container_net"); createHint("intro", $.i18n('conf_network_json_intro'), "editor_container_jsonserver"); createHint("intro", $.i18n('conf_network_fbs_intro'), "editor_container_fbserver"); - createHint("intro", $.i18n('conf_network_proto_intro'), "editor_container_protoserver"); if (BOBLIGHT_ENABLED) { diff --git a/dependencies/CMakeLists.txt b/dependencies/CMakeLists.txt index 838c25e5a..36728c2ed 100644 --- a/dependencies/CMakeLists.txt +++ b/dependencies/CMakeLists.txt @@ -86,136 +86,16 @@ function(compile_flattbuffer_schema SRC_FBS OUTPUT_DIR) endfunction() #============================================================================= -# PROTOBUFFER +# DISABLE EXTERNAL WARNINGS #============================================================================= -set(USE_SYSTEM_PROTO_LIBS ${DEFAULT_USE_SYSTEM_PROTO_LIBS} CACHE BOOL "use protobuf library from system") - -if (USE_SYSTEM_PROTO_LIBS) - find_package(Protobuf REQUIRED) -else () - set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf with tests") - set(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "Build protobuf shared") - - if (WIN32) - set(protobuf_MSVC_STATIC_RUNTIME OFF CACHE BOOL "Build protobuf static") - endif() - - add_subdirectory(external/protobuf/cmake) - - if(CMAKE_CROSSCOMPILING) - # when crosscompiling import the protoc executable targets from a file generated by a native build - option(IMPORT_PROTOC "Protoc export file (protoc_export.cmake) from a native build" "IMPORT_PROTOC-FILE_NOT_FOUND") - include(${IMPORT_PROTOC}) - else() - # export the protoc compiler so it can be used when cross compiling - export(TARGETS protoc FILE "${CMAKE_BINARY_DIR}/protoc_export.cmake") - endif() - - # define the include for the protobuf library at the parent scope - set(PROTOBUF_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf/src") - - # define the protoc executable at the parent scope - set(PROTOBUF_PROTOC_EXECUTABLE "$") -endif() -option(protobuf_BUILD_TESTS "" OFF) -set(PROTOBUF_PROTOC_EXECUTABLE ${PROTOBUF_PROTOC_EXECUTABLE} PARENT_SCOPE) -set(PROTOBUF_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS} PARENT_SCOPE) -include_directories(${PROTOBUF_INCLUDE_DIRS}) - if ( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX ) target_compile_options(turbojpeg PRIVATE "-w") - target_compile_options(protoc PRIVATE "-w") - target_compile_options(libprotoc PRIVATE "-w") - target_compile_options(libprotobuf PRIVATE "-w") - target_compile_options(libprotobuf-lite PRIVATE "-w") endif() if ( MSVC ) target_compile_options(turbojpeg PRIVATE "/W0") - target_compile_options(protoc PRIVATE "/W0") - target_compile_options(libprotoc PRIVATE "/W0") - target_compile_options(libprotobuf PRIVATE "/W0") - target_compile_options(libprotobuf-lite PRIVATE "/W0") endif() -message(STATUS "Using protobuf compiler: " ${PROTOBUF_PROTOC_EXECUTABLE}) - -#============================================================================= -# Copyright 2009 Kitware, Inc. -# Copyright 2009-2011 Philip Lowman -# Copyright 2008 Esben Mose Hansen, Ange Optimization ApS -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) -function(PROTOBUF_GENERATE_CPP SRCS HDRS) - if(NOT ARGN) - message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto files") - return() - endif() - - if(PROTOBUF_GENERATE_CPP_APPEND_PATH) - # Create an include path for each file specified - foreach(FIL ${ARGN}) - get_filename_component(ABS_FIL ${FIL} ABSOLUTE) - get_filename_component(ABS_PATH ${ABS_FIL} PATH) - list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) - if(${_contains_already} EQUAL -1) - list(APPEND _protobuf_include_path -I ${ABS_PATH}) - endif() - endforeach() - else() - set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR}) - endif() - - if(DEFINED PROTOBUF_IMPORT_DIRS) - foreach(DIR ${PROTOBUF_IMPORT_DIRS}) - get_filename_component(ABS_PATH ${DIR} ABSOLUTE) - list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) - if(${_contains_already} EQUAL -1) - list(APPEND _protobuf_include_path -I ${ABS_PATH}) - endif() - endforeach() - endif() - - if(CMAKE_CROSSCOMPILING OR USE_SYSTEM_PROTO_LIBS) - set(PROTOC_DEPENDENCY ${PROTOBUF_PROTOC_EXECUTABLE}) - else() - set(PROTOC_DEPENDENCY protoc) - endif() - - set(${SRCS}) - set(${HDRS}) - foreach(FIL ${ARGN}) - get_filename_component(ABS_FIL ${FIL} ABSOLUTE) - get_filename_component(FIL_WE ${FIL} NAME_WE) - - list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc") - list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h") - - add_custom_command( - OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc" - "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h" - COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} - ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL} - DEPENDS ${ABS_FIL} ${PROTOC_DEPENDENCY} - COMMENT "Running C++ protocol buffer compiler on ${FIL}" - VERBATIM - ) - set_property(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc" PROPERTY SKIP_AUTOMOC ON) - set_property(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h" PROPERTY SKIP_AUTOMOC ON) - endforeach() - - set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE) - set(${SRCS} ${${SRCS}} PARENT_SCOPE) - set(${HDRS} ${${HDRS}} PARENT_SCOPE) -endfunction() #============================================================================= # MBEDTLS diff --git a/dependencies/external/protobuf b/dependencies/external/protobuf deleted file mode 160000 index 89b14b1d1..000000000 --- a/dependencies/external/protobuf +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 89b14b1d16eba4d44af43256fc45b24a6a348557 diff --git a/include/protoserver/ProtoServer.h b/include/protoserver/ProtoServer.h deleted file mode 100644 index f8aebeaec..000000000 --- a/include/protoserver/ProtoServer.h +++ /dev/null @@ -1,69 +0,0 @@ -#pragma once - -// util -#include -#include - -// qt -#include - -class QTcpServer; -class ProtoClientConnection; -class NetOrigin; - -/// -/// @brief This class creates a TCP server which accepts connections wich can then send -/// in Protocol Buffer encoded commands. This interface to Hyperhdr is used by various -/// third-party applications -/// -class ProtoServer : public QObject -{ - Q_OBJECT - -public: - ProtoServer(const QJsonDocument& config, QObject* parent = nullptr); - ~ProtoServer() override; - -public slots: - /// - /// @brief Handle settings update - /// @param type The type from enum - /// @param config The configuration - /// - void handleSettingsUpdate(settings::type type, const QJsonDocument& config); - - void initServer(); - -private slots: - /// - /// @brief Is called whenever a new socket wants to connect - /// - void newConnection(); - - /// - /// @brief is called whenever a client disconnected - /// - void clientDisconnected(); - -private: - /// - /// @brief Start the server with current _port - /// - void startServer(); - - /// - /// @brief Stop server - /// - void stopServer(); - - -private: - QTcpServer* _server; - NetOrigin* _netOrigin; - Logger* _log; - int _timeout; - quint16 _port; - const QJsonDocument _config; - - QVector _openConnections; -}; diff --git a/include/ssdp/SSDPHandler.h b/include/ssdp/SSDPHandler.h index 6ca51a821..7f8c11629 100644 --- a/include/ssdp/SSDPHandler.h +++ b/include/ssdp/SSDPHandler.h @@ -22,7 +22,7 @@ class SSDPHandler : public SSDPServer { Q_OBJECT public: - SSDPHandler(WebServer* webserver, quint16 flatBufPort, quint16 protoBufPort, quint16 jsonServerPort, quint16 sslPort, const QString &name, QObject * parent = nullptr); + SSDPHandler(WebServer* webserver, quint16 flatBufPort,quint16 jsonServerPort, quint16 sslPort, const QString &name, QObject * parent = nullptr); ~SSDPHandler() override; /// diff --git a/include/ssdp/SSDPServer.h b/include/ssdp/SSDPServer.h index 171ca2c17..ceddd96c2 100644 --- a/include/ssdp/SSDPServer.h +++ b/include/ssdp/SSDPServer.h @@ -85,16 +85,7 @@ class SSDPServer : public QObject quint16 getFlatBufPort() const { return _fbsPort.toInt(); - } - /// - /// @brief set new protobuf server port - /// - void setProtoBufPort( quint16 port ) { _pbsPort = QString::number( port ); } - - /// - /// @brief Get current protobuf server port - /// - quint16 getProtoBufPort() const { return _pbsPort.toInt(); } + } /// /// @brief set new json server port /// diff --git a/include/utils/settings.h b/include/utils/settings.h index 982e1ea70..7bb924db2 100644 --- a/include/utils/settings.h +++ b/include/utils/settings.h @@ -31,7 +31,6 @@ namespace settings { VIDEODETECTION, NETWORK, FLATBUFSERVER, - PROTOSERVER, INVALID }; @@ -67,7 +66,6 @@ namespace settings { case type::VIDEODETECTION:return "videoDetection"; case type::NETWORK: return "network"; case type::FLATBUFSERVER: return "flatbufServer"; - case type::PROTOSERVER: return "protoServer"; default: return "invalid"; } } @@ -102,7 +100,6 @@ namespace settings { else if (type == "videoDetection") return type::VIDEODETECTION; else if (type == "network") return type::NETWORK; else if (type == "flatbufServer") return type::FLATBUFSERVER; - else if (type == "protoServer") return type::PROTOSERVER; else return type::INVALID; } } diff --git a/libsrc/CMakeLists.txt b/libsrc/CMakeLists.txt index b05ebe23a..125e255a0 100644 --- a/libsrc/CMakeLists.txt +++ b/libsrc/CMakeLists.txt @@ -8,7 +8,6 @@ add_subdirectory(commandline) add_subdirectory(blackborder) add_subdirectory(jsonserver) add_subdirectory(flatbufserver) -add_subdirectory(protoserver) add_subdirectory(ssdp) if(ENABLE_BOBLIGHT) add_subdirectory(boblightserver) diff --git a/libsrc/db/SettingsTable.cpp b/libsrc/db/SettingsTable.cpp index 883ddf4f3..dcca20f6e 100644 --- a/libsrc/db/SettingsTable.cpp +++ b/libsrc/db/SettingsTable.cpp @@ -117,7 +117,7 @@ bool SettingsTable::isSettingGlobal(const QString& type) const // list of global settings QStringList list; // server port services - list << settings::typeToString(settings::type::JSONSERVER) << settings::typeToString(settings::type::PROTOSERVER) + list << settings::typeToString(settings::type::JSONSERVER) << settings::typeToString(settings::type::FLATBUFSERVER) << settings::typeToString(settings::type::NETWORK) << settings::typeToString(settings::type::NETFORWARD) << settings::typeToString(settings::type::WEBSERVER) << settings::typeToString(settings::type::VIDEOGRABBER) << settings::typeToString(settings::type::SYSTEMGRABBER) diff --git a/libsrc/hyperhdrbase/SettingsManager.cpp b/libsrc/hyperhdrbase/SettingsManager.cpp index 7d55a9e18..7494aa660 100644 --- a/libsrc/hyperhdrbase/SettingsManager.cpp +++ b/libsrc/hyperhdrbase/SettingsManager.cpp @@ -39,26 +39,7 @@ SettingsManager::SettingsManager(quint8 instance, QObject* parent, bool readonly // get default config QJsonObject defaultConfig; for (settings::type selector = settings::type::SNDEFFECT; selector != settings::type::INVALID; selector = settings::type(((int)selector) + 1)) - { - if (selector == settings::type::VIDEOGRABBER) - { - if(!_sTable->recordExist(typeToString(selector)) && _sTable->recordExist("grabberV4L2")) - { - auto oldVideo = _sTable->getSettingsRecord("grabberV4L2").object(); - - oldVideo["device"] = oldVideo["available_devices"]; - - oldVideo["videoEncoding"] = oldVideo["v4l2Encoding"]; - oldVideo["videoMode"] = QString("%1x%2").arg(oldVideo["width"].toInt()).arg(oldVideo["height"].toInt()); - - defaultConfig.insert(typeToString(selector), oldVideo); - _sTable->deleteSettingsRecordString("grabberV4L2"); - - Warning(_log, "Found old V4L2 configuration. Migrating defaults to the new structures."); - continue; - } - } - + { if (selector != settings::type::LEDS) defaultConfig.insert(typeToString(selector), QJsonObject()); else diff --git a/libsrc/hyperhdrbase/hyperhdr.schema.json b/libsrc/hyperhdrbase/hyperhdr.schema.json index 9cb38ff86..6405cff29 100644 --- a/libsrc/hyperhdrbase/hyperhdr.schema.json +++ b/libsrc/hyperhdrbase/hyperhdr.schema.json @@ -59,10 +59,6 @@ { "$ref": "schema-flatbufServer.json" }, - "protoServer" : - { - "$ref": "schema-protoServer.json" - }, "boblightServer" : { "$ref": "schema-boblightServer.json" diff --git a/libsrc/hyperhdrbase/resource.qrc b/libsrc/hyperhdrbase/resource.qrc index 0c6f722f0..18a90f89a 100644 --- a/libsrc/hyperhdrbase/resource.qrc +++ b/libsrc/hyperhdrbase/resource.qrc @@ -15,7 +15,6 @@ schema/schema-forwarder.json schema/schema-jsonServer.json schema/schema-flatbufServer.json - schema/schema-protoServer.json schema/schema-boblightServer.json schema/schema-webConfig.json schema/schema-effects.json diff --git a/libsrc/hyperhdrbase/schema/schema-protoServer.json b/libsrc/hyperhdrbase/schema/schema-protoServer.json deleted file mode 100644 index a09d23a7f..000000000 --- a/libsrc/hyperhdrbase/schema/schema-protoServer.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "type" : "object", - "required" : true, - "title" : "edt_conf_pbs_heading_title", - "properties" : - { - "enable" : - { - "type" : "boolean", - "format": "checkbox", - "required" : true, - "title" : "edt_conf_general_enable_title", - "default" : true, - "propertyOrder" : 1 - }, - "port" : - { - "type" : "integer", - "required" : true, - "title" : "edt_conf_general_port_title", - "minimum" : 1024, - "maximum" : 65535, - "default" : 19445 - }, - "timeout" : - { - "type" : "integer", - "required" : true, - "title" : "edt_conf_pbs_timeout_title", - "append" : "edt_append_s", - "minimum" : 1, - "default" : 5, - "propertyOrder" : 3 - } - }, - "additionalProperties" : false -} diff --git a/libsrc/protoserver/CMakeLists.txt b/libsrc/protoserver/CMakeLists.txt deleted file mode 100644 index a43954e6c..000000000 --- a/libsrc/protoserver/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ - -# Define the current source locations -set(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/protoserver) -set(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/protoserver) - -include_directories( - ${CMAKE_CURRENT_BINARY_DIR} - ${PROTOBUF_INCLUDE_DIRS} -) - -set(ProtoServer_PROTOS ${CURRENT_SOURCE_DIR}/message.proto ) - -protobuf_generate_cpp(ProtoServer_PROTO_SRCS ProtoServer_PROTO_HDRS ${ProtoServer_PROTOS} ) - -### Split protoclient from protoserver as protoserver relates to HyperHDRDaemon and standalone capture binarys can't link to it - -add_library(protoclient - ${CURRENT_SOURCE_DIR}/ProtoClientConnection.h - ${CURRENT_SOURCE_DIR}/ProtoClientConnection.cpp - ${ProtoServer_PROTO_SRCS} - ${ProtoServer_PROTO_HDRS} -) - -add_library(protoserver - ${CURRENT_HEADER_DIR}/ProtoServer.h - ${CURRENT_SOURCE_DIR}/ProtoServer.cpp -) - -# disable warnings for auto generated proto files, we can't change the files .... -SET_SOURCE_FILES_PROPERTIES ( ${ProtoServer_PROTO_SRCS} ${ProtoServer_PROTO_HDRS} ${ProtoServer_PROTOS} PROPERTIES COMPILE_FLAGS -w ) - -target_link_libraries(protoclient - hyperhdr-base - hyperhdr-utils - libprotobuf - Qt${Qt_VERSION}::Gui -) - -target_link_libraries(protoserver - hyperhdr-base - hyperhdr-utils - protoclient - Qt${Qt_VERSION}::Gui -) diff --git a/libsrc/protoserver/ProtoClientConnection.cpp b/libsrc/protoserver/ProtoClientConnection.cpp deleted file mode 100644 index b3ef144c6..000000000 --- a/libsrc/protoserver/ProtoClientConnection.cpp +++ /dev/null @@ -1,245 +0,0 @@ -// qt -#include -#include -#include -#include - -// project includes -#include "ProtoClientConnection.h" - -// TODO Remove this class if third-party apps have been migrated (eg. Hyperion Android Grabber, Windows Screen grabber etc.) - -ProtoClientConnection::ProtoClientConnection(QTcpSocket* socket, int timeout, QObject *parent) - : QObject(parent) - , _log(Logger::getInstance("PROTOSERVER")) - , _socket(socket) - , _clientAddress(socket->peerAddress().toString()) - , _timeoutTimer(new QTimer(this)) - , _timeout(timeout * 1000) - , _priority() -{ - // timer setup - _timeoutTimer->setSingleShot(true); - _timeoutTimer->setInterval(_timeout); - connect(_timeoutTimer, &QTimer::timeout, this, &ProtoClientConnection::forceClose); - - // connect socket signals - connect(_socket, &QTcpSocket::readyRead, this, &ProtoClientConnection::readyRead); - connect(_socket, &QTcpSocket::disconnected, this, &ProtoClientConnection::disconnected); -} - -void ProtoClientConnection::readyRead() -{ - _receiveBuffer += _socket->readAll(); - - // check if we can read a message size - if (_receiveBuffer.size() <= 4) - { - return; - } - - // read the message size - uint32_t messageSize = - ((_receiveBuffer[0]<<24) & 0xFF000000) | - ((_receiveBuffer[1]<<16) & 0x00FF0000) | - ((_receiveBuffer[2]<< 8) & 0x0000FF00) | - ((_receiveBuffer[3] ) & 0x000000FF); - - // check if we can read a complete message - if ((uint32_t) _receiveBuffer.size() < messageSize + 4) - { - return; - } - - // read a message - proto::HyperionRequest message; - if (!message.ParseFromArray(_receiveBuffer.data() + 4, messageSize)) - { - sendErrorReply("Unable to parse message"); - } - - // handle the message - handleMessage(message); - - // remove message data from buffer - _receiveBuffer = _receiveBuffer.mid(messageSize + 4); -} - -void ProtoClientConnection::forceClose() -{ - _socket->close(); -} - -void ProtoClientConnection::disconnected() -{ - Debug(_log, "Socket Closed"); - _socket->deleteLater(); - emit clearGlobalInput(_priority); - emit clientDisconnected(); -} - -void ProtoClientConnection::handleMessage(const proto::HyperionRequest & message) -{ - switch (message.command()) - { - case proto::HyperionRequest::COLOR: - if (!message.HasExtension(proto::ColorRequest::colorRequest)) - { - sendErrorReply("Received COLOR command without ColorRequest"); - break; - } - handleColorCommand(message.GetExtension(proto::ColorRequest::colorRequest)); - break; - case proto::HyperionRequest::IMAGE: - if (!message.HasExtension(proto::ImageRequest::imageRequest)) - { - sendErrorReply("Received IMAGE command without ImageRequest"); - break; - } - handleImageCommand(message.GetExtension(proto::ImageRequest::imageRequest)); - break; - case proto::HyperionRequest::CLEAR: - if (!message.HasExtension(proto::ClearRequest::clearRequest)) - { - sendErrorReply("Received CLEAR command without ClearRequest"); - break; - } - handleClearCommand(message.GetExtension(proto::ClearRequest::clearRequest)); - break; - case proto::HyperionRequest::CLEARALL: - handleClearallCommand(); - break; - default: - handleNotImplemented(); - } -} - -void ProtoClientConnection::handleColorCommand(const proto::ColorRequest &message) -{ - // extract parameters - int priority = message.priority(); - int duration = message.has_duration() ? message.duration() : -1; - std::vector color{ ColorRgb{ uint8_t(qRed(message.rgbcolor())), uint8_t(qGreen(message.rgbcolor())), uint8_t(qBlue(message.rgbcolor())) } }; - - if (priority < 100 || priority >= 200) - { - sendErrorReply("The priority " + std::to_string(priority) + " is not in the valid priority range between 100 and 199."); - Error(_log, "The priority %d is not in the proto-connection range between 100 and 199.", priority); - return; - } - - // make sure the prio is registered before setColor() - if(priority != _priority) - { - emit clearGlobalInput(_priority); - emit registerGlobalInput(priority, hyperhdr::COMP_PROTOSERVER, "Proto@"+_clientAddress); - _priority = priority; - } - - // set output - emit setGlobalInputColor(_priority, color, duration); - - // send reply - sendSuccessReply(); -} - -void ProtoClientConnection::handleImageCommand(const proto::ImageRequest &message) -{ - // extract parameters - int priority = message.priority(); - int duration = message.has_duration() ? message.duration() : -1; - int width = message.imagewidth(); - int height = message.imageheight(); - const std::string & imageData = message.imagedata(); - - if (priority < 100 || priority >= 200) - { - sendErrorReply("The priority " + std::to_string(priority) + " is not in the valid priority range between 100 and 199."); - Error(_log, "The priority %d is not in the proto-connection range between 100 and 199.", priority); - return; - } - - // make sure the prio is registered before setInput() - if(priority != _priority) - { - emit clearGlobalInput(_priority); - emit registerGlobalInput(priority, hyperhdr::COMP_PROTOSERVER, "Proto@"+_clientAddress); - _priority = priority; - } - - // check consistency of the size of the received data - if ((int) imageData.size() != width*height*3) - { - sendErrorReply("Size of image data does not match with the width and height"); - return; - } - - // create ImageRgb - Image image(width, height); - memcpy(image.memptr(), imageData.c_str(), imageData.size()); - - emit setGlobalInputImage(_priority, image, duration); - - // send reply - sendSuccessReply(); -} - - -void ProtoClientConnection::handleClearCommand(const proto::ClearRequest &message) -{ - // extract parameters - int priority = message.priority(); - - // clear priority - emit clearGlobalInput(priority); - // send reply - sendSuccessReply(); -} - -void ProtoClientConnection::handleClearallCommand() -{ - // clear all priority - emit clearGlobalInput(-1); - - // send reply - sendSuccessReply(); -} - - -void ProtoClientConnection::handleNotImplemented() -{ - sendErrorReply("Command not implemented"); -} - -void ProtoClientConnection::sendMessage(const google::protobuf::Message &message) -{ - std::string serializedReply = message.SerializeAsString(); - uint32_t size = static_cast(serializedReply.size()); - uint8_t sizeData[] = {uint8_t(size >> 24), uint8_t(size >> 16), uint8_t(size >> 8), uint8_t(size)}; - _socket->write((const char *) sizeData, sizeof(sizeData)); - _socket->write(serializedReply.data(), serializedReply.length()); - _socket->flush(); -} - -void ProtoClientConnection::sendSuccessReply() -{ - // create reply - proto::HyperionReply reply; - reply.set_type(proto::HyperionReply::REPLY); - reply.set_success(true); - - // send reply - sendMessage(reply); -} - -void ProtoClientConnection::sendErrorReply(const std::string &error) -{ - // create reply - proto::HyperionReply reply; - reply.set_type(proto::HyperionReply::REPLY); - reply.set_success(false); - reply.set_error(error); - - // send reply - sendMessage(reply); -} diff --git a/libsrc/protoserver/ProtoClientConnection.h b/libsrc/protoserver/ProtoClientConnection.h deleted file mode 100644 index 8bbc9ed09..000000000 --- a/libsrc/protoserver/ProtoClientConnection.h +++ /dev/null @@ -1,158 +0,0 @@ -#pragma once - -#undef Error -#include "message.pb.h" - -// util -#include -#include -#include -#include - - - -class QTcpSocket; -class QTimer; - -namespace proto { - class HyperionRequest; -} - -/// -/// The Connection object created by a ProtoServer when a new connection is established -/// -class ProtoClientConnection : public QObject -{ - Q_OBJECT - -public: - /// - /// @brief Construct the client - /// @param socket The socket - /// @param timeout The timeout when a client is automatically disconnected and the priority unregistered - /// @param parent The parent - /// - explicit ProtoClientConnection(QTcpSocket* socket, int timeout, QObject *parent); - -signals: - /// - /// @brief forward register data to HyperHDRDaemon - /// - void registerGlobalInput(int priority, hyperhdr::Components component, const QString& origin = "ProtoBuffer", const QString& owner = "", unsigned smooth_cfg = 0); - - /// - /// @brief Forward clear command to HyperHDRDaemon - /// - void clearGlobalInput(int priority, bool forceClearAll=false); - - /// - /// @brief forward prepared image to HyperHDRDaemon - /// - bool setGlobalInputImage(int priority, const Image& image, int timeout_ms, bool clearEffect = false); - - /// - /// @brief Forward requested color - /// - void setGlobalInputColor(int priority, const std::vector &ledColor, int timeout_ms, const QString& origin = "ProtoBuffer" ,bool clearEffects = true); - - /// - /// @brief Emits whenever the client disconnected - /// - void clientDisconnected(); - -public slots: - /// - /// @brief Requests a registration from the client - /// - void registationRequired(int priority) { if (_priority == priority) _priority = -1; }; - - /// - /// @brief close the socket and call disconnected() - /// - void forceClose(); - -private slots: - /// - /// @brief Is called whenever the socket got new data to read - /// - void readyRead(); - - /// - /// @brief Is called when the socket closed the connection, also requests thread exit - /// - void disconnected(); - -private: - /// - /// Handle an incoming Proto message - /// - /// @param message the incoming message as string - /// - void handleMessage(const proto::HyperionRequest &message); - - /// - /// Handle an incoming Proto Color message - /// - /// @param message the incoming message - /// - void handleColorCommand(const proto::ColorRequest & message); - - /// - /// Handle an incoming Proto Image message - /// - /// @param message the incoming message - /// - void handleImageCommand(const proto::ImageRequest & message); - - /// - /// Handle an incoming Proto Clear message - /// - /// @param message the incoming message - /// - void handleClearCommand(const proto::ClearRequest & message); - - /// - /// Handle an incoming Proto Clearall message - /// - void handleClearallCommand(); - - /// - /// Handle an incoming Proto message of unknown type - /// - void handleNotImplemented(); - - /// - /// Send a message to the connected client - /// - /// @param message The Proto message to send - /// - void sendMessage(const google::protobuf::Message &message); - - /// - /// Send a standard reply indicating success - /// - void sendSuccessReply(); - - /// - /// Send an error message back to the client - /// - /// @param error String describing the error - /// - void sendErrorReply(const std::string & error); - -private: - Logger*_log; - - /// The TCP-Socket that is connected tot the Proto-client - QTcpSocket* _socket; - - /// address of client - const QString _clientAddress; - - QTimer*_timeoutTimer; - int _timeout; - int _priority; - - /// The buffer used for reading data from the socket - QByteArray _receiveBuffer; -}; diff --git a/libsrc/protoserver/ProtoServer.cpp b/libsrc/protoserver/ProtoServer.cpp deleted file mode 100644 index 20b0b187f..000000000 --- a/libsrc/protoserver/ProtoServer.cpp +++ /dev/null @@ -1,119 +0,0 @@ -#include "ProtoClientConnection.h" -#include - -// util -#include -#include - -// qt -#include -#include -#include - -ProtoServer::ProtoServer(const QJsonDocument& config, QObject* parent) - : QObject(parent) - , _server(new QTcpServer(this)) - , _log(Logger::getInstance("PROTOSERVER")) - , _timeout(5000) - , _config(config) -{ - -} - -ProtoServer::~ProtoServer() -{ - stopServer(); - delete _server; -} - -void ProtoServer::initServer() -{ - _netOrigin = NetOrigin::getInstance(); - connect(_server, &QTcpServer::newConnection, this, &ProtoServer::newConnection); - - // apply config - handleSettingsUpdate(settings::type::PROTOSERVER, _config); -} - -void ProtoServer::handleSettingsUpdate(settings::type type, const QJsonDocument& config) -{ - if(type == settings::type::PROTOSERVER) - { - const QJsonObject& obj = config.object(); - - quint16 port = obj["port"].toInt(19445); - - // port check - if(_server->serverPort() != port) - { - stopServer(); - _port = port; - } - - // new timeout just for new connections - _timeout = obj["timeout"].toInt(5000); - // enable check - obj["enable"].toBool(true) ? startServer() : stopServer(); - } -} - -void ProtoServer::newConnection() -{ - while(_server->hasPendingConnections()) - { - if(QTcpSocket * socket = _server->nextPendingConnection()) - { - if(_netOrigin->accessAllowed(socket->peerAddress(), socket->localAddress())) - { - Debug(_log, "New connection from %s", QSTRING_CSTR(socket->peerAddress().toString())); - ProtoClientConnection * client = new ProtoClientConnection(socket, _timeout, this); - // internal - connect(client, &ProtoClientConnection::clientDisconnected, this, &ProtoServer::clientDisconnected); - connect(client, &ProtoClientConnection::registerGlobalInput, GlobalSignals::getInstance(), &GlobalSignals::registerGlobalInput); - connect(client, &ProtoClientConnection::clearGlobalInput, GlobalSignals::getInstance(), &GlobalSignals::clearGlobalInput); - connect(client, &ProtoClientConnection::setGlobalInputImage, GlobalSignals::getInstance(), &GlobalSignals::setGlobalImage); - connect(client, &ProtoClientConnection::setGlobalInputColor, GlobalSignals::getInstance(), &GlobalSignals::setGlobalColor); - connect(GlobalSignals::getInstance(), &GlobalSignals::globalRegRequired, client, &ProtoClientConnection::registationRequired); - _openConnections.append(client); - } - else - socket->close(); - } - } -} - -void ProtoServer::clientDisconnected() -{ - ProtoClientConnection* client = qobject_cast(sender()); - client->deleteLater(); - _openConnections.removeAll(client); -} - -void ProtoServer::startServer() -{ - if(!_server->isListening()) - { - if(!_server->listen(QHostAddress::Any, _port)) - { - Error(_log,"Failed to bind port %d", _port); - } - else - { - Info(_log,"Started on port %d", _port); - } - } -} - -void ProtoServer::stopServer() -{ - if(_server->isListening()) - { - // close client connections - for(const auto& client : _openConnections) - { - client->forceClose(); - } - _server->close(); - Info(_log, "Stopped"); - } -} diff --git a/libsrc/protoserver/message.proto b/libsrc/protoserver/message.proto deleted file mode 100644 index d7593c328..000000000 --- a/libsrc/protoserver/message.proto +++ /dev/null @@ -1,81 +0,0 @@ -syntax = "proto2"; -package proto; - -message HyperionRequest { - enum Command { - COLOR = 1; - IMAGE = 2; - CLEAR = 3; - CLEARALL = 4; - } - - // command specification - required Command command = 1; - - // extensions to define all specific requests - extensions 10 to 100; -} - -message ColorRequest { - extend HyperionRequest { - optional ColorRequest colorRequest = 10; - } - - // priority to use when setting the color - required int32 priority = 1; - - // integer value containing the rgb color (0x00RRGGBB) - required int32 RgbColor = 2; - - // duration of the request (negative results in infinite) - optional int32 duration = 3; -} - -message ImageRequest { - extend HyperionRequest { - optional ImageRequest imageRequest = 11; - } - - // priority to use when setting the image - required int32 priority = 1; - - // width of the image - required int32 imagewidth = 2; - - // height of the image - required int32 imageheight = 3; - - // image data - required bytes imagedata = 4; - - // duration of the request (negative results in infinite) - optional int32 duration = 5; -} - -message ClearRequest { - extend HyperionRequest { - optional ClearRequest clearRequest = 12; - } - - // priority which need to be cleared - required int32 priority = 1; -} - -message HyperionReply { - enum Type { - REPLY = 1; - VIDEO = 2; - } - - // Identifies which field is filled in. - required Type type = 1; - - // flag indication success or failure - optional bool success = 2; - - // string indicating the reason for failure (if applicable) - optional string error = 3; - - // Proto Messages for video mode - optional int32 video = 4; -} diff --git a/libsrc/ssdp/SSDPHandler.cpp b/libsrc/ssdp/SSDPHandler.cpp index 36104f198..417d4ce1a 100644 --- a/libsrc/ssdp/SSDPHandler.cpp +++ b/libsrc/ssdp/SSDPHandler.cpp @@ -18,7 +18,7 @@ static const QString SSDP_IDENTIFIER("urn:hyperhdr.blogspot.com:device:basic:1"); -SSDPHandler::SSDPHandler(WebServer* webserver, quint16 flatBufPort, quint16 protoBufPort, quint16 jsonServerPort, quint16 sslPort, const QString& name, QObject * parent) +SSDPHandler::SSDPHandler(WebServer* webserver, quint16 flatBufPort, quint16 jsonServerPort, quint16 sslPort, const QString& name, QObject * parent) : SSDPServer(parent) , _webserver(webserver) , _localAddress() @@ -27,7 +27,6 @@ SSDPHandler::SSDPHandler(WebServer* webserver, quint16 flatBufPort, quint16 prot #endif { setFlatBufPort(flatBufPort); - setProtoBufPort(protoBufPort); setJsonServerPort(jsonServerPort); setSSLServerPort(sslPort); setHyperhdrName(name); @@ -95,14 +94,6 @@ void SSDPHandler::handleSettingsUpdate(settings::type type, const QJsonDocument& } } - if(type == settings::type::PROTOSERVER) - { - if(obj["port"].toInt() != SSDPServer::getProtoBufPort()) - { - SSDPServer::setProtoBufPort(obj["port"].toInt()); - } - } - if(type == settings::type::JSONSERVER) { if(obj["port"].toInt() != SSDPServer::getJsonServerPort()) @@ -258,7 +249,6 @@ QString SSDPHandler::buildDesc() const _uuid, QString::number(SSDPServer::getJsonServerPort()), QString::number(SSDPServer::getSSLServerPort()), - QString::number(SSDPServer::getProtoBufPort()), QString::number(SSDPServer::getFlatBufPort()) ); } diff --git a/src/hyperhdr/CMakeLists.txt b/src/hyperhdr/CMakeLists.txt index b5044a4ca..26c6fad3c 100644 --- a/src/hyperhdr/CMakeLists.txt +++ b/src/hyperhdr/CMakeLists.txt @@ -25,7 +25,6 @@ target_link_libraries(hyperhdr effectengine jsonserver flatbufserver - protoserver webserver ssdp database diff --git a/src/hyperhdr/hyperhdr.cpp b/src/hyperhdr/hyperhdr.cpp index 43ee32622..fef322e53 100644 --- a/src/hyperhdr/hyperhdr.cpp +++ b/src/hyperhdr/hyperhdr.cpp @@ -32,9 +32,6 @@ // Flatbuffer Server #include -// Protobuffer Server -#include - // ssdp #include @@ -199,15 +196,6 @@ void HyperHdrDaemon::freeObjects() _flatBufferServer = nullptr; } - if (_protoServer != nullptr) - { - auto protoServerThread = _protoServer->thread(); - protoServerThread->quit(); - protoServerThread->wait(); - delete protoServerThread; - _protoServer = nullptr; - } - //ssdp before webserver if (_ssdp != nullptr) { @@ -275,16 +263,6 @@ void HyperHdrDaemon::startNetworkServices() connect(this, &HyperHdrDaemon::settingsChanged, _flatBufferServer, &FlatBufferServer::handleSettingsUpdate); fbThread->start(); - // Create Proto server in thread - _protoServer = new ProtoServer(getSetting(settings::type::PROTOSERVER)); - QThread* pThread = new QThread(this); - pThread->setObjectName("ProtoServerThread"); - _protoServer->moveToThread(pThread); - connect(pThread, &QThread::started, _protoServer, &ProtoServer::initServer); - connect(pThread, &QThread::finished, _protoServer, &ProtoServer::deleteLater); - connect(this, &HyperHdrDaemon::settingsChanged, _protoServer, &ProtoServer::handleSettingsUpdate); - pThread->start(); - // Create Webserver in thread _webserver = new WebServer(getSetting(settings::type::WEBSERVER), false); QThread* wsThread = new QThread(this); @@ -307,8 +285,7 @@ void HyperHdrDaemon::startNetworkServices() // Create SSDP server in thread _ssdp = new SSDPHandler(_webserver, - getSetting(settings::type::FLATBUFSERVER).object()["port"].toInt(), - getSetting(settings::type::PROTOSERVER).object()["port"].toInt(), + getSetting(settings::type::FLATBUFSERVER).object()["port"].toInt(), getSetting(settings::type::JSONSERVER).object()["port"].toInt(), getSetting(settings::type::WEBSERVER).object()["sslPort"].toInt(), getSetting(settings::type::GENERAL).object()["name"].toString()); diff --git a/src/hyperhdr/hyperhdr.h b/src/hyperhdr/hyperhdr.h index 17f70312c..47f7c7519 100644 --- a/src/hyperhdr/hyperhdr.h +++ b/src/hyperhdr/hyperhdr.h @@ -60,7 +60,6 @@ class WebServer; class SettingsManager; class SSDPHandler; class FlatBufferServer; -class ProtoServer; class AuthManager; class NetOrigin; #ifdef ENABLE_SOUNDCAPWINDOWS @@ -156,7 +155,6 @@ public slots: cecHandler* _cecHandler; SSDPHandler* _ssdp; FlatBufferServer* _flatBufferServer; - ProtoServer* _protoServer; #if defined(ENABLE_SOUNDCAPWINDOWS) SoundCapWindows* _snd;