Some documentation updates.
[MUtilities.git] / include / MUtils / JobObject.h
blobb4ad98b1a777b816b44621844fcf548e83dd1836
1 ///////////////////////////////////////////////////////////////////////////////
2 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2017 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
20 //////////////////////////////////////////////////////////////////////////////////
22 /**
23 * @file
24 * @brief This file contains function for creating and managing job objects
26 * Each instance of MUtils::JobObject represents a job object. Call MUtils::JobObject::addProcessToJob() to add another sub-process to the job object. Call MUtils::JobObject::terminateJob() to terminate *all* sub-processes that currently belong to the job object at once.
28 * Note that all sub-processes that belong to the job object will be terminated when *this* process exits, gracefully or due to a crash. All sub-process belonging to a job object also are terminated when the corresponding MUtils::JobObject instance is destroyed.
31 #pragma once
33 #include <MUtils/Global.h>
35 class QProcess;
37 namespace MUtils
39 /**
40 * @brief This class represents a job object
42 * 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.
44 * 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!
46 class MUTILS_API JobObject
48 public:
49 /**
50 * \brief Create a new JobObject instance
52 * 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.
54 JobObject(void);
56 /**
57 * \brief Destroys the JobObject instance
59 * If the job object still has any running sub-processes left when the corresponding JobObject instance is destroyed, these sub-process are terminated!
61 ~JobObject(void);
63 /**
64 * \brief Test whether job object was created successfully
66 * 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.
68 * \return The function returns `true`, if and only if a job object was successfully created; otherwise it returns `false`.
70 bool isObjectCreated(void);
72 /**
73 * \brief Add a process to the job object
75 * 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
77 * \param process A read-only pointer to the [QProcess](http://doc.qt.io/qt-4.8/qprocess.html) 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.
79 * \return The function returns `true`, if and only if the process was successfully added to the job object; otherwise it returns `false`.
81 bool addProcessToJob(const QProcess *const process);
83 /**
84 * \brief Terminate all sub-processes of the job object
86 * This function immediately terminates *all* running sub-processes that belong to the job object represented by this JobObject instance at once.
88 * \param exitCode The exit code to be set for the sub-process when they are terminated.
90 * \return The function returns `true`, if the sub-processes were destroyed successfully, even if there were no running sub-process left; otherwise it returns `false`.
92 bool terminateJob(const quint32 &exitCode);
94 private:
95 uintptr_t m_jobPtr;
96 MUTILS_NO_COPY(JobObject)