Dbus connection updated for sending the gestures to screen-reader. 59/66859/5
authorshashank.p <shashank.p@samsung.com>
Thu, 21 Apr 2016 13:19:13 +0000 (18:49 +0530)
committerShashank Pandey <shashank.p@samsung.com>
Mon, 2 May 2016 06:57:31 +0000 (23:57 -0700)
Change-Id: Id141e2d2e449995aa60fa7378fad7d08544e526e
Signed-off-by: shashank.p <shashank.p@samsung.com>
src/e_mod_main.c
src/e_screen_reader_gestures.c
src/e_screen_reader_private.h

index 0391537..0700256 100644 (file)
@@ -4,12 +4,21 @@
 #include <e_screen_reader_config.h>
 #include <e_screen_reader_private.h>
 
+#define E_A11Y_SERVICE_BUS_NAME "org.enlightnement.wm-screen-reader"
+#define E_A11Y_SERVICE_NAVI_IFC_NAME "org.tizen.GestureNavigation"
+#define E_A11Y_SERVICE_NAVI_OBJ_PATH "/org/tizen/GestureNavigation"
+#define E_A11Y_SERVICE_TRACKER_IFC_NAME "org.tizen.WindowTracker"
+#define E_A11Y_SERVICE_TRACKER_OBJ_PATH "/org/tizen/WindowTracker"
+
+#define E_ATSPI_BUS_TIMEOUT 4000
+
 #undef DBG
 int _eina_log_dom = -1;
 #define DBG(...)  do EINA_LOG_DOM_DBG(_eina_log_dom, __VA_ARGS__); while(0)
 
 static Eina_Bool g_gesture_navi;
 static Eina_List *handlers;
+Eldbus_Connection *conn = NULL;
 
 EAPI E_Module_Api e_modapi =
 {
@@ -103,12 +112,27 @@ static const char *_gesture_enum_to_string(Gesture g)
 int _e_mod_atspi_dbus_broadcast(Gesture_Info *gi)
 {
    /* Implement this for gesture broadcast */
+   DEBUG("atspi bus broadcast callback");
    const char *name;
+   Eldbus_Message *msg;
 
+   if (!conn) return -1;
    name = _gesture_enum_to_string(gi->type);
    if (!name) return -1;
 
-   INFO("GestureDetected %s (%d %d %d %d %d)", name, gi->x_beg, gi->y_beg, gi->x_end, gi->y_end, gi->state);
+   msg = eldbus_message_signal_new(E_A11Y_SERVICE_NAVI_OBJ_PATH,
+                                    E_A11Y_SERVICE_NAVI_IFC_NAME, "GestureDetected");
+   if (!msg) return -1;
+
+   if (!eldbus_message_arguments_append(msg, "iiiiiiu", (int)gi->type, gi->x_beg, gi->y_beg, gi->x_end, gi->y_end, gi->state, gi->event_time))
+     {
+        eldbus_message_unref(msg);
+        INFO("Append failed");
+        return -1;
+     }
+
+   eldbus_connection_send(conn, msg, NULL, NULL, 0);
+   INFO("GestureDetected %s %d (%d %d %d %d %d %u)", name, (int)gi->type, gi->x_beg, gi->y_beg, gi->x_end, gi->y_end, gi->state, gi->event_time);
    return 0;
 }
 
@@ -118,7 +142,7 @@ _gesture_cb(void    *data,
             void    *event)
 {
    Gesture_Info *gi = event;
-
+   DEBUG("Gesture cb hit\n");
    if (g_gesture_navi)
      _e_mod_atspi_dbus_broadcast(gi);
 
@@ -133,7 +157,7 @@ _events_init(void)
       handlers, ecore_event_handler_add(event, cb, NULL));
    HANDLER_APPEND(E_EVENT_ATSPI_GESTURE_DETECTED, _gesture_cb);
    /* Use this list for other handlers */
-#undef APPEND_HANDLER
+#undef HANDLER_APPEND
 }
 
 static void
@@ -142,6 +166,69 @@ _events_shutdown(void)
    E_FREE_LIST(handlers, ecore_event_handler_del);
 }
 
+static void
+_on_name_cb(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
+{
+   DEBUG("On_name_cb");
+}
+
+static void
+_on_name_release_cb(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
+{
+   DEBUG("On_name_release_cb");
+}
+
+static int
+_fetch_a11y_bus_address(void)
+{
+   if (conn) return 0;
+   conn = eldbus_address_connection_get("unix:path=/var/run/dbus/system_bus_socket");
+   if (!conn)
+     {
+        ERROR("unable to get system bus");
+        goto fail;
+     }
+   INFO("Connected to: unix:path=/var/run/dbus/system_bus_socket");
+
+   if (!conn) return 0;
+   eldbus_name_request(conn, E_A11Y_SERVICE_BUS_NAME,
+                       ELDBUS_NAME_REQUEST_FLAG_DO_NOT_QUEUE, _on_name_cb, NULL);
+
+   INFO("AT-SPI dbus service initialized.");
+   return 0;
+fail:
+   INFO("Failed in _fetch_a11y_bus_address");
+   return -1;
+}
+
+int _a11y_bus_unregister(void)
+{
+   if (!conn) return 0;
+
+   eldbus_name_release(conn, E_A11Y_SERVICE_BUS_NAME, _on_name_release_cb, NULL);
+   eldbus_connection_unref(conn);
+   conn = NULL;
+
+   return 0;
+}
+
+void _e_mod_atspi_dbus_shutdown()
+{
+   DEBUG("dbus shutdown");
+
+   _a11y_bus_unregister();
+
+   eldbus_shutdown();
+}
+
+int _e_mod_atspi_dbus_init(void)
+{
+   DEBUG("dbus init");
+
+   eldbus_init();
+   return _fetch_a11y_bus_address();
+}
+
 EAPI void *
 e_modapi_init(E_Module *m)
 {
@@ -156,6 +243,8 @@ e_modapi_init(E_Module *m)
      goto fail;
    if (_e_mod_atspi_gestures_init())
      goto fail_gestures;
+   if (_e_mod_atspi_dbus_init())
+     goto fail_dbus;
 
    _events_init();
    g_gesture_navi = EINA_TRUE;
@@ -166,6 +255,8 @@ fail_gestures:
    _e_mod_atspi_config_shutdown();
 fail:
    ERROR("Module initialization failed.");
+fail_dbus:
+   ERROR("Dbus submodule initialization failed.");
 
    return NULL;
 }
@@ -184,6 +275,7 @@ e_modapi_shutdown(E_Module *m EINA_UNUSED)
    _e_mod_atspi_config_save();
    _e_mod_atspi_config_shutdown();
    _e_mod_atspi_gestures_shutdown();
+   _e_mod_atspi_dbus_shutdown();
 
    return 1;
 }
index 36d6cb9..894de19 100644 (file)
@@ -88,7 +88,7 @@ _gesture_info_free(void *data, void *info)
    free(data);
 }
 
-static void _event_emit(Gesture g, int x, int y, int x_e, int y_e, int state)
+static void _event_emit(Gesture g, int x, int y, int x_e, int y_e, int state, unsigned int event_time)
 {
    Gesture_Info *info = calloc(sizeof(Gesture_Info), 1);
    EINA_SAFETY_ON_NULL_RETURN(info);
@@ -99,6 +99,7 @@ static void _event_emit(Gesture g, int x, int y, int x_e, int y_e, int state)
    info->y_beg = y;
    info->y_end = y_e;
    info->state = state;
+   info->event_time = event_time;
 
    ecore_event_add(E_EVENT_ATSPI_GESTURE_DETECTED, info, _gesture_info_free, NULL);
 }
@@ -274,7 +275,7 @@ _flick_event_emit(Cover *cov)
         if (cov->flick_gesture.n_fingers == 3)
           type = THREE_FINGERS_FLICK_RIGHT_RETURN;
      }
-   _event_emit(type, ax, ay, axe, aye, 2);
+   _event_emit(type, ax, ay, axe, aye, 2, cov->event_time);
 }
 
 static void
@@ -590,10 +591,10 @@ _hover_event_emit(Cover *cov, int state)
    switch (cov->hover_gesture.n_fingers)
      {
       case 1:
-         _event_emit(ONE_FINGER_HOVER, ax, ay, ax, ay, state);
+         _event_emit(ONE_FINGER_HOVER, ax, ay, ax, ay, state, cov->event_time);
          break;
       case 2:
-         _event_emit(TWO_FINGERS_HOVER, ax, ay, ax, ay, state);
+         _event_emit(TWO_FINGERS_HOVER, ax, ay, ax, ay, state, cov->event_time);
          break;
       default:
          break;
@@ -638,7 +639,7 @@ _tap_event_emit(Cover *cov)
                _event_emit(ONE_FINGER_SINGLE_TAP,
                      cov->tap_gesture_data.x_org[0], cov->tap_gesture_data.y_org[0],
                      cov->tap_gesture_data.x_org[0], cov->tap_gesture_data.y_org[0],
-                     2);
+                     2, cov->event_time);
             }
          else if(cov->tap_gesture_data.tap_type == TWO_FINGERS_GESTURE)
             {
@@ -646,7 +647,7 @@ _tap_event_emit(Cover *cov)
                _event_emit(TWO_FINGERS_SINGLE_TAP,
                      cov->tap_gesture_data.x_org[0], cov->tap_gesture_data.y_org[0],
                      cov->tap_gesture_data.x_org[1], cov->tap_gesture_data.y_org[1],
-                     2);
+                     2, cov->event_time);
             }
          else if(cov->tap_gesture_data.tap_type == THREE_FINGERS_GESTURE)
             {
@@ -654,7 +655,7 @@ _tap_event_emit(Cover *cov)
                _event_emit(THREE_FINGERS_SINGLE_TAP,
                      cov->tap_gesture_data.x_org[0], cov->tap_gesture_data.y_org[0],
                      cov->tap_gesture_data.x_org[2], cov->tap_gesture_data.y_org[2],
-                     2);
+                     2, cov->event_time);
             }
          else
             {
@@ -668,7 +669,7 @@ _tap_event_emit(Cover *cov)
                _event_emit(ONE_FINGER_DOUBLE_TAP,
                      cov->tap_gesture_data.x_org[0], cov->tap_gesture_data.y_org[0],
                      cov->tap_gesture_data.x_org[0], cov->tap_gesture_data.y_org[0],
-                     2);
+                     2, cov->event_time);
             }
          else if(cov->tap_gesture_data.tap_type == TWO_FINGERS_GESTURE)
             {
@@ -676,7 +677,7 @@ _tap_event_emit(Cover *cov)
                _event_emit(TWO_FINGERS_DOUBLE_TAP,
                      cov->tap_gesture_data.x_org[0], cov->tap_gesture_data.y_org[0],
                      cov->tap_gesture_data.x_org[1], cov->tap_gesture_data.y_org[1],
-                     2);
+                     2, cov->event_time);
             }
          else if(cov->tap_gesture_data.tap_type == THREE_FINGERS_GESTURE)
             {
@@ -684,7 +685,7 @@ _tap_event_emit(Cover *cov)
                _event_emit(THREE_FINGERS_DOUBLE_TAP,
                      cov->tap_gesture_data.x_org[0], cov->tap_gesture_data.y_org[0],
                      cov->tap_gesture_data.x_org[2], cov->tap_gesture_data.y_org[2],
-                     2);
+                     2, cov->event_time);
             }
          else
             {
@@ -698,7 +699,7 @@ _tap_event_emit(Cover *cov)
                _event_emit(ONE_FINGER_TRIPLE_TAP,
                      cov->tap_gesture_data.x_org[0], cov->tap_gesture_data.y_org[0],
                      cov->tap_gesture_data.x_org[0], cov->tap_gesture_data.y_org[0],
-                     2);
+                     2, cov->event_time);
             }
          else if(cov->tap_gesture_data.tap_type == TWO_FINGERS_GESTURE)
             {
@@ -706,7 +707,7 @@ _tap_event_emit(Cover *cov)
                _event_emit(TWO_FINGERS_TRIPLE_TAP,
                      cov->tap_gesture_data.x_org[0], cov->tap_gesture_data.y_org[0],
                      cov->tap_gesture_data.x_org[1], cov->tap_gesture_data.y_org[1],
-                     2);
+                     2, cov->event_time);
             }
          else if(cov->tap_gesture_data.tap_type == THREE_FINGERS_GESTURE)
             {
@@ -714,7 +715,7 @@ _tap_event_emit(Cover *cov)
                _event_emit(THREE_FINGERS_TRIPLE_TAP,
                      cov->tap_gesture_data.x_org[0], cov->tap_gesture_data.y_org[0],
                      cov->tap_gesture_data.x_org[2], cov->tap_gesture_data.y_org[2],
-                     2);
+                     2, cov->event_time);
             }
          else
             {
index 1f2d7f4..39da7ff 100644 (file)
@@ -60,6 +60,7 @@ typedef struct {
      int x_beg, x_end;     // (x,y) coordinates when gesture begin
      int y_beg, y_end;     // (x,y) coordinates when gesture ends
      int state;            // 0 - begin, 1 - ongoing, 2 - ended
+     unsigned int event_time; //time stamp for the event
 } Gesture_Info;
 
 int _e_mod_log_init(void);