Cleanup and simplify server API

This commit is contained in:
Yves
2025-02-21 11:44:25 +01:00
parent 9f0b18b4ef
commit 0b1a017c2e
3 changed files with 67 additions and 69 deletions

View File

@@ -48,21 +48,23 @@ public:
static bool Started();
static void StopInstance();
const HttpServer &Start(const uint16_t local_port,
const std::string &remote_url,
bool *was_started = nullptr);
bool Stop();
static const HttpServer &Start(ClientContext &, bool *was_started = nullptr);
static bool Stop();
std::string LocalUrl() const;
void SendConnectedEvent(const std::string &token);
void SendCatalogChangedEvent();
private:
void UpdateDatabaseInstance(shared_ptr<DatabaseInstance> context_db);
void SendEvent(const std::string &message);
// Lifecycle
void DoStart(const uint16_t local_port, const std::string &remote_url);
void DoStop();
void Run();
void UpdateDatabaseInstance(shared_ptr<DatabaseInstance> context_db);
// Watcher
void Watch();
void StartWatcher();
void StopWatcher();
// Http handlers
void HandleGetLocalEvents(const httplib::Request &req,
httplib::Response &res);
void HandleGetLocalToken(const httplib::Request &req, httplib::Response &res);
@@ -76,10 +78,16 @@ private:
const httplib::ContentReader &content_reader);
std::string ReadContent(const httplib::ContentReader &content_reader);
// Http responses
void SetResponseContent(httplib::Response &res, const MemoryStream &content);
void SetResponseEmptyResult(httplib::Response &res);
void SetResponseErrorResult(httplib::Response &res, const std::string &error);
// Events
void SendEvent(const std::string &message);
void SendConnectedEvent(const std::string &token);
void SendCatalogChangedEvent();
uint16_t local_port;
std::string remote_url;
weak_ptr<DatabaseInstance> ddb_instance;