diff options
author | nags <nags@nags-desktop.(none)> | 2009-08-11 20:36:48 -0700 |
---|---|---|
committer | nags <nags@nags-desktop.(none)> | 2009-08-11 20:36:48 -0700 |
commit | 479ef9ae953fc39110859e0cca7af0b61a905d78 (patch) | |
tree | 57a5b601c8ea1b9be20b6753d9fd12bf92445c10 | |
parent | caed1328fbeb7e415640598bb6dc8617696264b8 (diff) |
2009-08-11 Nagappan Alagappan <nagappan@gmail.com>
* ldtp.c (get_current_time): Fixes bug 587614, Method to measure how
long a window is showing up.
* client-handler.c (handle_request): Fixes bug 587614, Method to
measure how long a window is showing up.
-rw-r--r-- | src/ChangeLog | 8 | ||||
-rw-r--r-- | src/client-handler.c | 19 | ||||
-rw-r--r-- | src/ldtp-command.h | 3 | ||||
-rw-r--r-- | src/ldtp.c | 127 |
4 files changed, 103 insertions, 54 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index b767689..8b63262 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2009-08-11 Nagappan Alagappan <nagappan@gmail.com> + + * ldtp.c (get_current_time): Fixes bug 587614, Method to measure how + long a window is showing up. + + * client-handler.c (handle_request): Fixes bug 587614, Method to + measure how long a window is showing up. + 2009-07-30 Nagappan Alagappan <nagappan@gmail.com> * tree-table.c (does_row_exist): Fixes bug 588674, It would be diff --git a/src/client-handler.c b/src/client-handler.c index df63a45..3b35e5c 100644 --- a/src/client-handler.c +++ b/src/client-handler.c @@ -43,6 +43,7 @@ extern gint ldtp_gui_timeout; extern gint ldtp_obj_timeout; extern GHashTable *event_notifier; extern GHashTable *client_context; +extern GHashTable *window_duration; extern gboolean ldtp_script_service; extern gboolean ldtp_external_xml_file; @@ -1172,6 +1173,24 @@ handle_request (LDTPClientContext* cctxt, set_new_context ((char *)cctxt->req->context, (char *)cctxt->req->component); return; + case LDTP_CMD_WINDOWUPTIME: { + GHashTable *window_up_time; + if (g_hash_table_lookup_extended (window_duration, cctxt->req->context, + NULL, (gpointer) &window_up_time)) { + char *start_time = g_hash_table_lookup (window_up_time, "start_time"); + char *end_time = g_hash_table_lookup (window_up_time, "end_time"); + g_print ("WINDOWUPTIME: %s %s\n", + start_time, + end_time); + cctxt->resp->data = g_strdup_printf ("%s-%s", + end_time, + start_time); + cctxt->resp->data_len = strlen (cctxt->resp->data); + } else + g_print ("NULL\n"); + return; + } + case LDTP_CMD_RELEASECONTEXT: release_last_context (); return; diff --git a/src/ldtp-command.h b/src/ldtp-command.h index 39fd8e4..eb96bb7 100644 --- a/src/ldtp-command.h +++ b/src/ldtp-command.h @@ -204,7 +204,8 @@ enum _LDTPCommandId { LDTP_CMD_VERIFYUNCHECKROW, LDTP_CMD_VERIFYVISIBLEBUTTONCOUNT, LDTP_CMD_WAITTILLGUIEXIST, - LDTP_CMD_WAITTILLGUINOTEXIST + LDTP_CMD_WAITTILLGUINOTEXIST, + LDTP_CMD_WINDOWUPTIME }; #endif @@ -57,6 +57,7 @@ pthread_mutex_t cb_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t client_thread_pool_mutex = PTHREAD_MUTEX_INITIALIZER; static char *env_ldtp_debug; static char *env_ldtp_debug_file; +GHashTable *window_duration = NULL; #ifdef ENABLE_GOPTIONPARSE static GOptionEntry entries [] = @@ -97,11 +98,29 @@ is_window_in_cctxt (char *window_name) return cctxt; } +static char* +get_current_time() +{ + char outstr[200]; + time_t t; + struct tm *tmp; + + t = time(NULL); + tmp = localtime(&t); + if (tmp == NULL) + return NULL; + + if (strftime(outstr, sizeof(outstr), "%Y %m %d %H %M %S", tmp) == 0) + return NULL; + + return g_strdup (outstr); +} + static void report_window_event (const AccessibleEvent *event, void *user_data) { g_print ("Event type: %s\n", event->type); - if (event_notifier && g_ascii_strcasecmp ("window:create", event->type) == 0) { + if (g_ascii_strcasecmp ("window:create", event->type) == 0) { uint32_t resp_size = 0; LDTPErrorCode status; char *resp_pckt = NULL; @@ -122,27 +141,39 @@ report_window_event (const AccessibleEvent *event, void *user_data) g_free (tmp); tmp = NULL; } - if (window_name) - SPI_freeString (title); - } else { - window_name = g_strdup (title); - if (window_name) { - g_print ("Window name: %s - %s\n", window_name, title); - SPI_freeString (title); - } - } + } else + window_name = get_window_name_in_appmap_format (title, + Accessible_getRole (event->source)); + SPI_freeString (title); if (window_name) { - g_print ("Window name: %s\n", window_name); - title = g_strdup(window_name); - g_free (window_name); - } - if ((cctxt = is_window_reg_for_events (title))) { + char *current_time = get_current_time (); + if (current_time) { + GHashTable *start_time; + start_time = g_hash_table_new_full (&g_str_hash, &g_str_equal, + &destroy_string, + &destroy_string); + if (start_time) { + g_hash_table_insert (start_time, + g_strdup ("start_time"), + g_strdup (current_time)); + g_hash_table_insert (start_time, + g_strdup ("end_time"), + g_strdup (current_time)); + } + g_free (current_time); + g_hash_table_replace (window_duration, + g_strdup (window_name), + start_time); + } + } else + return; + if ((cctxt = is_window_reg_for_events (window_name))) { /* Notify to client */ if (!cctxt || !cctxt->resp) { g_print ("CCTXT is lost\n"); - g_free (title); + g_free (window_name); return; } cctxt->resp->data = g_strdup (title); @@ -151,7 +182,7 @@ report_window_event (const AccessibleEvent *event, void *user_data) generate_notification_packet (cctxt, &status, &resp_pckt, &resp_size); if (status != LDTP_ERROR_SUCCESS) { - g_free (title); + g_free (window_name); g_print ("Error generating notification\n"); return; } @@ -160,43 +191,10 @@ report_window_event (const AccessibleEvent *event, void *user_data) send_response (cctxt->sock_fd, resp_pckt, resp_size, &status); g_free (cctxt->resp->data); cctxt->resp->data = NULL; - g_free (title); - return; - } - /* - If window title is used in old appmap format (like - dlgFind), then use the following approach - */ - window_name = get_window_name_in_appmap_format (title, - Accessible_getRole (event->source)); - g_free (title); - title = NULL; - if (window_name && is_window_reg_for_events (window_name) && - cctxt && cctxt->resp) { - /* - Notify to client - */ - if (window_name) { - g_free (window_name); - window_name = NULL; - } - cctxt->resp->resp_status = LDTP_ERROR_SUCCESS; - - generate_notification_packet (cctxt, &status, &resp_pckt, - &resp_size); - if (status != LDTP_ERROR_SUCCESS) { - g_print ("Error generating notification\n"); - return; - } - - g_print ("Notification: %s - Len - %d", resp_pckt, resp_size); - send_response (cctxt->sock_fd, resp_pckt, resp_size, &status); - return; - } - if (window_name) { g_free (window_name); - window_name = NULL; + return; } + g_free (window_name); } else if (g_ascii_strcasecmp ("window:close", event->type) == 0 || g_ascii_strcasecmp ("window:deactivate", event->type) == 0 || g_ascii_strcasecmp ("window:destroy", event->type) == 0) { @@ -246,7 +244,20 @@ report_window_event (const AccessibleEvent *event, void *user_data) window_name = get_window_name_in_appmap_format (title, Accessible_getRole (event->source)); if (window_name) { - g_print ("Window name: %s - %s\n", window_name, title); + char *current_time = get_current_time (); + if (current_time) { + GHashTable *end_time = NULL; + if (g_hash_table_lookup_extended(window_duration, + window_name, + NULL, + (gpointer) &end_time)) { + if (end_time) + g_hash_table_replace (end_time, + g_strdup ("end_time"), + g_strdup (current_time)); + } + g_free (current_time); + } cctxt = is_window_in_cctxt (window_name); if (cctxt && cctxt->app_map) { if (pthread_mutex_trylock (&cb_mutex) != EBUSY) { @@ -257,6 +268,7 @@ report_window_event (const AccessibleEvent *event, void *user_data) g_free (window_name); window_name = NULL; } + SPI_freeString (title); } } @@ -284,6 +296,11 @@ cleanup (int mysig) ldtp_debug_log_fp = NULL; } + if (window_duration) { + g_hash_table_destroy (window_duration); + window_duration = NULL; + } + pthread_mutex_lock (&client_thread_pool_mutex); if (event_notifier) { g_hash_table_destroy (event_notifier); @@ -651,6 +668,10 @@ main (int argc, char **argv) env_ldtp_debug = getenv ("LDTP_DEBUG"); env_ldtp_debug_file = getenv ("LDTP_DEBUG_LOGFILE"); + window_duration = g_hash_table_new_full (&g_str_hash, &g_str_equal, + &destroy_string, + &destroy_hashtable); + retval = pthread_create (&server_thread, NULL, &ldtp_server_thread, NULL); if (retval == EAGAIN) { |