From 23e0c5700d3023ee8fe78e2c64b081b1c956b7b9 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Sun, 31 Oct 2010 18:45:52 +0100 Subject: [PATCH 1/2] Proof of concept yesno with wakeup_wait() --- android/src/org/rockbox/RockboxYesno.java | 35 +++++----------------------- apps/hosted/yesno.c | 34 +++++++++++++++------------- firmware/export/config.h | 3 +- 3 files changed, 27 insertions(+), 45 deletions(-) diff --git a/android/src/org/rockbox/RockboxYesno.java b/android/src/org/rockbox/RockboxYesno.java index f655471..aa5e83d 100644 --- a/android/src/org/rockbox/RockboxYesno.java +++ b/android/src/org/rockbox/RockboxYesno.java @@ -26,15 +26,8 @@ import android.content.Intent; public class RockboxYesno { - private boolean result; - private boolean have_result; - - public RockboxYesno() - { - have_result = false; - } - - public void yesno_display(String text) + @SuppressWarnings("unused") + private void yesno_display(String text) { RockboxActivity a = (RockboxActivity) RockboxService.get_instance().get_activity(); Intent kbd = new Intent(a, YesnoActivity.class); @@ -43,30 +36,16 @@ public class RockboxYesno { public void onComplete(int resultCode, Intent data) { - if (resultCode == Activity.RESULT_OK) - { - result = true; - have_result = true; - } - else { - result = false; - have_result = true; - } + put_result(resultCode == Activity.RESULT_OK); } }); } - public boolean result_ready() - { - return have_result; - } - public boolean get_result() - { - return result; - } - - public boolean is_usable() + @SuppressWarnings("unused") + private boolean is_usable() { return RockboxService.get_instance().get_activity() != null; } + + private native void put_result(boolean result); } diff --git a/apps/hosted/yesno.c b/apps/hosted/yesno.c index 1e05e19..1553868 100644 --- a/apps/hosted/yesno.c +++ b/apps/hosted/yesno.c @@ -24,20 +24,32 @@ #include #include #include -#include #include "yesno.h" #include "settings.h" #include "lang.h" +#include "kernel.h" extern JNIEnv *env_ptr; static jclass RockboxYesno_class = NULL; static jobject RockboxYesno_instance = NULL; -static jmethodID yesno_func, result_ready, yesno_result; +static jmethodID yesno_func; +static struct wakeup yesno_wakeup; +static bool ret; + +JNIEXPORT void JNICALL +Java_org_rockbox_RockboxYesno_put_1result(JNIEnv *env, jobject this, jboolean result) +{ + (void)env; + (void)this; + ret = (bool)result; + wakeup_signal(&yesno_wakeup); +} static void yesno_init(void) { JNIEnv e = *env_ptr; - jmethodID yesno_is_usable; + wakeup_init(&yesno_wakeup); + static jmethodID yesno_is_usable; if (RockboxYesno_class == NULL) { /* get the class and its constructor */ @@ -51,14 +63,10 @@ static void yesno_init(void) constructor); yesno_func = e->GetMethodID(env_ptr, RockboxYesno_class, "yesno_display", "(Ljava/lang/String;)V"); - yesno_result = e->GetMethodID(env_ptr, RockboxYesno_class, - "get_result", "()Z"); - result_ready = e->GetMethodID(env_ptr, RockboxYesno_class, - "result_ready", "()Z"); + yesno_is_usable = e->GetMethodID(env_ptr, RockboxYesno_class, + "is_usable", "()Z"); } /* need to get it every time incase the activity died/restarted */ - yesno_is_usable = e->GetMethodID(env_ptr, RockboxYesno_class, - "is_usable", "()Z"); while (!e->CallBooleanMethod(env_ptr, RockboxYesno_instance, yesno_is_usable)) sleep(HZ/10); @@ -92,18 +100,12 @@ enum yesno_res gui_syncyesno_run(const struct text_message * main_message, JNIEnv e = *env_ptr; jstring message = build_message(main_message); - jboolean ret; e->CallVoidMethod(env_ptr, RockboxYesno_instance, yesno_func, message); e->ReleaseStringUTFChars(env_ptr, message, NULL); + wakeup_wait(&yesno_wakeup, TIMEOUT_BLOCK); - do { - sleep(HZ/10); - ret = e->CallBooleanMethod(env_ptr, RockboxYesno_instance, result_ready); - } while (!ret); - - ret = e->CallBooleanMethod(env_ptr, RockboxYesno_instance, yesno_result); return ret ? YESNO_YES : YESNO_NO; } diff --git a/firmware/export/config.h b/firmware/export/config.h index d005aae..3a73283 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h @@ -721,7 +721,8 @@ Lyre prototype 1 */ #if defined(HAVE_USBSTACK) || (CONFIG_CPU == JZ4732) \ || (CONFIG_CPU == AS3525) || (CONFIG_CPU == AS3525v2) \ - || defined(CPU_S5L870X) || (CONFIG_CPU == S3C2440) + || defined(CPU_S5L870X) || (CONFIG_CPU == S3C2440) \ + || defined(APPLICATION) #define HAVE_WAKEUP_OBJECTS #endif -- 1.7.2.3