From 8375f92802d3aa7667bfc6f22f6d2a72361c9808 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 4 Nov 2024 11:46:24 -0500 Subject: Websockets server! --- database.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 database.h (limited to 'database.h') diff --git a/database.h b/database.h new file mode 100644 index 0000000..d8d9b67 --- /dev/null +++ b/database.h @@ -0,0 +1,40 @@ +#ifndef DATABASE_H_0A27B356 +#define DATABASE_H_0A27B356 + +#include +#include +#include +#include +#include +#include +#include + +class database { + public: + // Feel free to throw an exception if the subscriber should be killed. + using subscribe_callback_type = std::function; + + std::string create(std::mt19937& rng); + + void subscribe(const std::string& token, subscribe_callback_type callback); + void post(const std::string& token, const std::string& msg); + + void setResult(const std::string& token, const std::string& result); + const std::string& getResult(const std::string& token); + + void mark_done(const std::string& token); + bool is_done(const std::string& token); + + private: + struct request { + std::vector> subscribers; + std::string result; + bool done = false; + }; + + std::mutex mutex_; + + std::map requests_; +}; + +#endif /* end of include guard: DATABASE_H_0A27B356 */ -- cgit 1.4.1