[screen reader] Code refactoring - 012 - smart notification 16/90116/1
authorLukasz Wlazly <l.wlazly@partner.samsung.com>
Mon, 5 Sep 2016 14:59:08 +0000 (16:59 +0200)
committerm.detko <m.detko@samsung.com>
Mon, 26 Sep 2016 15:10:20 +0000 (17:10 +0200)
Change-Id: I292b8dde1a59468bb05005913b1f6e6d4db14bfd

include/screen_reader.h
include/smart_notification.h
src/navigator.c
src/smart_notification.c
tests/smart_navi_suite.c

index c95f2e8f6139a0e0d9c49dd3809b299d8ef236e9..cb5ac3e686b47203b93ee10f61bf1c58b6959433 100644 (file)
@@ -60,6 +60,8 @@ typedef struct Screen_Reader_Vconf_Data_s Screen_Reader_Vconf_Data_t;
 
 typedef struct _Keyboard_Tracker_Data Keyboard_Tracker_Data;
 
+typedef struct _Smart_Notification_Data Smart_Notification_Data;
+
 typedef struct _Service_Data
 {
        Navigator_Data *navigator_data;
@@ -69,6 +71,7 @@ typedef struct _Service_Data
        Keyboard_Tracker_Data* keyboard_tracker_data;
        Window_Tracker_Data *window_tracker_data;
        Screen_Reader_Spi_Data_t *spi_data;
+       Smart_Notification_Data *smart_notification_data;
 
        //Set by vconf
        bool run_service;
index 6cdc85e672559f524dc1884a62e0289c03a4ac4d..753a98c2ef1100d55105285617b90762b7c8b24d 100644 (file)
@@ -1,5 +1,7 @@
 #ifndef SMART_NOTIFICATION_H_
 #define SMART_NOTIFICATION_H_
+#include <Ecore.h>
+#include "screen_reader.h"
 
 /**
  * @brief Type of notification events.
@@ -24,6 +26,10 @@ enum _Notification_Type
 
 typedef enum _Notification_Type Notification_Type;
 
+struct _Smart_Notification_Data{
+       Eina_Bool status;
+};
+
 /**
  * @brief Initializes notification submodule.
  *
@@ -39,12 +45,14 @@ typedef enum _Notification_Type Notification_Type;
  *    chain.
  * 4. After scrolling lists, some of item becomes visible
  *
- * @nore
+ * @return internal data struct object
+ *
+ * @note
  * 1 and 2 are handled internally by smart navigation submodule.
  * about events 3 and 4 submodule has to be informed by the developer
  * by using smart_notification API.
  */
-void smart_notification_init(void);
+Smart_Notification_Data *smart_notification_init();
 
 /**
  * @brief Notifies smart_notification about UI event.
@@ -63,7 +71,9 @@ void smart_notification(Notification_Type nt, int start_index, int end_index);
 
 /**
  * @brief Shutdowns notification subsystem.
+ *
+ * @param snd internal data struct
  */
-void smart_notification_shutdown(void);
+void smart_notification_shutdown(Smart_Notification_Data *snd);
 
 #endif /* end of include guard: SMART_NOTIFICATION_H_ */
index eabd0e28d3a4ab180fb3af3c587e3d5c4f7c9dfc..2d1dbe7b6714a56669577c4d00a2beae2f226b88 100644 (file)
@@ -275,7 +275,7 @@ static void _send_highlighted_object_info(AtspiAccessible * obj)
 
 }
 
-static void display_info_about_object(AtspiAccessible * obj, bool display_parent_info)
+static void display_info_about_object(AtspiAccessible *obj, bool display_parent_info)
 {
        if(!obj)
        {
@@ -331,7 +331,7 @@ static void display_info_about_object(AtspiAccessible * obj, bool display_parent
        DEBUG("INTERFACES:");
        GArray *ifaces = atspi_accessible_get_interfaces(obj);
        for (a = 0; ifaces && (a < ifaces->len); ++a) {
-               gchar * interface_name = g_array_index(ifaces, gchar *, a);
+               gchar *interface_name = g_array_index(ifaces, gchar *, a);
                DEBUG("   %s", interface_name);
                g_free(interface_name);
        }
@@ -345,7 +345,7 @@ static void display_info_about_object(AtspiAccessible * obj, bool display_parent
        g_free(description);
 }
 
-char *generate_description_for_subtrees(AtspiAccessible * obj)
+char *generate_description_for_subtrees(AtspiAccessible *obj)
 {
        DEBUG("START");
 
@@ -400,7 +400,7 @@ char *generate_description_for_subtrees(AtspiAccessible * obj)
         */
 }
 
-static int _check_list_children_count(AtspiAccessible * obj)
+static int _check_list_children_count(AtspiAccessible *obj)
 {
        int list_count = 0;
        int i;
@@ -423,7 +423,7 @@ static int _check_list_children_count(AtspiAccessible * obj)
        return list_count;
 }
 
-static int _find_popup_list_children_count(AtspiAccessible * obj)
+static int _find_popup_list_children_count(AtspiAccessible *obj)
 {
        int list_items_count = 0;
        int children_count = atspi_accessible_get_child_count(obj, NULL);
@@ -445,7 +445,7 @@ static int _find_popup_list_children_count(AtspiAccessible * obj)
        return 0;
 }
 
-static bool _widget_has_state(AtspiAccessible * obj, AtspiStateType type)
+static bool _widget_has_state(AtspiAccessible *obj, AtspiStateType type)
 {
        Eina_Bool ret = EINA_FALSE;
        AtspiStateSet *st = atspi_accessible_get_state_set(obj);
@@ -503,7 +503,7 @@ void add_slider_description(char *dest, uint dest_size, AtspiAccessible *obj)
        g_object_unref(value_iface);
 }
 
-char *generate_trait(AtspiAccessible * obj)
+char *generate_trait(AtspiAccessible *obj)
 {
        if (!obj)
                return strdup("");
@@ -533,7 +533,7 @@ char *generate_trait(AtspiAccessible * obj)
                if (parent_role == ATSPI_ROLE_TOOL_BAR) {
                        int children_count = atspi_accessible_get_child_count(parent, NULL);
                        int index = atspi_accessible_get_index_in_parent(obj, NULL);
-                       AtspiSelectionselection = atspi_accessible_get_selection_iface(parent);
+                       AtspiSelection *selection = atspi_accessible_get_selection_iface(parent);
                        gboolean is_selected = atspi_selection_is_child_selected(selection, index, &err);
                        GERROR_CHECK(err);
                        char tab_index[MENU_ITEM_TAB_INDEX_SIZE];
@@ -772,7 +772,7 @@ char *generate_trait(AtspiAccessible * obj)
        return strdup(ret);
 }
 
-char *generate_text_for_relation_objects(AtspiAccessible * obj, AtspiRelationType search, char *(*text_generate_cb)(AtspiAccessible *obj))
+char *generate_text_for_relation_objects(AtspiAccessible *obj, AtspiRelationType search, char *(*text_generate_cb)(AtspiAccessible *obj))
 {
        GError *err = NULL;
        GArray *relations;
@@ -1170,7 +1170,7 @@ static void _current_highlight_object_set(Navigator_Data *nd, Screen_Reader_Vcon
        DEBUG("END");
 }
 
-void test_debug(AtspiAccessible * current_widget)
+void test_debug(AtspiAccessible *current_widget)
 {
        int jdx;
        int count_child;
@@ -1688,7 +1688,6 @@ static void _activate_widget(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vco
        if(relation)
                g_object_unref(relation);
        g_object_unref(ss);
-
 }
 
 static void _quickpanel_change_state(gboolean quickpanel_switch)
@@ -2294,7 +2293,7 @@ static Eina_Bool _is_active_entry(Flat_Navi_Context *context)
        return EINA_FALSE;
 }
 
-static Eina_Bool _is_slider(AtspiAccessible * obj)
+static Eina_Bool _is_slider(AtspiAccessible *obj)
 {
        DEBUG("START");
 
@@ -2473,7 +2472,7 @@ AtspiAction *_get_main_window(Flat_Navi_Context *context)
        return action;
 }
 
-static int _find_action_index(AtspiAction * action, char *action_name_to_find)
+static int _find_action_index(AtspiAction *action, char *action_name_to_find)
 {
        int action_num = atspi_action_get_n_actions(action, NULL);
        char *action_name = NULL;
@@ -2864,7 +2863,7 @@ void clear(gpointer d)
        g_object_unref(obj);
 }
 
-static AtspiAccessible *_get_modal_descendant(AtspiAccessible * root)
+static AtspiAccessible *_get_modal_descendant(AtspiAccessible *root)
 {
        GError *err = NULL;
        AtspiStateSet *states = atspi_state_set_new(NULL);
@@ -2978,12 +2977,17 @@ Navigator_Data *navigator_init(Service_Data *sd)
        navigator_gestures_tracker_register(on_gesture_detected, sd);
        // register on active_window
        sd->gesture_adapter_data = dbus_gesture_adapter_init();
-       app_tracker_init();
+       sd->app_tracker_ctx = app_tracker_init();
        app_tracker_new_obj_highlighted_callback_register(_new_highlighted_obj_changed, sd->app_tracker_ctx);
        sd->window_tracker_data = window_tracker_init();
        window_tracker_register(sd->window_tracker_data, on_window_activate, sd);
        window_tracker_active_window_request(sd->window_tracker_data);
-       smart_notification_init();
+       sd->smart_notification_data = smart_notification_init();
+       if (sd->smart_notification_data == NULL){
+               ERROR("Smart Notification not initialized");
+               return NULL;
+       }
+
 #ifndef SCREEN_READER_TV
        sd->system_data = system_notifications_init(sd);
 #endif
@@ -3015,12 +3019,11 @@ void navigator_shutdown(Service_Data *sd)
        if (sd->flat_navi_context != NULL) {
                flat_navi_context_free(sd->flat_navi_context);
        }
-       dbus_gesture_adapter_shutdown(sd->gesture_adapter_data);
-       //app_tracker_shutdown(sd->app_tracker_ctx);
 
+       dbus_gesture_adapter_shutdown(sd->gesture_adapter_data);
        app_tracker_shutdown(sd->app_tracker_ctx);
        window_tracker_shutdown(sd->window_tracker_data);
-       smart_notification_shutdown();
+       smart_notification_shutdown(sd->smart_notification_data);
 #ifndef SCREEN_READER_TV
        system_notifications_shutdown(sd->system_data);
        sd->system_data = NULL;
index 821f0eb7940d6856f4a2f4b78162321ade7c5877..7c681c9334747de4868699bbd34ada993e2d4ed8 100644 (file)
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include <Ecore.h>
+
 #include <Ecore_Evas.h>
 #include <Evas.h>
 #include <atspi/atspi.h>
 #define RED  "\x1B[31m"
 #define RESET "\033[0m"
 
-static Eina_Bool status = EINA_FALSE;
-
-static void _smart_notification_focus_chain_end(void);
-static void _smart_notification_realized_items(int start_idx, int end_idx);
-static void _smart_notification_highlight(void);
-static void _smart_notification_highlight_actionable(void);
-static void _smart_notification_action(void);
-static void _smart_notification_contextual_menu(void);
-static void _smart_notification_long_press(void);
-static void _smart_notification_state_change(void);
+static void _handle_focus_chain_end(void);
+static void _handle_realized_items(int start_idx, int end_idx);
+static void _handle_highlight(void);
+static void _handle_highlight_actionable(void);
+static void _handle_action(void);
+static void _handle_contextual_menu(void);
+static void _handle_long_press(void);
+static void _handle_state_change(void);
 
 static void
 _playback_completed_cb(int id, void *user_data)
 {
-       const charpath = (const char*)user_data;
+       const char *path = (const char*)user_data;
        DEBUG("WAV Player", "Completed! [id:%d, path:%s]", id, path);
 }
 
@@ -55,44 +53,55 @@ static char *_get_sound_path(const char *file_path)
        DEBUG("path: (%s)", path);
        return path;
 }
-/**
- * @brief Smart Notifications event handler
- *
- * @param nt Notification event type
- * @param start_index int first visible items index smart_notification_realized_items
- * @param end_index int last visible items index used for smart_notification_realized_items
- */
+
 void smart_notification(Notification_Type nt, int start_index, int end_index)
 {
        DEBUG("START");
-       if (!status)
+       Service_Data *sd = get_pointer_to_service_data_struct();
+
+       if (sd == NULL || sd->smart_notification_data == NULL) {
+               ERROR("NULL context");
                return;
+       }
+
+       if (sd->smart_notification_data->status == EINA_FALSE) {
+               ERROR("smart_notification disabled");
+               return;
+       }
 
        switch (nt) {
        case FOCUS_CHAIN_END_NOTIFICATION_EVENT:
-               _smart_notification_focus_chain_end();
+               _handle_focus_chain_end();
                break;
+
        case REALIZED_ITEMS_NOTIFICATION_EVENT:
-               _smart_notification_realized_items(start_index, end_index);
+               _handle_realized_items(start_index, end_index);
                break;
+
        case HIGHLIGHT_NOTIFICATION_EVENT:
-               _smart_notification_highlight();
+               _handle_highlight();
                break;
+
        case HIGHLIGHT_NOTIFICATION_EVENT_ACTIONABLE:
-               _smart_notification_highlight_actionable();
+               _handle_highlight_actionable();
                break;
+
        case ACTION_NOTIFICATION_EVENT:
-               _smart_notification_action();
+               _handle_action();
                break;
+
        case CONTEXTUAL_MENU_NOTIFICATION_EVENT:
-               _smart_notification_contextual_menu();
+               _handle_contextual_menu();
                break;
+
        case LONG_PRESS_NOTIFICATION_EVENT:
-               _smart_notification_long_press();
+               _handle_long_press();
                break;
+
        case WINDOW_STATE_CHANGE_NOTIFICATION_EVENT:
-               _smart_notification_state_change();
+               _handle_state_change();
                break;
+
        default:
                DEBUG("Gesture type %d not handled in switch", nt);
        }
@@ -105,7 +114,7 @@ void smart_notification(Notification_Type nt, int start_index, int end_index)
  * @param start_index int first visible items index smart_notification_realized_items
  * @param end_index int last visible items index used for smart_notification_realized_items
  */
-void get_realized_items_count(AtspiAccessible * scrollable_object, int *start_idx, int *end_idx)
+void get_realized_items_count(AtspiAccessible *scrollable_object, int *start_idx, int *end_idx)
 {
        DEBUG("START");
        int count_child, jdx;
@@ -143,9 +152,11 @@ void get_realized_items_count(AtspiAccessible * scrollable_object, int *start_id
  * @param user_data UNUSED
  */
 
-static void _scroll_event_cb(AtspiEvent * event, gpointer user_data)
+static void _scroll_event_cb(AtspiEvent *event, gpointer user_data)
 {
-       if (!status)
+       Smart_Notification_Data *snd = (Smart_Notification_Data *)user_data;
+
+       if (snd == NULL || snd->status == EINA_FALSE)
                return;
 
        int start_index, end_index;
@@ -163,7 +174,7 @@ static void _scroll_event_cb(AtspiEvent * event, gpointer user_data)
                DEBUG("Scrolling finished");
                tts_speak_customized(_("IDS_SCROLLING_FINISHED"), EINA_FALSE, EINA_TRUE, event->source);
                get_realized_items_count((AtspiAccessible *) event->source, &start_index, &end_index);
-               _smart_notification_realized_items(start_index, end_index);
+               _handle_realized_items(start_index, end_index);
        }
 }
 
@@ -172,13 +183,27 @@ static void _scroll_event_cb(AtspiEvent * event, gpointer user_data)
  *
  *
  */
-void smart_notification_init(void)
+Smart_Notification_Data *smart_notification_init()
 {
        DEBUG("Smart Notification init!");
+       Smart_Notification_Data *snd = malloc(sizeof(Smart_Notification_Data));
+
+       if (snd == NULL) {
+               ERROR("memory not allocated");
+               return NULL;
+       }
+
+       snd->status = EINA_TRUE;
 
        AtspiEventListener *listener;
+       listener = atspi_event_listener_new(_scroll_event_cb, snd, NULL);
+
+       if (listener == NULL) {
+               ERROR("listener not created");
+               free(snd);
+               return NULL;
+       }
 
-       listener = atspi_event_listener_new(_scroll_event_cb, NULL, NULL);
        atspi_event_listener_register(listener, "object:scroll-start", NULL);
        atspi_event_listener_register(listener, "object:scroll-end", NULL);
 
@@ -186,30 +211,27 @@ void smart_notification_init(void)
        haptic_module_init();
 #endif
 
-       status = EINA_TRUE;
+       return snd;
 }
 
 /**
  * @brief Smart notifications shutdown
  *
  */
-void smart_notification_shutdown(void)
+void smart_notification_shutdown(Smart_Notification_Data *snd)
 {
 #ifndef SCREEN_READER_TV
        haptic_module_disconnect();
 #endif
-       status = EINA_FALSE;
+       free(snd);
 }
 
 /**
  * @brief Smart notifications focus chain event handler
  *
  */
-static void _smart_notification_focus_chain_end(void)
+static void _handle_focus_chain_end(void)
 {
-       if (!status)
-               return;
-
        DEBUG(RED "Smart notification - FOCUS CHAIN END" RESET);
        int wav_player_id;
        //sound to play when reached start/end not given hence using below.
@@ -224,59 +246,49 @@ static void _smart_notification_focus_chain_end(void)
  * @brief Smart notifications hightlight event handler
  *
  */
-static void _smart_notification_highlight(void)
+static void _handle_highlight(void)
 {
-       if (!status)
-               return;
        int wav_player_id;
-       gcharwav_path = _get_sound_path("focus_general.ogg");
+       gchar *wav_path = _get_sound_path("focus_general.ogg");
 
        DEBUG("Smart notification - HIGHLIGHT" RESET);
        wav_player_start(wav_path, SOUND_TYPE_MEDIA, _playback_completed_cb, (void*)wav_path, &wav_player_id);
        g_free(wav_path);
 }
 
-static void _smart_notification_highlight_actionable(void)
+static void _handle_highlight_actionable(void)
 {
-       if (!status)
-               return;
        int wav_player_id;
 
-       gcharwav_path = _get_sound_path("focus_actionable.ogg");
+       gchar *wav_path = _get_sound_path("focus_actionable.ogg");
 
        DEBUG("Smart notification - HIGHLIGHT" RESET);
        wav_player_start(wav_path, SOUND_TYPE_MEDIA, _playback_completed_cb, (void*)wav_path, &wav_player_id);
        g_free(wav_path);
 }
 
-static void _smart_notification_action(void)
+static void _handle_action(void)
 {
-       if (!status)
-               return;
        int wav_player_id;
-       gcharwav_path = _get_sound_path("clicked.ogg");
+       gchar *wav_path = _get_sound_path("clicked.ogg");
 
        DEBUG("Smart notification - ACTION" RESET);
        wav_player_start(wav_path, SOUND_TYPE_MEDIA, _playback_completed_cb, (void*)wav_path, &wav_player_id);
        g_free(wav_path);
 }
 
-static void _smart_notification_contextual_menu(void)
+static void _handle_contextual_menu(void)
 {
-       if (!status)
-               return;
        int wav_player_id;
-       gcharwav_path = _get_sound_path("contextual_menu.ogg");
+       gchar *wav_path = _get_sound_path("contextual_menu.ogg");
 
        DEBUG("Smart notification - context menu" RESET);
        wav_player_start(wav_path, SOUND_TYPE_MEDIA, _playback_completed_cb, (void*)wav_path, &wav_player_id);
        g_free(wav_path);
 }
 
-static void _smart_notification_long_press(void)
+static void _handle_long_press(void)
 {
-       if (!status)
-               return;
        int wav_player_id;
        gchar* wav_path = _get_sound_path("long_clicked.ogg");
 
@@ -285,12 +297,10 @@ static void _smart_notification_long_press(void)
        g_free(wav_path);
 }
 
-static void _smart_notification_state_change(void)
+static void _handle_state_change(void)
 {
-       if (!status)
-               return;
        int wav_player_id;
-       gcharwav_path = _get_sound_path("window_state_changed.ogg");
+       gchar *wav_path = _get_sound_path("window_state_changed.ogg");
 
        DEBUG("Smart notification - view change" RESET);
        wav_player_start(wav_path, SOUND_TYPE_MEDIA, _playback_completed_cb, (void*)wav_path, &wav_player_id);
@@ -301,11 +311,8 @@ static void _smart_notification_state_change(void)
  * @brief Smart notifications realized items event handler
  *
  */
-static void _smart_notification_realized_items(int start_idx, int end_idx)
+static void _handle_realized_items(int start_idx, int end_idx)
 {
-       if (!status)
-               return;
-
        if (start_idx == end_idx)
                return;
 
index 303082a762820876fdc1db15e726f8f7acc33c3e..6256a7666bb9d4860eacba0a48fdf9f96421fdb4 100644 (file)
@@ -56,6 +56,7 @@ static Screen_Reader_Vconf_Data_t *vconf_data;
 void setup(void)
 {
        Service_Data *data = get_pointer_to_service_data_struct();
+       data->smart_notification_data = malloc(sizeof(Smart_Notification_Data));
        data->run_service = 1;
        data->tracking_signal_name = HIGHLIGHT_CHANGED_SIG;