60 double start()
override;
64 if (task == the_agent) {
65 if (!task->
result().empty()) {
66 log() <<
"Agent terminated";
80 err_log() <<
"cannot set agent";
98 const std::string &jsonobj =
"{}") {
99 return "{\"method\": \"" + method +
"\", \"args\": " + jsonobj +
"}";
105 return (msg.substr(0, 12) ==
"AGENT EXIT: ");
110 return "AGENT EXIT: " + err_msg;
121 "\", \"args\": " + jsonobj +
"}");
130 if (msg.substr(0, terminate_msg.size()) == terminate_msg)
141 const std::string terminate_msg =
"{\"method\": \"terminate\"";
Tasks may use a bridge to communicate with an application running outside the event loop.
Definition: bridgetask.h:43
static std::string agentTerminatedMessage(const std::string &err_msg)
Format a message to signal that the Agent is gone.
Definition: bridgetask.h:109
void setAgent(Task *agent)
Definition: bridgetask.h:76
void sendMsgToAgent(const std::string &msg)
Send message to the agent.
Definition: bridgetask.h:128
virtual void sendMsgToClient(const std::string &msg)=0
The agent will call this to pass messages to the client.
void sendMsgToClient(const std::string &method, const std::string &jsonobj)
Format a message to the client.
Definition: bridgetask.h:119
static std::string msgToAgent(const std::string &method, const std::string &jsonobj="{}")
Format a message to the agent.
Definition: bridgetask.h:97
void die()
Terminate the bridge task.
Definition: bridgetask.h:84
double start() override
Will add the agent task to the EventLoop.
Definition: bridgetask.cpp:11
void taskFinished(Task *task) override
If the agent dies, a special message will be sent to notify the client.
Definition: bridgetask.h:63
BridgeTask(Task *agent=nullptr)
Create a bridge to the given agent task.
Definition: bridgetask.h:51
void sendMsgToAgent(const std::string &method, const std::string &jsonobj)
Format and send message to the agent.
Definition: bridgetask.h:135
static bool isAgentTerminatedMessage(const std::string &msg)
Definition: bridgetask.h:104
std::ostream & log() const
Write a line of info log.
Definition: logger.h:328
std::ostream & err_log() const
Write a line of error log.
Definition: logger.h:292
The purpose of a task is to manage socket connections, and/or to execute timers.
Definition: task.h:39
void setResult(const std::string &res)
Definition: task.cpp:18
void executeHandler(Task *receiver, const std::string &message)
Definition: task.h:222
bool hasStarted() const
Definition: task.h:115
void killChildTaskWhenFinished()
Definition: task.h:121
std::string result() const
To get the "result" of the task after it has finished.
Definition: task.h:167