From: Michal Szczecinski Date: Fri, 18 Dec 2015 09:45:23 +0000 (+0100) Subject: [Files Sharing Server] Added controller description. X-Git-Tag: tizen_3.0/TD_SYNC/20161201~222^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b494bbfb3a1d5db82fc407999fdf2ceb0e279fe7;p=sdk%2Fonline-doc.git [Files Sharing Server] Added controller description. Change-Id: I374126e7d2c11e6957b02fda62050d203c482ed6 Signed-off-by: Michal Szczecinski Signed-off-by: Agnieszka Janowicz --- diff --git a/org.tizen.sampledescriptions/html/mobile_n/files_sharing_server_sd_mn.htm b/org.tizen.sampledescriptions/html/mobile_n/files_sharing_server_sd_mn.htm index 51bc906..34cbefc 100644 --- a/org.tizen.sampledescriptions/html/mobile_n/files_sharing_server_sd_mn.htm +++ b/org.tizen.sampledescriptions/html/mobile_n/files_sharing_server_sd_mn.htm @@ -29,7 +29,7 @@

The Files Sharing Server sample application demonstrates how you can use Bluetooth OPP (Object Push Profile) API to receive files from other devices.

The following figure illustrates the application view:

Figure: Main view

-

Main view +

Main view

Prerequisites

@@ -52,9 +52,121 @@

Sample structure

The application uses a simple MVC (Model-View-Controller) architectural pattern. The application model consists of a media and Bluetooth module.

+

Controller

+

The controller module connects the view and the model. It delivers the following set of functions:

+
+/*Function initializes all application modules and event listeners.*/
+bool controller_init_application_modules(app_data_t *ad)
+{
+   ad->vd = view_init();
+   if (!ad->vd)
+      /*Error handling.*/
+   ad->md = model_init();
+      /*Error handling*/
+   __controller_init_events(ad);
+   return true;
+}
+
+ +
+/*Event handlers are stored in an Eina_List which is used to release allocated memory on application terminate event.*/
+static void __controller_init_events(app_data_t *ad)
+{
+   ad->app_events = eina_list_append(ad->app_events,
+         ecore_event_handler_add(app_utils_get_event_type(EVENT_CONNECTION_REQUEST),
+         __controller_handle_connection_request_event, ad));
+   ad->app_events = eina_list_append(ad->app_events,
+         ecore_event_handler_add(app_utils_get_event_type(EVENT_TRANSFER_IN_PROGRESS),
+         __controller_handle_transfer_in_progress_event, ad));
+   ad->app_events = eina_list_append(ad->app_events,
+         ecore_event_handler_add(app_utils_get_event_type(EVENT_ACCEPT_BUTTON_CLICKED),
+         __controller_handle_accept_button_clicked_event, ad));
+   ad->app_events = eina_list_append(ad->app_events,
+         ecore_event_handler_add(app_utils_get_event_type(EVENT_REJECT_BUTTON_CLICKED),
+         __controller_handle_reject_button_clicked_event, ad));
+   ad->app_events = eina_list_append(ad->app_events,
+         ecore_event_handler_add(app_utils_get_event_type(EVENT_TRANSFER_STARTED),
+         __controller_handle_transfer_started_event, ad));
+}
+
+ +

The event listeners described above are used to accept a file transfer, update the sending progress and handle user interaction. When the application receives the connection request from another device, custom event defined in the app_utils.c file is emitted. Callback function invoked in that case changes the state of the accept button.

+ +
+/*Callback enables the accept button.*/
+static Eina_Bool __controller_handle_connection_request_event(void *data, int type, void *event)
+{
+   app_data_t *ad = (app_data_t *) data;
+   if (!ad)
+      /*Error handling.*/
+   view_enable_accept_button(ad->vd);
+   return EINA_TRUE;
+}
+
+ +

When the accept button is enabled, the user can press it to confirm the files transfer. The __controller_handle_accept_button_clicked_event() function listed below changes the view state and starts the exchange process.

+ +
+static Eina_Bool __controller_handle_accept_button_clicked_event(void *data, int type, void *event)
+{
+   app_data_t *ad = (app_data_t *) data;
+   bt_module_transfer_accept(ad->md);
+   view_disable_accept_button(ad->vd);
+   view_enable_reject_button(ad->vd);
+   return EINA_TRUE;
+}
+
+ +

The __controller_handle_transfer_started_event() callback function is used to create an item in the received files list. It is called when a new file transfer starts.

+ +
+static Eina_Bool __controller_handle_transfer_started_event(void *data, int type, void *event)
+{
+   Elm_Object_Item *new_item = NULL;
+   app_data_t *ad = (app_data_t *) data;
+   file_t *recv_file = (file_t *) event;
+   if (!ad || !recv_file)
+      /*Error handling*/
+   /*Adding new item into the files list.*/
+   new_item = view_append_new_file(ad->vd, recv_file->file_name, &(recv_file->progress));
+   if (!new_item)
+      /*Error handling.*/
+   /*Bind the model with the view. New item is used later to update the sending progress.*/
+   file_data_set(recv_file, (void *) new_item);
+   return EINA_TRUE;
+}
+
+ +

The __controller_handle_transfer_in_progress_event() function is used to update the sending progress for each file. It is called when the bt_module emits the signal for item update. It uses the data stored in the internal file object. + +

+static Eina_Bool __controller_handle_transfer_in_progress_event(void *data, int type, void *event)
+{
+   app_data_t *ad = (app_data_t *) data;
+   file_t *file = (file_t *) event;
+   if(!file || !ad)
+      /*Error handling*/
+   view_update_progress((Elm_Object_Item *) file->data, (double) file->progress / 100.0);
+   return EINA_TRUE;
+}
+
+ +

When transfer starts, the application enables the reject button. It can be used by the user to stop the files exchange.

+ +
+static Eina_Bool __controller_handle_reject_button_clicked_event(void *data, int type, void *event)
+{
+   app_data_t *ad = (app_data_t *) data;
+   if (!ad)
+      /*Error handling.*/
+   bt_module_transfer_reject(ad->md);
+   view_disable_reject_button(ad->vd);
+   return EINA_TRUE;
+}
+

View

+

Model

-

Controller