dmlite
0.6
|
#include <TaskExec.h>
Public Member Functions | |
dmTaskExec () | |
~dmTaskExec () | |
int | submitCmd (std::string cmd) |
int | submitCmd (std::vector< std::string > &args) |
Executes a command. Returns a positive integer as a key to reference. More... | |
void | goCmd (int id) |
void | assignCmd (dmTask *task, std::vector< std::string > &args) |
Split che command string into the single parms. More... | |
int | waitResult (int taskID, int tmout=5) |
int | killTask (int taskID) |
dmTask * | getTask (int taskID) |
int | getTaskStdout (int taskID, std::string &stdout) |
void | tick () |
int | getTaskCounters (int &tot, int &running, int &finished) |
virtual void | onLoggingRequest (Logger::Level lvl, std::string const &msg)=0 |
Event invoked internally to log stuff. More... | |
virtual void | onErrLoggingRequest (std::string const &msg)=0 |
Event invoked internally to log stuff. More... | |
Public Attributes | |
std::string | instance |
Protected Member Functions | |
virtual void | onTaskCompleted (dmTask &task) |
virtual void | onTaskRunning (dmTask &task) |
NOTE the signature. This passes copies of Task objects, not the originals. More... | |
Private Member Functions | |
int | popen3 (int fd[3], pid_t *pid, const char **argv) |
virtual void | run (int key) |
int | killTask (dmTask *task) |
Private Attributes | |
int | taskcnt |
Used to create keys to be inserted into the map. This has to be treated modulo MAXINT or similar big number. More... | |
std::map< int, dmTask * > | tasks |
This map works like a sparse array :-) More... | |
Allows to spawn commands, useful for checksum calculations or file pulling The spawned commands are pollable, i.e. in a given moment it's possible to know the list of commands that are still running. Objects belonging to this class in general are created in the disk nodes, e.g. for running checksums or file copies and pulls
dmlite::dmTaskExec::dmTaskExec | ( | ) |
dmlite::dmTaskExec::~dmTaskExec | ( | ) |
void dmlite::dmTaskExec::assignCmd | ( | dmTask * | task, |
std::vector< std::string > & | args | ||
) |
Split che command string into the single parms.
dmTask* dmlite::dmTaskExec::getTask | ( | int | taskID | ) |
int dmlite::dmTaskExec::getTaskCounters | ( | int & | tot, |
int & | running, | ||
int & | finished | ||
) |
int dmlite::dmTaskExec::getTaskStdout | ( | int | taskID, |
std::string & | stdout | ||
) |
void dmlite::dmTaskExec::goCmd | ( | int | id | ) |
Actually starts the thread corresponding to a command that was just submitted Avoids race conditions
int dmlite::dmTaskExec::killTask | ( | int | taskID | ) |
|
private |
|
pure virtual |
Event invoked internally to log stuff.
|
pure virtual |
Event invoked internally to log stuff.
|
protectedvirtual |
event for immediate notifications when a task finishes Subclasses can specialize this and apply app-dependent behavior to perform actions when something has finished running NOTE the signature. This passes copies of Task objects, not the originals
|
protectedvirtual |
NOTE the signature. This passes copies of Task objects, not the originals.
|
private |
|
privatevirtual |
Here we invoke popen3 and block waiting for the process to end. Upon end it updates the corresponding instance of dmTask with the result and the stdout
int dmlite::dmTaskExec::submitCmd | ( | std::string | cmd | ) |
Executes a command. Returns a positive integer as a key to reference the execution status and the result The mechanics is that a detached thread is started. This guy invokes popen3 and blocks waiting for the process to end. Upon end it updates the corresponding instance of dmTask with the result and the stdout
int dmlite::dmTaskExec::submitCmd | ( | std::vector< std::string > & | args | ) |
Executes a command. Returns a positive integer as a key to reference.
void dmlite::dmTaskExec::tick | ( | ) |
Loops over all the tasks and:
int dmlite::dmTaskExec::waitResult | ( | int | taskID, |
int | tmout = 5 |
||
) |
Get the results of a task. Wait at max tmout seconds until the task finishes Return 0 if the task has finished and there is a result Return nonzero if the task is still running
std::string dmlite::dmTaskExec::instance |
|
private |
Used to create keys to be inserted into the map. This has to be treated modulo MAXINT or similar big number.
|
private |
This map works like a sparse array :-)