X-Git-Url: https://git.sesse.net/?p=nageru;a=blobdiff_plain;f=httpd.h;h=878a184d12858341287a17f20d22e03a1e19bc83;hp=630b0c38bfefb53205050e4eb9563e06455ba69d;hb=2f4224d7c48b3b22bcb24eb622fe6705fa16375f;hpb=df8ef0e2bcb4b9d5061ad9dd9435d77d761703a0 diff --git a/httpd.h b/httpd.h index 630b0c3..878a184 100644 --- a/httpd.h +++ b/httpd.h @@ -9,15 +9,21 @@ #include #include #include +#include #include #include #include +#include +#include struct MHD_Connection; struct MHD_Daemon; class HTTPD { public: + // Returns a pair of content and content-type. + using EndpointCallback = std::function()>; + HTTPD(); ~HTTPD(); @@ -26,6 +32,11 @@ public: header = data; } + // Should be called before start() (due to threading issues). + void add_endpoint(const std::string &url, const EndpointCallback &callback) { + endpoints[url] = callback; + } + void start(int port); void add_data(const char *buf, size_t size, bool keyframe); int64_t get_num_connected_clients() const { @@ -81,6 +92,7 @@ private: MHD_Daemon *mhd = nullptr; std::mutex streams_mutex; std::set streams; // Not owned. + std::unordered_map endpoints; std::string header; // Metrics.