diff options
Diffstat (limited to 'src/protocols/httpserver.cpp')
| -rw-r--r-- | src/protocols/httpserver.cpp | 57 |
1 files changed, 21 insertions, 36 deletions
diff --git a/src/protocols/httpserver.cpp b/src/protocols/httpserver.cpp index 96b87db..d11fdb0 100644 --- a/src/protocols/httpserver.cpp +++ b/src/protocols/httpserver.cpp @@ -5,6 +5,7 @@ #include <QJsonDocument> #include <QJsonObject> #include <QJsonValue> +#include <QtConcurrent/QtConcurrentRun> // orpheus #include "camera/veyeimx287m.h" @@ -12,6 +13,7 @@ #include "image.h" #include "imagealgos.h" #include "macro.h" +#include "utils/elapsed_logger.h" // rapidjson #include "rapidjson/document.h" @@ -54,9 +56,15 @@ bool HttpServer::start() m_server->route(apiPrefix + QStringLiteral("/sensor/image"), QHttpServerRequest::Method::Get, [this]() { return GET_image(); }); + // m_server->route(apiPrefix + QStringLiteral("/sensor/image"), + // QHttpServerRequest::Method::Get, + // [this]() { return GET_image_async(); }); m_server->route(apiPrefix + QStringLiteral("/sensor/image2"), QHttpServerRequest::Method::Get, [this]() { return GET_image(); }); + // m_server->route(apiPrefix + QStringLiteral("/sensor/image2"), + // QHttpServerRequest::Method::Get, + // [this]() { return GET_image_async(); }); const auto result = m_server->listen(m_address, m_port); @@ -95,53 +103,30 @@ QHttpServerResponse HttpServer::GET_image() QHttpServerResponse::StatusCode::Ok}; } -QHttpServerResponse HttpServer::GET_pixels() +QFuture<QHttpServerResponse> HttpServer::GET_image_async() { - QElapsedTimer t; - t.start(); - // std::shared_ptr<std::nullptr_t> logTime = std::make_shared<std::nullptr_t>(nullptr, [t]() { - // qDebug() << "HttpServer::GET_pixels: elapsed" << t.nsecsElapsed() / 1000 << "(us)"; - // }); - static constexpr bool logTime{false}; - if constexpr (logTime) { - const std::shared_ptr<std::nullptr_t> - timeLogger{nullptr, [t](auto unused_ptr) { - qDebug() << "HttpServer::GET_pixels: elapsed" << t.nsecsElapsed() / 1000 - << "(us)"; - }}; - } + return QtConcurrent::run(std::bind(&HttpServer::GET_image, this)); +} - // Image img; +QHttpServerResponse HttpServer::GET_pixels() +{ if (!m_camera) { qWarning() << "NO CAM"; return QHttpServerResponse::StatusCode::ServiceUnavailable; } - const auto image = m_camera->getImage(); - + std::shared_ptr<Image> image; { - // const auto sharedCam = m_camera.lock(); - // FIME: don't cast anything, use interface - // auto cam = dynamic_cast<VeyeIMX287m *>(sharedCam.get()); - // auto cam = dynamic_cast<VeyeIMX287m *>(m_camera); - - // if (!cam) { - - // yeaah - // ::img = &img; - // if (!cam->getImage(img)) { - // if (!m_camera->getImage(&img)) { - if (!image) { - qWarning() << "cannot get image"; - return QHttpServerResponse::StatusCode::ServiceUnavailable; - } + const elapsed_logger logger{__func__}; + /*const auto */ image = m_camera->getImage(); + } - // ::pixels = std::move(img.pixels()); - // ++cam->processedCounter; - // FIXME: take into account - // ++m_camera->processedCounter; + if (!image) { + qWarning() << "cannot get image"; + return QHttpServerResponse::StatusCode::ServiceUnavailable; } + // FIXME: inc m_camera->processedCounter // FIXME: not thread-safe, don't use this static shared_ptr at all const auto pixels = image->sharedPixels(); // const auto lines = pixelsToLines(::pixels); |
