aboutsummaryrefslogtreecommitdiffstats
path: root/include/Handler.hpp
diff options
context:
space:
mode:
authorNiklas Halle <niklas@niklashalle.net>2020-08-26 12:00:21 +0200
committerNiklas Halle <niklas@niklashalle.net>2020-08-26 12:00:21 +0200
commit1efd8ab1b4d4a2b1c8236aee33f51d960964c20b (patch)
treeaa4cc7b0d06bce498fabce0a05274e91e4fc6ae0 /include/Handler.hpp
parent600b2ff02ff7727156df17742f1468aefdbcea9c (diff)
downloadn_core-1efd8ab1b4d4a2b1c8236aee33f51d960964c20b.tar.gz
n_core-1efd8ab1b4d4a2b1c8236aee33f51d960964c20b.zip
fixes (i hope)
Diffstat (limited to 'include/Handler.hpp')
-rw-r--r--include/Handler.hpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/Handler.hpp b/include/Handler.hpp
index 3aed302..3328d91 100644
--- a/include/Handler.hpp
+++ b/include/Handler.hpp
@@ -3,6 +3,7 @@
#include <queue>
#include <string>
#include <functional>
+#include <utility>
#include "crow.h"
@@ -12,14 +13,26 @@ namespace Handler {
void *payload)> handler_function;
struct CommandHandler {
+ CommandHandler(std::string command, handler_function func, std::queue<json> *description, void *payload = nullptr)
+ : command{std::move(command)}, func{std::move(func)}, description{description}, payload{payload} {}
+
~CommandHandler() {
delete description;
+ description = nullptr;
+ }
+
+ CommandHandler(CommandHandler &&o) noexcept {
+ func = o.func;
+ description = o.description;
+ o.description = nullptr;
+ payload = o.payload;
}
[[nodiscard]] json exec(std::string const &arguments, std::string const &session) const {
return func(arguments, session, payload);
}
+ std::string command;
handler_function func{nullptr};
// handler takes ownership of the description, using it after passing is unsafe
std::queue<json> *description{nullptr};