ndt-dev - [ndt-dev] [ndt] r491 committed - Clean up, add stop signal on pause.
Subject: NDT-DEV email list created
List archive
- From:
- To:
- Subject: [ndt-dev] [ndt] r491 committed - Clean up, add stop signal on pause.
- Date: Mon, 15 Aug 2011 17:13:47 +0000
Revision: 491
Author:
Date: Mon Aug 15 10:13:26 2011
Log: Clean up, add stop signal on pause.
http://code.google.com/p/ndt/source/detail?r=491
Modified:
/branches/android/Android/res/values/strings.xml
/branches/android/Android/src/net/measurementlab/ndt/NdtService.java
=======================================
--- /branches/android/Android/res/values/strings.xml Mon Jun 20 09:23:24 2011
+++ /branches/android/Android/res/values/strings.xml Mon Aug 15 10:13:26 2011
@@ -36,6 +36,11 @@
<string name="test_again">Press Start to test again.</string>
<string name="mlab">M-Lab</string>
<string name="mlabdesc">Network Diagnostic Tool (NDT) provides a sophisticated speed and diagnostic test. An NDT test reports more than just the upload and download speeds — it also attempts to determine what, if any, problems limited these speeds, differentiating between computer configuration and network infrastructure problems. While the diagnostic messages are most useful for expert users, they can also help novice users by allowing them to provide detailed trouble reports to their network administrator.</string>
- <string name="server_location_header">Preparing Your Tests...</string>
+ <string name="tests_preparing_header">Preparing Your Tests...</string>
+ <string name="tests_now_testing_header">Now Testing</string>
+ <string name="tests_upload_header">Upload Speed</string>
+ <string name="tests_download_header">Download Speed</string>
+ <string name="tests_test_server">Test Server</string>
+ <string name="tests_your_computer">Your Computer</string>
</resources>
=======================================
--- /branches/android/Android/src/net/measurementlab/ndt/NdtService.java Thu Jul 7 11:15:40 2011
+++ /branches/android/Android/src/net/measurementlab/ndt/NdtService.java Mon Aug 15 10:13:26 2011
@@ -1,7 +1,10 @@
package net.measurementlab.ndt;
import android.app.Service;
+import android.content.BroadcastReceiver;
+import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;
@@ -12,13 +15,16 @@
public static final int COMPLETE = 3;
public static final String INTENT_UPDATE_STATUS = "net.measurementlab.ndt.UpdateStatus";
+ public static final String INTENT_STOP_TESTS = "net.measurementlab.ndt.StopTests";
public static final String EXTRA_STATE = "status";
private Intent intent;
private String networkType;
- private boolean testRunning;
+ private CaptiveUiServices uiServices;
+
+ private BroadcastReceiver stopReceiver;
@Override
public IBinder onBind(Intent intent) {
@@ -36,17 +42,20 @@
public void onStart(Intent intent, int startId) {
Log.i("ndt", "Starting NDT service.");
super.onStart(intent, startId);
- if (testRunning) {
+ if (uiServices != null) {
return;
}
if (null != intent) {
networkType = intent.getStringExtra("networkType");
}
+ stopReceiver = createReceiver();
+ registerReceiver(stopReceiver, new IntentFilter(
+ NdtService.INTENT_STOP_TESTS));
+ uiServices = new CaptiveUiServices();
try {
- testRunning = true;
new Thread(new NdtTests(
Constants.SERVER_HOST[Constants.DEFAULT_SERVER],
- new CaptiveUiServices(),
networkType)).start();
+ uiServices, networkType)).start();
} catch (Throwable tr) {
Log.e("ndt", "Problem running tests.", tr);
}
@@ -55,10 +64,32 @@
@Override
public void onDestroy() {
super.onDestroy();
+ if (COMPLETE != uiServices.status) {
+ uiServices.requestStop();
+ }
+ uiServices = null;
+ unregisterReceiver(stopReceiver);
Log.i("ndt", "Finishing NDT service.");
}
+
+ private BroadcastReceiver createReceiver() {
+ BroadcastReceiver receiver = new BroadcastReceiver() {
+
+ @Override
+ public void onReceive(Context context, Intent intent)
{
+ Log.i("ndt", "Stop request received.");
+ uiServices.requestStop();
+ }
+ };
+ Log.i("ndt", "Stop receiver created.");
+ return receiver;
+
+ }
private class CaptiveUiServices implements UiServices {
+ private boolean wantToStop = false;
+
+ int status = PREPARING;
@Override
public void appendString(String str, int viewId) {
@@ -69,6 +100,7 @@
Log.i("ndt", "Starting upload test.");
intent.putExtra("status", UPLOADING);
sendBroadcast(intent);
+ status = UPLOADING;
Log.i("ndt", "Broadcast status change.");
}
@@ -76,6 +108,7 @@
Log.i("ndt", "Starting download test.");
intent.putExtra("status", DOWNLOADING);
sendBroadcast(intent);
+ status = DOWNLOADING;
Log.i("ndt", "Broadcast status change.");
}
}
@@ -93,6 +126,7 @@
@Override
public void onBeginTest() {
Log.d("ndt", "Test begun.");
+ wantToStop = false;
}
@Override
@@ -100,12 +134,15 @@
Log.d("ndt", "Test ended.");
intent.putExtra("status", COMPLETE);
sendBroadcast(intent);
+ wantToStop = false;
+ status = COMPLETE;
Log.i("ndt", "Broadcast status change.");
}
@Override
public void onFailure(String errorMessage) {
Log.d("ndt", String.format("Failed: %1$s.",
errorMessage));
+ wantToStop = false;
}
@Override
@@ -149,8 +186,11 @@
@Override
public boolean wantToStop() {
- return false;
+ return wantToStop;
}
+ void requestStop() {
+ wantToStop = true;
+ }
}
}
- [ndt-dev] [ndt] r491 committed - Clean up, add stop signal on pause., ndt, 08/15/2011
Archive powered by MHonArc 2.6.16.