From 33cbe2a5c488ba179d1defef87a4bb959c95bd32 Mon Sep 17 00:00:00 2001
From: Michal Pawluk
+ The entire application life-cycle is implemented in the main source file, using a common Tizen application structure:
+
+ The application's initilization procedure is executed in __create_app() callback function, which is invoked on application's startup.
+
+ Finally, the controller_init() function is invoked, which controls the entire initialization process
+ (see the code snippet below for details).
+
+ The following functions, listed within the code snippet above, are responsible for:
+ Application initialization
+
+int main(int argc, char *argv[])
+{
+ appdata_s ad = {{0,},};
+ int ret = 0;
+ ui_app_lifecycle_callback_s event_callback;
+
+ event_callback.create = __create_app;
+ event_callback.terminate = __terminate_app;
+ event_callback.pause = __pause_app;
+ event_callback.resume = __resume_app;
+ event_callback.app_control = __control_app;
+
+ ret = ui_app_main(argc, argv, &event_callback, &ad);
+ if (ret != APP_ERROR_NONE)
+ controller_log(DLOG_ERROR, "Function ui_app_main() failed with error = %d", ret);
+
+ return ret;
+}
+
+
+
+static bool __create_app(void *data)
+{
+ appdata_s *ad = (appdata_s *)data;
+
+ return controller_init(&ad->view, &ad->model);
+}
+
+
+
+bool controller_init(viewdata_s *vd, modeldata_s *md)
+{
+ if (!model_init(md))
+ return false;
+
+ if (!__add_event_handlers())
+ return false;
+
+ if (!view_create_base_gui(vd, __paths_popup_opened))
+ return false;
+
+ __init_view_app();
+
+ return true;
+}
+
+
+
+
+ If any of the above functions (except __init_view_app()) fails, then application is terminated and the
+ __terminate_app() callback function is called. For details, see the Application termination section.
+
+bool model_init(modeldata_s *md)
+{
+ if (!md) {
+ controller_log(DLOG_ERROR, "Invalid argument");
+ return false;
+ }
+
+ __modeldata = md;
+
+ return (__modeldata != NULL);
+}
+
+
+static bool __add_event_handlers(void)
+{
+ return (model_add_event_handler(APP_EVENT_LOW_BATTERY, __app_event_low_battery_cb) &&
+ model_add_event_handler(APP_EVENT_LOW_MEMORY, __app_event_low_memory_cb) &&
+ model_add_event_handler(APP_EVENT_DEVICE_ORIENTATION_CHANGED, __app_event_device_orientation_changed_cb) &&
+ model_add_event_handler(APP_EVENT_LANGUAGE_CHANGED, __app_event_language_changed_cb) &&
+ model_add_event_handler(APP_EVENT_REGION_FORMAT_CHANGED, __app_event_region_format_changed_cb) &&
+ model_add_event_handler(APP_EVENT_SUSPENDED_STATE_CHANGED, __app_event_suspended_state_changed_cb));
+}
+
+ See the Model section for model_add_event_handler() function reference.
+
+static void __init_view_app(void)
+{
+ char *id = NULL;
+ char *name = NULL;
+ char *version = NULL;
+
+ if (model_app_get_id(&id) &&
+ model_app_get_name(&name) &&
+ model_app_get_version(&version))
+ view_update_application_tab(id, name, version);
+
+ char *paths[PATHS_LIST_ITEMS_COUNT] = { NULL };
+
+ if (model_app_get_data_path(&paths[PIT_DATA]) &&
+ model_app_get_cache_path(&paths[PIT_CACHE]) &&
+ model_app_get_resource_path(&paths[PIT_RESOURCE]) &&
+ model_app_get_shared_data_path(&paths[PIT_SHARED_DATA]) &&
+ model_app_get_shared_resource_path(&paths[PIT_SHARED_RESOURCE]) &&
+ model_app_get_shared_trusted_path(&paths[PIT_SHARED_TRUSTED]) &&
+ model_app_get_external_data_path(&paths[PIT_EXTERNAL_DATA]) &&
+ model_app_get_external_cache_path(&paths[PIT_EXTERNAL_CACHE]) &&
+ model_app_get_external_shared_data_path(&paths[PIT_EXTERNAL_SHARED_DATA]) &&
+ model_app_get_tep_resource_path(&paths[PIT_TEP_RESOURCE])) {
+ int i;
+ view_update_paths_tab(paths);
+
+ for (i = 0; i < PATHS_LIST_ITEMS_COUNT; i++)
+ free(paths[i]);
+ }
+}
+
+