PhoenixSwarm  3.5.0
Library to ease communication between daemons
Loading...
Searching...
No Matches
phoenix_function_call.h File Reference
#include <tuple>
#include <vector>
#include <utility>
#include <iostream>
#include "data_all.h"
#include "PLog.h"
#include "phoenix_createData.h"
+ Include dependency graph for phoenix_function_call.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  static_for_deserialise_message< First, Last >
 Iterate over function parameters. More...
 
struct  static_for_deserialise_message< N, N >
 Iterate over function parameters (end) More...
 

Functions

template<typename R, typename... T>
bool phoenix_function_call (PLog &log, Data &result, const DataStreamMsg &input, R(*func)(T...))
 Call the function with message.
 
template<typename... T>
bool phoenix_function_call (PLog &log, Data &result, const DataStreamMsg &input, void(*func)(T...))
 Call the function with message.
 

Function Documentation

◆ phoenix_function_call() [1/2]

template<typename R, typename... T>
bool phoenix_function_call ( PLog & log,
Data & result,
const DataStreamMsg & input,
R(* func )(T...) )

Call the function with message.

Parameters
[out]log: logger
[out]result: result of the function call
input: input parameters of the function
func: function to be called
Returns
true on success, false otherwise

Definition at line 57 of file phoenix_function_call.h.

57 {
58 std::tuple<T...> args = std::tuple<T...>();
59 DataStreamIter iter = (DataStreamIter)input.data();
60 bool isOk(true);
61 //We have to deserialise the parameters of the function
62 static_for_deserialise_message<0, std::tuple_size<std::tuple<T... > >{} >()(log, isOk, iter, args);
63 if(isOk){
64 //Then we can call the function
65 R res = std::apply(func, args);
66 //And get back the result, in the res message
67 result = phoenix_createData(res);
68 return isOk;
69 }else{
70 log.getLogError() << "phoenix_function_call : cannot deserialise arguments to function of " << input.size() << " byte(s)" << std::endl;
71 return false;
72 }
73}
Data phoenix_createData(const T &value)
Create a Data from a value.
Iterate over function parameters.

References phoenix_createData().

Referenced by FunctionCall< _Callable >::call().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ phoenix_function_call() [2/2]

template<typename... T>
bool phoenix_function_call ( PLog & log,
Data & result,
const DataStreamMsg & input,
void(* func )(T...) )

Call the function with message.

Parameters
[out]log: logger
[out]result: result of the function call
input: input parameters of the function
func: function to be called
Returns
true on success, false otherwise

Definition at line 83 of file phoenix_function_call.h.

83 {
84 std::tuple<T...> args = std::tuple<T...>();
85 DataStreamIter iter = (DataStreamIter)input.data();
86 bool isOk(true);
87 //We have to deserialise the parameters of the function
88 static_for_deserialise_message<0, std::tuple_size<std::tuple<T... > >{} >()(log, isOk, iter, args);
89 if(isOk){
90 //Then we can call the function
91 std::apply(func, args);
92 //And get back the result, in the res message
93 result.setType("void");
94 return isOk;
95 }else{
96 log.getLogError() << "phoenix_function_call : cannot deserialise arguments to function of " << input.size() << " byte(s)" << std::endl;
97 return false;
98 }
99}
void setType(const PString &type)
Sets the type of the Data.

References Data::setType().

+ Here is the call graph for this function: