Extends support for uniquely identyfing objects. 56/136156/1
authorRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Mon, 10 Apr 2017 08:42:22 +0000 (10:42 +0200)
committerShinwoo Kim <cinoo.kim@samsung.com>
Wed, 28 Jun 2017 08:48:56 +0000 (17:48 +0900)
- adds atspi_accessible_get_unique_id function, which returns unique
identifier across all bridges,
- and atspi_accessible_get_bus_name function, which returns identifier
of the bridge for given object.

Change-Id: Idccd85e3269e5a36c8d96bc8588f4eac175c52f6

atspi/atspi-accessible.c
atspi/atspi-accessible.h
test/at_spi2_tool.c

index c3392bd..e112574 100644 (file)
@@ -237,11 +237,62 @@ atspi_accessible_get_name (AtspiAccessible *obj, GError **error)
   return g_strdup (obj->name);
 }
 
+
+/**
+ * atspi_accessible_get_unique_id:
+ * @obj: a pointer to the #AtspiAccessible object on which to operate.
+ *
+ * Gets the identificator, uniquely identifying object, or NULL if an error occured.
+ *
+ * Returns: a UTF-8 string describing the #AtspiAccessible object
+ * or NULL on exception or NULL object passed.
+ **/
+gchar *
+atspi_accessible_get_unique_id(AtspiAccessible *obj, GError **error)
+{
+  if (!obj) {
+    g_set_error(error, ATSPI_ERROR, ATSPI_ERROR_IPC, "argument is null");
+    return NULL;
+  }
+
+  gchar *id = NULL;
+  gchar *bus_name = atspi_accessible_get_bus_name(obj, error);
+  if (bus_name && bus_name[0]) {
+    gchar *path = atspi_accessible_get_path(obj, error);
+    if (path && path[0])
+      id = g_strdup_printf("%s:%s", bus_name, path);
+         else
+      g_set_error(error, ATSPI_ERROR, ATSPI_ERROR_IPC, "failed to get path");
+    g_free(path);
+  }
+  else
+    g_set_error(error, ATSPI_ERROR, ATSPI_ERROR_IPC, "failed to get bus name");
+  g_free(bus_name);
+  return id;
+}
+
+/**
+ * atspi_accessible_get_bus_name:
+ * @obj: a pointer to the #AtspiAccessible object on which to operate.
+ *
+ * Gets the bus name, where object belongs.
+ *
+ * Returns: a UTF-8 string describing the #AtspiAccessible object's
+ * bus name or empty string on exception or NULL object passed.
+ **/
+gchar *
+atspi_accessible_get_bus_name(AtspiAccessible *obj, GError **error)
+{
+  if (!obj || !obj->parent.app)
+    return g_strdup("");
+  return g_strdup (obj->parent.app->bus_name);
+}
+
 /**
  * atspi_accessible_get_path:
  * @obj: a pointer to the #AtspiAccessible object on which to operate.
  *
- * Gets the path, uniquely identifying object.
+ * Gets the path, uniquely identifying object over its bus name.
  *
  * Returns: a UTF-8 string describing the #AtspiAccessible object
  * or empty string on exception or NULL object passed.
index f07394e..de60b90 100644 (file)
@@ -77,6 +77,10 @@ gchar * atspi_accessible_get_description (AtspiAccessible *obj, GError **error);
 
 gchar * atspi_accessible_get_path (AtspiAccessible *obj, GError **error);
 
+gchar * atspi_accessible_get_bus_name (AtspiAccessible *obj, GError **error);
+
+gchar * atspi_accessible_get_unique_id (AtspiAccessible *obj, GError **error);
+
 AtspiAccessible * atspi_accessible_get_parent (AtspiAccessible *obj, GError **error);
 
 gint atspi_accessible_get_child_count (AtspiAccessible *obj, GError **error);
index 018acc7..948aae4 100644 (file)
@@ -311,7 +311,7 @@ static char *_get_object_in_relation(AtspiAccessible *source, AtspiRelationType
 
        g_array_free(relations, TRUE);
 
-       return ret ? atspi_accessible_get_path(ret, NULL) : g_strdup("");
+       return ret ? atspi_accessible_get_unique_id(ret, NULL) : g_strdup("");
 }
 
 static char *_get_info(AtspiAccessible *node, int length_limit)
@@ -321,7 +321,7 @@ static char *_get_info(AtspiAccessible *node, int length_limit)
 
        char *node_name = atspi_accessible_get_name(node, NULL);
        char *node_role_name = atspi_accessible_get_role_name(node, NULL);
-       char *path = atspi_accessible_get_path(node, NULL);
+       char *unique_id = atspi_accessible_get_unique_id(node, NULL);
 
        char *attributes = _get_attributes(node, length_limit);
        Box_Size *box_size = _get_box_size(node);
@@ -332,7 +332,7 @@ static char *_get_info(AtspiAccessible *node, int length_limit)
 
        char result[SAFE_BUFFER_SIZE];
        int ret = snprintf(result, SAFE_BUFFER_SIZE, "[[%s],[%s],[%s],[%s,%s,%s,%s],[%s],[%s],[%s,%s]]",
-                                               path,
+                                               unique_id,
                                                node_role_name,
                                                attributes,
                                                box_size->x,
@@ -349,7 +349,7 @@ static char *_get_info(AtspiAccessible *node, int length_limit)
 
        free(node_name);
        free(node_role_name);
-       free(path);
+       free(unique_id);
        free(attributes);
        if (box_size) {
                free(box_size->width);
@@ -377,12 +377,12 @@ static void _test_atspi_parent_child_relation(AtspiAccessible *obj, AtspiAccessi
                else
                        snprintf(parent_status, NUMBER_WIDTH, "%d", parent_index);
 
-               char *parent_path = atspi_accessible_get_path(parent, NULL);
-               char *parent_candidate_path = atspi_accessible_get_path(parent_candidate, NULL);
+               char *parent_unique_id = atspi_accessible_get_unique_id(parent, NULL);
+               char *parent_candidate_unique_id = atspi_accessible_get_unique_id(parent_candidate, NULL);
                snprintf(output, CHECK_OUTPUT_WIDTH, "[FAIL<%d,%s><%s,%s>]", parent_candidate_index, parent_status,
-                               parent_candidate_path, parent_path);
-               free(parent_path);
-               free(parent_candidate_path);
+                               parent_candidate_unique_id, parent_unique_id);
+               free(parent_unique_id);
+               free(parent_candidate_unique_id);
 
        } else {
                snprintf(output, CHECK_OUTPUT_WIDTH, "[OK]");