summaryrefslogtreecommitdiff
path: root/apps/hosted/yesno.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/hosted/yesno.c')
-rw-r--r--apps/hosted/yesno.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/apps/hosted/yesno.c b/apps/hosted/yesno.c
index 9858e66438..2a8c02edd5 100644
--- a/apps/hosted/yesno.c
+++ b/apps/hosted/yesno.c
@@ -24,22 +24,34 @@
24#include <jni.h> 24#include <jni.h>
25#include <stdbool.h> 25#include <stdbool.h>
26#include <stdio.h> 26#include <stdio.h>
27#include <system.h>
28#include "yesno.h" 27#include "yesno.h"
29#include "settings.h" 28#include "settings.h"
30#include "lang.h" 29#include "lang.h"
30#include "kernel.h"
31 31
32extern JNIEnv *env_ptr; 32extern JNIEnv *env_ptr;
33static jclass RockboxYesno_class = NULL; 33static jclass RockboxYesno_class = NULL;
34static jobject RockboxYesno_instance = NULL; 34static jobject RockboxYesno_instance = NULL;
35static jmethodID yesno_func, result_ready, yesno_result; 35static jmethodID yesno_func;
36static struct wakeup yesno_wakeup;
37static bool ret;
38
39JNIEXPORT void JNICALL
40Java_org_rockbox_RockboxYesno_put_1result(JNIEnv *env, jobject this, jboolean result)
41{
42 (void)env;
43 (void)this;
44 ret = (bool)result;
45 wakeup_signal(&yesno_wakeup);
46}
36 47
37static void yesno_init(void) 48static void yesno_init(void)
38{ 49{
39 JNIEnv e = *env_ptr; 50 JNIEnv e = *env_ptr;
40 jmethodID yesno_is_usable; 51 static jmethodID yesno_is_usable;
41 if (RockboxYesno_class == NULL) 52 if (RockboxYesno_class == NULL)
42 { 53 {
54 wakeup_init(&yesno_wakeup);
43 /* get the class and its constructor */ 55 /* get the class and its constructor */
44 RockboxYesno_class = e->FindClass(env_ptr, 56 RockboxYesno_class = e->FindClass(env_ptr,
45 "org/rockbox/RockboxYesno"); 57 "org/rockbox/RockboxYesno");
@@ -51,14 +63,10 @@ static void yesno_init(void)
51 constructor); 63 constructor);
52 yesno_func = e->GetMethodID(env_ptr, RockboxYesno_class, 64 yesno_func = e->GetMethodID(env_ptr, RockboxYesno_class,
53 "yesno_display", "(Ljava/lang/String;)V"); 65 "yesno_display", "(Ljava/lang/String;)V");
54 yesno_result = e->GetMethodID(env_ptr, RockboxYesno_class, 66 yesno_is_usable = e->GetMethodID(env_ptr, RockboxYesno_class,
55 "get_result", "()Z"); 67 "is_usable", "()Z");
56 result_ready = e->GetMethodID(env_ptr, RockboxYesno_class,
57 "result_ready", "()Z");
58 } 68 }
59 /* need to get it every time incase the activity died/restarted */ 69 /* need to get it every time incase the activity died/restarted */
60 yesno_is_usable = e->GetMethodID(env_ptr, RockboxYesno_class,
61 "is_usable", "()Z");
62 while (!e->CallBooleanMethod(env_ptr, RockboxYesno_instance, 70 while (!e->CallBooleanMethod(env_ptr, RockboxYesno_instance,
63 yesno_is_usable)) 71 yesno_is_usable))
64 sleep(HZ/10); 72 sleep(HZ/10);
@@ -92,16 +100,13 @@ enum yesno_res gui_syncyesno_run(const struct text_message * main_message,
92 100
93 JNIEnv e = *env_ptr; 101 JNIEnv e = *env_ptr;
94 jstring message = build_message(main_message); 102 jstring message = build_message(main_message);
95 jboolean ret;
96 103
97 e->CallVoidMethod(env_ptr, RockboxYesno_instance, yesno_func, message); 104 e->CallVoidMethod(env_ptr, RockboxYesno_instance, yesno_func, message);
98
99 do {
100 sleep(HZ/10);
101 ret = e->CallBooleanMethod(env_ptr, RockboxYesno_instance, result_ready);
102 } while (!ret);
103 105
104 ret = e->CallBooleanMethod(env_ptr, RockboxYesno_instance, yesno_result); 106 wakeup_wait(&yesno_wakeup, TIMEOUT_BLOCK);
107
108 e->DeleteLocalRef(env_ptr, message);
109
105 return ret ? YESNO_YES : YESNO_NO; 110 return ret ? YESNO_YES : YESNO_NO;
106} 111}
107 112