25 #ifndef CARGO_IPC_INTERNALS_METHOD_REQUEST_HPP
26 #define CARGO_IPC_INTERNALS_METHOD_REQUEST_HPP
43 template<
typename SentDataType,
typename ReceivedDataType>
46 const std::shared_ptr<SentDataType>&
data,
52 std::shared_ptr<void>
data;
66 template<
typename SentDataType,
typename ReceivedDataType>
69 const std::shared_ptr<SentDataType>&
data,
72 std::shared_ptr<MethodRequest> request(
new MethodRequest(methodID, peerID));
76 request->serialize = [](
const int fd, std::shared_ptr<void>&
data)->
void {
77 LOGS(
"Method serialize, peerID: " << fd);
78 cargo::saveToFD<SentDataType>(fd, *std::static_pointer_cast<SentDataType>(
data));
81 request->parse = [](
const int fd)->std::shared_ptr<void> {
82 LOGS(
"Method parse, peerID: " << fd);
83 std::shared_ptr<ReceivedDataType>
data(
new ReceivedDataType());
84 cargo::loadFromFD<ReceivedDataType>(fd, *
data);
88 if(process ==
nullptr){
90 LOGT(
"No method to process result");
94 LOGS(
"Method process");
95 process(resultBuilder.build<ReceivedDataType>());
105 #endif // CARGO_IPC_INTERNALS_METHOD_REQUEST_HPP
MethodID methodID
Definition: method-request.hpp:49
std::function< void(Result< Data > &&) > type
Definition: result.hpp:73
std::function< void(ResultBuilder &)> ResultBuilderHandler
Definition: result-builder.hpp:66
static std::shared_ptr< MethodRequest > create(const MethodID methodID, const PeerID &peerID, const std::shared_ptr< SentDataType > &data, const typename ResultHandler< ReceivedDataType >::type &process)
Definition: method-request.hpp:67
#define LOGS(MSG)
Automatically create LoggerScope object which logs at the construction and destruction.
Definition: logger-scope.hpp:78
std::string PeerID
Definition: types.hpp:45
MethodRequest(const MethodID methodID, const PeerID &peerID)
Definition: method-request.hpp:58
Definition: method-request.hpp:38
MessageID getNextMessageID()
Generate an unique message id.
Definition: types.cpp:46
std::function< std::shared_ptr< void >cargo::ipc::FileDescriptor fd)> ParseCallback
Generic function type used as callback for reading and parsing data.
Definition: types.hpp:72
Class for storing result of a method - data or exception.
std::shared_ptr< void > data
Definition: method-request.hpp:52
MethodRequest(const MethodRequest &)=delete
MethodRequest & operator=(const MethodRequest &)=delete
PeerID peerID
Definition: method-request.hpp:50
char data[368]
Definition: initctl.cpp:41
Definition: result-builder.hpp:36
unsigned int MethodID
Definition: types.hpp:43
std::function< void(cargo::ipc::FileDescriptor fd, std::shared_ptr< void > &data)> SerializeCallback
Generic function type used as callback for serializing and saving serialized data to the descriptor...
Definition: types.hpp:64
SerializeCallback serialize
Definition: method-request.hpp:53
Class for storing result of a method - data or exception.
ResultBuilderHandler process
Definition: method-request.hpp:55
#define LOGT(MESSAGE)
Logging tracing information.
Definition: logger.hpp:156
MessageID messageID
Definition: method-request.hpp:51
ParseCallback parse
Definition: method-request.hpp:54
std::string MessageID
Definition: types.hpp:44
Scope logger class declaration.