Mercurial > dwindows
comparison android/dw.cpp @ 2513:0fa54c340902
Android: Second try at that new fix... move it into _dw_main_launch()
This way we don't block the UI thread while waiting to see if the
relaunch is requested, the old way we block the full 10 seconds no
matter what.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 07 May 2021 11:11:10 +0000 |
parents | 0945d0428dfe |
children | 5f711e86a211 |
comparison
equal
deleted
inserted
replaced
2512:e57765c7a437 | 2513:0fa54c340902 |
---|---|
72 | 72 |
73 | 73 |
74 /* Call the dwmain entry point, Android has no args, so just pass the app path */ | 74 /* Call the dwmain entry point, Android has no args, so just pass the app path */ |
75 void _dw_main_launch(char *arg) | 75 void _dw_main_launch(char *arg) |
76 { | 76 { |
77 char *argv[2] = { arg, NULL }; | |
78 dwmain(1, argv); | |
79 } | |
80 | |
81 /* Called when DWindows activity starts up... so we create a thread | |
82 * to call the dwmain() entrypoint... then we wait for dw_main() | |
83 * to be called and return. | |
84 * Parameters: | |
85 * path: The path to the Android app. | |
86 */ | |
87 JNIEXPORT void JNICALL | |
88 Java_org_dbsoft_dwindows_DWindows_dwindowsInit(JNIEnv* env, jobject obj, jstring path) | |
89 { | |
90 static HEV startup = 0; | 77 static HEV startup = 0; |
91 | 78 |
92 /* Safety check to prevent multiple initializations... */ | 79 /* Safety check to prevent multiple initializations... */ |
93 if(startup) | 80 if(startup) |
94 { | 81 { |
98 dw_event_post(startup); | 85 dw_event_post(startup); |
99 return; | 86 return; |
100 } | 87 } |
101 else | 88 else |
102 { | 89 { |
103 char *arg; | 90 char *argv[2] = {arg, NULL}; |
104 | 91 |
105 /* Wait for a short while to see if we get called again... | 92 /* Wait for a short while to see if we get called again... |
106 * if we get called again we will be posted, if not... | 93 * if we get called again we will be posted, if not... |
107 * just wait for the timer to expire. | 94 * just wait for the timer to expire. |
108 */ | 95 */ |
109 startup = dw_event_new(); | 96 startup = dw_event_new(); |
110 /* Wait for 10 seconds to see if we get called again */ | 97 /* Wait for 10 seconds to see if we get called again */ |
111 dw_event_wait(startup, 10000); | 98 dw_event_wait(startup, 10000); |
112 | 99 |
113 /* Continue after being posted or after our timeout */ | 100 /* Continue after being posted or after our timeout */ |
114 arg = strdup(env->GetStringUTFChars((jstring) path, NULL)); | 101 dwmain(1, argv); |
115 | 102 } |
103 free(arg); | |
104 } | |
105 | |
106 /* Called when DWindows activity starts up... so we create a thread | |
107 * to call the dwmain() entrypoint... then we wait for dw_main() | |
108 * to be called and return. | |
109 * Parameters: | |
110 * path: The path to the Android app. | |
111 */ | |
112 JNIEXPORT void JNICALL | |
113 Java_org_dbsoft_dwindows_DWindows_dwindowsInit(JNIEnv* env, jobject obj, jstring path) | |
114 { | |
115 char *arg = strdup(env->GetStringUTFChars((jstring) path, NULL)); | |
116 | |
117 if(!_dw_main_event) | |
118 { | |
116 /* Save our class object pointer for later */ | 119 /* Save our class object pointer for later */ |
117 _dw_obj = env->NewGlobalRef(obj); | 120 _dw_obj = env->NewGlobalRef(obj); |
118 | 121 |
119 /* Save the JNIEnv for the main thread */ | 122 /* Save the JNIEnv for the main thread */ |
120 pthread_key_create(&_dw_env_key, NULL); | 123 pthread_key_create(&_dw_env_key, NULL); |
121 pthread_setspecific(_dw_env_key, env); | 124 pthread_setspecific(_dw_env_key, env); |
122 | 125 |
123 /* Create the dwmain event */ | 126 /* Create the dwmain event */ |
124 _dw_main_event = dw_event_new(); | 127 _dw_main_event = dw_event_new(); |
125 | 128 } |
126 /* Launch the new thread to execute dwmain() */ | 129 |
127 dw_thread_new((void *) _dw_main_launch, arg, 0); | 130 /* Launch the new thread to execute dwmain() */ |
128 } | 131 dw_thread_new((void *) _dw_main_launch, arg, 0); |
129 } | 132 } |
130 | 133 |
131 typedef struct _sighandler | 134 typedef struct _sighandler |
132 { | 135 { |
133 struct _sighandler *next; | 136 struct _sighandler *next; |