rpc.hpp 0.8.1
Simple RPC Header-Only Library
Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
rpc_hpp::server::server_interface< Serial > Class Template Reference

Class defining an interface for serving functions via RPC. More...

#include <rpc.hpp>

Public Types

using adapter_t = Serial
 

Public Member Functions

 server_interface (const server_interface &)=delete
 
server_interfaceoperator= (const server_interface &)=delete
 
 server_interface (server_interface &&) noexcept=default
 
server_interfaceoperator= (server_interface &&) noexcept=default
 
template<typename Val >
std::unordered_map< typename Serial::bytes_t, Val > & get_func_cache (const std::string &func_name)
 Gets a reference to the server's function cache. More...
 
RPC_HPP_INLINE void clear_all_cache () noexcept
 Clears the server's function cache.
 
template<typename R , typename... Args>
void bind_cached (std::string func_name, R(*func_ptr)(Args...))
 Binds a string to a callback, utilizing the server's cache. More...
 
template<typename R , typename... Args, typename F >
RPC_HPP_INLINE void bind_cached (std::string func_name, F &&func)
 Binds a string to a callback, utilizing the server's cache. More...
 
template<typename R , typename... Args>
void bind (std::string func_name, R(*func_ptr)(Args...))
 Binds a string to a callback. More...
 
template<typename R , typename... Args, typename F >
RPC_HPP_INLINE void bind (std::string func_name, F &&func)
 Binds a string to a callback. More...
 
Serial::bytes_t dispatch (typename Serial::bytes_t &&bytes) const
 Parses the received serialized data and determines which function to call. More...
 

Protected Member Functions

template<typename R , typename... Args>
void dispatch_cached_func (R(*func)(Args...), typename Serial::serial_t &serial_obj)
 

Static Protected Member Functions

template<typename R , typename... Args>
static void dispatch_func (R(*func)(Args...), typename Serial::serial_t &serial_obj)
 

Detailed Description

template<typename Serial>
class rpc_hpp::server::server_interface< Serial >

Class defining an interface for serving functions via RPC.

Template Parameters
Serialserial_adapter type that controls how objects are serialized/deserialized

Member Function Documentation

◆ bind() [1/2]

template<typename Serial >
template<typename R , typename... Args, typename F >
RPC_HPP_INLINE void rpc_hpp::server::server_interface< Serial >::bind ( std::string  func_name,
F &&  func 
)
inline

Binds a string to a callback.

Template Parameters
RReturn type of the callback function
ArgsVariadic argument type(s) for the function
FCallback type (could be function or lambda or functor)
Parameters
func_nameName to bind the callback to
funcCallback to run when dispatch is called with bound name

◆ bind() [2/2]

template<typename Serial >
template<typename R , typename... Args>
void rpc_hpp::server::server_interface< Serial >::bind ( std::string  func_name,
R(*)(Args...)  func_ptr 
)
inline

Binds a string to a callback.

Template Parameters
RReturn type of the callback function
ArgsVariadic argument type(s) for the function
Parameters
func_nameName to bind the callback to
func_ptrPointer to callback that runs when dispatch is called with bound name

◆ bind_cached() [1/2]

template<typename Serial >
template<typename R , typename... Args, typename F >
RPC_HPP_INLINE void rpc_hpp::server::server_interface< Serial >::bind_cached ( std::string  func_name,
F &&  func 
)
inline

Binds a string to a callback, utilizing the server's cache.

Template Parameters
RReturn type of the callback function
ArgsVariadic argument type(s) for the function
FCallback type (could be function or lambda or functor)
Parameters
func_nameName to bind the callback to
funcCallback to run when dispatch is called with bound name

◆ bind_cached() [2/2]

template<typename Serial >
template<typename R , typename... Args>
void rpc_hpp::server::server_interface< Serial >::bind_cached ( std::string  func_name,
R(*)(Args...)  func_ptr 
)
inline

Binds a string to a callback, utilizing the server's cache.

Template Parameters
RReturn type of the callback function
ArgsVariadic argument type(s) for the function
Parameters
func_nameName to bind the callback to
func_ptrPointer to callback that runs when dispatch is called with bound name

◆ dispatch()

template<typename Serial >
Serial::bytes_t rpc_hpp::server::server_interface< Serial >::dispatch ( typename Serial::bytes_t &&  bytes) const
inline

Parses the received serialized data and determines which function to call.

Parameters
bytesData to be parsed into a serial object
Returns
Serial::bytes_t Data parsed out of a serial object after dispatching the callback
Note
nodiscard because original bytes are consumed

◆ get_func_cache()

template<typename Serial >
template<typename Val >
std::unordered_map< typename Serial::bytes_t, Val > & rpc_hpp::server::server_interface< Serial >::get_func_cache ( const std::string &  func_name)
inline

Gets a reference to the server's function cache.

Template Parameters
ValType of the return value for a function
Parameters
func_nameName of the function to get the cached return value(s) for
Returns
std::unordered_map<typename Serial::bytes_t, Val>& Reference to the hashmap containing the return values with the serialized function call as the key

The documentation for this class was generated from the following file: