summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/iscanner.h4
-rw-r--r--src/main.cpp2
-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
-rw-r--r--src/scanner.cpp22
-rw-r--r--src/scanner.h4
9 files changed, 83 insertions, 2 deletions
diff --git a/src/iscanner.h b/src/iscanner.h
index 9ce03b7..75300e1 100644
--- a/src/iscanner.h
+++ b/src/iscanner.h
@@ -14,6 +14,10 @@ public:
std::vector<std::shared_ptr<IProtocol>> protocols);
virtual ~IScanner() = default;
+public:
+ virtual bool startAllProtocols() = 0;
+ virtual void stopAllProtocols() = 0;
+
protected:
std::shared_ptr<ICamera> m_camera;
std::vector<std::shared_ptr<IProtocol>> m_protocols;
diff --git a/src/main.cpp b/src/main.cpp
index 6986751..01e4eac 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -209,6 +209,8 @@ int main(int argc, char *argv[])
std::vector<std::shared_ptr<IProtocol>>{
httpServer});
+ scanner->startAllProtocols();
+
QHttpServer qHttpServer;
qHttpServer.route("/v1/profile", [&]() -> QHttpServerResponse {
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;
+};
diff --git a/src/scanner.cpp b/src/scanner.cpp
index 1f14ca0..07d3c0f 100644
--- a/src/scanner.cpp
+++ b/src/scanner.cpp
@@ -1,8 +1,30 @@
#include "scanner.h"
+#include "protocols/iprotocol.h"
+
Scanner::Scanner(std::shared_ptr<ICamera> camera,
std::vector<std::shared_ptr<IProtocol>> protocols)
: IScanner{camera, protocols}
{
// m_protocols.push_back()
}
+
+bool Scanner::startAllProtocols()
+{
+ for (const auto& protocol : m_protocols) {
+ if (!protocol->start()) {
+ stopAllProtocols();
+
+ return false;
+ }
+ }
+
+ return true;
+}
+
+void Scanner::stopAllProtocols()
+{
+ for (const auto& protocol : m_protocols) {
+ protocol->stop();
+ }
+}
diff --git a/src/scanner.h b/src/scanner.h
index f1c1f52..8031dda 100644
--- a/src/scanner.h
+++ b/src/scanner.h
@@ -8,4 +8,8 @@ public:
explicit Scanner(std::shared_ptr<ICamera> camera,
std::vector<std::shared_ptr<IProtocol>> protocols);
~Scanner() override = default;
+
+public:
+ bool startAllProtocols() override;
+ void stopAllProtocols() override;
};