diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/Handler.hpp | 11 | ||||
-rw-r--r-- | include/Response.hpp | 8 |
2 files changed, 17 insertions, 2 deletions
diff --git a/include/Handler.hpp b/include/Handler.hpp index 3d4b830..3aed302 100644 --- a/include/Handler.hpp +++ b/include/Handler.hpp @@ -1,5 +1,9 @@ #pragma once +#include <queue> +#include <string> +#include <functional> + #include "crow.h" namespace Handler { @@ -8,12 +12,17 @@ namespace Handler { void *payload)> handler_function; struct CommandHandler { + ~CommandHandler() { + delete description; + } + [[nodiscard]] json exec(std::string const &arguments, std::string const &session) const { return func(arguments, session, payload); } handler_function func{nullptr}; - std::string description; + // handler takes ownership of the description, using it after passing is unsafe + std::queue<json> *description{nullptr}; void *payload{nullptr}; }; diff --git a/include/Response.hpp b/include/Response.hpp index 53043c8..82edb53 100644 --- a/include/Response.hpp +++ b/include/Response.hpp @@ -8,13 +8,19 @@ namespace Response { using Reply::AnnotationType; typedef crow::json::wvalue json; + // create a full response of just plain text json simple_response(std::string const &text, std::string const &session = "null", bool success = true); + // "nested" annotations: the extra field is again an array of text-annotation pairs + json create_annotation(AnnotationType annotation, std::vector<json> &&extra); + // construct an extra field with no special annotations in the extra json create_annotation(AnnotationType annotation = AnnotationType::none, std::string const &extra = ""); + // text with no special annotation json create_text(std::string const &text); - + // text with annotations json create_text(std::string const &text, std::vector<json> &&annotations); + // create a response from multiple texts json create_response(std::vector<json> &&reply, std::string const &session = "null", bool success = true); }
\ No newline at end of file |