Skip to content

Commit

Permalink
Add protobuf as optional component
Browse files Browse the repository at this point in the history
Will be included only on systems that can provide development protobuf compiler&libraries (for example Linux). Or you can build it yourself. That legacy library is excluded from submodules now and won't be shipped alongside HyperHDR anymore.
  • Loading branch information
awawa-dev committed Nov 23, 2021
1 parent 4835a97 commit 6f3c177
Show file tree
Hide file tree
Showing 24 changed files with 880 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ jobs:
# Install deps
- name: Install deps
shell: bash
run: brew update && brew install qt@6 xz ccache
run: brew update && brew install qt@6 xz ccache protobuf

# Build process
- name: Build packages
Expand Down
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ endif(CCACHE_FOUND)

# Set build variables
SET ( DO_NOT_USE_QT_VERSION_6_LIBS OFF )
SET ( DEFAULT_PROTOBUF ON )
SET ( DEFAULT_BOBLIGHT ON )
SET ( DEFAULT_WS281XPWM OFF )
SET ( DEFAULT_AVAHI ON )
Expand Down Expand Up @@ -214,6 +215,16 @@ if(DEFAULT_CEC)
endif()
endif()

if (DEFAULT_PROTOBUF)
find_package(Protobuf)
if (NOT Protobuf_FOUND)
message( WARNING "Could not find protobuf libraries (macOS: protobuf, Linux: libprotobuf-dev protobuf-compiler, Windows: need to compile yourself)" )
SET ( DEFAULT_PROTOBUF OFF )
else()
# cmake_policy(SET CMP0071 NEW)
endif()
endif()

# set the build options
option(ENABLE_BOBLIGHT "Enable BOBLIGHT component" ${DEFAULT_BOBLIGHT} )
message(STATUS "ENABLE_BOBLIGHT = ${ENABLE_BOBLIGHT}")
Expand Down Expand Up @@ -263,6 +274,9 @@ message(STATUS "ENABLE_SOUNDCAPLINUX = ${ENABLE_SOUNDCAPLINUX}")
option(ENABLE_CEC "Enable CEC" ${DEFAULT_CEC})
message(STATUS "ENABLE_CEC = ${ENABLE_CEC}")

option(ENABLE_PROTOBUF "Enable PROTOBUF" ${DEFAULT_PROTOBUF})
message(STATUS "ENABLE_PROTOBUF = ${ENABLE_PROTOBUF}")

SET ( FLATBUFFERS_INSTALL_BIN_DIR ${CMAKE_BINARY_DIR}/flatbuf )
SET ( FLATBUFFERS_INSTALL_LIB_DIR ${CMAKE_BINARY_DIR}/flatbuf )

Expand Down
2 changes: 2 additions & 0 deletions HyperhdrConfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
// Define to enable the usb / hid devices
#cmakedefine ENABLE_USB_HID

#cmakedefine ENABLE_PROTOBUF

// the hyperhdr build id string
#define HYPERHDR_BUILD_ID "${HYPERHDR_BUILD_ID}"
#define HYPERHDR_GIT_REMOTE "${HYPERHDR_GIT_REMOTE}"
Expand Down
29 changes: 29 additions & 0 deletions assets/webconfig/js/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ $(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;
Expand All @@ -25,6 +26,13 @@ $(document).ready( function() {
//flatbufserver
$('#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")));

if (window.serverInfo.hasPROTOBUF == 1)
{
//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)
Expand Down Expand Up @@ -99,6 +107,22 @@ $(document).ready( function() {
requestWriteConfig(conf_editor_fbs.getValue());
});

if (window.serverInfo.hasPROTOBUF == 1)
{
//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)
{
Expand Down Expand Up @@ -139,6 +163,11 @@ $(document).ready( function() {
createHint("intro", $.i18n('conf_network_json_intro'), "editor_container_jsonserver");
createHint("intro", $.i18n('conf_network_fbs_intro'), "editor_container_fbserver");

if (window.serverInfo.hasPROTOBUF == 1)
{
createHint("intro", $.i18n('conf_network_proto_intro'), "editor_container_protoserver");
}

if (BOBLIGHT_ENABLED)
{
createHint("intro", $.i18n('conf_network_bobl_intro'), "editor_container_boblightserver");
Expand Down
69 changes: 69 additions & 0 deletions include/protoserver/ProtoServer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#pragma once

// util
#include <utils/Logger.h>
#include <utils/settings.h>

// qt
#include <QVector>

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<ProtoClientConnection*> _openConnections;
};
2 changes: 1 addition & 1 deletion include/ssdp/SSDPHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SSDPHandler : public SSDPServer
{
Q_OBJECT
public:
SSDPHandler(WebServer* webserver, quint16 flatBufPort,quint16 jsonServerPort, quint16 sslPort, const QString &name, QObject * parent = nullptr);
SSDPHandler(WebServer* webserver, quint16 flatBufPort, quint16 protoBufPort, quint16 jsonServerPort, quint16 sslPort, const QString &name, QObject * parent = nullptr);
~SSDPHandler() override;

///
Expand Down
11 changes: 10 additions & 1 deletion include/ssdp/SSDPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,16 @@ 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
///
Expand Down
3 changes: 3 additions & 0 deletions include/utils/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace settings {
VIDEODETECTION,
NETWORK,
FLATBUFSERVER,
PROTOSERVER,
INVALID
};

Expand Down Expand Up @@ -66,6 +67,7 @@ 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";
}
}
Expand Down Expand Up @@ -100,6 +102,7 @@ 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;
}
}
3 changes: 3 additions & 0 deletions libsrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ add_subdirectory(commandline)
add_subdirectory(blackborder)
add_subdirectory(jsonserver)
add_subdirectory(flatbufserver)
if (ENABLE_PROTOBUF)
add_subdirectory(protoserver)
endif()
add_subdirectory(ssdp)
if(ENABLE_BOBLIGHT)
add_subdirectory(boblightserver)
Expand Down
6 changes: 6 additions & 0 deletions libsrc/api/JsonAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,12 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject &message, const QString
info["systemGrabbers"] = systemDevice;
#endif

#if defined(ENABLE_PROTOBUF)
info["hasPROTOBUF"] = 1;
#else
info["hasPROTOBUF"] = 0;
#endif

#if defined(ENABLE_CEC)
info["hasCEC"] = 1;
#else
Expand Down
2 changes: 1 addition & 1 deletion libsrc/db/SettingsTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
list << settings::typeToString(settings::type::JSONSERVER) << settings::typeToString(settings::type::PROTOSERVER)
<< 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)
Expand Down
4 changes: 4 additions & 0 deletions libsrc/hyperhdrbase/hyperhdr.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
{
"$ref": "schema-flatbufServer.json"
},
"protoServer" :
{
"$ref": "schema-protoServer.json"
},
"boblightServer" :
{
"$ref": "schema-boblightServer.json"
Expand Down
1 change: 1 addition & 0 deletions libsrc/hyperhdrbase/resource.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<file alias="schema-forwarder.json">schema/schema-forwarder.json</file>
<file alias="schema-jsonServer.json">schema/schema-jsonServer.json</file>
<file alias="schema-flatbufServer.json">schema/schema-flatbufServer.json</file>
<file alias="schema-protoServer.json">schema/schema-protoServer.json</file>
<file alias="schema-boblightServer.json">schema/schema-boblightServer.json</file>
<file alias="schema-webConfig.json">schema/schema-webConfig.json</file>
<file alias="schema-effects.json">schema/schema-effects.json</file>
Expand Down
37 changes: 37 additions & 0 deletions libsrc/hyperhdrbase/schema/schema-protoServer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"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
}
5 changes: 4 additions & 1 deletion libsrc/leddevice/dev_net/ProviderUdpSSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ProviderUdpSSL::ProviderUdpSSL(const QJsonObject &deviceConfig)
_latchTime_ms = 1;

bool error = false;

try
{
mbedtls_ctr_drbg_init(&ctr_drbg);
Expand All @@ -52,7 +53,9 @@ ProviderUdpSSL::ProviderUdpSSL(const QJsonObject &deviceConfig)
{
error = true;
}
Error(_log, "Failed to initialize seed");

if (error)
Error(_log, "Failed to initialize mbedtls seed");
}

ProviderUdpSSL::~ProviderUdpSSL()
Expand Down
45 changes: 45 additions & 0 deletions libsrc/protoserver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

# 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} )
set_property(SOURCE ${CMAKE_SOURCE_DIR}/build/libsrc/protoserver/message.pb.cc PROPERTY SKIP_AUTOMOC ON)
set_property(SOURCE ${CMAKE_SOURCE_DIR}/build/libsrc/protoserver/message.pb.h PROPERTY SKIP_AUTOMOC ON)
### 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
${PROTOBUF_LIBRARY}
Qt${Qt_VERSION}::Gui
)

target_link_libraries(protoserver
hyperhdr-base
hyperhdr-utils
protoclient
Qt${Qt_VERSION}::Gui
)
Loading

0 comments on commit 6f3c177

Please sign in to comment.