]> git.sesse.net Git - nageru/blobdiff - httpd.h
Add an HTTP endpoint for enumerating channels and one for getting only their colors...
[nageru] / httpd.h
diff --git a/httpd.h b/httpd.h
index 630b0c38bfefb53205050e4eb9563e06455ba69d..878a184d12858341287a17f20d22e03a1e19bc83 100644 (file)
--- a/httpd.h
+++ b/httpd.h
@@ -9,15 +9,21 @@
 #include <atomic>
 #include <condition_variable>
 #include <deque>
+#include <functional>
 #include <mutex>
 #include <set>
 #include <string>
+#include <unordered_map>
+#include <utility>
 
 struct MHD_Connection;
 struct MHD_Daemon;
 
 class HTTPD {
 public:
+       // Returns a pair of content and content-type.
+       using EndpointCallback = std::function<std::pair<std::string, std::string>()>;
+
        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<Stream *> streams;  // Not owned.
+       std::unordered_map<std::string, EndpointCallback> endpoints;
        std::string header;
 
        // Metrics.