summaryrefslogtreecommitdiff
path: root/navit/android/src/org/navitproject/navit/NavitWatch.java
diff options
context:
space:
mode:
Diffstat (limited to 'navit/android/src/org/navitproject/navit/NavitWatch.java')
-rw-r--r--navit/android/src/org/navitproject/navit/NavitWatch.java89
1 files changed, 45 insertions, 44 deletions
diff --git a/navit/android/src/org/navitproject/navit/NavitWatch.java b/navit/android/src/org/navitproject/navit/NavitWatch.java
index 5f13c83a3..bfa56913e 100644
--- a/navit/android/src/org/navitproject/navit/NavitWatch.java
+++ b/navit/android/src/org/navitproject/navit/NavitWatch.java
@@ -1,4 +1,4 @@
-/**
+/*
* Navit, a modular navigation system.
* Copyright (C) 2005-2008 Navit Team
*
@@ -23,87 +23,88 @@ import android.os.Handler;
import android.os.Message;
import android.util.Log;
-import java.lang.Thread;
+class NavitWatch implements Runnable {
-public class NavitWatch implements Runnable {
- private Thread thread;
- private static Handler handler = new Handler() {
- public void handleMessage(Message m) {
- Log.e("NavitWatch","Handler received message");
- }
- };
- private boolean removed;
- private int watch_func;
- private int watch_fd;
- private int watch_cond;
- private int watch_callbackid;
- private boolean callback_pending;
- private Runnable callback_runnable;
-
- public native void poll(int func, int fd, int cond);
+ private static WatchHandler sHandler = new WatchHandler();
+ private Thread mThread;
+ private boolean mRemoved;
+ private long mWatchFunc;
+ private int mWatchFd;
+ private int mWatchCond;
+ private long mWatchCallbackid;
+ private boolean mCallbackPending;
+ private Runnable mCallbackRunnable;
- public native void WatchCallback(int id);
-
- NavitWatch(int func, int fd, int cond, int callbackid) {
- // Log.e("NavitWatch","Creating new thread for "+fd+" "+cond+" from current thread "
- // + java.lang.Thread.currentThread().getName());
- watch_func = func;
- watch_fd = fd;
- watch_cond = cond;
- watch_callbackid = callbackid;
+ NavitWatch(long func, int fd, int cond, long callbackid) {
+ Log.d("NavitWatch","Creating new thread for " + fd + " " + cond + " from current thread "
+ + java.lang.Thread.currentThread().getName());
+ mWatchFunc = func;
+ mWatchFd = fd;
+ mWatchCond = cond;
+ mWatchCallbackid = callbackid;
final NavitWatch navitwatch = this;
- callback_runnable = new Runnable() {
+ mCallbackRunnable = new Runnable() {
public void run() {
navitwatch.callback();
}
};
- thread = new Thread(this, "poll thread");
- thread.start();
+ mThread = new Thread(this, "poll thread");
+ mThread.start();
}
+ public native void poll(long func, int fd, int cond);
+
+ public native void watchCallback(long id);
+
public void run() {
- for (;;) {
+ for (; ; ) {
// Log.e("NavitWatch","Polling "+watch_fd+" "+watch_cond + " from "
// + java.lang.Thread.currentThread().getName());
- poll(watch_func, watch_fd, watch_cond);
+ poll(mWatchFunc, mWatchFd, mWatchCond);
// Log.e("NavitWatch","poll returned");
- if (removed) {
+ if (mRemoved) {
break;
}
- callback_pending = true;
- handler.post(callback_runnable);
+ mCallbackPending = true;
+ sHandler.post(mCallbackRunnable);
try {
// Log.e("NavitWatch","wait");
synchronized (this) {
- if (callback_pending) {
+ if (mCallbackPending) {
this.wait();
}
}
// Log.e("NavitWatch","wait returned");
} catch (Exception e) {
- Log.e("NavitWatch","Exception " + e.getMessage());
+ Log.e("NavitWatch", "Exception " + e.getMessage());
}
- if (removed) {
+ if (mRemoved) {
break;
}
}
}
- public void callback() {
+ private void callback() {
// Log.e("NavitWatch","Calling Callback");
- if (!removed) {
- WatchCallback(watch_callbackid);
+ if (!mRemoved) {
+ watchCallback(mWatchCallbackid);
}
synchronized (this) {
- callback_pending = false;
+ mCallbackPending = false;
// Log.e("NavitWatch","Waking up");
this.notify();
}
}
public void remove() {
- removed = true;
- thread.interrupt();
+ mRemoved = true;
+ mThread.interrupt();
+ }
+
+ static class WatchHandler extends Handler {
+ public void handleMessage(Message m) {
+ Log.d("NavitWatch", "Handler received message");
+ }
}
}