comparison android/dw.cpp @ 2502:b6319aed3298

Android: Massive thread safety overhaul. Not quite back to fully functional. WebView is having many complaints about not being on the UI thread... better to get this figured out early... All UI calls will be wrapped in a waitOnUiThread() closure. This is our version of Android's runOnUiThread() except it waits for the closure to finish running so we can return results... and also so that our calls will be in the order desired in the application.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 06 May 2021 09:55:32 +0000
parents 41984ffb5ca2
children 1c2a79313b04
comparison
equal deleted inserted replaced
2501:41984ffb5ca2 2502:b6319aed3298
88 Java_org_dbsoft_dwindows_DWindows_dwindowsInit(JNIEnv* env, jobject obj, jstring path) 88 Java_org_dbsoft_dwindows_DWindows_dwindowsInit(JNIEnv* env, jobject obj, jstring path)
89 { 89 {
90 static int runcount = 0; 90 static int runcount = 0;
91 91
92 /* Safety check to prevent multiple initializations... */ 92 /* Safety check to prevent multiple initializations... */
93 #if defined(__arm__) || defined(__aarch64__)
94 if(runcount == 0) 93 if(runcount == 0)
95 #else
96 if(runcount == 1)
97 #endif
98 { 94 {
99 char *arg = strdup(env->GetStringUTFChars((jstring) path, NULL)); 95 char *arg = strdup(env->GetStringUTFChars((jstring) path, NULL));
100 96
101 /* Save our class object pointer for later */ 97 /* Save our class object pointer for later */
102 _dw_obj = env->NewGlobalRef(obj); 98 _dw_obj = env->NewGlobalRef(obj);
108 /* Create the dwmain event */ 104 /* Create the dwmain event */
109 _dw_main_event = dw_event_new(); 105 _dw_main_event = dw_event_new();
110 106
111 /* Launch the new thread to execute dwmain() */ 107 /* Launch the new thread to execute dwmain() */
112 dw_thread_new((void *) _dw_main_launch, arg, 0); 108 dw_thread_new((void *) _dw_main_launch, arg, 0);
113
114 /* Wait until dwmain() calls dw_main() then return */
115 dw_event_wait(_dw_main_event, DW_TIMEOUT_INFINITE);
116 } 109 }
117 runcount++; 110 runcount++;
118 } 111 }
119 112
120 typedef struct _sighandler 113 typedef struct _sighandler
465 /* 458 /*
466 * Runs a message loop for Dynamic Windows. 459 * Runs a message loop for Dynamic Windows.
467 */ 460 */
468 void API dw_main(void) 461 void API dw_main(void)
469 { 462 {
470 /* Post the event so dwindowsInit() will return...
471 * allowing the app to start handling events.
472 */
473 dw_event_post(_dw_main_event);
474 dw_event_reset(_dw_main_event);
475
476 /* We don't actually run a loop here, 463 /* We don't actually run a loop here,
477 * we launched a new thread to run the loop there. 464 * we launched a new thread to run the loop there.
478 * Just wait for dw_main_quit() on the DWMainEvent. 465 * Just wait for dw_main_quit() on the DWMainEvent.
479 */ 466 */
480 dw_event_wait(_dw_main_event, DW_TIMEOUT_INFINITE); 467 dw_event_wait(_dw_main_event, DW_TIMEOUT_INFINITE);
3176 */ 3163 */
3177 void API dw_notebook_page_set_text(HWND handle, ULONG pageid, const char *text) 3164 void API dw_notebook_page_set_text(HWND handle, ULONG pageid, const char *text)
3178 { 3165 {
3179 JNIEnv *env; 3166 JNIEnv *env;
3180 3167
3181 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) 3168 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3182 { 3169 {
3183 // Construct a String 3170 // Construct a String
3184 jstring jstr = env->NewStringUTF(text); 3171 jstring jstr = env->NewStringUTF(text);
3185 // First get the class that contains the method you need to call 3172 // First get the class that contains the method you need to call
3186 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 3173 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);