diff options
Diffstat (limited to 'navit/android/src/org/navitproject/navit/NavitWatch.java')
-rw-r--r-- | navit/android/src/org/navitproject/navit/NavitWatch.java | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/navit/android/src/org/navitproject/navit/NavitWatch.java b/navit/android/src/org/navitproject/navit/NavitWatch.java index 7933d1b0a..5f13c83a3 100644 --- a/navit/android/src/org/navitproject/navit/NavitWatch.java +++ b/navit/android/src/org/navitproject/navit/NavitWatch.java @@ -27,7 +27,7 @@ import java.lang.Thread; public class NavitWatch implements Runnable { private Thread thread; - private static Handler handler =new Handler() { + private static Handler handler = new Handler() { public void handleMessage(Message m) { Log.e("NavitWatch","Handler received message"); } @@ -39,16 +39,19 @@ public class NavitWatch implements Runnable { private int watch_callbackid; private boolean callback_pending; private Runnable callback_runnable; + public native void poll(int func, int fd, int cond); + 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; - final NavitWatch navitwatch=this; + // 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; + final NavitWatch navitwatch = this; callback_runnable = new Runnable() { public void run() { navitwatch.callback(); @@ -57,41 +60,49 @@ public class NavitWatch implements Runnable { thread = new Thread(this, "poll thread"); thread.start(); } + public void run() { for (;;) { - // Log.e("NavitWatch","Polling "+watch_fd+" "+watch_cond + " from " + java.lang.Thread.currentThread().getName()); + // Log.e("NavitWatch","Polling "+watch_fd+" "+watch_cond + " from " + // + java.lang.Thread.currentThread().getName()); poll(watch_func, watch_fd, watch_cond); // Log.e("NavitWatch","poll returned"); - if (removed) + if (removed) { break; - callback_pending=true; + } + callback_pending = true; handler.post(callback_runnable); try { // Log.e("NavitWatch","wait"); - synchronized(this) { - if (callback_pending) + synchronized (this) { + if (callback_pending) { 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 (removed) { break; + } } } + public void callback() { // Log.e("NavitWatch","Calling Callback"); - if (!removed) + if (!removed) { WatchCallback(watch_callbackid); - synchronized(this) { - callback_pending=false; + } + synchronized (this) { + callback_pending = false; // Log.e("NavitWatch","Waking up"); this.notify(); } } + public void remove() { - removed=true; + removed = true; thread.interrupt(); } } |