~ara/ubuntu/lucid/ldtp/ldtp_fix_551457

« back to all changes in this revision

Viewing changes to src/ldtp.c

  • Committer: Bazaar Package Importer
  • Author(s): Ara Pulido
  • Date: 2009-08-13 09:54:47 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090813095447-oxj1hf00ff8wljbf
Tags: 1.7.0-0ubuntu1
* New upstream release (Fixes LP: #412882)
* debian/control:
  + Changed Depends from deprecated python-gnome2-desktop
    to python-wnck and python-gtksourceview (Fixes LP: #412871)

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#include "client-handler.h"
35
35
#include "ldtp-error.h"
36
36
#include "ldtp-logger.h"
 
37
#include "device.h"
37
38
 
38
39
#ifndef ENABLE_GOPTIONPARSE
39
40
#include <getopt.h>
57
58
pthread_mutex_t client_thread_pool_mutex = PTHREAD_MUTEX_INITIALIZER;
58
59
static char *env_ldtp_debug;
59
60
static char *env_ldtp_debug_file;
 
61
GHashTable *window_duration = NULL;
60
62
 
61
63
#ifdef ENABLE_GOPTIONPARSE
62
64
static GOptionEntry entries [] = 
74
76
#endif
75
77
 
76
78
static LDTPClientContext*
77
 
is_window_reg_for_events (char *context)
 
79
is_window_reg_for_events (char *context, char *window_name)
78
80
{
79
81
        LDTPClientContext *cctxt = NULL;
80
82
        if (event_notifier) {
81
83
                cctxt = g_hash_table_find (event_notifier, search_title_based, context);
 
84
                if (cctxt && context && cctxt->req && cctxt->req->context) {
 
85
                        g_print ("Registered window title: %s - %s\n", context, cctxt->req->context);
 
86
                        return cctxt;
 
87
                }
 
88
                cctxt = g_hash_table_find (event_notifier, search_title_based, window_name);
82
89
                if (cctxt && context && cctxt->req && cctxt->req->context)
83
90
                        g_print ("Registered window title: %s - %s\n", context, cctxt->req->context);
84
91
        }
97
104
        return cctxt;
98
105
}
99
106
 
 
107
static char*
 
108
get_current_time()
 
109
{
 
110
        char outstr[200];
 
111
        time_t t;
 
112
        struct tm *tmp;
 
113
 
 
114
        t = time(NULL);
 
115
        tmp = localtime(&t);
 
116
        if (tmp == NULL)
 
117
                return NULL;
 
118
 
 
119
        if (strftime(outstr, sizeof(outstr), "%Y %m %d %H %M %S", tmp) == 0)
 
120
                return NULL;
 
121
 
 
122
        return g_strdup (outstr);
 
123
}
 
124
 
100
125
static void
101
126
report_window_event  (const AccessibleEvent *event, void *user_data)
102
127
{
103
128
        g_print ("Event type: %s\n", event->type);
104
 
        if (event_notifier && g_ascii_strcasecmp ("window:create", event->type) == 0) {
 
129
        if (g_ascii_strcasecmp ("window:create", event->type) == 0) {
105
130
                uint32_t resp_size = 0;
106
131
                LDTPErrorCode status;
107
132
                char *resp_pckt = NULL;
122
147
                                g_free (tmp);
123
148
                                tmp = NULL;
124
149
                        }
125
 
                        if (window_name)
126
 
                                SPI_freeString (title);
 
150
                } else
 
151
                        window_name = get_window_name_in_appmap_format (title,
 
152
                                                                        Accessible_getRole (event->source));
 
153
                if (window_name) {
 
154
                        char *current_time = get_current_time ();
 
155
                        if (current_time) {
 
156
                                GHashTable *start_time;
 
157
                                start_time = g_hash_table_new_full (&g_str_hash, &g_str_equal,
 
158
                                                                    &destroy_string,
 
159
                                                                    &destroy_string);
 
160
                                if (start_time) {
 
161
                                        g_hash_table_insert (start_time,
 
162
                                                             g_strdup ("start_time"),
 
163
                                                             g_strdup (current_time));
 
164
                                        g_hash_table_insert (start_time,
 
165
                                                             g_strdup ("end_time"),
 
166
                                                             g_strdup (current_time));
 
167
                                }
 
168
                                g_free (current_time);
 
169
                                g_hash_table_replace (window_duration,
 
170
                                                      g_strdup (window_name),
 
171
                                                      start_time);
 
172
                        }
127
173
                } else {
128
 
                        window_name = g_strdup (title);
129
 
                        if (window_name) {
130
 
                                g_print ("Window name: %s - %s\n", window_name, title);
131
 
                                SPI_freeString (title);
132
 
                        }
133
 
                }
134
 
                if (window_name) {
135
 
                        g_print ("Window name: %s\n", window_name);
136
 
                        title = g_strdup(window_name);
137
 
                        g_free (window_name);
138
 
                }
139
 
                if ((cctxt = is_window_reg_for_events (title))) {
 
174
                        SPI_freeString (title);
 
175
                        return;
 
176
                }
 
177
                if ((cctxt = is_window_reg_for_events (window_name, title))) {
140
178
                        /*
141
179
                          Notify to client
142
180
                        */
143
181
                        if (!cctxt || !cctxt->resp) {
144
182
                                g_print ("CCTXT is lost\n");
145
 
                                g_free (title);
 
183
                                g_free (window_name);
 
184
                                SPI_freeString (title);
146
185
                                return;
147
186
                        }
148
 
                        cctxt->resp->data = g_strdup (title);
149
 
                        cctxt->resp->data_len = g_utf8_strlen (title, -1);
 
187
                        cctxt->resp->data = g_strdup (window_name);
 
188
                        cctxt->resp->data_len = g_utf8_strlen (window_name, -1);
150
189
                        cctxt->resp->resp_status = LDTP_ERROR_SUCCESS;
151
190
 
152
191
                        generate_notification_packet (cctxt, &status, &resp_pckt, &resp_size);
153
192
                        if (status != LDTP_ERROR_SUCCESS) {
154
 
                                g_free (title);
 
193
                                SPI_freeString (title);
 
194
                                g_free (window_name);
155
195
                                g_print ("Error generating notification\n");
156
196
                                return;
157
197
                        }
160
200
                        send_response (cctxt->sock_fd, resp_pckt, resp_size, &status);
161
201
                        g_free (cctxt->resp->data);
162
202
                        cctxt->resp->data = NULL;
163
 
                        g_free (title);
164
 
                        return;
165
 
                }
166
 
                /*
167
 
                  If window title is used in old appmap format (like
168
 
                  dlgFind), then use the following approach
169
 
                */
170
 
                window_name = get_window_name_in_appmap_format (title,
171
 
                                                                Accessible_getRole (event->source));
172
 
                g_free (title);
173
 
                title = NULL;
174
 
                if (window_name && is_window_reg_for_events (window_name) &&
175
 
                    cctxt && cctxt->resp) {
176
 
                        /*
177
 
                          Notify to client
178
 
                        */
179
 
                        if (window_name) {
180
 
                                g_free (window_name);
181
 
                                window_name = NULL;
182
 
                        }
183
 
                        cctxt->resp->resp_status = LDTP_ERROR_SUCCESS;
184
 
 
185
 
                        generate_notification_packet (cctxt, &status, &resp_pckt,
186
 
                                                      &resp_size);
187
 
                        if (status != LDTP_ERROR_SUCCESS) {
188
 
                                g_print ("Error generating notification\n");
189
 
                                return;
190
 
                        }
191
 
 
192
 
                        g_print ("Notification: %s - Len - %d", resp_pckt, resp_size);
193
 
                        send_response (cctxt->sock_fd, resp_pckt, resp_size, &status);
194
 
                        return;
195
 
                }
196
 
                if (window_name) {
 
203
                        SPI_freeString (title);
197
204
                        g_free (window_name);
198
 
                        window_name = NULL;
 
205
                        return;
199
206
                }
 
207
                g_free (window_name);
 
208
                SPI_freeString (title);
200
209
        } else if (g_ascii_strcasecmp ("window:close", event->type) == 0 ||
201
210
                   g_ascii_strcasecmp ("window:deactivate", event->type) == 0 ||
202
211
                   g_ascii_strcasecmp ("window:destroy", event->type) == 0) {
246
255
                window_name = get_window_name_in_appmap_format (title,
247
256
                                                                Accessible_getRole (event->source));
248
257
                if (window_name) {
249
 
                        g_print ("Window name: %s - %s\n", window_name, title);
 
258
                        char *current_time = get_current_time ();
 
259
                        if (current_time) {
 
260
                                GHashTable *end_time = NULL;
 
261
                                if (g_hash_table_lookup_extended(window_duration,
 
262
                                                                 window_name,
 
263
                                                                 NULL,
 
264
                                                                 (gpointer) &end_time)) {
 
265
                                        if (end_time)
 
266
                                                g_hash_table_replace (end_time,
 
267
                                                                      g_strdup ("end_time"),
 
268
                                                                      g_strdup (current_time));
 
269
                                }
 
270
                                g_free (current_time);
 
271
                        }
250
272
                        cctxt = is_window_in_cctxt (window_name);
251
273
                        if (cctxt && cctxt->app_map) {
252
274
                                if (pthread_mutex_trylock (&cb_mutex) != EBUSY) {
257
279
                        g_free (window_name);
258
280
                        window_name = NULL;
259
281
                }
 
282
 
260
283
                SPI_freeString (title);
261
284
        }
262
285
}
284
307
                ldtp_debug_log_fp = NULL;
285
308
        }
286
309
 
 
310
        if (window_duration) {
 
311
                g_hash_table_destroy (window_duration);
 
312
                window_duration = NULL;
 
313
        }
 
314
 
287
315
        pthread_mutex_lock (&client_thread_pool_mutex);
288
316
        if (event_notifier) {
289
317
                g_hash_table_destroy (event_notifier);
651
679
        env_ldtp_debug = getenv ("LDTP_DEBUG");
652
680
        env_ldtp_debug_file = getenv ("LDTP_DEBUG_LOGFILE");
653
681
 
 
682
        window_duration = g_hash_table_new_full (&g_str_hash, &g_str_equal,
 
683
                                                 &destroy_string,
 
684
                                                 &destroy_hashtable);
 
685
 
654
686
        retval = pthread_create (&server_thread, NULL, &ldtp_server_thread, 
655
687
                                 NULL);
656
688
        if (retval == EAGAIN) {
661
693
        }
662
694
        debug_log_file_name = get_log_file_name ();
663
695
        ldtp_debug_log_fp = fopen (debug_log_file_name, "a");
 
696
 
 
697
        /* get the keyboard keycodes from xmodmod -pke */
 
698
        get_keyboard_keycodes();
 
699
 
664
700
        spi_init = SPI_init ();
665
701
 
666
702
        window_listener = SPI_createAccessibleEventListener (report_window_event, NULL);