cpp-console-game/eRPC/Server.hpp
ethanglide c9a50d363e Refine RPC library
Got multiple remote calls from one client working

Improved error messages

Got function name and arguments sent over as well as return values
2024-07-08 16:15:55 -04:00

45 lines
800 B
C++

#ifndef ERPC_SERVER_HPP
#define ERPC_SERVER_HPP
#include <string>
#include <functional>
#include <unordered_map>
namespace eRPC
{
class Server
{
public:
/**
* Construct a server on the given port.
*/
Server(int port);
/**
* Destroy the server.
*/
~Server();
/**
* Start the server loop.
*/
void start();
/**
* Stop the server loop.
*/
void stop();
/**
* Bind a method to a callback.
*/
void bindMethod(std::string method, std::function<std::pair<bool, std::string>(std::vector<std::string>)> callback);
private:
int sockfd;
bool running;
std::unordered_map<std::string, std::function<std::pair<bool, std::string>(std::vector<std::string>)>> methods;
};
}
#endif // ERPC_SERVER_HPP