diff options
author | Sadie Powell <sadie@witchery.services> | 2025-02-20 14:46:31 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2025-02-20 14:57:55 +0000 |
commit | 96839ae1b82fa51340ad9769fe57087c8dac5ede (patch) | |
tree | fb2f2953388b086a06cfe8338b6929222aa2bcee /include/modules | |
parent | 5420f4858052bd00d86b19380755ed8eec5d2770 (diff) |
Move RPC types to the RPC namespace.
Diffstat (limited to 'include/modules')
-rw-r--r-- | include/modules/rpc.h | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/include/modules/rpc.h b/include/modules/rpc.h index 68523e5fa..b33c26800 100644 --- a/include/modules/rpc.h +++ b/include/modules/rpc.h @@ -14,6 +14,14 @@ namespace RPC { + class Block; + class Event; + class Request; + class ServiceInterface; + + /** Represents possible types of RPC value. */ + using Value = std::variant<Block, Anope::string, std::nullptr_t, bool, double, int64_t, uint64_t>; + /** Represents standard RPC errors from the JSON-RPC and XML-RPC specifications. */ enum Error : int64_t @@ -25,64 +33,61 @@ namespace RPC }; } -class RPCBlock +class RPC::Block { public: - /** Represents possible types of RPC value. */ - using RPCValue = std::variant<RPCBlock, Anope::string, std::nullptr_t, bool, double, int64_t, uint64_t>; - /** Retrieves the list of RPC replies. */ inline const auto &GetReplies() const { return this->replies; } template <typename Stringable> - inline RPCBlock &Reply(const Anope::string &key, const Stringable &value) + inline Block &Reply(const Anope::string &key, const Stringable &value) { this->replies.emplace(key, Anope::ToString(value)); return *this; } - inline RPCBlock &ReplyBlock(const Anope::string &key) + inline Block &ReplyBlock(const Anope::string &key) { - auto it = this->replies.emplace(key, RPCBlock()); - return std::get<RPCBlock>(it.first->second); + auto it = this->replies.emplace(key, Block()); + return std::get<Block>(it.first->second); } - inline RPCBlock &ReplyBool(const Anope::string &key, bool value) + inline Block &ReplyBool(const Anope::string &key, bool value) { this->replies.emplace(key, value); return *this; } - inline RPCBlock &ReplyFloat(const Anope::string &key, double value) + inline Block &ReplyFloat(const Anope::string &key, double value) { this->replies.emplace(key, value); return *this; } - inline RPCBlock &ReplyInt(const Anope::string &key, int64_t value) + inline Block &ReplyInt(const Anope::string &key, int64_t value) { this->replies.emplace(key, value); return *this; } - inline RPCBlock &ReplyNull(const Anope::string &key) + inline Block &ReplyNull(const Anope::string &key) { this->replies.emplace(key, nullptr); return *this; } - inline RPCBlock &ReplyUInt(const Anope::string &key, uint64_t value) + inline Block &ReplyUInt(const Anope::string &key, uint64_t value) { this->replies.emplace(key, value); return *this; } private: - Anope::map<RPCValue> replies; + Anope::map<Value> replies; }; -class RPCRequest final - : public RPCBlock +class RPC::Request final + : public RPC::Block { private: std::optional<std::pair<int64_t, Anope::string>> error; @@ -93,7 +98,7 @@ public: std::deque<Anope::string> data; HTTPReply &reply; - RPCRequest(HTTPReply &r) + Request(HTTPReply &r) : reply(r) { } @@ -106,36 +111,37 @@ public: inline const auto &GetError() const { return this->error; } }; -class RPCServiceInterface; - -class RPCEvent +class RPC::Event { private: Anope::string event; protected: - RPCEvent(const Anope::string& e) + Event(const Anope::string& e) : event(e) { } public: - virtual ~RPCEvent() = default; + virtual ~Event() = default; const auto &GetEvent() const { return event; } - virtual bool Run(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) = 0; + virtual bool Run(ServiceInterface *iface, HTTPClient *client, Request &request) = 0; }; -class RPCServiceInterface +class RPC::ServiceInterface : public Service { public: - RPCServiceInterface(Module *creator, const Anope::string &sname) : Service(creator, "RPCServiceInterface", sname) { } + ServiceInterface(Module *creator, const Anope::string &sname) + : Service(creator, "RPCServiceInterface", sname) + { + } - virtual bool Register(RPCEvent *event) = 0; + virtual bool Register(Event *event) = 0; - virtual bool Unregister(RPCEvent *event) = 0; + virtual bool Unregister(Event *event) = 0; - virtual void Reply(RPCRequest &request) = 0; + virtual void Reply(Request &request) = 0; }; |