Evas_Object *custom_ev_list;
Elm_Genlist_Item_Class *custom_ev_itc;
/* The structure of callbacks handlers used by the Controller module to establish interaction with the Model module. */
- viewcallbacks_s *callbacks;
+ viewcallbacks_s callbacks;
};
typedef struct __viewdata viewdata_s;
<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 attaching callback functions invoked by the View module in order to perform required tasks:
+ <ul>
+ <li><span style="font-family: Courier New,Courier,monospace">__controller_event_do_publish_cb()</span> - publish the custom event registered by the user;</li>
+ <li><span style="font-family: Courier New,Courier,monospace">__controller_event_get_system_info_cb()</span> - query system's event information to populate the list with relevant data;</li>
+ <li><span style="font-family: Courier New,Courier,monospace">__controller_event_set_custom_info_cb()</span> - register event handler to be invoked on custom event occurance.</li>
+ </ul>
+ The first and the third callback function is called when the user performs appropriate action from the application's UI. The second callback function is called during the application's UI creation.
+ The application's UI is afterwards created by the <span style="font-family: Courier New,Courier,monospace">view_create_base_gui()</span> function. Its source code is not listed
+ within this documentation, as it is not a subject of this document. At the end of the initialization phase, a callback function is attached to each of the available system events within the
+ <span style="font-family: Courier New,Courier,monospace">__add_system_event_handlers()</span> function.
+ </p>
+
+<pre class="prettyprint">
+bool controller_init(viewdata_s *vd)
+{
+ vd->callbacks.do_publish_cb = __controller_event_do_publish_cb;
+ vd->callbacks.get_system_info_cb = __controller_event_get_system_info_cb;
+ vd->callbacks.set_custom_info_cb = __controller_event_set_custom_info_cb;
+
+ if (!view_create_base_gui(vd))
+ return false;
+
+ __add_system_event_handlers();
+
+ return true;
+}
+</pre>
+
+<pre class="prettyprint">
+static void __controller_event_do_publish_cb(const char *event_name)
+{
+ controller_log(DLOG_INFO, "Event publishing: '%s'.", event_name);
+
+ model_publish_event(event_name);
+}
+</pre>
+
+ <p>
+ The <span style="font-family: Courier New,Courier,monospace">__controller_event_get_system_info_cb()</span> is invoked by the View module as long as the function returns
+ <span style="font-family: Courier New,Courier,monospace">true</span> value. Each time the function is called with incremented <span style="font-family: Courier New,Courier,monospace">index</span>
+ value. As a result, the system's event information <span style="font-family: Courier New,Courier,monospace">ev_info</span>, stored at specified
+ <span style="font-family: Courier New,Courier,monospace">index</span>, is returned. The requested data structure is obtained with the
+ <span style="font-family: Courier New,Courier,monospace">model_get_system_event_info()</span> function.
+ </p>
+
+<pre class="prettyprint">
+static bool __controller_event_get_system_info_cb(int index, void **ev_info)
+{
+ *ev_info = NULL;
+
+ if (index >= model_get_system_events_count())
+ return false;
+
+ system_ev_info_s *ev_info_tmp = NULL;
+ if (!model_get_system_event_info(index, &ev_info_tmp))
+ return false;
+
+ *ev_info = (system_ev_info_s *)ev_info_tmp;
+
+ return true;
+}
+</pre>
+
+ <p>
+ The <span style="font-family: Courier New,Courier,monospace">__controller_event_set_custom_info_cb()</span> callback function is invoked by the View model when the user requests to register
+ custom event. If the registration procedure succeeds (see the <span style="font-family: Courier New,Courier,monospace">__controller_register_custom_event()</span> function's implementation for
+ details), the reference to the event's information structure is returned via the <span style="font-family: Courier New,Courier,monospace">ev_info</span> argument.
+ </p>
+
+<pre class="prettyprint">
+static bool __controller_event_set_custom_info_cb(const char *event_name, void **ev_info)
+{
+ *ev_info = NULL;
+
+ custom_ev_info_s *ev_info_tmp = NULL;
+ if (!__controller_register_custom_event(event_name, &ev_info_tmp))
+ return false;
+
+ *ev_info = (custom_ev_info_s *)ev_info_tmp;
+
+ return true;
+}
+</pre>
+
+<pre class="prettyprint">
+bool __controller_register_custom_event(const char *event_name, custom_ev_info_s **ev_info)
+{
+ *ev_info = NULL;
+ bool name_exists = false;
+
+ /* The event's name, assigned by the user, must be unique, so we have to check if it does not exist yet. */
+ if (!model_check_event_exists(event_name, &name_exists))
+ return false;
+
+ /* If there is already an event registered with the given name, then the function fails. */
+ if (name_exists) {
+ controller_log(DLOG_WARN, "Custom event '%s' already registered.", event_name);
+ return false;
+ }
+
+ /* Otherwise new event's information structure is created. */
+ if (!model_create_custom_event_info(event_name, ev_info))
+ return false;
+
+ /* Finally, the event's callback function is assigned, to be invoked when the event occurs. */
+ if (!model_add_custom_event_handler(*ev_info, __custom_event_cb, (void *)(*ev_info)))
+ return false;
+
+ controller_log(DLOG_INFO, "Custom event registered: '%s'.", (*ev_info)->name);
+
+ return true;
+}
+</pre>
+
<h3 id="app-finit">Application termination</h3>
<h3 id="ev-system">System events</h3>
</script>
</body>
-</html>
\ No newline at end of file
+</html>