<h3 id="app-init">Application initialization</h3>
+ <p>
+ The entire application's life-cycle is implemented in the main source file, using a common Tizen application structure:
+ </p>
+
+<pre class="prettyprint">
+int main(int argc, char *argv[])
+{
+ appdata_s ad = {{0,},};
+ int ret = 0;
+
+ ui_app_lifecycle_callback_s event_callback;
+ app_event_handler_h handlers[5] = {NULL, };
+
+ 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;
+
+ ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, __ui_app_low_battery, &ad);
+ ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, __ui_app_low_memory, &ad);
+ ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, __ui_app_orient_changed, &ad);
+ ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, __ui_app_lang_changed, &ad);
+ ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, __ui_app_region_changed, &ad);
+
+ 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;
+}
+</pre>
+
+ <p>
+ The application's initilization procedure is executed in <span style="font-family: Courier New,Courier,monospace">__create_app()</span> callback function, which is invoked on application's startup.
+ </p>
+
+<pre class="prettyprint">
+static bool __create_app(void *data)
+{
+ appdata_s *ad = (appdata_s *)data;
+
+ return controller_init(&ad->view);
+}
+</pre>
+
+ <p>
+ Finally, the <span style="font-family: Courier New,Courier,monospace">controller_init()</span> function is invoked, which controls the entire initialization process
+ (see the code snippet below for details). This function is responsible for:
+ <ul>
+ <li>
+ Resource Manager engine initialization (<span style="font-family: Courier New,Courier,monospace">model_init()</span>);
+ </li>
+ <li>
+ User interface creation (<span style="font-family: Courier New,Courier,monospace">view_create_base_gui()</span>) and initialization
+ (<span style="font-family: Courier New,Courier,monospace">__controller_init_dpi()</span>).
+ </li>
+ </ul>
+ </p>
+
+<pre class="prettyprint">
+bool controller_init(viewdata_s *vd)
+{
+ if (!model_init())
+ return false;
+
+ if (!view_create_base_gui(vd))
+ return false;
+
+ __controller_init_dpi(vd);
+
+ return true;
+}
+</pre>
+
+ <p>
+ For reference of model related functions that are not listed here refer to the <a href="#model">Model</a> section.
+ </p>
+
+ <p>
+ The view related source code is not listed here, as it is not a subject of this document.
+ </p>
+
+ <p>
+ The <span style="font-family: Courier New,Courier,monospace">model_init()</span> function simply invokes
+ <span style="font-family: Courier New,Courier,monospace">app_resource_manager_init()</span> API function in order to get access to the Resource Manager engine (see the code snippet below for reference).
+ </p>
+
+<pre class="prettyprint">
+bool model_init(void)
+{
+ return __model_init_app_resource_manager();
+}
+</pre>
+
+<pre class="prettyprint">
+bool __model_init_app_resource_manager(void)
+{
+ int ret = app_resource_manager_init();
+ if (ret != APP_RESOURCE_ERROR_NONE) {
+ controller_log(DLOG_ERROR, "Function app_resource_manager_init() failed with error %d.", ret);
+ return false;
+ }
+
+ return true;
+}
+</pre>
+
+ <p>
+ The <span style="font-family: Courier New,Courier,monospace">__controller_init_dpi()</span> function gets the 'tizen.png' image's file path from the Resource Manager and updates the view with the
+ image relevant to the screen's DPI.
+ </p>
+
+<pre class="prettyprint">
+static void __controller_init_dpi(viewdata_s *vd)
+{
+ char *file_path = NULL;
+
+ if (!model_get_app_resource(APP_RESOURCE_TYPE_IMAGE, "tizen.png", &file_path))
+ return;
+
+ view_show_dpi_image(vd, file_path);
+ free(file_path);
+}
+</pre>
+
+ <p>
+ For reference of model related functions that are not listed here refer to the <a href="#model">Model</a> section.
+ </p>
+
+ <p>
+ The view related source code is not listed here, as it is not a subject of this document.
+ </p>
+
<h3 id="app-finit">Application termination</h3>
<h3 id="model">Model</h3>