From: Michal Pawluk Date: Tue, 29 Dec 2015 13:37:59 +0000 (+0100) Subject: [SAMPLE APP][Bluetooth LE Collector] Initialization section added X-Git-Tag: tizen_3.0/TD_SYNC/20161201~210^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=28b0b2abb4cacf3d502ab14773fc94233756cecb;p=sdk%2Fonline-doc.git [SAMPLE APP][Bluetooth LE Collector] Initialization section added Change-Id: Ib74d490db604a6994fac80fd965dd2bd66f55d14 Signed-off-by: Michal Pawluk --- diff --git a/org.tizen.sampledescriptions/html/mobile_n/bluetooth_le_collector_sd_mn.htm b/org.tizen.sampledescriptions/html/mobile_n/bluetooth_le_collector_sd_mn.htm index 943c4cc..d8ef4c7 100644 --- a/org.tizen.sampledescriptions/html/mobile_n/bluetooth_le_collector_sd_mn.htm +++ b/org.tizen.sampledescriptions/html/mobile_n/bluetooth_le_collector_sd_mn.htm @@ -75,6 +75,129 @@ The first 4 features are delivered to the user via the UI (http://tizen.org/privilege/bluetooth privilege must be set.

+

Implementation

+ +

+The entire application's workflow is described in subsections below. +

+ +

Application's initialization and termination

+ +

+The application is initialized on application's startup with controller_create() function invoked from the +create callback assigned in the main() function. +

+ +
+bool controller_create(viewdata_s *vd)
+{
+   vd->scan_start_cb = __scan_start_request_cb;
+   vd->scan_cancel_cb = __scan_cancel_request_cb;
+   vd->peer_select_cb = __peer_select_request_cb;
+
+   if (!view_main_create(vd))
+      return false;
+
+   if (__is_feature_supported(FEATURE_BLUETOOTH)) {
+      if (__is_feature_supported(FEATURE_BLUETOOTH_LE)) {
+         if (!__init()) {
+            __set_state(VS_DEACTIVE);
+            view_main_display_message("Bluetooth activation error.");
+         }
+      } else {
+         view_main_display_message("Bluetooth Low Energy is not supported.");
+      }
+   } else {
+      view_main_display_message("Bluetooth is not supported.");
+   }
+
+   return true;
+}
+
+ +

+At the beginning, the following callback functions responsible for handling requests from the UI are assigned: +

    +
  • __scan_start_request_cb() - starts Bluetooth LE network scanning; is called on "Scan" button tap;
  • +
  • __scan_cancel_request_cb() - cancels Bluetooth LE network scanning; is called on "Cancel" button tap;
  • +
  • __peer_select_request_cb() - selects the advertiser's device for its detailed information acquisition; + is called on remote device selection from the list of available advertisers.
  • +
+Next, the application's main view is created with view_main_create() function which is not described here as it is not the subject of this +document. Afterwards, the availability of Bluetooth and Bluetooth LE features is checked using __is_feature_supported() function with +http://tizen.org/feature/network.bluetooth and +http://tizen.org/feature/network.bluetooth.le arguments, respectively. If the Bluetooth related features' verification is passed, +the Bluetooth adapter is initialized with the __init() function. Otherwise, an appropriate error message is displayed and the UI is updated +with __set_state() function. +

+ +
+static bool __init(void)
+{
+   bool is_enabled = false;
+
+   if (bt_init()) {
+      bt_set_callbacks(__bt_device_state_changed_cb, NULL);
+
+      bt_get_state(&is_enabled);
+      if (is_enabled)
+         __set_state(VS_ACTIVE);
+   }
+
+   return true;
+}
+
+ +

+The __init() function initializes the Bluetooth adapter and sets +__bt_device_state_changed_cb() callback function for its state change handling (updating the UI to reflect the current adapter's state). +Finally, the Bluetooth adapter's state is verified with bt_get_state() function to acknowledge its successful initialization. +At the end, the UI is updated with the __set_state() function. +

+ +

+At the end of the application's lifecycle, the controller_terminate() function is invoked from the +terminate callback assigned in the main() function. +

+ +
+void controller_terminate(viewdata_s *vd)
+{
+   bt_unset_callbacks();
+   bt_deinit();
+   view_main_destroy(vd);
+   model_free();
+}
+
+ +

+The application's termination procedure is very simple and relies on Bluetooth adapter deinitialization (bt_deinit()), allocated +resources cleaning (bt_unset_callbacks(), model_free()) +and view destroying (view_main_destroy()). +

+ +

+For undescribed function's reference, see the Reference section. +

+ + + +