From 28b0b2abb4cacf3d502ab14773fc94233756cecb Mon Sep 17 00:00:00 2001
From: Michal Pawluk
+The entire application's workflow is described in subsections below. +
+ ++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: +
+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. +
+ + + + -- 2.7.4