From 0fdae0386e2e55f489853561dc15055a168e5df1 Mon Sep 17 00:00:00 2001 From: Nikita Kostovsky Date: Mon, 17 Nov 2025 16:28:45 +0100 Subject: introduce Scanner --- src/protocols/httpserver.cpp | 23 +++++++++++++++++++++-- src/protocols/httpserver.h | 5 +++++ src/protocols/iprotocol.h | 4 ++++ src/protocols/pixelsudpstreamer.cpp | 7 +++++++ src/protocols/pixelsudpstreamer.h | 14 ++++++++++++++ 5 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/protocols/pixelsudpstreamer.cpp create mode 100644 src/protocols/pixelsudpstreamer.h (limited to 'src/protocols') diff --git a/src/protocols/httpserver.cpp b/src/protocols/httpserver.cpp index f1b562e..d10518b 100644 --- a/src/protocols/httpserver.cpp +++ b/src/protocols/httpserver.cpp @@ -28,8 +28,14 @@ HttpServer::HttpServer(std::shared_ptr camera, : IProtocol{camera} , INIT_FIELD(address) , INIT_FIELD(port) - , m_server{std::make_shared()} +// , m_server{std::make_shared()} { +} + +bool HttpServer::start() +{ + m_server = std::make_shared(); + // TODO: move these vars outside const auto apiPrefix = QStringLiteral("/v1"); const auto pixelsPath = apiPrefix + "/pixels"; @@ -52,7 +58,20 @@ HttpServer::HttpServer(std::shared_ptr camera, QHttpServerRequest::Method::Get, [this]() { return GET_image(); }); - qDebug().noquote() << Q_FUNC_INFO << ": listen: " << m_server->listen(m_address, m_port); + const auto result = m_server->listen(m_address, m_port); + + qDebug().noquote() << Q_FUNC_INFO << ": listen: " << result; + + if (!result) { + m_server.reset(); + } + + return result; +} + +void HttpServer::stop() +{ + m_server.reset(); } QHttpServerResponse HttpServer::GET_image() diff --git a/src/protocols/httpserver.h b/src/protocols/httpserver.h index 600ead4..bfc1e56 100644 --- a/src/protocols/httpserver.h +++ b/src/protocols/httpserver.h @@ -29,6 +29,11 @@ public: const uint16_t port = DefaultPort); ~HttpServer() override = default; + // IProtocol +public: + bool start() override; + void stop() override; + // TODO: methods starting with GET_/POST_ will be routed automatically public: QHttpServerResponse GET_image(); diff --git a/src/protocols/iprotocol.h b/src/protocols/iprotocol.h index 2d65dac..75259bc 100644 --- a/src/protocols/iprotocol.h +++ b/src/protocols/iprotocol.h @@ -10,6 +10,10 @@ public: explicit IProtocol(std::shared_ptr camera); virtual ~IProtocol() = default; +public: + virtual bool start() = 0; + virtual void stop() = 0; + protected: std::shared_ptr m_camera; }; diff --git a/src/protocols/pixelsudpstreamer.cpp b/src/protocols/pixelsudpstreamer.cpp new file mode 100644 index 0000000..d7c66c7 --- /dev/null +++ b/src/protocols/pixelsudpstreamer.cpp @@ -0,0 +1,7 @@ +#include "pixelsudpstreamer.h" + +PixelsUdpStreamer::PixelsUdpStreamer(std::shared_ptr camera) + : IProtocol{camera} +{} + +bool PixelsUdpStreamer::start() {} diff --git a/src/protocols/pixelsudpstreamer.h b/src/protocols/pixelsudpstreamer.h new file mode 100644 index 0000000..db8acc3 --- /dev/null +++ b/src/protocols/pixelsudpstreamer.h @@ -0,0 +1,14 @@ +#pragma once + +#include "iprotocol.h" + +class PixelsUdpStreamer : public IProtocol +{ +public: + explicit PixelsUdpStreamer(std::shared_ptr camera); + ~PixelsUdpStreamer() override = default; + +public: + bool start() override; + void stop() override; +}; -- cgit v1.2.3-70-g09d2