… | |
… | |
45 | |
45 | |
46 | public native void WatchCallback(int id); |
46 | public native void WatchCallback(int id); |
47 | |
47 | |
48 | NavitWatch(int fd, int cond, int callbackid) |
48 | NavitWatch(int fd, int cond, int callbackid) |
49 | { |
49 | { |
50 | // Log.e("NavitWatch","Creating new thread for "+fd+" "+cond+" from current thread " + java.lang.Thread.currentThread().getName()); |
50 | Log.e("NavitWatch","Creating new thread for "+fd+" "+cond+" from current thread " + java.lang.Thread.currentThread().getName()); |
51 | watch_fd = fd; |
51 | watch_fd = fd; |
52 | watch_cond = cond; |
52 | watch_cond = cond; |
53 | watch_callbackid = callbackid; |
53 | watch_callbackid = callbackid; |
54 | final NavitWatch navitwatch = this; |
54 | final NavitWatch navitwatch = this; |
55 | callback_runnable = new Runnable() |
55 | callback_runnable = new Runnable() |
… | |
… | |
65 | |
65 | |
66 | public void run() |
66 | public void run() |
67 | { |
67 | { |
68 | for (;;) |
68 | for (;;) |
69 | { |
69 | { |
70 | // Log.e("NavitWatch","Polling "+watch_fd+" "+watch_cond + " from " + java.lang.Thread.currentThread().getName()); |
70 | Log.e("NavitWatch","Polling "+watch_fd+" "+watch_cond + " from " + java.lang.Thread.currentThread().getName()); |
71 | poll(watch_fd, watch_cond); |
71 | poll(watch_fd, watch_cond); |
72 | // Log.e("NavitWatch","poll returned"); |
72 | Log.e("NavitWatch","poll returned"); |
73 | if (removed) break; |
73 | if (removed) break; |
74 | callback_pending = true; |
74 | callback_pending = true; |
75 | handler.post(callback_runnable); |
75 | handler.post(callback_runnable); |
76 | try |
76 | try |
77 | { |
77 | { |
78 | // Log.e("NavitWatch","wait"); |
78 | Log.e("NavitWatch","wait"); |
79 | synchronized (this) |
79 | synchronized (this) |
80 | { |
80 | { |
81 | if (callback_pending) this.wait(); |
81 | if (callback_pending) this.wait(); |
82 | } |
82 | } |
83 | // Log.e("NavitWatch","wait returned"); |
83 | Log.e("NavitWatch","wait returned"); |
84 | } |
84 | } |
85 | catch (Exception e) |
85 | catch (Exception e) |
86 | { |
86 | { |
87 | Log.e("NavitWatch", "Exception " + e.getMessage()); |
87 | Log.e("NavitWatch", "Exception " + e.getMessage()); |
88 | } |
88 | } |
… | |
… | |
90 | } |
90 | } |
91 | } |
91 | } |
92 | |
92 | |
93 | public void callback() |
93 | public void callback() |
94 | { |
94 | { |
95 | // Log.e("NavitWatch","Calling Callback"); |
95 | Log.e("NavitWatch","Calling Callback"); |
96 | if (!removed) WatchCallback(watch_callbackid); |
96 | if (!removed) WatchCallback(watch_callbackid); |
97 | synchronized (this) |
97 | synchronized (this) |
98 | { |
98 | { |
99 | callback_pending = false; |
99 | callback_pending = false; |
100 | // Log.e("NavitWatch","Waking up"); |
100 | Log.e("NavitWatch","Waking up"); |
101 | this.notify(); |
101 | this.notify(); |
102 | } |
102 | } |
103 | } |
103 | } |
104 | |
104 | |
105 | public void remove() |
105 | public void remove() |