summaryrefslogtreecommitdiff
path: root/src/protocols/httpserver.h
blob: e3ca66fb1fb967c24fdf2a8965a1bc5c3927ba1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once

// qt
#include <QFuture>
#include <QHostAddress>
#include <QHttpServerResponse>
// #include <QObject>

// orpheus
#include "iprotocol.h"

class ICamera;
class QHttpServer;

class HttpServer : public IProtocol
{
private:
    struct Stats
    {
        uint64_t GET_pixels_us{0};
    } m_stats{0};

public:
    static constexpr auto DefaultAddress = QHostAddress::Any;
    static constexpr uint16_t DefaultPort{8080};

public:
    explicit HttpServer(std::shared_ptr<ICamera> camera,
                        const QHostAddress &address = DefaultAddress,
                        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();
    /*!
     * \brief GET_image_async
     * \warning may crash
     * \return 
     */
    QFuture<QHttpServerResponse> GET_image_async();
    QHttpServerResponse GET_pixels();

    QHttpServerResponse POST_params(const QHttpServerRequest &request);
    QHttpServerResponse GET_params();

private:
    QHostAddress m_address{DefaultAddress};
    uint16_t m_port{DefaultPort};

    std::shared_ptr<QHttpServer> m_server;
};