[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r13262: Add option to kill application if it doesn't respond to term (torbrowser/trunk/src/processtest)



Author: sjm217
Date: 2008-01-24 17:06:19 -0500 (Thu, 24 Jan 2008)
New Revision: 13262

Modified:
   torbrowser/trunk/src/processtest/processtest.cpp
   torbrowser/trunk/src/processtest/processtest.h
Log:
Add option to kill application if it doesn't respond to terminate()

Modified: torbrowser/trunk/src/processtest/processtest.cpp
===================================================================
--- torbrowser/trunk/src/processtest/processtest.cpp	2008-01-24 20:00:37 UTC (rev 13261)
+++ torbrowser/trunk/src/processtest/processtest.cpp	2008-01-24 22:06:19 UTC (rev 13262)
@@ -48,7 +48,7 @@
 
     // Initialize the process handler
     _browser = new BrowserProcess();
-    _isRunning = false;
+    _appState = Stopped;
  
     // Connect up the button
     QObject::connect(_button, SIGNAL(clicked()), this, SLOT(onClicked()));
@@ -61,12 +61,19 @@
 
 void ProcessTest::onClicked()
 {
-    if (isRunning)
+    if (Started == _appState)
     {
         // Application is running: kill it
         _button->setText(tr("Terminating..."));
+        _appState = Terminating;
         _browser->terminate();
     }
+    else if (Terminating == _appState)
+    {
+        // Application is terminating: really kill it
+        _button->setText(tr("Killing..."));
+        _browser->kill();
+    }
     else
     {
         // Application is not running: start it
@@ -79,19 +86,19 @@
 {
     // Application has started
     _button->setText(tr("Running..."));
-    _isRunning = true;
+    _appState = Started;
 }
 
 void ProcessTest::onFinished()
 {
     // Application has finished
     _button->setText(tr("Stopped"));
-    _isRunning = false;
+    _appState = Stopped;
 }
 
 void ProcessTest::onFailed()
 {
     // Application failed to start
     _button->setText(tr("Failed"));
-    _isRunning = false;
+    _appState = Stopped;
 }

Modified: torbrowser/trunk/src/processtest/processtest.h
===================================================================
--- torbrowser/trunk/src/processtest/processtest.h	2008-01-24 20:00:37 UTC (rev 13261)
+++ torbrowser/trunk/src/processtest/processtest.h	2008-01-24 22:06:19 UTC (rev 13262)
@@ -50,6 +50,13 @@
     // Button was clicked
     void onClicked();
 private:
+    // What state is the application in
+    enum AppStateEnum {
+      Stopped,
+      Started,
+      Terminating
+    };
+
     // The push button
     QPushButton *_button;
     // Process handler
@@ -57,7 +64,7 @@
     // Command line to start
     QString _cmd;
     // Is the application running
-    bool _isRunning;
+    AppStateEnum _appState;
 };
 
 #endif