summaryrefslogtreecommitdiff
path: root/src/protocols
diff options
context:
space:
mode:
authorNikita Kostovsky <nikita@kostovsky.me>2025-11-17 16:28:45 +0100
committerNikita Kostovsky <nikita@kostovsky.me>2025-11-17 16:28:45 +0100
commit0fdae0386e2e55f489853561dc15055a168e5df1 (patch)
treeb91087c4696a3281fee528fc838b5447272432e0 /src/protocols
parent99b78ccb9cdb82d64aa3da32dd47b052d3f51732 (diff)
introduce Scanner
Diffstat (limited to 'src/protocols')
-rw-r--r--src/protocols/httpserver.cpp23
-rw-r--r--src/protocols/httpserver.h5
-rw-r--r--src/protocols/iprotocol.h4
-rw-r--r--src/protocols/pixelsudpstreamer.cpp7
-rw-r--r--src/protocols/pixelsudpstreamer.h14
5 files changed, 51 insertions, 2 deletions
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<ICamera> camera,
: IProtocol{camera}
, INIT_FIELD(address)
, INIT_FIELD(port)
- , m_server{std::make_shared<QHttpServer>()}
+// , m_server{std::make_shared<QHttpServer>()}
{
+}
+
+bool HttpServer::start()
+{
+ m_server = std::make_shared<QHttpServer>();
+
// TODO: move these vars outside
const auto apiPrefix = QStringLiteral("/v1");
const auto pixelsPath = apiPrefix + "/pixels";
@@ -52,7 +58,20 @@ HttpServer::HttpServer(std::shared_ptr<ICamera> 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<ICamera> camera);
virtual ~IProtocol() = default;
+public:
+ virtual bool start() = 0;
+ virtual void stop() = 0;
+
protected:
std::shared_ptr<ICamera> 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<ICamera> 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<ICamera> camera);
+ ~PixelsUdpStreamer() override = default;
+
+public:
+ bool start() override;
+ void stop() override;
+};