12#ifndef ROOT_TMPWorkerExecutor
13#define ROOT_TMPWorkerExecutor
76template<
class F,
class T =
void,
class R =
void>
90 unsigned code = msg.first;
92 std::string reply =
"S" + std::to_string(
GetNWorker());
95 msg.second->ReadUInt(
n);
112 reply +=
": unknown code received: " + std::to_string(code);
126template<
class F,
class R>
137 unsigned code = msg.first;
139 std::string reply =
"S" + std::to_string(
GetNWorker());
142 const auto &res =
fFunc();
155 reply +=
": unknown code received: " + std::to_string(code);
167template<
class F,
class T>
174 unsigned code = msg.first;
176 std::string reply =
"S" + std::to_string(
GetNWorker());
179 msg.second->ReadUInt(
n);
182 reply +=
": unknown code received: " + std::to_string(code);
206 unsigned code = msg.first;
208 std::string myId =
"S" + std::to_string(
GetPid());
std::pair< unsigned, std::unique_ptr< TBufferFile > > MPCodeBufPair
An std::pair that wraps the code and optional object contained in a message.
int MPSend(TSocket *s, unsigned code)
Send a message with the specified code on the specified socket.
typedef void((*Func_t)())
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
@ 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.