#pragma once #include "item-selection-helpers.hpp" #include "message-buffer.hpp" #include "message-dispatcher.hpp" #include #include #include #include #include #include namespace advss { struct HttpRequest { std::string method; std::string path; std::string body; std::map headers; }; using HttpRequestBuffer = std::shared_ptr>; class HttpServerSelection; class HttpServerSettingsDialog; class HttpServer : public Item { public: HttpServer(); HttpServer(const HttpServer &); HttpServer &operator=(const HttpServer &); ~HttpServer(); static std::shared_ptr Create() { return std::make_shared(); } void Load(obs_data_t *obj); void Save(obs_data_t *obj) const; HttpRequestBuffer RegisterForRequests(); int GetPort() const { return _port; } bool IsListening() const; void Start(); void Stop(); private: int _port = 16384; bool _startOnLoad = true; struct Impl; std::unique_ptr _impl; friend HttpServerSelection; friend HttpServerSettingsDialog; }; class HttpServerSettingsDialog : public ItemSettingsDialog { Q_OBJECT public: HttpServerSettingsDialog(QWidget *parent, const HttpServer &); static bool AskForSettings(QWidget *parent, HttpServer &settings); private: QSpinBox *_port; QCheckBox *_startOnLoad; QGridLayout *_layout; }; class HttpServerSelection : public ItemSelection { Q_OBJECT public: HttpServerSelection(QWidget *parent = nullptr); void SetServer(const std::string &); void SetServer(const std::weak_ptr &); }; class HttpServerSignalManager : public QObject { Q_OBJECT public: HttpServerSignalManager(QObject *parent = nullptr); static HttpServerSignalManager *Instance(); signals: void Rename(const QString &, const QString &); void Add(const QString &); void Remove(const QString &); }; HttpServer *GetHttpServerByName(const std::string &); std::weak_ptr GetWeakHttpServerByName(const std::string &); std::weak_ptr GetWeakHttpServerByQString(const QString &); std::string GetWeakHttpServerName(const std::weak_ptr &); std::deque> &GetHttpServers(); } // namespace advss