[LDTP-Dev] [PATCH] New searching algorithm implementation

jpremkumar jpremkumar at novell.com
Fri Sep 23 01:59:34 PDT 2005


Hi All,

I have completed implementation of the new searching algorithm which I
have proposed few weeks back. This new algorithm works based on the
child index of the GUI object with respect to its immediate parent. I
have also implemented the remap() component function using which we can
handle GUI objects generated at run time. More clear details about the
remap component function and its usage will be available in the API
reference page in our web site after the patch is accepted by the
maintainer and checked into CVS.

Thanks 
Premkumar J


Index: appmap.c
===================================================================
RCS file: /cvs/pyldtp/appmap.c,v
retrieving revision 1.11
diff -u -p -r1.11 appmap.c
--- appmap.c	5 Sep 2005 12:17:55 -0000	1.11
+++ appmap.c	23 Sep 2005 16:26:06 -0000
@@ -4,6 +4,7 @@
  * Author:
  *    Nagappan A <anagappan at novell.com>
  *    S Thanikachalam <sthanikachalam at novell.com>
+ *    Premkumar J <jpremkumar at novell.com>
  *
  * Copyright 2004, 2005 Novell, Inc.
  *
@@ -57,6 +58,55 @@ char *read_line (int fd)
   return NULL;
 }
 
+void add_child_attributes (char *cur_entry, GHashTable
*cur_context_table)
+{
+  char *token = NULL;
+  int offset;
+  char *component = NULL;
+	    
+  token = strtok (strdup (cur_entry), "=");
+  if (token)
+    component = strdup (token);
+	    
+  offset = strlen (component) + 1;
+  if (cur_entry[offset] == '{')
+    {
+      char *end = strstr (cur_entry, "}");
+      if (end)
+	{
+	  char *key, *value;
+	  char *all_attributes;
+	  GHashTable *hash_attributes;
+	  int len = (end - cur_entry) - (offset+1);
+	 
+	  all_attributes = (char *) malloc (sizeof (char) * len + 1);
+	  strncpy (all_attributes, (cur_entry + offset + 1), len);
+	  all_attributes[len] = '\0';
+	 
+	  /*
+	    Create new attribute hash table
+	  */
+	  hash_attributes = g_hash_table_new (&g_str_hash, &g_str_equal);
+	  key = strtok (strdup (all_attributes), "=");
+	  while (key)
+	    {
+	      // Strip any white spaces
+	      key = g_strdup (g_strstrip (key));
+	      value = strtok (NULL, ",");
+	      if (value)
+		// Strip any white spaces
+		value = g_strdup (g_strstrip (value));
+	      g_print ("%s: %s\n", key, value);
+	      if (hash_attributes)
+		g_hash_table_insert (hash_attributes, key, value);
+	      key = strtok (NULL, "=");
+	    }
+	  if (component)
+	    g_hash_table_insert (cur_context_table, component,
hash_attributes);
+	}
+    }
+}
+
 void print_attributes (char *key, char *value, char *userdata)
 {
   g_print ("\t|-------%s = %s\n", key, value);
@@ -79,12 +129,16 @@ void print_context (char *key, GHashTabl
 */
 Appmap *appmap_init (char *gui_map_filename)
 {
-  int fd;
+  int fd, i;
+  //int quit_flag = 0;
   FILE *fp;
+  char *userdata = NULL;
+  char *cur_entry = NULL;
   GHashTable *appmap;
+  GHashTable *cur_context_table = NULL;
 
   appmap = g_hash_table_new (&g_str_hash, &g_str_equal);
-
+    
   fp = fopen (gui_map_filename, "r");
   if (fp ==NULL)
     {
@@ -94,98 +148,37 @@ Appmap *appmap_init (char *gui_map_filen
     }
   fd = fileno (fp);
 
-  {
-    char *data;
-    char *context = NULL;
-    char *component = NULL;
-    GHashTable *hash_components = NULL;
-
-    while (1)
-      {
-	data = read_line (fd);
-	if (data == NULL)
-	  { 
-	    if (hash_components)
-	      g_hash_table_insert (appmap, context, hash_components);
-	    break;
-	  }
-	/*
-	  FIXME: Thanika
-	  In appmap.map file [gedit] is defined
-	*/
-	if (data[0] == '[')
-	  {
-	    if (hash_components && context)
-	      {
-		g_hash_table_insert (appmap, context, hash_components);
-	      }
-					
-	    char *end = strstr (data, "]");
-	    if (end)
-	      {	
-		int len = end - data;
-
-		hash_components = g_hash_table_new (&g_str_hash, &g_str_equal);
-					
-		context = (char *) malloc (sizeof (char) * len + 1);
-		strncpy (context, (data+1), len-1);
-		context[len-1] = '\0';
-	      }
-	    continue;
-	  }
-	if (context)
-	  {
-	    char *token;
-	    int offset;
-
-	    token = strtok (strdup (data), "=");
-	    if (token)
-	      component = strdup (token);
-
-	    offset = strlen (component) + 1;
-	    if (data[offset] == '{')
-	      {
-		char *end = strstr (data, "}");
-		if (end)
-		  {
-		    char *key, *value;
-		    char *all_attributes;
-		    GHashTable *hash_attributes;
-		    int len = (end - data) - (offset+1);
-
-		    all_attributes = (char *) malloc (sizeof (char) * len + 1);
-		    strncpy (all_attributes, (data+offset+1), len);
-		    all_attributes[len] = '\0';
-
-		    /*
-		      Create new attribute hash table
-		    */
-		    hash_attributes = g_hash_table_new (&g_str_hash, &g_str_equal);
-		    key = strtok (strdup (all_attributes), "=");
-		    while (key)
-		      {
-			// Strip any white spaces
-			key = g_strdup (g_strstrip (key));
-			value = strtok (NULL, ",");
-			if (value)
-			  // Strip any white spaces
-			  value = g_strdup (g_strstrip (value));
-			g_print ("%s: %s\n", key, value);
-			g_hash_table_insert (hash_attributes, key, value);
-			key = strtok (NULL, "=");
-		      }
-		    if (component)
-		      g_hash_table_insert (hash_components, component,
hash_attributes);
-		  }
-	      }
-	  }
-	free(data);
-      }
-  }
-  /*
-    Print all the data in hash table
-  */
-  g_hash_table_foreach (appmap, (GHFunc)&print_context, NULL);
+  cur_entry = read_line (fd);
+  while(1)
+    {
+      int cur_entry_len;
+      char *context = NULL;
+      if (!cur_entry)
+	break;
+      cur_entry_len = strlen (cur_entry);
+      if (cur_entry [0] == '[' && cur_entry [cur_entry_len - 2] == ']')
+	{
+	  cur_context_table = g_hash_table_new (&g_str_hash, &g_str_equal);
+	  context = (char *) malloc (sizeof (char) * (cur_entry_len - 1));
+	  for (i = 1; i < cur_entry_len - 2; i++)
+	    context [i-1] = cur_entry [i];
+	  context[i-1] = '\0';
+	  if (appmap) 
+	    g_hash_table_insert (appmap, g_strdup (context),
cur_context_table);
+	  g_free (context);
+	}
+      else if (cur_entry[0] == '\n') 
+	{
+	  cur_entry = read_line (fd);
+	  continue;
+	}
+      else
+	{
+	  add_child_attributes (cur_entry, cur_context_table);
+	}
+      cur_entry = read_line (fd);
+    }
+  g_hash_table_foreach (appmap, (GHFunc)&print_context, userdata);
   return appmap;
 }
 
@@ -215,7 +208,7 @@ gboolean remove_appmap_entries (gpointer
 {
   Appmap *context;
   extern Appmap *appmap;
-
+    
   context = g_hash_table_lookup (appmap, (char *)key);
   g_hash_table_foreach_remove (context,
(GHRFunc)&remove_context_entries, context);
   if (key)
@@ -230,57 +223,11 @@ gboolean remove_appmap_entries (gpointer
 void free_appmap ()
 {
   extern Appmap *appmap;
-
+    
   g_hash_table_foreach_remove (appmap, (GHRFunc)&remove_appmap_entries,
NULL);
   g_hash_table_destroy (appmap);
 }
 
-/*
-  If only partial component / context name is available in .sdd file
then
-  use the respective string and get the component / context handle
-*/
-static gboolean find (gpointer key, gpointer value, gpointer user_data)
-{
-  char *strkey, *strvalue, *data;
-  strkey = (char *) key;
-  strvalue = (char *) value;
-  data = (char *) user_data;
-  g_print ("Find: - Key: %s - Search: %s\n", strkey, data);
-  if (data && strncasecmp (key, data, strlen (data)) == 0)
-    return TRUE;
-  else
-    return FALSE;
-}
-
-/*
-  Get component definition
-*/
-GHashTable* get_component_def (Appmap *ht, char *context, char
*component)
-{
-  GHashTable *ht_context, *ht_component = NULL;
-
-  if (context == NULL || component == NULL || ht == NULL)
-    return NULL;
-  /*
-    Search given context in hash table
-  */
-  ht_context = g_hash_table_lookup (ht, context);
-  if (!ht_context)
-    ht_context = g_hash_table_find (ht, (GHRFunc)&find, context);
-  if (ht_context)
-    {
-      /*
-	Search given component in hash table
-      */
-      ht_component = g_hash_table_lookup (ht_context, component);
-      if (!ht_component)
-	ht_component = g_hash_table_find (ht_context, (GHRFunc)&find,
component);
-    }
-  else
-    g_print ("Context definition %s not found\n", context);
-  return ht_component;
-}
-
 char *get_property (GHashTable *ht, char *property)
 {
   char *value = NULL;
Index: appmap.h
===================================================================
RCS file: /cvs/pyldtp/appmap.h,v
retrieving revision 1.4
diff -u -p -r1.4 appmap.h
--- appmap.h	5 Sep 2005 12:17:55 -0000	1.4
+++ appmap.h	23 Sep 2005 16:26:06 -0000
@@ -4,6 +4,7 @@
  * Author:
  *    Nagappan A <anagappan at novell.com>
  *    S Thanikachalam <sthanikachalam at novell.com>
+ *    Premkumar J <jpremkumar at novell.com>
  *
  * Copyright 2004, 2005 Novell, Inc.
  *
@@ -30,9 +31,8 @@ typedef GHashTable Appmap;
 
 Appmap *appmap_init (char *);
 void   free_appmap (void);
-void   populate_appmap (void);
+void   add_child_attributes (char *, GHashTable *);
 char   *read_line (int);
 char   *get_property (GHashTable *, char *);
-GHashTable *get_component_def (Appmap *, char *, char*);
 
 #endif /*__APPMAP_H__*/
Index: gui.c
===================================================================
RCS file: /cvs/pyldtp/gui.c,v
retrieving revision 1.45
diff -u -p -r1.45 gui.c
--- gui.c	5 Sep 2005 12:17:55 -0000	1.45
+++ gui.c	23 Sep 2005 16:26:06 -0000
@@ -5,6 +5,7 @@
  *    Nagappan A <anagappan at novell.com>
  *    S Thanikachalam <sthanikachalam at novell.com>
  *    Poornima <pnayak at novell.com>
+ *    Premkumar J <jpremkumar at novell.com>
  *
  * Copyright 2004, 2005 Novell, Inc.
  *
@@ -33,45 +34,82 @@ static char *last_existing_context = NUL
 extern char *ldtp_debug;
 Accessible *accessible_app;
 
-void extract_keys (char *key, char *value, KeyList *key_list)
+int push (struct node *head, int value)
 {
-  if (key != NULL)
+  struct node *new_node;
+
+  new_node = (struct node *) malloc (sizeof (struct node));
+  if (new_node)
     {
-      key_list->key_count++;
-      if (!key_list->key)
-	key_list->key = (char **) malloc (sizeof (char *));
-      else
-	key_list->key = (char **) realloc (key_list->key, 
-					   sizeof (char *) * key_list->key_count);
-      /*
-	TODO: Check whether key duped while returned 
-      */
-      key_list->key[key_list->key_count-1] = strdup(key);
+      new_node->child_index = value;
+      new_node->next = head->next;
+      head->next = new_node;
+      return 1;
     }
+  else
+    return 0;
 }
 
-/*
-  FIXME: Thanika, why this function ?
-  A samll description here will be fine...
-*/
-KeyList *get_keys (GHashTable *ht)
+int pop (struct node *head)
 {
-  KeyList *key_list;
-
-  key_list = (KeyList *) malloc (sizeof (KeyList));
+  struct node *temp;
+  int index;
+  if (head->next)
+    {
+      index = head->next->child_index;
+      temp = head->next;
+      head->next = temp->next;
+      g_free (temp);
+    }
+  else
+    index = -1;
+  return index;
+}
 
-  key_list->key_count = 0;
-  key_list->key = NULL;
+struct node *init_stack ()
+{
+  struct node *head;
+  head = (struct node *) malloc (sizeof (struct node));
+  if (head)
+    {
+      head->child_index = -1;
+      head->next = NULL;
+      return head;
+    }
+  else
+    return NULL;
+}
 
-  g_hash_table_foreach (ht, (GHFunc)&extract_keys, key_list);
+struct node *trace_path_to_parent (GHashTable *context, char
*context_name, GHashTable *component)
+{
+  struct node *head;
+  char *parent_name;
 
-  return key_list;
+  head = init_stack ();
+  if (!head)
+    {
+      log_msg (LOG_CAUSE, "Problem in initialising stack");
+      return NULL;
+    }
+  else
+    {
+      push (head, atoi (get_property (component, "child_index")));
+      parent_name = get_property (component, "parent");
+      while (g_strcasecmp (context_name, parent_name))
+	{
+	  component = (GHashTable *) get_property (context, parent_name);
+	  if (component)
+	    {
+	      push (head, atoi (get_property (component, "child_index")));
+	      parent_name = get_property (component, "parent");
+	    }
+	  else
+	    break;
+	}
+    }
+  return head;
 }
 
-/*
-  FIXME: Thanika, is this description, ok ?
-  Get class index based on the class string defined locally
-*/
 int get_class_id (char *class)
 {
   /*
@@ -82,15 +120,15 @@ int get_class_id (char *class)
   if (class == NULL)
     return class_id;
 
-  if (g_ascii_strcasecmp (class, "check_box") == 0)
+  if (g_ascii_strcasecmp (class, "check box") == 0)
     class_id = CHECK_BOX;
-  else if (g_ascii_strcasecmp (class, "check_menu_item") == 0)
+  else if (g_ascii_strcasecmp (class, "check menu item") == 0)
     class_id = CHECK_MENU_ITEM;
-  else if (g_ascii_strcasecmp (class, "combo_box") == 0)
+  else if (g_ascii_strcasecmp (class, "combo box") == 0)
     class_id = COMBO_BOX;
   else if (g_ascii_strcasecmp (class, "dialog") == 0)
     class_id = DIALOG;
-  else if (g_ascii_strcasecmp (class, "file_chooser") == 0)
+  else if (g_ascii_strcasecmp (class, "file chooser") == 0)
     class_id = FILE_CHOOSER;
   else if (g_ascii_strcasecmp (class, "fontchooser") == 0)
     class_id = FONT_CHOOSER;
@@ -100,47 +138,47 @@ int get_class_id (char *class)
     class_id = ICON;
   else if (g_ascii_strcasecmp (class, "label") == 0)
     class_id = LABEL;
-  else if (g_ascii_strcasecmp (class, "layered_pane") == 0)
+  else if (g_ascii_strcasecmp (class, "layered pane") == 0)
     class_id = LAYERED_PANE;
   else if (g_ascii_strcasecmp (class, "list") == 0)
     class_id = LIST;
   else if (g_ascii_strcasecmp (class, "menu") == 0)
     class_id = MENU;
-  else if (g_ascii_strcasecmp (class, "menu_bar") == 0)
+  else if (g_ascii_strcasecmp (class, "menu bar") == 0)
     class_id = MENU_BAR;
-  else if (g_ascii_strcasecmp (class, "menu_item") == 0)
+  else if (g_ascii_strcasecmp (class, "menu item") == 0)
     class_id = MENU_ITEM;
-  else if (g_ascii_strcasecmp (class, "page_tab") == 0)
+  else if (g_ascii_strcasecmp (class, "page tab") == 0)
     class_id = PAGE_TAB;
-  else if (g_ascii_strcasecmp (class, "page_tab_list") == 0)
+  else if (g_ascii_strcasecmp (class, "page tab list") == 0)
     class_id = PAGE_TAB_LIST;
   else if (g_ascii_strcasecmp (class, "panel") == 0)
     class_id = PANEL;
-  else if (g_ascii_strcasecmp (class, "password_text") == 0)
+  else if (g_ascii_strcasecmp (class, "password text") == 0)
     class_id = PASSWORD_TEXT;
-  else if (g_ascii_strcasecmp (class, "push_button") == 0)
+  else if (g_ascii_strcasecmp (class, "push button") == 0)
     class_id = PUSH_BUTTON;
-  else if (g_ascii_strcasecmp (class, "radio_button") == 0)
+  else if (g_ascii_strcasecmp (class, "radio button") == 0)
     class_id = RADIO_BUTTON;
-  else if (g_ascii_strcasecmp (class, "radio_menu_item") == 0)
+  else if (g_ascii_strcasecmp (class, "radio menu item") == 0)
     class_id = RADIO_MENU_ITEM;
-  else if (g_ascii_strcasecmp (class, "scroll_bar") == 0)
+  else if (g_ascii_strcasecmp (class, "scroll bar") == 0)
     class_id = SCROLL_BAR;
   else  if (g_ascii_strcasecmp (class, "slider") == 0)
     class_id = SLIDER;
-  else if (g_ascii_strcasecmp (class, "spin_button") == 0)
+  else if (g_ascii_strcasecmp (class, "spin button") == 0)
     class_id = SPIN_BUTTON;
   else if (g_ascii_strcasecmp (class, "table") == 0)
     class_id = TABLE;
-  else if (g_ascii_strcasecmp (class, "table_cell") == 0)
+  else if (g_ascii_strcasecmp (class, "table cell") == 0)
     class_id = TABLE_CELL;
   else if (g_ascii_strcasecmp (class, "text") == 0)
     class_id = TEXT;
-  else if (g_ascii_strcasecmp (class, "toggle_button") == 0)
+  else if (g_ascii_strcasecmp (class, "toggle button") == 0)
     class_id = TOGGLE_BUTTON;
-  else if (g_ascii_strcasecmp (class, "tool_bar") == 0)
+  else if (g_ascii_strcasecmp (class, "tool bar") == 0)
     class_id = TOOL_BAR;
-  else if(g_ascii_strcasecmp (class, "tree_table") == 0)
+  else if(g_ascii_strcasecmp (class, "tree table") == 0)
     class_id = TREE_TABLE;
   else if(g_ascii_strcasecmp (class, "statusbar") == 0)
     class_id = STATUS_BAR;
@@ -150,439 +188,40 @@ int get_class_id (char *class)
     class_id = CALENDAR;
   else if(g_ascii_strcasecmp (class, "alert") == 0)
     class_id = ALERT;
-  else if(g_ascii_strcasecmp (class, "tool_bar") == 0)
+  else if(g_ascii_strcasecmp (class, "tool bar") == 0)
     class_id = TOOL_BAR;
-  else if(g_ascii_strcasecmp (class, "password_text") == 0)
+  else if(g_ascii_strcasecmp (class, "password text") == 0)
     class_id = PASSWORD_TEXT;	  
   return class_id;
 }
 
-Accessible *is_child_obj_matching (Accessible *accessible,
AccessibleRole role, int index)
-{
-  static int tmp_index = 0;
-  int i, num_child;
-  Accessible *child, *parent = NULL;
-  num_child = Accessible_getChildCount (accessible);
-  /*
-    FIXME: This search algorithm has to be refined
-  */
-  for (i = 0; i < num_child; i++)
-    {
-      char *name;
-      char *role_name;
-      child = Accessible_getChildAtIndex (accessible, i);
-      if (!child)
-	continue;
-      name = Accessible_getName (child);
-      role_name = Accessible_getRoleName (child);
-      if (ldtp_debug && strcmp (ldtp_debug, "2") == 0)
-	g_print ("Child object Name: %s - Role: %s - %d - %d - %d - %d\n",
-		 name, role_name, Accessible_getRole (child), role, index,
tmp_index);
-      SPI_freeString (role_name);
-      SPI_freeString (name);
-
-      if (Accessible_getRole (child) == role)
-	{
-	  if (index == tmp_index)
-	    {
-	      tmp_index = 0;
-	      return child;
-	    }
-	  else
-	    tmp_index++;
-	  Accessible_unref (child);
-	}
-      else
-	{
-	  parent = child;
-	  /*
-	    Call this function recursively, until we reach the end of
-	    depth first search in all the given object handle
-	  */
-	  child = is_child_obj_matching (parent, role, index);
-	  Accessible_unref (parent);
-	  if (child != NULL)
-	    {
-	      return child;
-	    }
-	}
-    }
-  return NULL;
-}
-
-int is_matching (Accessible *child, GHashTable *ht, char *context);
-
-Accessible *get_childs_parent (Accessible *child, GHashTable
*parent_info, char *context)
-{
-  int status;
-  Accessible *tmp;
-  Accessible *parent;
-
-  tmp = child;
-  do
-    {
-      char *name, *role_name;
-      parent = Accessible_getParent (tmp);
-      name = Accessible_getName (parent);
-      role_name = Accessible_getRoleName (parent);
-      g_print ("Parent object - Name: %s - Role: %s\n", name,
role_name);
-      SPI_freeString (name);
-      SPI_freeString (role_name);
-      status = is_matching (parent, parent_info, context);
-      if (tmp != child)
-	Accessible_unref (tmp);
-      tmp = parent;
-      if (status == 1)
-	{
-	  return parent;
-	}
-    } while (status == 0);
-  if (tmp != child)
-    Accessible_unref (tmp);
-  return NULL;
-}
-
-/*
-  Verify accessible object name with appmap definition
-*/
-int is_matching (Accessible *child, GHashTable *ht, char *context)
+int object_state_contains (Accessible *object, int control_type)
 {
-  int flag = 0;
-  int class_id = 0;
-
+  int i;
+  int count;
+  gchar *msg;
   char *name = NULL;
-  char *label = NULL;
-  char *class = NULL;
-
-  AccessibleRole role;
-
-  /*
-    FIXME: Check return value
-  */
-  role = Accessible_getRole (child);
-  class = get_property (ht, "class");
-  label = get_property (ht, "label");
+  SPIBoolean object_state;
+  AccessibleStateSet *state;
 
-  if (class)
-    {
-      class_id = get_class_id (class);
-      if (ldtp_debug && strcmp (ldtp_debug, "2") == 0)
-	g_print ("Class: %s - %d - %d Label: %s\n", class, role, class_id,
label);
-    }
-  else
-    g_print ("Class id is not defined\n");
-  if (role == class_id || role == EXTENDED)
+  name = Accessible_getRoleName (object);
+  state = Accessible_getStateSet (object);
+  count = state_list[control_type].states_count;
+  for (i = 0; i < count; i++)
     {
-      int i, n_keys;
-      KeyList *key_list;
-
-      /*
-	Get the size of hash table
-      */
-      n_keys = g_hash_table_size (ht);
-      key_list = get_keys (ht);
-
-      if (ldtp_debug && strcmp (ldtp_debug, "2") == 0)
-	g_print ("Key count: %d\n", key_list->key_count);
-      /*
-	Find the object which matches with all the attributes
-	defined in guimap
-      */
-      for (i = 0; i < key_list->key_count; i++)
-	{
-	  char *prop; // Property
-
-	  prop = key_list->key[i];
-	  if (ldtp_debug && strcmp (ldtp_debug, "2") == 0)
-	    g_print ("Class type: %s\n", prop);
-	  if (strcasecmp (prop, "label") == 0)
-	    {
-	      name = Accessible_getName (child);
-	      if (ldtp_debug && strcmp (ldtp_debug, "2") == 0)
-		{
-		  g_print ("Object name: %s\n", name);
-		  g_print ("Object label: %s\n", label);
-		}
-	      if (name == NULL || label == NULL)
-		return 0;
-              if (strchr (name, ' ') != NULL)
-                g_strstrip (name);
-	      if (last_existing_context && last_new_context)
-		{
-		  gchar *tmp_name = NULL;
-		  gchar *tmp_label = NULL;
-		  gchar *tmp_last_new_context = NULL;
-		  gchar *tmp_last_existing_context = NULL;
-
-		  g_print ("%s - %s - %s - %s\n", last_existing_context,
last_new_context, label, name);
-		  tmp_name = g_ascii_strup (name, strlen (name));
-		  tmp_label = g_ascii_strup (label, strlen (label));
-		  tmp_last_new_context = g_ascii_strup (last_new_context,
-							strlen (last_new_context));
-		  tmp_last_existing_context = g_ascii_strup (last_existing_context,
-							     strlen (last_existing_context));
-
-		  if ((strcasecmp (label, last_existing_context) == 0 ||
-		       strncasecmp (label, last_existing_context,
-				    strlen (last_existing_context)) == 0 ||
-		       strstr (tmp_label, tmp_last_existing_context) != NULL) &&
-		      (strcasecmp (name, last_new_context) == 0 ||
-		       strncasecmp (name, last_new_context, strlen
(last_new_context)) == 0 ||
-		       strstr (tmp_name, tmp_last_new_context) != NULL))
-		    {
-		      g_print ("%s - %s - %s - %s\n", last_existing_context,
last_new_context, label, name);
-		      /*
-			FIXME: regular expr should be implemented
-		      */
-		      SPI_freeString (name);
-		      flag++;
-		    }
-		  else if (strcasecmp (name, label) == 0)
-		    {
-		      g_print ("%s - %s - %s - %s\n", last_existing_context,
last_new_context, label, name);
-		      /*
-			FIXME: regular expr should be implemented
-		      */
-		      SPI_freeString (name);
-		      flag++;
-		    }
-		  else
-		    {
-		      SPI_freeString (name);
-		    }
-		  g_free (tmp_name);
-		  g_free (tmp_label);
-		  g_free (tmp_last_new_context);
-		  g_free (tmp_last_existing_context);
-		}
-	      else if (g_ascii_strcasecmp (name, label) == 0)
-		{
-		  SPI_freeString (name);
-		  flag++;
-		}
-              else
-		{
-		  SPI_freeString (name);
-		  /*
-		    FIXME: Add comments
-		    Why we return here ?
-		  */
-		  return 0;
-	        }
-            }
-	  else if (strcasecmp (prop, "label_by") == 0)
-	    {
-	      int i;
-	      int max_accessible = 0;
-	      char *label_by = NULL;
-	      AccessibleRelation **relation;
-
-	      relation = Accessible_getRelationSet (child);
-	      max_accessible = AccessibleRelation_getNTargets (*relation);
-	      label_by = get_property (ht, "label_by");
-
-	      if (max_accessible > 0)
-		{
-		  for (i = 0; i < AccessibleRelation_getNTargets (relation[i]); i++)
-		    {
-		      AccessibleRelationType relation_type;
-		      relation_type = AccessibleRelation_getRelationType
(relation[i]);
-		      g_print ("Relation: %d\n", i);
-		      if (relation_type == SPI_RELATION_LABELED_BY ||
-			  relation_type == SPI_RELATION_CONTROLLED_BY ||
-			  relation_type == SPI_RELATION_LABEL_FOR)
-			{
-			  char *name = NULL;
-			  Accessible *tmp_obj;
-
-			  tmp_obj = AccessibleRelation_getTarget (relation[i], i);
-			  name = Accessible_getName (tmp_obj);
-			  g_print ("Relation: %d - %s\n", i, name);
-			  /*
-			    FIXME: String should be stripped
-			  */
-			  if (strncasecmp (name, label_by, strlen (label_by)) == 0)
-			    {
-			      g_print ("Name / Label_By matches\n");
-			      // Label matched
-			      SPI_freeString (name);
-			      Accessible_unref (tmp_obj);
-			      Accessible_unref (*relation);
-			      flag++;
-			      continue;
-			    }
-			  SPI_freeString (name);
-			  Accessible_unref (tmp_obj);
-			}
-		    }
-		}
-	      Accessible_unref (*relation);
-	      continue;
-	    }
-	  else if (strcasecmp (prop, "class") == 0)
-	    {
-	      char *role, *tmp;
-	      role = Accessible_getRoleName (child);
-	      tmp = strdup (role);
-	      tmp = g_strdelimit (tmp, " ", '_');
-	      if (strcasecmp (tmp, get_property (ht, key_list->key[i])) == 0)
-		flag++;
-	      free (tmp);
-	      SPI_freeString (role);
-	      continue;
-	    }
-	  else if (strcasecmp(prop, "app_name") == 0)
-	    {
-	      flag++;
-	      continue;
-	    }
-	  else if (strcasecmp (prop, "parent") == 0)
-	    {
-	      int i;
-	      int parent_index = -1;
-	      extern int class_id; // Accessing global class_id
-	      int tmp_class_id = class_id;
-	      for (i = 0; i < key_list->key_count; i++)
-		{
-		  if (strcasecmp (key_list->key[i], "parent") == 0)
-		    parent_index = i;
-		}
-	      if (parent_index != -1)
-		{
-		  extern Appmap *appmap;
-		  GHashTable *parent_info;
-		  Accessible *parent;
-
-		  g_print ("Parent index - Component: %s\n", get_property (ht,
key_list->key[parent_index]));
-		  parent_info = get_component_def (appmap, context, get_property (ht,
key_list->key[parent_index]));
-		  /*
-		    FIXME:
-		    atoi has to be removed instead strtol function should be used
-		  */
-		  if ((parent = get_childs_parent (child, parent_info, context)) !=
NULL)
-		    {
-		      g_print ("Parent matches\n");
-		      flag++;
-		      Accessible_unref (parent);
-		    }
-		  class_id = tmp_class_id;
-		}
-	      continue;
-	    }
-	  else if (strcasecmp (prop, "instance_index") == 0)
-	    {
-	      static int i = 0;
-	      int index;
-	      char *s_index;
-
-	      s_index = get_property (ht, "instance_index");
-	      /*
-		FIXME:
-		Handle integer type too
-		atoi has to be removed instead strtol function should be used
-	      */
-	      index = atoi (s_index);
-	      g_print ("Instance index: %d - %d\n", index, i);
-	      if (i == index)
-		{
-		  i = 0;
-		  return 1;
-		}
-	      else
-		{
-		  i++;
-		  return 0;
-		}
-	    }
-	  else if (strcasecmp (prop, "relevant_index") == 0)
-	    {
-	      int i, index;
-	      char *s_index;
-	      int parent_index = -1;
-	      extern int class_id; // Accessing global class_id
-	      int tmp_class_id = class_id;
-	      for (i = 0; i < key_list->key_count; i++)
-		{
-		  if (strcasecmp (key_list->key[i], "parent") == 0)
-		    parent_index = i;
-		}
-	      if (parent_index != -1)
-		{
-		  extern Appmap *appmap;
-		  GHashTable *parent_info;
-		  Accessible *parent;
-
-		  parent_info = get_component_def (appmap, context, get_property (ht,
key_list->key[parent_index]));
-		  s_index = get_property (ht, "relevant_index");
-		  /*
-		    FIXME:
-		    atoi has to be removed instead strtol function should be used
-		  */
-		  index = atoi (s_index);
-		  if ((parent = get_childs_parent (child, parent_info, context)) !=
NULL)
-		    {
-		      static int tmp_index = 0;
-		      if (index == tmp_index)
-			{
-			  Accessible *child_obj = NULL;
-			  child_obj = is_child_obj_matching (parent, Accessible_getRole
(child), index);
-			  if (child_obj)
-			    {
-			      flag++;
-			      Accessible_unref (child_obj);
-			    }
-			  tmp_index = 0;
-			} //if
-		      else
-			{
-			  tmp_index++;
-			}
-		      Accessible_unref (parent);
-		    }
-		  class_id = tmp_class_id;
-		}
-	      continue;
-	    }
-	  else if (strcasecmp (prop, "state") == 0)
-	    {
-	      SPIBoolean selected;
-	      AccessibleStateSet *state;
-
-	      state = Accessible_getStateSet (child);
-	      selected = AccessibleStateSet_contains (state,
SPI_STATE_SELECTED);
-
-	      if (selected)
-		{
-		  g_print ("Object state: selected\n");
-		  flag++;
-		}
-	      else
-		return 0;
-	    }
-	  else
-	    {
-	      gchar *msg;
-	      flag = 0;
-	      // FIXME: Need to refine this print statement
-	      g_print ("Unsupported property type '%s' encountered in object
definition\n", prop);
-	      msg = g_strdup_printf ("Unsupported property type '%s'
encountered in appmap", prop);
-	      log_msg (LOG_WARNING, msg);
-	      free (msg);
-	      break;
-	    }
-	} // for
-      if (flag != key_list->key_count)
+      object_state = AccessibleStateSet_contains (state,
+						  state_list[control_type].states [i]);
+      if (object_state != 1)
 	{
-	  g_print ("Flag count does not match\n");
-	  flag = 0;
+	  msg = g_strdup_printf ("%s required states are not enabled", name);
+	  log_msg (LOG_CAUSE, msg);
+	  SPI_freeString (name);
+	  free (msg);
+	  return -1;
 	}
-      else
-	flag = 1;
-    } // if
-  if (flag == 0 && (role == FRAME || role == DIALOG || role ==
FILE_CHOOSER ||
-		    role == FONT_CHOOSER || role == ALERT || role == DESKTOP_FRAME))
-    flag = -1;
-  return flag;
+    }
+  SPI_freeString (name);
+  return 0;
 }
 
 /*
@@ -615,7 +254,6 @@ Accessible *get_accessible_app_handle (c
       child = Accessible_getChildAtIndex (desktop, i);
       if (!child)
 	continue;
-
       /*
 	Application name of child handle
       */
@@ -658,218 +296,247 @@ Accessible *get_accessible_app_handle (c
       SPI_freeString (name);
       Accessible_unref (child);
     }
-
   Accessible_unref (desktop);
   return NULL;
 }
 
 /*
-  Get accessible handle of the given object
-*/
-Accessible *get_accessible_object_handle (Accessible *accessible,
GHashTable *ht, char *context)
+ * To get accessible handle of the context (window)
+ */
+Accessible *get_accessible_context_handle (Accessible *app_handle, char
*context)
 {
-  int i, num_child, flag;
-  Accessible *child, *parent;
-  num_child = Accessible_getChildCount (accessible);
-  if (ldtp_debug && strcmp (ldtp_debug, "2") == 0)
-    g_print ("Child count: %d\n", num_child);
-  /*
-    FIXME: This search algorithm has to be refined
-  */
-  for (i = 0; i < num_child; i++)
+  int i;
+  long child_count;
+  char *child_name;
+  Accessible *child;
+
+  child_count = Accessible_getChildCount (app_handle);
+  if (child_count > 0)
     {
-      char *name;
-      char *role;
-      child = Accessible_getChildAtIndex (accessible, i);
-      if (!child)
-	continue;
-      name = Accessible_getName (child);
-      role = Accessible_getRoleName (child);
-      if (ldtp_debug && strcmp (ldtp_debug, "2") == 0)
-	g_print ("Name: %s - Role: %s\n", name, role);
-      SPI_freeString (role);
-      SPI_freeString (name);
-      flag = is_matching (child, ht, context);
-      if (flag == 1)
+      for (i = 0; i < child_count; i++)
 	{
-	  /*
-	    Return if object matches
-	  */
-	  if (ldtp_debug && strcmp (ldtp_debug, "2") == 0)
-	    g_print ("Object matches\n");
-	  return child;
-	}
-      else if (flag == -1)
-	{
-	  if (ldtp_debug && strcmp (ldtp_debug, "2") == 0)
-	    g_print ("Object does not match\n");
-	  Accessible_unref (child);
-	  continue;
-	}
-      else
-	{
-	  parent = child;
-	  /*
-	    Call this function recursively, until we reach the end of
-	    depth first search in all the given object handle
-	  */
-	  child = get_accessible_object_handle (child, ht, context);
-	  Accessible_unref (parent);
-	  if (child != NULL)
+	  child = Accessible_getChildAtIndex (app_handle, i);
+	  child_name = Accessible_getName (child);
+	  if (last_new_context && last_existing_context)
 	    {
+	      if (g_strcasecmp (context, last_existing_context) == 0)
+		{
+		  if (g_strcasecmp (last_new_context, child_name) == 0)
+		    {		     
+		      SPI_freeString (child_name);
+		      return child;
+		    } 
+		}
+	    }
+	  if (g_strcasecmp (context, child_name) == 0)
+	    {
+	      SPI_freeString (child_name);
 	      return child;
 	    }
+	  else
+	    {
+	      SPI_freeString (child_name);
+	      Accessible_unref (child);
+	    }
 	}
     }
   return NULL;
 }
 
 /*
-  Get gui handle based on context and compoment
+  Get accessible handle of the given object
 */
-Accessible *get_gui_handle (Appmap *appmap, char *context, char
*component)
+Accessible *get_accessible_object_handle (struct node *head, Accessible
*context)
 {
-  char *parent = NULL;
-  char *app_name = NULL;
-
-  GHashTable *ht_parent;
-  GHashTable *ht_context;
-  GHashTable *ht_component;
-
-  /* Accessible *accessible_app;*/
-  Accessible *accessible_object;
-  Accessible *accessible_parent = NULL;
-  Accessible *accessible_context;
-
-  ht_context = get_component_def (appmap, context, context);
-  ht_component = get_component_def (appmap, context, component);
+  int i;
+  Accessible *child, *parent;
 
-  /*
-    FIXME: Add more comments
-    app_name is must for context
-  */
-  if (!ht_context)
+  if (head)
     {
-      g_print ("Unable to find context\n");
-      log_msg (LOG_ERROR, "Unable to find context");
-      return NULL;
+      i = pop (head);
+      parent = context;
+      while (i != -1)
+	{
+	  child = Accessible_getChildAtIndex (parent, i);
+	  if (!child)	  
+	    {
+	      Accessible_unref (parent);
+	      log_msg (LOG_CAUSE, "No child found for the given child index");
+	      return NULL;
+	    }
+	  Accessible_unref (parent);
+	  parent = child;
+	  i = pop (head);
+	}
+      g_free (head);
+      return parent;
     }
-  app_name = get_property (ht_context, "app_name");
-  g_print ("Application name: %s\n", app_name);
-  g_print ("Context: %s - Component: %s\n", context, component);
-  accessible_app = get_accessible_app_handle (app_name);
-  if (accessible_app)
-    g_print ("Application handle found\n");
   else
-    {
-      g_print ("Application handle not found\n");
-      log_msg (LOG_ERROR, "Application handle not found");
       return NULL;
+}
+
+char *get_relation_name (Accessible *object)
+{
+  int i;
+  int max_accessible = 0;
+  char *label_by = NULL;
+  AccessibleRelation **relation;
+
+  relation = Accessible_getRelationSet (object);
+  max_accessible = AccessibleRelation_getNTargets (*relation);
+  if (max_accessible > 0)
+    {
+      for (i = 0; i < AccessibleRelation_getNTargets (relation[i]); i
++)
+	{
+	  AccessibleRelationType relation_type;
+	  relation_type = AccessibleRelation_getRelationType (relation[i]);
+	  if (relation_type == SPI_RELATION_LABELED_BY ||
+	      relation_type == SPI_RELATION_CONTROLLED_BY ||
+	      relation_type == SPI_RELATION_LABEL_FOR)
+	    {
+	      char *name = NULL;
+	      Accessible *tmp_obj;
+	      
+	      tmp_obj = AccessibleRelation_getTarget (relation[i], i);
+	      name = Accessible_getName (tmp_obj);
+	      if (g_strcasecmp (name, "") == 0)
+		{
+		  SPI_freeString (name);
+		  Accessible_unref (tmp_obj);
+		  Accessible_unref (*relation);
+		  return NULL;
+		}
+	      label_by = g_strdup (name);
+	      SPI_freeString (name);
+	      Accessible_unref (tmp_obj);
+	      Accessible_unref (*relation);
+	      return label_by;
+	    }
+	}
     }
+  Accessible_unref (*relation);
+  return NULL;
+}
 
+int is_object_matching (Accessible *object, GHashTable
*comp_attributes)
+{
+  char *accessible_label;
+  char *hash_label;
   /*
-    Search object handle based on context from application handle
-  */
-  accessible_context = get_accessible_object_handle (accessible_app,
-						     ht_context, context);
-  if (accessible_context)
-    g_print ("Context handle found\n");
-  else
+   * NOTE: Checking if the obtained object is the required one with
respect to label only
+   */
+  hash_label = g_hash_table_lookup (comp_attributes, "label");
+  if (hash_label)
     {
-      Accessible_unref (accessible_app);
-      g_print ("Context handle not found\n");
-      return NULL;
+      accessible_label = Accessible_getName (object);
+      if (g_strcasecmp (accessible_label, hash_label) == 0)
+	{
+	  SPI_freeString (accessible_label);
+	  return 1;
+	}
+      else
+	{
+	  SPI_freeString (accessible_label);
+	  return 0;
+	}
     }
-
-  if (strcmp (context, component) == 0)
+  else
     {
-      if (!ht_component)
+      hash_label = g_hash_table_lookup (comp_attributes, "label_by");
+      if (hash_label)
 	{
-	  g_print ("Unable to find component\n");
+	  accessible_label = get_relation_name (object);
+	  if (g_strcasecmp (accessible_label, hash_label) == 0)
+	    {
+	      g_free (accessible_label);
+	      return 1;
+	    }
+	  else
+	    {
+	      g_free (accessible_label);
+	      return 0;
+	    }
 	}
-      g_print ("Context and Component name are same\n");
-      log_msg (LOG_WARNING, "Context and Component name are same");
-      Accessible_unref (accessible_app);
-      return accessible_context;
     }
-  /*
-    FIXME: If accessible_context is NULL ?
-    Handle this...
-  */
+  return 1;
+}
 
-  if (!ht_component)
+/*
+  Get gui handle based on context and compoment
+*/
+Accessible *get_gui_handle (Appmap *appmap, char *context, char
*component)
+{
+  char *app_name;
+  char *window_name;
+  char *class;
+  int class_id;
+  struct node *head;
+
+  GHashTable *cur_window;
+  GHashTable *cur_component;
+
+  Accessible *object_handle = NULL;
+  Accessible *context_handle = NULL;
+  Accessible *application_handle = NULL;
+
+  cur_window = g_hash_table_lookup (appmap, context);
+  if (!cur_window)
     {
-      g_print ("Unable to find component\n");
-      log_msg (LOG_WARNING, "Component handle not found");
+      g_print ("Unable to find context in Appmap\n");
+      log_msg (LOG_ERROR, "Unable to find context in Appmap");
+      return NULL;
     }
-  /*
-    FIXME: More clear about this TODO is required
-    TODO: This can be made as recursive resolution for parent
-  */
-  parent = get_property (ht_component, "parent");
-
-  if (parent != NULL)
+  else
     {
-      ht_parent = get_component_def (appmap, context, parent);
-      if (ht_parent)
+      cur_component = (GHashTable *) g_hash_table_lookup (cur_window,
context);
+      app_name = get_property (cur_component, "parent");
+      window_name = get_property (cur_component, "label");
+      cur_component = (GHashTable *) g_hash_table_lookup (cur_window,
component);
+      if (!cur_component)
 	{
-	  /*
-	    Search object handle based on parent from context handle
-	  */
-	  accessible_parent = get_accessible_object_handle
(accessible_context,
-							    ht_parent, context);
-	  /*
-	    FIXME: Thanika, is this description ok ?
-	    To narrow down the scope of search
-	  */
-	  if (accessible_parent)
-	    {
-	      char *name;
-	      g_print ("Found parent handle\n");
-	      name = Accessible_getName (accessible_parent);
-	      Accessible_unref (accessible_parent);
-	      g_print ("Accessible context: Name - %s\n", name);
-	      SPI_freeString (name);
+	  g_print ("Unable to find component: %s in Appmap\n", component);
+	  log_msg (LOG_ERROR, "Unable to find component in Appmap");
+	  return NULL;
+	}
+      else
+	{
+	  application_handle = get_accessible_app_handle (app_name);
+	  context_handle = get_accessible_context_handle (application_handle,
window_name);
+	  Accessible_unref (application_handle);
+	  if (context_handle)
+	    {
+		if (!g_strcasecmp (context, component))
+		  {
+		    return context_handle;
+		  }
+		head = trace_path_to_parent (cur_window, context, cur_component);
+		object_handle = get_accessible_object_handle (head, context_handle);
+		if (!is_object_matching (object_handle, cur_component))
+		  {
+		    g_print ("Obtained handle does not match with Appmap entry!!\n");
+		    log_msg (LOG_ERROR, "Obtained handle does not match with Appmap
entry!!");
+		    Accessible_unref (object_handle);
+		    return NULL;
+		  }
+		class = Accessible_getRoleName (object_handle);
+		class_id = get_class_id (class);
+		SPI_freeString (class);
+		return object_handle;
 	    }
 	  else
 	    {
-	      g_print ("Unable to find parent handle\n");
-	      log_msg (LOG_WARNING, "Parent handle not found");
-	      Accessible_unref (accessible_context);
-	      Accessible_unref (accessible_app);
+	      if (g_strcasecmp (context, component))
+		{
+		  g_print ("Given context is not open\n");
+		  log_msg (LOG_ERROR, "Given context is not open");
+		}
 	      return NULL;
-	    }
+	  }
 	}
-      else
-	{
-	  g_print ("Unable to find parent handle\n");
-	  log_msg (LOG_WARNING, "Parent handle not found");
-	  Accessible_unref (accessible_context);
-	  Accessible_unref (accessible_app);
-	  return NULL;
-	}
-    }
-  else
-    g_print ("Parent handle not required\n");
-
-  class_id = 0;
-  /*
-    Search object handle based on component from context handle
-  */
-  accessible_object = get_accessible_object_handle (accessible_context,
-						    ht_component, context);
-  if (!accessible_object)
-    {
-      g_print ("Unable to find context handle - %s\n", context);
-      log_msg (LOG_ERROR, "Context handle not found");
     }
-
-  Accessible_unref (accessible_context);
-  Accessible_unref (accessible_app);
-  return accessible_object;
 }
 
-static Accessible *get_object_handle (Accessible *accessible, char
*object)
+Accessible *get_object_handle (Accessible *accessible, char *object)
 {
   int i, num_child;
   char *role_name;
@@ -925,6 +592,33 @@ Accessible *get_menu_handle (Accessible 
   return get_object_handle (accessible, "menu");
 }
 
+int get_object_type (Accessible *accessible)
+{
+  int object_type = 0;
+  AccessibleRole role;
+  role = Accessible_getRole (accessible);
+
+  if (role == SPI_ROLE_LIST)
+    object_type = LIST;
+  if (role == SPI_ROLE_MENU)
+    object_type = MENU;
+  if (role == SPI_ROLE_TEXT)
+    object_type = TEXT;
+  if (role == SPI_ROLE_TOGGLE_BUTTON)
+    object_type = TOGGLE_BUTTON;
+  if (role == SPI_ROLE_TABLE_CELL)
+    object_type = TABLE_CELL;
+  if (role == SPI_ROLE_EXTENDED)
+    {
+      char *role_name;
+      role_name = Accessible_getRoleName (accessible);
+      if (strcasecmp (role_name, "calendar event") == 0)
+	object_type = CALENDAR_EVENT;
+      SPI_freeString (role_name);
+    }
+  return object_type;
+}
+
 int get_child_object_type (Accessible *accessible)
 {
   int i;
@@ -968,72 +662,16 @@ int get_child_object_type (Accessible *a
   return 0;
 }
 
-int get_object_type (Accessible *accessible)
-{
-  int object_type = 0;
-  AccessibleRole role;
-  role = Accessible_getRole (accessible);
-
-  if (role == SPI_ROLE_LIST)
-    object_type = LIST;
-  if (role == SPI_ROLE_MENU)
-    object_type = MENU;
-  if (role == SPI_ROLE_TEXT)
-    object_type = TEXT;
-  if (role == SPI_ROLE_TOGGLE_BUTTON)
-    object_type = TOGGLE_BUTTON;
-  if (role == SPI_ROLE_TABLE_CELL)
-    object_type = TABLE_CELL;
-  if (role == SPI_ROLE_EXTENDED)
-    {
-      char *role_name;
-      role_name = Accessible_getRoleName (accessible);
-      if (strcasecmp (role_name, "calendar event") == 0)
-	object_type = CALENDAR_EVENT;
-      SPI_freeString (role_name);
-    }
-  return object_type;
-}
-
-int object_state_contains (Accessible *object, int control_type)
-{
-  int i;
-  int count;
-  gchar *msg;
-  char *name = NULL;
-  SPIBoolean object_state;
-  AccessibleStateSet *state;
-
-  name = Accessible_getRoleName (object);
-  state = Accessible_getStateSet (object);
-  count = state_list[control_type].states_count;
-  for (i = 0; i < count; i++)
-    {
-      object_state = AccessibleStateSet_contains (state,
-						  state_list[control_type].states [i]);
-      if (object_state != 1)
-	{
-	  msg = g_strdup_printf ("%s required states are not enabled", name);
-	  log_msg (LOG_CAUSE, msg);
-	  SPI_freeString (name);
-	  free (msg);
-	  return -1;
-	}
-    }
-  SPI_freeString (name);
-  return 0;
-}
-
 int set_new_context (char *existing_context, char *new_context)
 {
   if (last_new_context)
     {
-      free (last_new_context);
+      g_free (last_new_context);
       last_new_context = NULL;
     }
   if (last_existing_context)
     {
-      free (last_existing_context);
+      g_free (last_existing_context);
       last_existing_context = NULL;
     }
   last_new_context = strdup (new_context);
@@ -1045,12 +683,12 @@ int release_last_context ()
 {
   if (last_new_context)
     {
-      free (last_new_context);
+      g_free (last_new_context);
       last_new_context = NULL;
     }
   if (last_existing_context)
     {
-      free (last_existing_context);
+      g_free (last_existing_context);
       last_existing_context = NULL;
     }
   return 1;
Index: gui.h
===================================================================
RCS file: /cvs/pyldtp/gui.h,v
retrieving revision 1.22
diff -u -p -r1.22 gui.h
--- gui.h	20 Sep 2005 18:57:33 -0000	1.22
+++ gui.h	23 Sep 2005 16:26:06 -0000
@@ -4,6 +4,7 @@
  * Author:
  *    Nagappan A <anagappan at novell.com>
  *    S Thanikachalam <sthanikachalam at novell.com>
+ *    Premkumar J <jpremkumar at novell.com>
  *
  * Copyright 2004, 2005 Novell, Inc.
  *
@@ -225,15 +226,27 @@
 int class_id;
 int cmd_id;
 
-typedef struct
+struct object_info
 {
-  int key_count;
-  char **key;
-}KeyList;
+    char *object_type;
+    char *prefix;
+    int instance_index;
+};
 
-// Commented as it was throwing error has to look into this
-Accessible *get_gui_handle(Appmap *, char *, char *);
+typedef struct object_info OBJECT_INFO;
+
+struct node
+{
+    int child_index;
+    struct node *next;
+};
+
+// Stack related functions
+int push (struct node *head, int value);
+int pop (struct node *head);
+struct node *init_stack ();
 
+Accessible *get_object_handle (Accessible *, char *);
 Accessible *get_list_handle (Accessible *);
 Accessible *get_text_handle (Accessible *);
 Accessible *get_menu_handle (Accessible *);
@@ -242,6 +255,14 @@ int get_child_object_type (Accessible *)
 int get_object_type (Accessible *);
 int object_state_contains (Accessible *, int);
 
+Accessible *get_gui_handle(Appmap *, char *, char *);
+struct node *trace_path_to_parent (GHashTable *context, char
*context_name, GHashTable *component);
+Accessible *get_accessible_object_handle (struct node *head, Accessible
*context_object);
+Accessible *get_accessible_context_handle (Accessible *app_handle, char
*context);
+Accessible *get_accessible_app_handle (char *app_name);
+int is_object_matching (Accessible *object, GHashTable
*hash_attributes);
+char *get_relation_name (Accessible *object);
+
 int set_new_context (char *, char *);
 int release_last_context (void);
 
Index: ldtp.c
===================================================================
RCS file: /cvs/pyldtp/ldtp.c,v
retrieving revision 1.126
diff -u -p -r1.126 ldtp.c
--- ldtp.c	22 Sep 2005 20:05:35 -0000	1.126
+++ ldtp.c	23 Sep 2005 16:26:06 -0000
@@ -4,6 +4,7 @@
  * Author:
  *    Nagappan A <anagappan at novell.com>
  *    Shankar Ganesh <shagan.glare at gmail.com>
+ *    Premkumar J <jpremkumar at novell.com>
  *
  * Copyright 2004, 2005 Novell, Inc.
  *
@@ -28,7 +29,7 @@
 #include "gui.h"
 
 int leaked;
-int default_sleep = 3; // 3 seconds sleep before doing any operation
+int default_sleep = 1; // 3 seconds sleep before doing any operation
 Appmap *appmap = NULL;
 char **params = NULL;
 char *ldtp_debug = NULL;
@@ -37,6 +38,7 @@ char *component_name = NULL;
 
 static PyObject *ldtp_error;
 static PyObject *callback_objects = NULL;
+static GHashTable *old_contextmap = NULL;
 
 static PyObject *init_appmap (PyObject *self, PyObject *args)
 {
@@ -2319,6 +2321,52 @@ static PyObject *select_calendar_date (P
   return status;
 }
 
+static PyObject *remap (PyObject *self, PyObject *args)
+{
+  Accessible *context;
+  char *app_name = NULL;
+  GHashTable *new_hashtable;
+
+  if (!PyArg_ParseTuple (args, "ss", &app_name, &window_name))
+    {
+      return PyErr_Format (ldtp_error, "%s", "Argument missing /
invalid");
+    }
+    
+  context = get_gui_handle (appmap, window_name, window_name);
+  if (!context)
+    {
+      g_print ("Unable to get context handle!\n");
+      return Py_BuildValue ("i", 0);
+    }
+  new_hashtable = do_remap (app_name, context);
+
+  old_contextmap = (GHashTable *) g_hash_table_lookup (appmap,
window_name);
+  g_hash_table_insert (appmap, window_name, new_hashtable);
+  Accessible_unref (context);
+  return Py_BuildValue ("i", 1);
+}
+
+static PyObject *undo_remap (PyObject *self, PyObject *args)
+{
+  GHashTable *new_hashtable;
+
+  if (!PyArg_ParseTuple (args, "s", &window_name))
+    {
+      return PyErr_Format (ldtp_error, "%s", "Argument missing /
invalid");
+    }
+
+  new_hashtable = g_hash_table_lookup (appmap, window_name);
+  if (!new_hashtable)
+    {
+      g_print ("Unable to find given context in Appmap!\n");
+      return Py_BuildValue ("i", 0);
+    }
+
+  g_hash_table_insert (appmap, window_name, old_contextmap);
+  g_hash_table_destroy (new_hashtable);
+  return Py_BuildValue ("i", 1);
+}
+
 static PyObject *start_logging (PyObject *self, PyObject *args)
 {
   char *log_file_name;
@@ -2535,6 +2583,10 @@ static PyMethodDef ldtp_methods[] = {
    "Checks if the text has the given property"},
   {"selectcalendardate", (PyCFunction) select_calendar_date,
METH_VARARGS,
    "select the given date in the calendar object"},
+  {"remap", (PyCFunction) remap, METH_VARARGS,
+   "Correct hash tables with proper child index after an UI change"},
+  {"undoremap", (PyCFunction) undo_remap, METH_VARARGS,
+   "Revert appmap entries to the original values"},
   {NULL, NULL, 0, NULL}           /* sentinel */
 };
 
Index: ldtp.h
===================================================================
RCS file: /cvs/pyldtp/ldtp.h,v
retrieving revision 1.17
diff -u -p -r1.17 ldtp.h
--- ldtp.h	14 Sep 2005 13:45:27 -0000	1.17
+++ ldtp.h	23 Sep 2005 16:26:06 -0000
@@ -118,4 +118,7 @@ int tree_table_main(Accessible *object, 
 //tool_bar.c
 int tool_bar_main (Accessible *object, int command, char **params);
 
+//remap.c
+GHashTable *do_remap (char *app_name, Accessible *object);
+
 #endif /*_LDTP_H_*/
Index: setup.py
===================================================================
RCS file: /cvs/pyldtp/setup.py,v
retrieving revision 1.29
diff -u -p -r1.29 setup.py
--- setup.py	19 Sep 2005 20:30:02 -0000	1.29
+++ setup.py	23 Sep 2005 16:26:06 -0000
@@ -74,7 +74,7 @@ status, inc_other = commands.getstatusou
 if status != 0:
     sys.exit ('Unable to get: pkg-config --cflags-only-other cspi-1.0')
 
-source_files = ['appmap.c', 'check_box.c', 'check_menu_item.c',
'combo_box.c', 'gui.c', 'icon.c', 'label.c', 'layered_pane.c', 'ldtp.c',
'list.c', 'log.c', 'menu.c', 'menu_item.c', 'panel.c',
'page_tab_list.c', 'push_button.c', 'radio_button.c',
'radio_menu_item.c', 'scroll_bar.c', 'slider.c', 'spin_button.c',
'table.c', 'text.c', 'toggle_button.c', 'tree_table.c', 'status_bar.c',
'calendar_view.c','tool_bar.c']
+source_files = ['appmap.c', 'check_box.c', 'check_menu_item.c',
'combo_box.c', 'gui.c', 'icon.c', 'label.c', 'layered_pane.c', 'ldtp.c',
'list.c', 'log.c', 'menu.c', 'menu_item.c', 'panel.c',
'page_tab_list.c', 'push_button.c', 'radio_button.c',
'radio_menu_item.c', 'scroll_bar.c', 'slider.c', 'spin_button.c',
'table.c', 'text.c', 'toggle_button.c', 'tree_table.c', 'status_bar.c',
'calendar_view.c','tool_bar.c', 'remap.c']
 
 ldtp_module = Extension ('ldtp',
                          library_dirs=lib_path,

=========================================================================
/*
  File: remap.h
*/
#ifndef __REMAP_H__
#define __REMAP_H__


/*struct object_info
{
    char *object_type;
    char *prefix;
    int instance_index;
};

typedef struct object_info OBJECT_INFO;*/

void reset_count ();
char *add_appmap_data (Accessible *accessible, char *parent_name, int
child_index, GHashTable *context); 
GHashTable *do_remap (char *application_name, Accessible *accessible); 
void accessible_object_handle (Accessible *accessible, char
*parent_name, int child_index, GHashTable *context); 
OBJECT_INFO *get_object_info (Accessible *accessible);
int filter_appmap_data (Accessible *accessible, OBJECT_INFO *cur_obj,
char *label);

#endif


======================================================================

/*
 * Linux Desktop Testing Project http://www.gnomebangalore.org/ldtp
 *
 * Author:
 *    Premkumar J <jpremkumar at novell.com>
 *
 * Copyright 2004, 2005 Novell, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "ldtp.h"
#include "gui.h"
#include "remap.h"

int table = 0,
  canvas = 0,
  column_header = 0,
  combo_box = 0,
  page_tab_list = 0,
  page_tab = 0,
  spin_button = 0,
  button = 0,
  radio_button = 0,
  check_box = 0,
  tree_table = 0,
  layered_pane = 0,
  text = 0,
  cal_view = 0,
  panel = 0,
  filler = 0,
  menubar = 0,
  menu = 0,
  separator = 0,
  scroll_bar = 0,
  scroll_pane = 0,
  split_pane = 0,
  slider = 0,
  html_container = 0,
  password_text = 0,
  progress_bar = 0,
  status_bar = 0,
  tool_bar = 0,
  label = 0,
  unknown = 0;

void reset_count()
{
  table = 0;
  canvas = 0;
  column_header = 0;
  combo_box = 0;
  page_tab_list = 0;
  page_tab = 0;
  spin_button = 0;
  button = 0;
  radio_button = 0;
  tree_table = 0;
  layered_pane = 0;
  text = 0;
  cal_view = 0;
  panel = 0;
  filler = 0;
  menubar = 0;
  menu = 0;
  separator = 0;
  scroll_bar = 0;
  scroll_pane = 0;
  split_pane = 0;
  slider = 0;
  html_container = 0;
  password_text = 0;
  progress_bar = 0;
  status_bar = 0;
  tool_bar = 0;
  label = 0;
  check_box = 0;
  unknown = 0;
}

char *strip_delim (char *data, char delim)
{
  int i;
  int j = 0;
  char *stripped_data = NULL;

  stripped_data = (char *) malloc (sizeof (char) * strlen (data) + 1);

  for (i = 0; i < strlen (data); i++)
    {
      if (data[i] == delim)
	{
	    break;
	}
	  stripped_data[j++] = data[i];
    }
  stripped_data[j] = '\0';
  return stripped_data;
}

/*
 * This function filters the appmap entries
 */
int filter_appmap_data (Accessible *accessible, OBJECT_INFO *obj_info,
char *label)
{
  if (g_strcasecmp (obj_info->object_type, "label") == 0 ||
      g_strcasecmp (obj_info->object_type, "separator") == 0 ||
      g_strcasecmp (obj_info->object_type, "table_cell") == 0)
    return 0;
  if (g_strcasecmp (label, "ukngrip") == 0)
    return 0;
  if (g_strcasecmp (obj_info->object_type, "menu_item") == 0)
    {
      Accessible *parent;
      Accessible *grand_parent;
      int parent_type;
      parent = Accessible_getParent (accessible);
      grand_parent = Accessible_getParent (parent);
      parent_type = Accessible_getRole (grand_parent);
      if (parent_type == SPI_ROLE_COMBO_BOX)
	{
	  Accessible_unref (parent);
	  Accessible_unref (grand_parent);
	  return 0;
	}
      else
	{
	  Accessible_unref (parent);
	  Accessible_unref (grand_parent);
	  return 1;
	}
    }

  if (g_strcasecmp (obj_info->object_type, "list_item") == 0)
    return 0;

  if (g_strcasecmp (obj_info->object_type, "unknown") == 0)
    {
      Accessible *parent;
      int parent_type;
      parent = Accessible_getParent (accessible);
      parent_type = Accessible_getRole (parent);
      if (parent_type == SPI_ROLE_TABLE || 
	  parent_type == SPI_ROLE_TREE_TABLE)
	{
	  Accessible_unref (parent);
	  return 0;
	}
      else
	{
	  Accessible_unref (parent);
	  return 1;
	}
    }

  return 1;
}

/*
 * This function creates entry in the Appmap file corresponding to the
object passed to it
 */
char *add_appmap_data (Accessible *accessible, char *parent_name, int
child_index, GHashTable *current_context)
{
  char *name;
  char *label;
  char *accessible_name;
  char *label_by;
  GHashTable *hash_attributes;
  OBJECT_INFO *cur_obj_info = NULL;
    
  cur_obj_info = get_object_info (accessible);
  accessible_name = Accessible_getName (accessible);
  label_by = get_relation_name (accessible);
  if (label_by)
    {
      if (g_strcasecmp (label_by,"") == 0)
	label = g_strdup (accessible_name);
      else
	label = g_strdup (label_by);
    }
  else
    label = g_strdup (accessible_name);

  if (strcmp (label, "") != 0)
    {
      char *stripped_data = NULL;
      char *value = NULL;
      if (strchr (label, ' '))
	stripped_data = strip_white_space (label);
      else
	stripped_data = g_strdup (label);
      if (strstr (stripped_data, "."))
	{
	  value = strip_delim (stripped_data, '.');
	  g_free (stripped_data);
	  stripped_data = g_strdup (value);
	  g_free (value);
	  value = NULL;
	}
      if (strstr (stripped_data, ":"))
	{
	  value = strip_delim (stripped_data, ':');
	  g_free (stripped_data);
	  stripped_data = g_strdup (value);
	  g_free (value);
	  value = NULL;
	}
      name = g_strdup_printf ("%s%s", cur_obj_info->prefix,
stripped_data);
	
      value = g_hash_table_lookup (current_context, name);
      if (value)
	{
	  if (name)
	    g_free (name);
	  name = g_strdup_printf ("%s%s%d", cur_obj_info->prefix,
stripped_data, cur_obj_info->instance_index);
	}
      g_free (stripped_data);
    }
  else
    name = g_strdup_printf ("%s%d", cur_obj_info->prefix,
cur_obj_info->instance_index);

  g_free (label);
  label = g_strdup (accessible_name);
  SPI_freeString (accessible_name);

  if (filter_appmap_data (accessible, cur_obj_info, name))
    {
      hash_attributes = g_hash_table_new (&g_str_hash, &g_str_equal);
      if (hash_attributes)
	{
	  g_hash_table_insert (hash_attributes, g_strdup ("class"), g_strdup
(cur_obj_info->object_type));
	  g_hash_table_insert (hash_attributes, g_strdup ("parent"), g_strdup
(parent_name));
	  g_hash_table_insert (hash_attributes, g_strdup ("child_index"),
g_strdup_printf ("%d", child_index));
	  if (g_strcasecmp (label,"") != 0 && 
	      g_strcasecmp (cur_obj_info->object_type, "combo_box") != 0)
	    g_hash_table_insert (hash_attributes, g_strdup ("label"), g_strdup
(label));
	  else
	    {
	      if (label_by)
		{
		  g_hash_table_insert (hash_attributes, g_strdup ("label_by"),
g_strdup (label_by));
		  g_free (label_by);
		}
	    }
	}
      if (current_context)
	g_hash_table_insert (current_context, g_strdup (name),
hash_attributes);	
      g_free (label);
      g_free (cur_obj_info->object_type);
      g_free (cur_obj_info->prefix);
      g_free (cur_obj_info);
      return name;
    }
  else
    {
      g_free (name);
      g_free (label);
      g_free (cur_obj_info->object_type);
      g_free (cur_obj_info->prefix);
      g_free (cur_obj_info);
      return NULL;
    }
}

/*
 * This function returns the information about the accessible object
 * passed
 */
OBJECT_INFO *get_object_info (Accessible *accessible)
{
  OBJECT_INFO *obj_info;
  int role;

  obj_info = (OBJECT_INFO *) malloc (sizeof (OBJECT_INFO));
  role = Accessible_getRole (accessible);

  if (role == SPI_ROLE_PAGE_TAB) 
    {
      obj_info->prefix = g_strdup ("ptab");
      page_tab++;
      obj_info->instance_index = page_tab;
      obj_info->object_type = g_strdup ("page_tab");
    }
  else if (role == SPI_ROLE_PAGE_TAB_LIST) 
    {
      obj_info->prefix = g_strdup ("ptl");
      page_tab_list++;
      obj_info->instance_index = page_tab_list;
      obj_info->object_type = g_strdup ("page_tab_list");
    }
  else if (role == SPI_ROLE_TABLE) 
    {
      obj_info->prefix = g_strdup ("tbl");
      table++;
      obj_info->instance_index = table;
      obj_info->object_type = g_strdup ("table");
    }
  else if (role == SPI_ROLE_COMBO_BOX) 
    {
      obj_info->prefix = g_strdup ("cbo");
      combo_box++;
      obj_info->instance_index = combo_box;
      obj_info->object_type = g_strdup ("combo_box");
    }
  else if (role == SPI_ROLE_SPIN_BUTTON) 
    {
      obj_info->prefix = g_strdup ("sbtn");
      spin_button++;
      obj_info->instance_index = spin_button;
      obj_info->object_type = g_strdup ("spin_button");
    }
  else if (role == SPI_ROLE_FONT_CHOOSER) 
    {
      obj_info->prefix = g_strdup ("dlg");
      obj_info->instance_index = -1; /* Value -1 signifies not
applicable  */
      obj_info->object_type = g_strdup ("font_chooser");
    }
  else if (role == SPI_ROLE_RADIO_BUTTON) 
    {
      obj_info->prefix = g_strdup ("rbtn");
      radio_button++;
      obj_info->instance_index = radio_button;
      obj_info->object_type = g_strdup ("radio_button");
    }
  else if (role == SPI_ROLE_TREE_TABLE) 
    {
      obj_info->prefix = g_strdup ("ttbl");
      tree_table++;
      obj_info->instance_index = tree_table;
      obj_info->object_type = g_strdup ("tree_table");
    }
  else if (role == SPI_ROLE_LAYERED_PANE) 
    {
      obj_info->prefix = g_strdup ("pane");
      layered_pane++;
      obj_info->instance_index = layered_pane;
      obj_info->object_type = g_strdup ("layered_pane");
    }
  else if (role == SPI_ROLE_FRAME) 
    {
      obj_info->prefix = g_strdup ("frm");
      obj_info->instance_index = -1;
      obj_info->object_type = g_strdup ("frame");
    }
  else if (role == SPI_ROLE_DIALOG) 
    {
      obj_info->prefix = g_strdup ("dlg");
      obj_info->instance_index = -1;
      obj_info->object_type = g_strdup ("dialog");
    }
  else if (role == SPI_ROLE_ALERT) 
    {
      obj_info->prefix = g_strdup ("dlg");
      obj_info->instance_index = -1;
      obj_info->object_type = g_strdup ("alert");
    }
  else if (role == SPI_ROLE_CALENDAR) 
    {
      obj_info->prefix = g_strdup ("calview");
      cal_view++;
      obj_info->instance_index = cal_view;
      obj_info->object_type = g_strdup ("calendar_view");
    }
  else if (role == SPI_ROLE_PANEL) 
    {
      obj_info->prefix = g_strdup ("pnl");
      panel++;
      obj_info->instance_index = panel;
      obj_info->object_type = g_strdup ("panel");
    }
  else if (role == SPI_ROLE_LABEL) 
    {
      obj_info->prefix = g_strdup ("lbl");
      label++;
      obj_info->instance_index = label;
      obj_info->object_type = g_strdup ("label");
    }
  else if (role == SPI_ROLE_MENU_BAR) 
    {
      obj_info->prefix = g_strdup ("mbr");
      menubar++;
      obj_info->instance_index = menubar;
      obj_info->object_type = g_strdup ("menu_bar");
    }
  else if (role == SPI_ROLE_MENU) 
    {
      obj_info->prefix = g_strdup ("mnu");
      menu++;
      obj_info->instance_index = menu;
      obj_info->object_type = g_strdup ("menu");
    }
  else if (role == SPI_ROLE_MENU_ITEM) 
    {
      obj_info->prefix = g_strdup ("mnu");
      menu++;
      obj_info->instance_index = menu;
      obj_info->object_type = g_strdup ("menu_item");
    }
  else if (role == SPI_ROLE_LIST_ITEM) 
    {
      obj_info->prefix = g_strdup ("lst");
      obj_info->instance_index = -1;
      obj_info->object_type = g_strdup ("list_item");
    }
  else if (role == SPI_ROLE_CHECK_MENU_ITEM) 
    {
      obj_info->prefix = g_strdup ("mnu");
      menu++;
      obj_info->instance_index = menu;
      obj_info->object_type = g_strdup ("check_menu_item");
    }
  else if (role == SPI_ROLE_RADIO_MENU_ITEM)
    {
      obj_info->prefix = g_strdup ("mnu");
      menu++;
      obj_info->instance_index = menu;
      obj_info->object_type = g_strdup ("radio_menu_item");
    }
  else if (role == SPI_ROLE_PUSH_BUTTON) 
    {
      obj_info->prefix = g_strdup ("btn");
      button++;
      obj_info->instance_index = button;
      obj_info->object_type = g_strdup ("push_button");
    }
  else if (role == SPI_ROLE_TOGGLE_BUTTON) 
    {
      obj_info->prefix = g_strdup ("btn");
      button++;
      obj_info->instance_index = button;
      obj_info->object_type = g_strdup ("toggle_button");
    }
  else if (role == SPI_ROLE_SCROLL_BAR) 
    {
      obj_info->prefix = g_strdup ("scbr");
      scroll_bar++;
      obj_info->instance_index = scroll_bar;
      obj_info->object_type = g_strdup ("scroll_bar");
    }
  else if (role == SPI_ROLE_SCROLL_PANE) 
    {
      obj_info->prefix = g_strdup ("scpn");
      scroll_pane++;
      obj_info->instance_index = scroll_pane;
      obj_info->object_type = g_strdup ("scroll_pane");
    }
  else if (role == SPI_ROLE_TEXT) 
    {
      obj_info->prefix = g_strdup ("txt");
      text++;
      obj_info->instance_index = text;
      obj_info->object_type = g_strdup ("text");
    }
  else if (role == SPI_ROLE_PASSWORD_TEXT) 
    {
      obj_info->prefix = g_strdup ("txt");
      text++;
      obj_info->instance_index = text;
      obj_info->object_type = g_strdup ("password_text");
    }
  else if (role == SPI_ROLE_STATUS_BAR) 
    {
      obj_info->prefix = g_strdup ("stat");
      status_bar++;
      obj_info->instance_index = status_bar;
      obj_info->object_type = g_strdup ("statusbar");
    }
  else if (role == SPI_ROLE_TABLE_COLUMN_HEADER) 
    {
      obj_info->prefix = g_strdup ("tch");
      column_header++;
      obj_info->instance_index = status_bar;
      obj_info->object_type = g_strdup ("table_column_header");
    }
  else if (role == SPI_ROLE_SEPARATOR) 
    {
      obj_info->prefix = g_strdup ("spr");
      separator++;
      obj_info->instance_index = separator;
      obj_info->object_type = g_strdup ("separator");
    }
  else if (role == SPI_ROLE_FILLER) 
    {
      obj_info->prefix = g_strdup ("flr");
      filler++;
      obj_info->instance_index = filler;
      obj_info->object_type = g_strdup ("filler");
    }
  else if (role == SPI_ROLE_CANVAS) 
    {
      obj_info->prefix = g_strdup ("cnvs");
      canvas++;
      obj_info->instance_index = canvas;
      obj_info->object_type = g_strdup ("canvas");
    }
  else if (role == SPI_ROLE_SPLIT_PANE) 
    {
      obj_info->prefix = g_strdup ("splt");
      split_pane++;
      obj_info->instance_index = split_pane;
      obj_info->object_type = g_strdup ("split_pane");
    }
  else if (role == SPI_ROLE_SLIDER) 
    {
      obj_info->prefix = g_strdup ("sldr");
      slider++;
      obj_info->instance_index = slider;
      obj_info->object_type = g_strdup ("slider");
    }
  else if (role == SPI_ROLE_HTML_CONTAINER) 
    {
      obj_info->prefix = g_strdup ("html");
      html_container++;
      obj_info->instance_index = html_container;
      obj_info->object_type = g_strdup ("html_container");
    }
  else if (role == SPI_ROLE_PROGRESS_BAR) 
    {
      obj_info->prefix = g_strdup ("pbar");
      progress_bar++;
      obj_info->instance_index = progress_bar;
      obj_info->object_type = g_strdup ("progree_bar");
    }
  else if (role == SPI_ROLE_TOOL_BAR) 
    {
      obj_info->prefix = g_strdup ("tbar");
      tool_bar++;
      obj_info->instance_index = tool_bar;
      obj_info->object_type = g_strdup ("tool_bar");
    }
  else if (role == SPI_ROLE_CHECK_BOX) 
    {
      obj_info->prefix = g_strdup ("chk");
      check_box++;
      obj_info->instance_index = check_box;
      obj_info->object_type = g_strdup ("check_box");
    }
  else if (role == SPI_ROLE_TABLE_CELL) 
    {
      obj_info->prefix = g_strdup ("tblc");
      obj_info->instance_index = -1;
      obj_info->object_type = g_strdup ("table_cell");
    }
  else 
    {
      obj_info->prefix = g_strdup("ukn");
      unknown++;
      obj_info->instance_index = unknown;
      obj_info->object_type = g_strdup ("unknown");
    }
  return obj_info;
}

GHashTable *do_remap (char *application_name, Accessible
*accessible_context)
{
  GHashTable *current_context = NULL;
  reset_count ();
  current_context = g_hash_table_new (&g_str_hash, &g_str_equal);
  accessible_object_handle (accessible_context, application_name, 0,
current_context);
  return current_context;
}

/*
  Get accessible handle of the given object
*/
void accessible_object_handle (Accessible *accessible, char*
parent_name, 
			       int child_index, GHashTable *current_context)
{
    int i, num_child;
    Accessible *child;
    char *current_parent = NULL;
    char *temp_parent = NULL;

    num_child = Accessible_getChildCount (accessible);
    temp_parent = add_appmap_data (accessible, parent_name, child_index,
current_context);
    if (temp_parent)
    {
	current_parent = g_strdup (temp_parent);
	g_free (temp_parent);
	for (i = 0; i < num_child; i++)
	{
	    child = Accessible_getChildAtIndex (accessible, i);
	    if (!child)
		continue;
	    /*
	      Call this function recursively, until we reach the end of
	      depth first search in all the given object handle
	    */
	    accessible_object_handle (child, current_parent, i,
current_context);
	    Accessible_unref (child);
	}
	g_free (current_parent);
    }
}




More information about the Ldtp-dev mailing list