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;
61
63
#ifdef ENABLE_GOPTIONPARSE
62
64
static GOptionEntry entries [] =
76
78
static LDTPClientContext*
77
is_window_reg_for_events (char *context)
79
is_window_reg_for_events (char *context, char *window_name)
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);
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);
119
if (strftime(outstr, sizeof(outstr), "%Y %m %d %H %M %S", tmp) == 0)
122
return g_strdup (outstr);
101
126
report_window_event (const AccessibleEvent *event, void *user_data)
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;
126
SPI_freeString (title);
151
window_name = get_window_name_in_appmap_format (title,
152
Accessible_getRole (event->source));
154
char *current_time = get_current_time ();
156
GHashTable *start_time;
157
start_time = g_hash_table_new_full (&g_str_hash, &g_str_equal,
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));
168
g_free (current_time);
169
g_hash_table_replace (window_duration,
170
g_strdup (window_name),
128
window_name = g_strdup (title);
130
g_print ("Window name: %s - %s\n", window_name, title);
131
SPI_freeString (title);
135
g_print ("Window name: %s\n", window_name);
136
title = g_strdup(window_name);
137
g_free (window_name);
139
if ((cctxt = is_window_reg_for_events (title))) {
174
SPI_freeString (title);
177
if ((cctxt = is_window_reg_for_events (window_name, title))) {
143
181
if (!cctxt || !cctxt->resp) {
144
182
g_print ("CCTXT is lost\n");
183
g_free (window_name);
184
SPI_freeString (title);
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;
152
191
generate_notification_packet (cctxt, &status, &resp_pckt, &resp_size);
153
192
if (status != LDTP_ERROR_SUCCESS) {
193
SPI_freeString (title);
194
g_free (window_name);
155
195
g_print ("Error generating notification\n");
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;
167
If window title is used in old appmap format (like
168
dlgFind), then use the following approach
170
window_name = get_window_name_in_appmap_format (title,
171
Accessible_getRole (event->source));
174
if (window_name && is_window_reg_for_events (window_name) &&
175
cctxt && cctxt->resp) {
180
g_free (window_name);
183
cctxt->resp->resp_status = LDTP_ERROR_SUCCESS;
185
generate_notification_packet (cctxt, &status, &resp_pckt,
187
if (status != LDTP_ERROR_SUCCESS) {
188
g_print ("Error generating notification\n");
192
g_print ("Notification: %s - Len - %d", resp_pckt, resp_size);
193
send_response (cctxt->sock_fd, resp_pckt, resp_size, &status);
203
SPI_freeString (title);
197
204
g_free (window_name);
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 ();
260
GHashTable *end_time = NULL;
261
if (g_hash_table_lookup_extended(window_duration,
264
(gpointer) &end_time)) {
266
g_hash_table_replace (end_time,
267
g_strdup ("end_time"),
268
g_strdup (current_time));
270
g_free (current_time);
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) {
651
679
env_ldtp_debug = getenv ("LDTP_DEBUG");
652
680
env_ldtp_debug_file = getenv ("LDTP_DEBUG_LOGFILE");
682
window_duration = g_hash_table_new_full (&g_str_hash, &g_str_equal,
654
686
retval = pthread_create (&server_thread, NULL, &ldtp_server_thread,
656
688
if (retval == EAGAIN) {
662
694
debug_log_file_name = get_log_file_name ();
663
695
ldtp_debug_log_fp = fopen (debug_log_file_name, "a");
697
/* get the keyboard keycodes from xmodmod -pke */
698
get_keyboard_keycodes();
664
700
spi_init = SPI_init ();
666
702
window_listener = SPI_createAccessibleEventListener (report_window_event, NULL);