packio
Public Types | Public Member Functions | List of all members
packio::dispatcher< Rpc, Map, Lockable > Class Template Reference

The dispatcher class, used to store and dispatch procedures. More...

#include <packio/dispatcher.h>

Public Types

using rpc_type = Rpc
 The RPC protocol type.
 
using mutex_type = Lockable
 The mutex type used to protect the procedure map.
 
using args_type = decltype(typename rpc_type::request_type{}.args)
 The type of the arguments used by the RPC protocol.
 
using function_type = internal::movable_function< void(completion_handler< rpc_type >, args_type &&args)>
 The type of function stored in the dispatcher.
 
using function_ptr_type = std::shared_ptr< function_type >
 A shared pointer to function_type.
 

Public Member Functions

template<typename SyncProcedure >
bool add (std::string_view name, args_specs< SyncProcedure > arg_specs, SyncProcedure &&fct)
 Add a synchronous procedure to the dispatcher. More...
 
template<typename SyncProcedure >
bool add (std::string_view name, SyncProcedure &&fct)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename AsyncProcedure >
bool add_async (std::string_view name, args_specs< AsyncProcedure > arg_specs, AsyncProcedure &&fct)
 Add an asynchronous procedure to the dispatcher. More...
 
template<typename AsyncProcedure >
bool add_async (std::string_view name, AsyncProcedure &&fct)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename Executor , typename CoroProcedure , std::size_t N = internal::func_traits<CoroProcedure>::args_count>
bool add_coro (std::string_view name, const Executor &executor, args_specs< CoroProcedure > arg_specs, CoroProcedure &&coro)
 Add a coroutine to the dispatcher. More...
 
template<typename Executor , typename CoroProcedure >
bool add_coro (std::string_view name, const Executor &executor, CoroProcedure &&coro)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename ExecutionContext , typename CoroProcedure , std::size_t N = internal::func_traits<CoroProcedure>::args_count>
bool add_coro (std::string_view name, ExecutionContext &ctx, args_specs< CoroProcedure > arg_specs, CoroProcedure &&coro)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename ExecutionContext , typename CoroProcedure >
bool add_coro (std::string_view name, ExecutionContext &ctx, CoroProcedure &&coro)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool remove (const std::string &name)
 Remove a procedure from the dispatcher. More...
 
bool has (const std::string &name) const
 Check if a procedure is registered. More...
 
size_t clear ()
 Remove all procedures. More...
 
std::vector< std::string > known () const
 Get the name of all known procedures. More...
 

Detailed Description

template<typename Rpc, template< class... > class Map = default_map, typename Lockable = default_mutex>
class packio::dispatcher< Rpc, Map, Lockable >

The dispatcher class, used to store and dispatch procedures.

Template Parameters
RpcRPC protocol implementation
MapThe container used to associate procedures to their name
LockableThe lockable used to protect accesses to the procedure map

Member Function Documentation

◆ add()

template<typename Rpc , template< class... > class Map = default_map, typename Lockable = default_mutex>
template<typename SyncProcedure >
bool packio::dispatcher< Rpc, Map, Lockable >::add ( std::string_view  name,
args_specs< SyncProcedure >  arg_specs,
SyncProcedure &&  fct 
)
inline

Add a synchronous procedure to the dispatcher.

Parameters
nameThe name of the procedure
arg_specsThe argument specifications (optional)
fctThe procedure itself

◆ add_async()

template<typename Rpc , template< class... > class Map = default_map, typename Lockable = default_mutex>
template<typename AsyncProcedure >
bool packio::dispatcher< Rpc, Map, Lockable >::add_async ( std::string_view  name,
args_specs< AsyncProcedure >  arg_specs,
AsyncProcedure &&  fct 
)
inline

Add an asynchronous procedure to the dispatcher.

Parameters
nameThe name of the procedure
arg_specsThe argument specifications (optional)
fctThe procedure itself

◆ add_coro()

template<typename Rpc , template< class... > class Map = default_map, typename Lockable = default_mutex>
template<typename Executor , typename CoroProcedure , std::size_t N = internal::func_traits<CoroProcedure>::args_count>
bool packio::dispatcher< Rpc, Map, Lockable >::add_coro ( std::string_view  name,
const Executor &  executor,
args_specs< CoroProcedure >  arg_specs,
CoroProcedure &&  coro 
)
inline

Add a coroutine to the dispatcher.

Parameters
nameThe name of the procedure
executorThe executor used to execute the coroutine
arg_specsThe argument specifications (optional)
coroThe coroutine to use as procedure

◆ clear()

template<typename Rpc , template< class... > class Map = default_map, typename Lockable = default_mutex>
size_t packio::dispatcher< Rpc, Map, Lockable >::clear ( )
inline

Remove all procedures.

Returns
The number of procedures removed

◆ has()

template<typename Rpc , template< class... > class Map = default_map, typename Lockable = default_mutex>
bool packio::dispatcher< Rpc, Map, Lockable >::has ( const std::string &  name) const
inline

Check if a procedure is registered.

Parameters
nameThe name of the procedure to check
Returns
True if the procedure is known

◆ known()

template<typename Rpc , template< class... > class Map = default_map, typename Lockable = default_mutex>
std::vector<std::string> packio::dispatcher< Rpc, Map, Lockable >::known ( ) const
inline

Get the name of all known procedures.

Returns
Vector containing the name of all known procedures

◆ remove()

template<typename Rpc , template< class... > class Map = default_map, typename Lockable = default_mutex>
bool packio::dispatcher< Rpc, Map, Lockable >::remove ( const std::string &  name)
inline

Remove a procedure from the dispatcher.

Parameters
nameThe name of the procedure to remove
Returns
True if the procedure was removed, False if it was not found

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