aboutsummaryrefslogblamecommitdiffstats
path: root/include/Handler.hpp
blob: 3aed302e16aa4888fd35abe67c3ee099192516ed (plain) (tree)
1
2
3
4
5
6

            



                     







                                                                                        



                               




                                                                                                 

                                                                                       




                                                                                                                 
#pragma once

#include <queue>
#include <string>
#include <functional>

#include "crow.h"

namespace Handler {
    typedef crow::json::wvalue json;
    typedef std::function<json(std::string const &arguments, std::string const &session,
                               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};
        // handler takes ownership of the description, using it after passing is unsafe
        std::queue<json> *description{nullptr};
        void *payload{nullptr};
    };

    std::vector<std::string> tokenizeArguments(std::string const &arguments, std::string const &delimiter = " ");
}