From 2ca76d3d2fa7147ab6dc0f236a47b06866a0d5c0 Mon Sep 17 00:00:00 2001
From: con <qtc-committer@nokia.com>
Date: Wed, 29 Jul 2009 18:51:58 +0200
Subject: [PATCH] Realize when the remote application has finished.

---
 tests/manual/trk/launcher.cpp | 18 +++++++++---------
 tests/manual/trk/trkutils.h   |  1 +
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/tests/manual/trk/launcher.cpp b/tests/manual/trk/launcher.cpp
index 9d71a5f0ad1..309f3f95b91 100644
--- a/tests/manual/trk/launcher.cpp
+++ b/tests/manual/trk/launcher.cpp
@@ -122,7 +122,6 @@ private:
     void trkWrite(const TrkMessage &msg);
     // convienience messages
     void sendTrkInitialPing();
-    void waitForTrkFinished();
     void sendTrkAck(byte token);
 
     // kill process and breakpoints
@@ -138,6 +137,7 @@ private:
     void handleWaitForFinished(const TrkResult &result);
     void handleStop(const TrkResult &result);
     void handleSupportMask(const TrkResult &result);
+    void waitForTrkFinished(const TrkResult &data);
 
     void handleAndReportCreateProcess(const TrkResult &result);
     void handleResult(const TrkResult &data);
@@ -307,14 +307,9 @@ void Adapter::sendTrkInitialPing()
     queueTrkMessage(msg);
 }
 
-void Adapter::waitForTrkFinished()
+void Adapter::waitForTrkFinished(const TrkResult &result)
 {
-    TrkMessage msg;
-    // initiate one last roundtrip to ensure all is flushed
-    msg.code = 0x00; // Ping
-    msg.token = nextTrkWriteToken();
-    msg.callBack = CB(handleWaitForFinished);
-    queueTrkMessage(msg);
+    sendTrkMessage(TrkPing, CB(handleWaitForFinished));
 }
 
 void Adapter::sendTrkAck(byte token)
@@ -508,6 +503,11 @@ void Adapter::handleResult(const TrkResult &result)
         case TrkNotifyDeleted: { // NotifyDeleted
             logMessage(prefix + "NOTE: LIBRARY UNLOAD: " + str);
             sendTrkAck(result.token);
+            const char *data = result.data.data();
+            ushort itemType = extractShort(data);
+            if (itemType == 0) { // process
+                sendTrkMessage(TrkDisconnect, CB(waitForTrkFinished));
+            }
             break;
         }
         case TrkNotifyProcessorStarted: { // NotifyProcessorStarted
@@ -602,7 +602,7 @@ void Adapter::handleCreateProcess(const TrkResult &result)
 void Adapter::handleWaitForFinished(const TrkResult &result)
 {
     logMessage("   FINISHED: " + stringFromArray(result.data));
-    //qApp->exit(1);
+    qApp->exit(0);
 }
 
 void Adapter::handleSupportMask(const TrkResult &result)
diff --git a/tests/manual/trk/trkutils.h b/tests/manual/trk/trkutils.h
index 4e62bb5a24c..b8066466606 100644
--- a/tests/manual/trk/trkutils.h
+++ b/tests/manual/trk/trkutils.h
@@ -42,6 +42,7 @@ namespace trk {
 enum Command {
     TrkPing = 0x00,
     TrkConnect = 0x01,
+    TrkDisconnect = 0x02,
     TrkVersions = 0x04,
     TrkSupported = 0x05,
     TrkCpuType = 0x06,
-- 
GitLab