Author: remi
Date: 2009-03-18 11:27:12 +0100 (Wed, 18 Mar 2009)
New Revision: 4121
Modified:
software_suite_v2/software/tuxdroid-gadget-framework/branches/changes-for-bridge-version/tuxdroid-gadget-framework/sources/com/kysoh/tuxdroid/gadget/framework/container/GadgetInstance.java
Log:
* added the killing of the gadget subprocess when the gadget is aborted
Modified:
software_suite_v2/software/tuxdroid-gadget-framework/branches/changes-for-bridge-version/tuxdroid-gadget-framework/sources/com/kysoh/tuxdroid/gadget/framework/container/GadgetInstance.java
===================================================================
---
software_suite_v2/software/tuxdroid-gadget-framework/branches/changes-for-bridge-version/tuxdroid-gadget-framework/sources/com/kysoh/tuxdroid/gadget/framework/container/GadgetInstance.java
2009-03-18 10:15:23 UTC (rev 4120)
+++
software_suite_v2/software/tuxdroid-gadget-framework/branches/changes-for-bridge-version/tuxdroid-gadget-framework/sources/com/kysoh/tuxdroid/gadget/framework/container/GadgetInstance.java
2009-03-18 10:27:12 UTC (rev 4121)
@@ -22,6 +22,10 @@
package com.kysoh.tuxdroid.gadget.framework.container;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileReader;
import java.io.IOException;
import java.util.Vector;
import java.util.UUID;
@@ -69,8 +73,77 @@
public void abort() {
if (shell != null) {
shell.stop();
+ killProcessFromThisGadget();
}
}
+
+ private boolean isWindows() {
+ String osName =
System.getProperty("os.name").toLowerCase();
+ return osName.startsWith("windows");
+ }
+
+ private void killProcess(String pid)
+ {
+ String [] command = null;
+ if (isWindows())
+ {
+ command = new String[4];
+ command[0] = "TASKKILL";
+ command[1] = "/PID";
+ command[2] = pid;
+ command[3] = "/F";
+ }
+ else
+ {
+ command = new String[3];
+ command[0] = "kill";
+ command[1] = "-9";
+ command[2] = pid;
+ }
+ try {
+ Runtime.getRuntime().exec(command);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void killProcessFromThisGadget()
+ {
+ File pidFilesPath = new
File(gadget.getInterpreter().getWorkingPath(), "states");
+ if (!pidFilesPath.isDirectory())
+ {
+ return;
+ }
+ File[] files = pidFilesPath.listFiles(new FileFilter()
+ {
+ public boolean accept(File pathname)
+ {
+ return
pathname.getAbsolutePath().endsWith(".pid");
+ }
+ });
+ for (File file : files)
+ {
+ try
+ {
+ BufferedReader input = new
BufferedReader(new FileReader(file));
+ String pid = null;
+ try
+ {
+ pid = input.readLine();
+ killProcess(pid);
+ }
+ finally
+ {
+ input.close();
+ }
+ }
+ catch (IOException ex)
+ {
+ continue;
+ }
+ file.delete();
+ }
+ }
@Override
public void run() {
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn