E-MailRelay
Public Member Functions | List of all members
GNet::Task Class Reference

A class for running an exectuable in a separate process with an asychronous completion callback. More...

#include <gtask.h>

Public Member Functions

 Task (TaskCallback &, EventState es, const std::string &exec_error_format={}, const G::Identity &=G::Identity::invalid())
 Constructor for an object that can be start()ed or run(). More...
 
 ~Task ()
 Destructor. More...
 
void start (const G::ExecutableCommand &commandline)
 Starts the task by spawning a new process with the given command-line and also starting a thread to wait for it. More...
 
void start (const G::ExecutableCommand &commandline, const G::Environment &env, G::NewProcess::Fd fd_stdin=G::NewProcess::Fd::devnull(), G::NewProcess::Fd fd_stdout=G::NewProcess::Fd::pipe(), G::NewProcess::Fd fd_stderr=G::NewProcess::Fd::devnull(), const G::Path &cd=G::Path())
 Overload with more control over the execution environment. More...
 
void stop ()
 Attempts to kill the spawned process. More...
 
std::pair< int, std::string > run (const G::ExecutableCommand &commandline, const G::Environment &env, G::NewProcess::Fd fd_stdin=G::NewProcess::Fd::devnull(), G::NewProcess::Fd fd_stdout=G::NewProcess::Fd::pipe(), G::NewProcess::Fd fd_stderr=G::NewProcess::Fd::devnull(), const G::Path &cd=G::Path())
 Runs the task synchronously and returns the exit code and pipe output. More...
 
 Task (const Task &)=delete
 
 Task (Task &&)=delete
 
Taskoperator= (const Task &)=delete
 
Taskoperator= (Task &&)=delete
 

Detailed Description

A class for running an exectuable in a separate process with an asychronous completion callback.

Definition at line 45 of file gtask.h.

Constructor & Destructor Documentation

◆ Task()

GNet::Task::Task ( TaskCallback callback,
EventState  es,
const std::string &  exec_error_format = {},
const G::Identity id = G::Identity::invalid() 
)

Constructor for an object that can be start()ed or run().

The two trailing parameters are passed to the G::NewProcess class.

Definition at line 249 of file gtask.cpp.

◆ ~Task()

GNet::Task::~Task ( )

Destructor.

Kills the spawned process and waits for it to terminate, where necessary.

Definition at line 258 of file gtask.cpp.

Member Function Documentation

◆ run()

std::pair< int, std::string > GNet::Task::run ( const G::ExecutableCommand commandline,
const G::Environment env,
G::NewProcess::Fd  fd_stdin = G::NewProcess::Fd::devnull(),
G::NewProcess::Fd  fd_stdout = G::NewProcess::Fd::pipe(),
G::NewProcess::Fd  fd_stderr = G::NewProcess::Fd::devnull(),
const G::Path cd = G::Path() 
)

Runs the task synchronously and returns the exit code and pipe output.

Throws if killed. The callback interface is not used.

Definition at line 282 of file gtask.cpp.

◆ start() [1/2]

void GNet::Task::start ( const G::ExecutableCommand commandline)

Starts the task by spawning a new process with the given command-line and also starting a thread to wait for it.

The wait thread signals completion of the child process via the event loop and the TaskCallback interface. Standard output goes to the pipe and standard error is discarded. Throws Busy if still busy from a prior call to start().

Definition at line 298 of file gtask.cpp.

◆ start() [2/2]

void GNet::Task::start ( const G::ExecutableCommand commandline,
const G::Environment env,
G::NewProcess::Fd  fd_stdin = G::NewProcess::Fd::devnull(),
G::NewProcess::Fd  fd_stdout = G::NewProcess::Fd::pipe(),
G::NewProcess::Fd  fd_stderr = G::NewProcess::Fd::devnull(),
const G::Path cd = G::Path() 
)

Overload with more control over the execution environment.

See also G::NewProcess.

Definition at line 307 of file gtask.cpp.

◆ stop()

void GNet::Task::stop ( )

Attempts to kill the spawned process.

No task-done callback will be triggered.

Definition at line 269 of file gtask.cpp.


The documentation for this class was generated from the following files: