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

            
                 
                 
                     
                  
 





                                                                                        
                                                                    

                           
                                                                                                                       
 
                                                    

                                                                                                
 
                            

                                                      



                                                                                                                 
 
#pragma once

#include <string>
#include <vector>
#include <functional>
#include <utility>

#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;
    typedef std::function<std::vector<json>()> description_function;

    struct CommandHandler {
        CommandHandler(std::string command, handler_function func, description_function desc, void *payload = nullptr);

        CommandHandler(CommandHandler &&o) noexcept;

        [[nodiscard]] json exec(std::string const &arguments, std::string const &session) const;

        std::string command;
        handler_function func{nullptr};
        description_function get_description{nullptr};
        void *payload{nullptr};
    };

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