[screen reader] Code refactoring - 006 - screen_reader_system 38/89738/1
authorm.detko <m.detko@samsung.com>
Tue, 6 Sep 2016 07:47:13 +0000 (09:47 +0200)
committerm.detko <m.detko@samsung.com>
Mon, 26 Sep 2016 08:46:05 +0000 (10:46 +0200)
Change-Id: Ib8812149103c35d0436e9559b36af32f6742d4da

include/keyboard_tracker.h
include/screen_reader.h
include/screen_reader_system.h
src/main.c
src/navigator.c
src/screen_reader.c
src/screen_reader_system.c

index 8ed21a54471b56674ebb28bb34e2346e2c952e08..dda26079ac1c9932bf5265966b05e0faa2d242dd 100644 (file)
@@ -1,6 +1,7 @@
 /**
  * @brief Supported Keys
  */
+
 enum _Key
 {
    KEY_LEFT,
index 438e0e69f27e28011b2466497db80a160434073f..ae56c9a521df8f4499a4e2e61a1bb7b0d5543db7 100644 (file)
@@ -48,10 +48,13 @@ typedef struct _Gestures_Config Gestures_Config;
 
 typedef struct _Cover Cover;
 
+typedef struct Screen_Reader_System_Data_s Screen_Reader_System_Data_t;
+
 typedef struct _Service_Data
 {
        Navigator_Data *navigator_data;
        Flat_Navi_Context *flat_navi_context;
+       Screen_Reader_System_Data_t *system_data;
 
        //Set by vconf
        bool run_service;
index c2031a6d60d9bbb3bac63be2197ef55ce1788257..d8964cd6af1b95687ef6c175739e98045766d722 100644 (file)
@@ -1,11 +1,16 @@
+#ifndef SCREEN_READER_SYSTEM_H_
+#define SCREEN_READER_SYSTEM_H_
+
 #ifndef SCREEN_READER_TV
-void system_notifications_init(void);
-void system_notifications_shutdown(void);
+Screen_Reader_System_Data_t *system_notifications_init(Service_Data *service_data);
+void system_notifications_shutdown(Screen_Reader_System_Data_t *system_data);
 
-void device_time_get(void);
-void device_battery_get(void);
-void device_signal_strenght_get(void);
-void device_missed_events_get(void);
-void device_date_get(void);
-void device_bluetooth_get(void);
+void device_time_get(Service_Data *service_data);
+void device_battery_get(Service_Data *service_data);
+void device_signal_strenght_get(Service_Data *service_data);
+void device_missed_events_get(Service_Data *service_data);
+void device_date_get(Service_Data *service_data);
+void device_bluetooth_get(Service_Data *service_data);
 #endif
+
+#endif // _SCREEN_READER_SYSTEM_H_
index 766234d67bbbdc9f6fd419cce7cad6bc3f8886a3..5059332324e3986bc9d8f0b68994c7388eb9028e 100644 (file)
@@ -265,7 +265,7 @@ static int app_terminate(void *data)
        keyboard_tracker_shutdown();
 #endif
        DEBUG("terminate service");
-       screen_reader_terminate_service(data);
+       screen_reader_terminate_service(sd);
        DEBUG("clear ScreenReaderEnabled property");
        screen_reader_switch_enabled_set(EINA_FALSE);
        screen_reader_switch_wm_enabled_set(EINA_FALSE);
index c8287c18cad25aea1ae2fa649ff32ecd261b73a8..6c7a637daf607016ed68de462b3d034e229ebe91 100644 (file)
@@ -71,7 +71,7 @@
      error = NULL;\
    }
 
-static void on_window_activate(void *data, AtspiAccessible * window);
+static void on_window_activate(void *data, AtspiAccessible *window);
 static void _highlight_on_slider(Eina_Bool is_slider);
 
 typedef struct {
@@ -1925,17 +1925,17 @@ static void _widget_scroll(Navigator_Data *nd, Flat_Navi_Context *context, Gestu
 }
 
 #ifndef SCREEN_READER_TV
-static void _read_quickpanel(void)
+static void _read_quickpanel(Service_Data *service_data)
 {
        DEBUG("START");
 
-       device_time_get();
-       device_battery_get();
-       device_bluetooth_get();
-       device_signal_strenght_get();
+       device_time_get(service_data);
+       device_battery_get(service_data);
+       device_bluetooth_get(service_data);
+       device_signal_strenght_get(service_data);
 
-       device_date_get();
-       device_missed_events_get();
+       device_date_get(service_data);
+       device_missed_events_get(service_data);
        if (sound_feedback)
                smart_notification(CONTEXTUAL_MENU_NOTIFICATION_EVENT, 0, 0);
        DEBUG("END");
@@ -2619,7 +2619,7 @@ static void on_gesture_detected(void *data, const Eldbus_Message *msg)
                                return;
                        nd->last_hover_event_time = info->state != 1 ? -1 : info->event_time;
 #if defined(ELM_ACCESS_KEYBOARD) && defined(X11_ENABLED)
-                       keyboard_win = top_window_get(info->x_end, info->y_end, NULL);  //TODO: pass screen_reader_gestures context instead of NULL
+                       keyboard_win = top_window_get(info->x_end, info->y_end, sd->screen_reader_gestures_ctx);        //TODO: pass screen_reader_gestures context instead of NULL
                        if (keyboard_win && ecore_x_e_virtual_keyboard_get(keyboard_win)) {
                                elm_access_adaptor_emit_read(keyboard_win, info->x_end, info->y_end);
                                break;
@@ -2670,7 +2670,7 @@ static void on_gesture_detected(void *data, const Eldbus_Message *msg)
                break;
        case ONE_FINGER_SINGLE_TAP:
 #if defined(ELM_ACCESS_KEYBOARD) && defined(X11_ENABLED)
-               keyboard_win = top_window_get(info->x_end, info->y_end, NULL);          //TODO: pass screen_reader_gestures context instead of NULL
+               keyboard_win = top_window_get(info->x_end, info->y_end, sd->screen_reader_gestures_ctx);                //TODO: pass screen_reader_gestures context instead of NULL
                if (keyboard_win && ecore_x_e_virtual_keyboard_get(keyboard_win)) {
                        elm_access_adaptor_emit_read(keyboard_win, info->x_end, info->y_end);
                        break;
@@ -2688,7 +2688,7 @@ static void on_gesture_detected(void *data, const Eldbus_Message *msg)
                break;
        case ONE_FINGER_DOUBLE_TAP:
 #if defined(ELM_ACCESS_KEYBOARD) && defined(X11_ENABLED)
-               keyboard_win = top_window_get(info->x_end, info->y_end, NULL);          //TODO: pass screen_reader_gestures context instead of NULL
+               keyboard_win = top_window_get(info->x_end, info->y_end, sd->screen_reader_gestures_ctx);                //TODO: pass screen_reader_gestures context instead of NULL
                if (keyboard_win && ecore_x_e_virtual_keyboard_get(keyboard_win)) {
                        elm_access_adaptor_emit_activate(keyboard_win, info->x_end, info->y_end);
                        break;
@@ -2711,7 +2711,7 @@ static void on_gesture_detected(void *data, const Eldbus_Message *msg)
                break;
        case TWO_FINGERS_TRIPLE_TAP:
 #ifndef SCREEN_READER_TV
-               _read_quickpanel();
+               _read_quickpanel(sd);
 #endif
                break;
        case THREE_FINGERS_SINGLE_TAP:
@@ -2887,7 +2887,7 @@ static AtspiAccessible *_get_modal_descendant(AtspiAccessible * root)
        return ret;
 }
 
-static void on_window_activate(void *data, AtspiAccessible * window)
+static void on_window_activate(void *data, AtspiAccessible *window)
 {
        DEBUG("START");
 
@@ -2982,7 +2982,7 @@ Navigator_Data *navigator_init(Service_Data *sd)
        window_tracker_active_window_request();
        smart_notification_init();
 #ifndef SCREEN_READER_TV
-       system_notifications_init();
+       sd->system_data = system_notifications_init(sd);
 #endif
 
        return nd;
@@ -3019,7 +3019,8 @@ void navigator_shutdown(Service_Data *sd)
        window_tracker_shutdown();
        smart_notification_shutdown();
 #ifndef SCREEN_READER_TV
-       system_notifications_shutdown();
+       system_notifications_shutdown(sd->system_data);
+       sd->system_data = NULL;
 #endif
 
        free(sd->navigator_data);
index 861c634bd929f473fae133fcf42ebb9e55afa833..8bd3df629a345f451512cdc5f499752203f07280 100644 (file)
@@ -37,6 +37,7 @@ Service_Data service_data = {
        .app_tracker_ctx = NULL,
        .reading_adapter_data = NULL,
        .gesture_adapter_data = NULL,
+       .system_data = NULL,
 
        //Set by vconf
        .run_service = 1,
index b3a457bb550bb0f58989fede2833c92404d69927..ed86bd84301c370e4d4a211bc17e2883aa5dc05f 100644 (file)
 #define MAX_SIM_COUNT 2
 #define DATE_TIME_BUFFER_SIZE 26
 
-TapiHandle *tapi_handle[MAX_SIM_COUNT + 1] = { 0, };
+struct Screen_Reader_System_Data_s {
+       TapiHandle *tapi_handle[MAX_SIM_COUNT + 1];
+};
 
 static void device_system_cb(device_callback_e type, void *value, void *user_data);
 
-static void tapi_init(void)
+static void tapi_init(Screen_Reader_System_Data_t *system_data)
 {
        int i = 0;
        char **cp_list = tel_get_cp_name_list();
@@ -53,27 +55,33 @@ static void tapi_init(void)
 
        DEBUG("TAPI INIT");
        for (i = 0; cp_list[i]; ++i) {
-               tapi_handle[i] = tel_init(cp_list[i]);
+               system_data->tapi_handle[i] = tel_init(cp_list[i]);
                DEBUG("CP_LIST %d = %s", i, cp_list[i]);
        }
-
 }
 
 /**
  * @brief Initializer for smart notifications
  *
  */
-void system_notifications_init(void)
+Screen_Reader_System_Data_t *system_notifications_init(Service_Data *service_data)
 {
        DEBUG("******************** START ********************");
+
        int ret = -1;
+       Screen_Reader_System_Data_t *system_data = malloc(sizeof(Screen_Reader_System_Data_t));
+
+       if (!system_data) {
+               ERROR("malloc(%d) failed", sizeof(Screen_Reader_System_Data_t));
+               return NULL;
+       }
 
        // BATTERY LOW/FULL
-       device_add_callback(DEVICE_CALLBACK_BATTERY_LEVEL, device_system_cb, NULL);
+       device_add_callback(DEVICE_CALLBACK_BATTERY_LEVEL, device_system_cb, service_data);
        // BATTERY CHARGING/NOT-CHARGING
-       device_add_callback(DEVICE_CALLBACK_BATTERY_CHARGING, device_system_cb, NULL);
+       device_add_callback(DEVICE_CALLBACK_BATTERY_CHARGING, device_system_cb, service_data);
        // SCREEN OFF/ON
-       device_add_callback(DEVICE_CALLBACK_DISPLAY_STATE, device_system_cb, NULL);
+       device_add_callback(DEVICE_CALLBACK_DISPLAY_STATE, device_system_cb, service_data);
 
        ret = bt_initialize();
        if (ret != BT_ERROR_NONE) {
@@ -85,19 +93,24 @@ void system_notifications_init(void)
                ERROR("ret == %d", ret);
        }
 
-       tapi_init();
+       tapi_init(system_data);
 
        DEBUG(" ********************* END ********************* ");
+
+       return system_data;
 }
 
 /**
  * @brief Initializer for smart notifications
  *
  */
-void system_notifications_shutdown(void)
+void system_notifications_shutdown(Screen_Reader_System_Data_t *system_data)
 {
        int ret = -1;
 
+       if (system_data)
+               free(system_data);
+
        // BATTERY LOW/FULL
        device_remove_callback(DEVICE_CALLBACK_BATTERY_LEVEL, device_system_cb);
        // BATTERY CHARGING/NOT-CHARGING
@@ -126,8 +139,16 @@ void system_notifications_shutdown(void)
  */
 static void device_system_cb(device_callback_e type, void *value, void *user_data)
 {
+       if (!user_data) {
+               ERROR("Invalid parameter");
+               return;
+       }
+
+       Service_Data *service_data = (Service_Data *)user_data;
+
        if (type == DEVICE_CALLBACK_BATTERY_LEVEL) {
                device_battery_level_e status;
+
                if (device_battery_get_level_status(&status)) {
                        ERROR("Cannot get battery level status");
                        return;
@@ -142,6 +163,7 @@ static void device_system_cb(device_callback_e type, void *value, void *user_dat
                }
        } else if (type == DEVICE_CALLBACK_BATTERY_CHARGING) {
                bool charging;
+
                if (device_battery_is_charging(&charging)) {
                        ERROR("Cannot check if battery is charging");
                        return;
@@ -151,6 +173,7 @@ static void device_system_cb(device_callback_e type, void *value, void *user_dat
                        tts_speak(_("IDS_SYSTEM_NOT_CHARGING"), EINA_FALSE);
        } else if (type == DEVICE_CALLBACK_DISPLAY_STATE) {
                display_state_e state;
+
                if (device_display_get_state(&state)) {
                        ERROR("Cannot check if battery is charging");
                        return;
@@ -180,7 +203,7 @@ static int _read_text_get(char *key)
        return read_text;
 }
 
-void device_time_get(void)
+void device_time_get(Service_Data *service_data)
 {
        char buffer[DATE_TIME_BUFFER_SIZE];
        int disp_12_24 = VCONFKEY_TIME_FORMAT_12;
@@ -255,7 +278,7 @@ char *device_error_to_string(int e)
        }
 }
 
-void device_battery_get(void)
+void device_battery_get(Service_Data *service_data)
 {
        char *buffer = NULL;
        char *charging_text = NULL;
@@ -316,7 +339,7 @@ void device_battery_get(void)
        free(buffer);
 }
 
-static void _signal_strength_sim_get(void)
+static void _signal_strength_sim_get(Service_Data *service_data)
 {
        int i = 0;
        int val = 0;
@@ -326,15 +349,21 @@ static void _signal_strength_sim_get(void)
        char *buffer = NULL;
        int service_type = TAPI_NETWORK_SERVICE_TYPE_UNKNOWN;
        char *service_type_text = NULL;
+       Screen_Reader_System_Data_t *system_data = service_data->system_data;
+
+       if (!system_data) {
+               ERROR("system data is null");
+               return;
+       }
 
        str_buf = eina_strbuf_new();
 
-       for (i = 0; tapi_handle[i]; ++i) {
+       for (i = 0; system_data->tapi_handle[i]; ++i) {
                ++sim_card_count;
        }
 
-       for (i = 0; tapi_handle[i]; ++i) {
-               ret = tel_get_property_int(tapi_handle[i], TAPI_PROP_NETWORK_SIGNALSTRENGTH_LEVEL, &val);
+       for (i = 0; system_data->tapi_handle[i]; ++i) {
+               ret = tel_get_property_int(system_data->tapi_handle[i], TAPI_PROP_NETWORK_SIGNALSTRENGTH_LEVEL, &val);
                if (ret != TAPI_API_SUCCESS) {
                        ERROR("Can not get %s", TAPI_PROP_NETWORK_SIGNALSTRENGTH_LEVEL);
                        val = 0;
@@ -346,7 +375,7 @@ static void _signal_strength_sim_get(void)
                        eina_strbuf_append_printf(str_buf, "%s %d; ", _("IDS_SYSTEM_SIGNAL_STRENGTH"), val);
                DEBUG("sim: %d TAPI_PROP_NETWORK_SIGNALSTRENGTH_LEVEL %d", i, val);
 
-               ret = tel_get_property_int(tapi_handle[i], TAPI_PROP_NETWORK_SERVICE_TYPE, &service_type);
+               ret = tel_get_property_int(system_data->tapi_handle[i], TAPI_PROP_NETWORK_SERVICE_TYPE, &service_type);
                if (ret != TAPI_API_SUCCESS) {
                        ERROR("Can not get %s", TAPI_PROP_NETWORK_SERVICE_TYPE);
                }
@@ -400,12 +429,11 @@ static void _signal_strength_sim_get(void)
 
        DEBUG("Text to say: %s", buffer);
        tts_speak(buffer, EINA_FALSE);
-
        eina_strbuf_string_free(str_buf);
        free(buffer);
 }
 
-static void _signal_strength_wifi_get(void)
+static void _signal_strength_wifi_get(Service_Data *service_data)
 {
        int val = 0;
        int ret = -1;
@@ -487,16 +515,17 @@ static void _signal_strength_wifi_get(void)
        }
 }
 
-void device_signal_strenght_get(void)
+void device_signal_strenght_get(Service_Data *service_data)
 {
        if (!_read_text_get(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_SIGNAL_STRENGHT)) {
                return;
        }
-       _signal_strength_sim_get();
-       _signal_strength_wifi_get();
+
+       _signal_strength_sim_get(service_data);
+       _signal_strength_wifi_get(service_data);
 }
 
-void device_missed_events_get(void)
+void device_missed_events_get(Service_Data *service_data)
 {
        notification_list_h list = NULL;
        notification_list_h elem = NULL;
@@ -558,7 +587,7 @@ void device_missed_events_get(void)
        }
 }
 
-void device_date_get(void)
+void device_date_get(Service_Data *service_data)
 {
        char buffer[DATE_TIME_BUFFER_SIZE];
        int date_format = SETTING_DATE_FORMAT_DD_MM_YYYY;
@@ -626,7 +655,7 @@ static bool bonded_device_get_cb(bt_device_info_s * device_info, void *user_data
        return false;
 }
 
-void device_bluetooth_get(void)
+void device_bluetooth_get(Service_Data *service_data)
 {
        char *buffer = NULL;
        int device_count = 0;
@@ -637,6 +666,7 @@ void device_bluetooth_get(void)
 
        bt_adapter_state_e adapter_state = BT_ADAPTER_DISABLED;
        int ret = bt_adapter_get_state(&adapter_state);
+
        if (ret != BT_ERROR_NONE) {
                ERROR("ret == %d", ret);
                return;