1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "JobObject.h"
31 #define WIN32_LEAN_AND_MEAN
37 JobObject::JobObject(void)
41 HANDLE jobObject = CreateJobObject(NULL, NULL);
42 if((jobObject != NULL) && (jobObject != INVALID_HANDLE_VALUE))
44 JOBOBJECT_EXTENDED_LIMIT_INFORMATION jobExtendedLimitInfo;
45 memset(&jobExtendedLimitInfo, 0, sizeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
46 memset(&jobExtendedLimitInfo.BasicLimitInformation, 0, sizeof(JOBOBJECT_BASIC_LIMIT_INFORMATION));
47 jobExtendedLimitInfo.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE | JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION;
48 if(SetInformationJobObject(jobObject, JobObjectExtendedLimitInformation, &jobExtendedLimitInfo, sizeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION)))
50 m_hJobObject = jobObject;
54 qWarning("Failed to set job object information!");
55 CloseHandle(jobObject);
60 qWarning("Failed to create the job object!");
64 JobObject::~JobObject(void)
68 CloseHandle(m_hJobObject);
73 bool JobObject::addProcessToJob(const QProcess *proc)
77 qWarning("Cannot assign process to job: No job bject available!");
81 if(Q_PID pid = proc->pid())
84 if(!GetExitCodeProcess(pid->hProcess, &exitCode))
86 qWarning("Cannot assign process to job: Failed to query process status!");
90 if(exitCode != STILL_ACTIVE)
92 qWarning("Cannot assign process to job: Process is not running anymore!");
96 if(!AssignProcessToJobObject(m_hJobObject, pid->hProcess))
98 qWarning("Failed to assign process to job object!");
106 qWarning("Cannot assign process to job: Process handle not available!");
111 bool JobObject::terminateJob(unsigned int exitCode)
115 if(TerminateJobObject(m_hJobObject, exitCode))
121 qWarning("Failed to terminate job object!");
127 qWarning("Cannot assign process to job: No job bject available!");