1212#error Python headers needed to compile C extensions, please install development version of Python.
1313#endif
1414
15+ struct android_app * g_state = NULL ;
16+
17+
18+ static PyObject * androidembed_poll (PyObject * self , PyObject * args ) {
19+ int indent ;
20+ int events ;
21+ struct android_poll_source * source ;
22+ int timeout ;
23+
24+ if (!PyArg_ParseTuple (args , "i" , & timeout )) {
25+ return NULL ;
26+ }
27+
28+ while ((indent = ALooper_pollAll (
29+ timeout , NULL , & events , (void * * )& source )) >= 0 ) {
30+
31+ // Process this event
32+ if (source != NULL ) {
33+ source -> process (g_state , source );
34+ }
35+
36+ // Check if we are exiting.
37+ if (g_state -> destroyRequested != 0 ) {
38+ Py_RETURN_FALSE ;
39+ }
40+ }
41+
42+ Py_RETURN_TRUE ;
43+ }
44+
1545static PyObject * androidembed_log (PyObject * self , PyObject * args ) {
1646 char * logstr = NULL ;
1747 if (!PyArg_ParseTuple (args , "s" , & logstr )) {
@@ -22,8 +52,8 @@ static PyObject *androidembed_log(PyObject *self, PyObject *args) {
2252}
2353
2454static PyMethodDef AndroidEmbedMethods [] = {
25- {"log" , androidembed_log , METH_VARARGS ,
26- "Log on android platform " },
55+ {"log" , androidembed_log , METH_VARARGS , "Log on android platform" },
56+ { "poll" , androidembed_poll , METH_VARARGS , "Poll the android events " },
2757 {NULL , NULL , 0 , NULL }
2858};
2959
@@ -55,7 +85,9 @@ int asset_extract(AAssetManager *am, char *src_file, char *dst_file) {
5585
5686void android_main (struct android_app * state ) {
5787 app_dummy ();
88+
5889 LOGI ("Starting minimal bootstrap." );
90+ g_state = state ;
5991
6092 char * env_argument = NULL ;
6193 int fd = -1 ;
0 commit comments