From 76e39a3ebdc8b0865c4dc420ad71e186d91467b3 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 29 Jun 2017 10:54:44 -0700 Subject: [PATCH] Make code windows specific --- assignment-client/src/AssignmentClientApp.cpp | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/assignment-client/src/AssignmentClientApp.cpp b/assignment-client/src/AssignmentClientApp.cpp index ed684dcb65..bc03808c1e 100644 --- a/assignment-client/src/AssignmentClientApp.cpp +++ b/assignment-client/src/AssignmentClientApp.cpp @@ -24,13 +24,27 @@ #include #include +#ifdef WIN32 VOID CALLBACK parentDiedCallback(PVOID lpParameter, BOOLEAN timerOrWaitFired) { - if (!timerOrWaitFired) { + if (!timerOrWaitFired && qApp) { qDebug() << "Parent process died, quitting"; qApp->quit(); } } +void watchParentProcess(int parentPID) { + DWORD processID = parentPID; + HANDLE procHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processID); + + HANDLE newHandle; + RegisterWaitForSingleObject(&newHandle, procHandle, parentDiedCallback, NULL, INFINITE, WT_EXECUTEONLYONCE); +} +#else +void watchParentProcess(int parentPID) { + qWarning() << "Parent PID option not implemented on this plateform"; +} +#endif // WIN32 + AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) : QCoreApplication(argc, argv) { @@ -212,16 +226,12 @@ AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) : } } - DWORD processID; - HANDLE procHandle; - HANDLE newHandle; if (parser.isSet(parentPIDOption)) { bool ok = false; - processID = parser.value(parentPIDOption).toInt(&ok); + int parentPID = parser.value(parentPIDOption).toInt(&ok); if (ok) { - procHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processID); - RegisterWaitForSingleObject(&newHandle, procHandle, parentDiedCallback, NULL, INFINITE, WT_EXECUTEONLYONCE); + watchParentProcess(parentPID); } }