VSM C++ SDK
Vehicle Specific Modules SDK
callback.h File Reference

Generic callback which can be used to define and create an instance of an abstract callable operation with arbitrary arguments. More...

#include <ugcs/vsm/defs.h>
#include <ugcs/vsm/exception.h>
#include <ugcs/vsm/debug.h>
#include <tuple>
#include <memory>
#include <functional>

Go to the source code of this file.

Classes

class  ugcs::vsm::Callback_base< Result >
 Callback which can be executed. More...
 
class  ugcs::vsm::Callback_base< Result >::Ptr< Callback >
 Pointer class type. More...
 
class  ugcs::vsm::Callback< Callable, Enable, Args >
 Generic callback. More...
 
class  ugcs::vsm::callback_internal::Dummy_callback_helper< Result, Args >
 Helper class for creating dummy callbacks. More...
 
class  ugcs::vsm::callback_internal::Dummy_callback_helper< void, Args... >
 Specialization for void return type. More...
 
struct  ugcs::vsm::callback_internal::Callback_args_checker< Callback, idx, Args >
 Helper structure for checking callback argument types. More...
 
struct  ugcs::vsm::callback_internal::Callback_args_checker< Callback, 0 >
 No arguments to check case. More...
 
struct  ugcs::vsm::callback_internal::Callback_args_checker< Callback, idx, Arg >
 Tail recursion case. More...
 
struct  ugcs::vsm::callback_internal::Callback_args_checker< Callback, idx, Arg, Args... >
 Recursion unrolling template. More...
 
class  ugcs::vsm::Callback_forced_args< Callable, Forced_args_tuple, Args >
 Helper class for defining custom callback creation functions which force several first arguments for the user callback. More...
 
class  ugcs::vsm::Callback_proxy< Result, Args >
 Helper class for proxying callback invocation. More...
 
class  ugcs::vsm::Callback_proxy< Result, Args >::Hasher
 Callback proxy hasher based on referenced callback. More...
 

Namespaces

 ugcs
 UGCS root namespace.
 
 ugcs::vsm
 All VSM SDK functionality resides in this namespace.
 

Macros

#define __UNPACK_PARAMS(...)   __VA_ARGS__
 Internal helper for unpacking parenthesis-enclosed parameters lists. More...
 
#define DEFINE_CALLBACK_BUILDER(__name, __types, __values)
 Define callback builder function. More...
 
#define DEFINE_CALLBACK_BUILDER_TEMPLATE(__name, __template, __types, __values)
 The same as DEFINE_CALLBACK_BUILDER, but allows specifying additional template parameters for builders which arguments depend on templates. More...
 

Functions

template<class Callable , typename... Args>
Callback< Callable, void, Args... >::Ptr ugcs::vsm::Make_callback (Callable &&callable, Args &&...args)
 Create a callback. More...
 
template<class Result , typename... Args>
callback_internal::Dummy_callback_helper< Result, Args... >::Callback_type::Ptr ugcs::vsm::Make_dummy_callback ()
 Create dummy callback. More...
 
template<class Callback_ptr , typename Result , typename... Args>
constexpr void ugcs::vsm::Callback_check_type ()
 Check if the specified callback type corresponds to the partial prototype. More...
 
template<class Ptr_tuple , size_t arg_idx>
void ugcs::vsm::internal::Assign_ptr_tuple_impl (Ptr_tuple &tuple __UNUSED)
 Assign_ptr_tuple implementation specialization for tail last recursive call.
 
template<class Ptr_tuple , size_t arg_idx, typename Arg , typename... Args>
void ugcs::vsm::internal::Assign_ptr_tuple_impl (Ptr_tuple &tuple, Arg &&arg, Args &&...args)
 Assign_ptr_tuple implementation recursive definition. More...
 
template<class Ptr_tuple , typename... Args>
void ugcs::vsm::internal::Assign_ptr_tuple (Ptr_tuple &tuple, Args &&...args)
 Helper function for assigning values to location pointers by pointers stored in a tuple. More...
 

Detailed Description

Generic callback which can be used to define and create an instance of an abstract callable operation with arbitrary arguments.

The main benefit is that callback can be executed without knowing anything about the arguments of the associated operation. For example, ugcs::vsm::Request class uses callbacks to notify request handlers about the completion of a particular request.

Macro Definition Documentation

#define __UNPACK_PARAMS (   ...)    __VA_ARGS__

Internal helper for unpacking parenthesis-enclosed parameters lists.

#define DEFINE_CALLBACK_BUILDER (   __name,
  __types,
  __values 
)
Value:
template <class __Callable, typename... __Args> \
__DEFINE_CALLBACK_BUILDER_BODY(__name, __types, __values)
__DEFINE_CALLBACK_BUILDER_BODY(Make_write_callback,(Io_result),(Io_result::OTHER_FAILURE)) template< class __Callable
Convenience builder for write operation callbacks.

Define callback builder function.

Use when forced arguments required.

Parameters
__nameName for a created function.
__typesTypes of forced arguments (parenthesis-enclosed comma-separated list).
__valuesInitial values for the forced arguments (parenthesis-enclosed comma-separated list).

Usage example:

1 DEFINE_CALLBACK_BUILDER(Make_data_handler,
2  (ugcs::vsm::Io_result, ugcs::vsm::Io_buffer::Ptr),
3  (ugcs::vsm::Io_result::OK, nullptr));
Examples:
async_workflow.cpp.
#define DEFINE_CALLBACK_BUILDER_TEMPLATE (   __name,
  __template,
  __types,
  __values 
)
Value:
template <__UNPACK_PARAMS __template, class __Callable, typename... __Args> \
__DEFINE_CALLBACK_BUILDER_BODY(__name, __types, __values)
#define __UNPACK_PARAMS(...)
Internal helper for unpacking parenthesis-enclosed parameters lists.
Definition: callback.h:25
__DEFINE_CALLBACK_BUILDER_BODY(Make_write_callback,(Io_result),(Io_result::OTHER_FAILURE)) template< class __Callable
Convenience builder for write operation callbacks.

The same as DEFINE_CALLBACK_BUILDER, but allows specifying additional template parameters for builders which arguments depend on templates.

Parameters
__nameSee DEFINE_CALLBACK_BUILDER
__templateAdditional template parameters (parenthesis-enclosed comma-separated list).
__typesSee DEFINE_CALLBACK_BUILDER
__valuesSee DEFINE_CALLBACK_BUILDER

Function Documentation

template<class Ptr_tuple , typename... Args>
void ugcs::vsm::internal::Assign_ptr_tuple ( Ptr_tuple &  tuple,
Args &&...  args 
)

Helper function for assigning values to location pointers by pointers stored in a tuple.

template<class Ptr_tuple , size_t arg_idx, typename Arg , typename... Args>
void ugcs::vsm::internal::Assign_ptr_tuple_impl ( Ptr_tuple &  tuple,
Arg &&  arg,
Args &&...  args 
)

Assign_ptr_tuple implementation recursive definition.