MuldeR's Utilities for Qt MUtilities

Public Member Functions | List of all members
MUtils::JobObject Class Reference

This class represents a job object. More...

`#include <JobObject.h>`

## Public Member Functions
| JobObject (void)
| Create a new JobObject instance. More...
| ~JobObject (void)
| Destroys the JobObject instance. More...
bool | isObjectCreated (void)
| Test whether job object was created successfully. More...
bool | addProcessToJob (const QProcess *const process)
| Add a process to the job object. More...
bool | terminateJob (const quint32 &exitCode)
| Terminate all sub-processes of the job object. More...

## Detailed Description

This class represents a job object.

Call addProcessToJob() to add another sub-process to this job object. Call terminateJob() to terminate all sub-processes that belong to this job object. Note that all sub-processes that belong to this job object will also be terminated when this process exits, gracefully or due to a crash.

Also, when the JobObject instance is destroyed, all sub-process that belong to its corresponding job object and that are still running will be terminated!

## Constructor & Destructor Documentation

## § JobObject()

MUtils::JobObject::JobObject | ( | void |  | ) |

Create a new JobObject instance.

Creating a new JobObject instance automatically creates a new job object on the system-level. Check isObjectCreated() to test whether the job object was successfully created or not.

## § ~JobObject()

MUtils::JobObject::~JobObject | ( | void |  | ) |

Destroys the JobObject instance.

If the job object still has any running sub-processes left when the corresponding JobObject instance is destroyed, these sub-process are terminated!

## Member Function Documentation

## § addProcessToJob()

bool MUtils::JobObject::addProcessToJob | ( | const QProcess *const | process | ) |

Add a process to the job object.

This function adds a another sub-process to the job object that is represented by this JobObject instance. Job object limitations apply to the sub-process a

Parameters

  process | A read-only pointer to the QProcess object that represents the sub-process to be added to the job object. The sub-process must be in the "running" state; otherwise the function will fail.

Returns
  The function returns `true`, if and only if the process was successfully added to the job object; otherwise it returns `false`.

## § isObjectCreated()

bool MUtils::JobObject::isObjectCreated | ( | void |  | ) |

Test whether job object was created successfully.

The job object will be created automatically when a new JobObject instance is created. However, the constructor has no to tell whether the job object was created successfully on the system-level. Call this function to test whether the job object has been created.

Returns
  The function returns `true`, if and only if a job object was successfully created; otherwise it returns `false`.

## § terminateJob()

bool MUtils::JobObject::terminateJob | ( | const quint32 & | exitCode | ) |

Terminate all sub-processes of the job object.

This function immediately terminates all running sub-processes that belong to the job object represented by this JobObject instance at once.

Parameters

  exitCode | The exit code to be set for the sub-process when they are terminated.

Returns
  The function returns `true`, if the sub-processes were destroyed successfully, even if there were no running sub-process left; otherwise it returns `false`.

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

- include/MUtils/JobObject.h