UDK 3.2.7 C/C++ API Reference
|
00001 /* 00002 * Copyright (C) 2010 The Android Open Source Project 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 * 00016 */ 00017 00018 #ifndef _ANDROID_NATIVE_APP_GLUE_H 00019 #define _ANDROID_NATIVE_APP_GLUE_H 00020 00021 #include <poll.h> 00022 #include <pthread.h> 00023 #include <sched.h> 00024 00025 #include <android/configuration.h> 00026 #include <android/looper.h> 00027 #include <android/native_activity.h> 00028 00029 #ifdef __cplusplus 00030 extern "C" { 00031 #endif 00032 00084 struct android_app; 00085 00090 struct android_poll_source { 00091 // The identifier of this source. May be LOOPER_ID_MAIN or 00092 // LOOPER_ID_INPUT. 00093 int32_t id; 00094 00095 // The android_app this ident is associated with. 00096 struct android_app* app; 00097 00098 // Function to call to perform the standard processing of data from 00099 // this source. 00100 void (*process)(struct android_app* app, struct android_poll_source* source); 00101 }; 00102 00111 struct android_app { 00112 // The application can place a pointer to its own state object 00113 // here if it likes. 00114 void* userData; 00115 00116 // Fill this in with the function to process main app commands (APP_CMD_*) 00117 void (*onAppCmd)(struct android_app* app, int32_t cmd); 00118 00119 // Fill this in with the function to process input events. At this point 00120 // the event has already been pre-dispatched, and it will be finished upon 00121 // return. Return 1 if you have handled the event, 0 for any default 00122 // dispatching. 00123 int32_t (*onInputEvent)(struct android_app* app, AInputEvent* event); 00124 00125 // The ANativeActivity object instance that this app is running in. 00126 ANativeActivity* activity; 00127 00128 // The current configuration the app is running in. 00129 AConfiguration* config; 00130 00131 // This is the last instance's saved state, as provided at creation time. 00132 // It is NULL if there was no state. You can use this as you need; the 00133 // memory will remain around until you call android_app_exec_cmd() for 00134 // APP_CMD_RESUME, at which point it will be freed and savedState set to NULL. 00135 // These variables should only be changed when processing a APP_CMD_SAVE_STATE, 00136 // at which point they will be initialized to NULL and you can malloc your 00137 // state and place the information here. In that case the memory will be 00138 // freed for you later. 00139 void* savedState; 00140 size_t savedStateSize; 00141 00142 // The ALooper associated with the app's thread. 00143 ALooper* looper; 00144 00145 // When non-NULL, this is the input queue from which the app will 00146 // receive user input events. 00147 AInputQueue* inputQueue; 00148 00149 // When non-NULL, this is the window surface that the app can draw in. 00150 ANativeWindow* window; 00151 00152 // Current content rectangle of the window; this is the area where the 00153 // window's content should be placed to be seen by the user. 00154 ARect contentRect; 00155 00156 // Current state of the app's activity. May be either APP_CMD_START, 00157 // APP_CMD_RESUME, APP_CMD_PAUSE, or APP_CMD_STOP; see below. 00158 int activityState; 00159 00160 // This is non-zero when the application's NativeActivity is being 00161 // destroyed and waiting for the app thread to complete. 00162 int destroyRequested; 00163 00164 // ------------------------------------------------- 00165 // Below are "private" implementation of the glue code. 00166 00167 pthread_mutex_t mutex; 00168 pthread_cond_t cond; 00169 00170 int msgread; 00171 int msgwrite; 00172 00173 pthread_t thread; 00174 00175 struct android_poll_source cmdPollSource; 00176 struct android_poll_source inputPollSource; 00177 00178 int running; 00179 int stateSaved; 00180 int destroyed; 00181 int redrawNeeded; 00182 AInputQueue* pendingInputQueue; 00183 ANativeWindow* pendingWindow; 00184 ARect pendingContentRect; 00185 }; 00186 00187 enum { 00195 LOOPER_ID_MAIN = 1, 00196 00204 LOOPER_ID_INPUT = 2, 00205 00209 LOOPER_ID_USER = 3, 00210 }; 00211 00212 enum { 00218 APP_CMD_INPUT_CHANGED, 00219 00225 APP_CMD_INIT_WINDOW, 00226 00233 APP_CMD_TERM_WINDOW, 00234 00239 APP_CMD_WINDOW_RESIZED, 00240 00246 APP_CMD_WINDOW_REDRAW_NEEDED, 00247 00253 APP_CMD_CONTENT_RECT_CHANGED, 00254 00259 APP_CMD_GAINED_FOCUS, 00260 00265 APP_CMD_LOST_FOCUS, 00266 00270 APP_CMD_CONFIG_CHANGED, 00271 00276 APP_CMD_LOW_MEMORY, 00277 00281 APP_CMD_START, 00282 00286 APP_CMD_RESUME, 00287 00295 APP_CMD_SAVE_STATE, 00296 00300 APP_CMD_PAUSE, 00301 00305 APP_CMD_STOP, 00306 00311 APP_CMD_DESTROY, 00312 }; 00313 00318 int8_t android_app_read_cmd(struct android_app* android_app); 00319 00325 void android_app_pre_exec_cmd(struct android_app* android_app, int8_t cmd); 00326 00332 void android_app_post_exec_cmd(struct android_app* android_app, int8_t cmd); 00333 00337 void app_dummy(); 00338 00343 extern void android_main(struct android_app* app); 00344 00345 #ifdef __cplusplus 00346 } 00347 #endif 00348 00349 #endif /* _ANDROID_NATIVE_APP_GLUE_H */