12#ifndef ROOT_TMPWorkerExecutor
13#define ROOT_TMPWorkerExecutor
77template<
class F,
class T =
void,
class R =
void>
91 unsigned code =
msg.first;
96 msg.second->ReadUInt(
n);
113 reply +=
": unknown code received: " + std::to_string(code);
127template<
class F,
class R>
138 unsigned code =
msg.first;
143 const auto &res =
fFunc();
156 reply +=
": unknown code received: " + std::to_string(code);
168template<
class F,
class T>
175 unsigned code =
msg.first;
179 msg.second->ReadUInt(
n);
182 std::string
reply =
"S" + std::to_string(
GetNWorker()) +
": unknown code received: " + std::to_string(code);
206 unsigned code =
msg.first;
208 std::string
myId =
"S" + std::to_string(
GetPid());
int MPSend(TSocket *s, unsigned code)
Send a message with the specified code on the specified socket.
std::pair< unsigned, std::unique_ptr< TBufferFile > > MPCodeBufPair
An std::pair that wraps the code and optional object contained in a message.
F fFunc
the function to be executed
TMPWorkerExecutor(F func, const std::vector< T > &args)
void HandleInput(MPCodeBufPair &msg)
Handle a message with an EMPCode.
std::vector< T > fArgs
a vector containing the arguments that must be passed to fFunc
void HandleInput(MPCodeBufPair &msg)
Handle a message with an EMPCode.
TMPWorkerExecutor(F func, R redfunc)
F fFunc
the function to be executed
bool fCanReduce
true if fReducedResult can be reduced with a new result, false until we have produced one result
R fRedFunc
the reduce function
This class works together with TProcessExecutor to allow the execution of functions in server process...
bool fCanReduce
true if fReducedResult can be reduced with a new result, false until we have produced one result
F fFunc
the function to be executed
R fRedFunc
the reduce function
void HandleInput(MPCodeBufPair &msg)
Handle a message with an EMPCode.
decltype(fFunc(fArgs.front())) fReducedResult
the result of the execution
TMPWorkerExecutor(F func, const std::vector< T > &args, R redfunc)
std::vector< T > fArgs
a vector containing the arguments that must be passed to fFunc
This class works in conjuction with TMPClient, reacting to messages received from it as specified by ...
unsigned GetNWorker() const
This class implements client sockets.
@ kSendResult
Ask for a kFuncResult/kProcResult.
@ kIdling
We are ready for the next task.
@ kFuncResult
The message contains the result of a function execution.
@ kExecFuncWithArg
Execute function with the argument contained in the message.
@ kExecFunc
Execute function without arguments.