diff options
| author | Nikita Kostovsky <nikita@kostovsky.me> | 2025-11-14 22:49:35 +0100 |
|---|---|---|
| committer | Nikita Kostovsky <nikita@kostovsky.me> | 2025-11-14 22:49:35 +0100 |
| commit | 5b1b873f3f09f3e1644141a2cfc67b3a84dc4492 (patch) | |
| tree | edbc25ac40dcd2c2a3b47b1ed823b4d6466fea0c /src/protocols/httpserver.cpp | |
| parent | ac27fb455c76aee4f9e9f65747483006909b14ab (diff) | |
cleanup
Diffstat (limited to 'src/protocols/httpserver.cpp')
| -rw-r--r-- | src/protocols/httpserver.cpp | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/src/protocols/httpserver.cpp b/src/protocols/httpserver.cpp index 8819490..164ce54 100644 --- a/src/protocols/httpserver.cpp +++ b/src/protocols/httpserver.cpp @@ -22,8 +22,7 @@ extern uint8_t pgm_image[64 + img_width * img_height * sizeof(uint8_t)]; extern size_t pgm_image_size; extern std::mutex pgm_image_mtx; -HttpServer::HttpServer(ICamera *camera, - // QObject *parent, +HttpServer::HttpServer(std::shared_ptr<ICamera> camera, const QHostAddress &address, const uint16_t port) : IProtocol{camera} @@ -44,10 +43,34 @@ HttpServer::HttpServer(ICamera *camera, [this](const QHttpServerRequest &request) { return POST_params(request); }); + m_server->route(apiPrefix + QStringLiteral("/sensor/image"), + QHttpServerRequest::Method::Get, + [this]() { return GET_image(); }); + m_server->route(apiPrefix + QStringLiteral("/sensor/image2"), + QHttpServerRequest::Method::Get, + [this]() { return GET_image(); }); qDebug().noquote() << Q_FUNC_INFO << ": listen: " << m_server->listen(m_address, m_port); } +QHttpServerResponse HttpServer::GET_image() +{ + static Image img; + + if (!m_camera->getImage(&img)) { + qCritical() << "cannot get image"; + return QHttpServerResponse::StatusCode::ServiceUnavailable; + } + + pgm_save(&img); + std::lock_guard<std::mutex> lg(pgm_image_mtx); + + return QHttpServerResponse{QByteArray{(const char *) (pgm_image), + static_cast<qsizetype>( + pgm_image_size)}, + QHttpServerResponse::StatusCode::Ok}; +} + QHttpServerResponse HttpServer::GET_pixels() { QElapsedTimer t; @@ -69,22 +92,26 @@ QHttpServerResponse HttpServer::GET_pixels() // 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); + // auto cam = dynamic_cast<VeyeIMX287m *>(m_camera); - if (!cam) { + // if (!cam) { + if (!m_camera) { qWarning() << "NO CAM"; return QHttpServerResponse::StatusCode::ServiceUnavailable; } // yeaah // ::img = &img; - if (!cam->getImage(img)) { + // if (!cam->getImage(img)) { + if (!m_camera->getImage(&img)) { qWarning() << "cannot get image"; return QHttpServerResponse::StatusCode::ServiceUnavailable; } // ::pixels = std::move(img.pixels()); - ++cam->processedCounter; + // ++cam->processedCounter; + // FIXME: take into account + // ++m_camera->processedCounter; } // FIXME: not thread-safe, don't use this static shared_ptr at all |
