From: Mike Gorse Date: Tue, 31 Aug 2010 02:11:30 +0000 (-0400) Subject: Merge branch 'master' into p2p X-Git-Tag: AT_SPI2_ATK_2_12_0~336^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f0061858ec3c9151fe4b20e390678093ea8f32df;hp=3e707fcae1f498038f7c2894eedc49c063bf1690;p=platform%2Fcore%2Fuifw%2Fat-spi2-atk.git Merge branch 'master' into p2p --- diff --git a/atk-adaptor/adaptors/application-adaptor.c b/atk-adaptor/adaptors/application-adaptor.c index 71f146b..1877b8f 100644 --- a/atk-adaptor/adaptors/application-adaptor.c +++ b/atk-adaptor/adaptors/application-adaptor.c @@ -28,6 +28,9 @@ #include "common/spi-dbus.h" #include "introspection.h" +/* for spi_global_app_data is there a better way? */ +#include "../bridge.h" + static dbus_bool_t impl_get_ToolkitName (DBusMessageIter * iter, void *user_data) { @@ -87,12 +90,24 @@ impl_GetLocale (DBusConnection * bus, DBusMessage * message, void *user_data) return NULL; } +static DBusMessage * +impl_get_app_bus(DBusConnection *bus, DBusMessage *msg, void *data) +{ +DBusMessage *reply; + +reply = dbus_message_new_method_return(msg); +if(reply) dbus_message_append_args(reply, DBUS_TYPE_STRING, &(spi_global_app_data->app_bus_addr), DBUS_TYPE_INVALID); + +return reply; +} + static DRouteMethod methods[] = { {impl_registerToolkitEventListener, "registerToolkitEventListener"}, {impl_registerObjectEventListener, "registerObjectEventListener"}, {impl_pause, "pause"}, {impl_resume, "resume"}, {impl_GetLocale, "GetLocale"}, + {impl_get_app_bus, "GetApplicationBusAddress"}, {NULL, NULL} }; diff --git a/atk-adaptor/bridge.c b/atk-adaptor/bridge.c index a8e0335..5fcd4fc 100644 --- a/atk-adaptor/bridge.c +++ b/atk-adaptor/bridge.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -175,23 +176,6 @@ set_reply (DBusPendingCall *pending, void *user_data) *replyptr = dbus_pending_call_steal_reply (pending); } -static DBusMessage * -send_and_allow_reentry (DBusConnection *bus, DBusMessage *message, DBusError *error) -{ - DBusPendingCall *pending; - DBusMessage *reply = NULL; - - if (!dbus_connection_send_with_reply (bus, message, &pending, -1)) - { - return NULL; - } - dbus_pending_call_set_notify (pending, set_reply, (void *)&reply, NULL); - while (!reply) - { - if (!dbus_connection_read_write_dispatch (bus, -1)) return NULL; - } - return reply; -} /*---------------------------------------------------------------------------*/ static void @@ -273,7 +257,6 @@ register_reply (DBusPendingCall *pending, void *user_data) if (strcmp (dbus_message_get_signature (reply), "(so)") != 0) { g_warning ("AT-SPI: Could not obtain desktop path or name\n"); -printf("sig: %s\n", dbus_message_get_signature(reply)); } else { @@ -305,6 +288,7 @@ register_application (SpiBridge * app) DBusMessageIter iter; DBusError error; DBusPendingCall *pending; + const int max_addr_length = 128; /* should be long enough */ dbus_error_init (&error); @@ -331,6 +315,13 @@ register_application (SpiBridge * app) if (message) dbus_message_unref (message); +/* could this be better, we accept some amount of race in getting the temp name*/ +/* make sure the directory exists */ +mkdir("/tmp/at-spi2/", S_IRWXU); +app->app_bus_addr = g_malloc(max_addr_length * sizeof(char)); +sprintf(app->app_bus_addr, "unix:path=/tmp/at-spi2/socket-%d-%d", getpid(), +rand()); + return TRUE; } @@ -507,6 +498,43 @@ install_plug_hooks () socket_class->embed = socket_embed_hook; } +static void +new_connection_cb (DBusServer *server, DBusConnection *con, void *data) +{ + GList *new_list; + + dbus_connection_ref(con); + dbus_connection_setup_with_g_main(con, NULL); + droute_intercept_dbus (con); + droute_context_register (spi_global_app_data->droute, con); + + new_list = g_list_append (spi_global_app_data->direct_connections, con); + if (new_list) + spi_global_app_data->direct_connections = new_list; +} + +static int +setup_bus (void) +{ + DBusServer *server; + DBusError err; + + dbus_error_init(&err); + server = dbus_server_listen(spi_global_app_data->app_bus_addr, &err); + + /* is there a better way to handle this */ + if (server == NULL) + return -1; + + dbus_server_setup_with_g_main(server, NULL); + dbus_server_set_new_connection_function(server, new_connection_cb, NULL, NULL); + + spi_global_app_data->server = server; + + return 0; +} + + gchar *atspi_dbus_name = NULL; static gboolean atspi_no_register = FALSE; @@ -621,6 +649,7 @@ signal_filter (DBusConnection *bus, DBusMessage *message, void *user_data) * * - DRoute for routing message to their accessible objects. * - Event handlers for emmitting signals on specific ATK events. + * - setup the bus for p2p communication * - Application registration with the AT-SPI registry. * */ @@ -687,8 +716,9 @@ adaptor_init (gint * argc, gchar ** argv[]) } } - dbus_connection_setup_with_g_main (spi_global_app_data->bus, - g_main_context_default ()); + spi_global_app_data->main_context = g_main_context_new (); + + dbus_connection_setup_with_g_main (spi_global_app_data->bus, NULL); /* Hook our plug-and socket functions */ install_plug_hooks (); @@ -704,7 +734,7 @@ adaptor_init (gint * argc, gchar ** argv[]) /* Register droute for routing AT-SPI messages */ spi_global_app_data->droute = - droute_new (spi_global_app_data->bus); + droute_new (); treepath = droute_add_one (spi_global_app_data->droute, "/org/a11y/atspi/cache", spi_global_cache); @@ -742,6 +772,9 @@ adaptor_init (gint * argc, gchar ** argv[]) spi_initialize_text (accpath); spi_initialize_value (accpath); + droute_context_register (spi_global_app_data->droute, + spi_global_app_data->bus); + /* Register methods to send D-Bus signals on certain ATK events */ spi_atk_register_event_listeners (); @@ -756,6 +789,8 @@ adaptor_init (gint * argc, gchar ** argv[]) else get_registered_event_listeners (spi_global_app_data); + setup_bus(); + g_atexit (exit_func); return 0; diff --git a/atk-adaptor/bridge.h b/atk-adaptor/bridge.h index 05fa56a..728b245 100644 --- a/atk-adaptor/bridge.h +++ b/atk-adaptor/bridge.h @@ -48,6 +48,9 @@ struct _SpiBridge DBusConnection *bus; DRouteContext *droute; + GMainContext *main_context; + DBusServer *server; + GList *direct_connections; /* SpiRegister *reg; @@ -56,6 +59,7 @@ struct _SpiBridge */ gchar *desktop_name; gchar *desktop_path; +char *app_bus_addr; GList *events; }; diff --git a/atk-adaptor/event.c b/atk-adaptor/event.c index b973021..28de5ff 100644 --- a/atk-adaptor/event.c +++ b/atk-adaptor/event.c @@ -53,11 +53,23 @@ typedef struct _SpiReentrantCallClosure } SpiReentrantCallClosure; static void +switch_main_context (GMainContext *cnx) +{ + GList *list; + + dbus_server_setup_with_g_main (spi_global_app_data->server, cnx); + dbus_connection_setup_with_g_main (spi_global_app_data->bus, cnx); + for (list = spi_global_app_data->direct_connections; list; list = list->next) + dbus_connection_setup_with_g_main (list->data, cnx); +} + +static void set_reply (DBusPendingCall * pending, void *user_data) { SpiReentrantCallClosure* closure = (SpiReentrantCallClosure *) user_data; closure->reply = dbus_pending_call_steal_reply (pending); + switch_main_context (NULL); g_main_loop_quit (closure->loop); } @@ -67,25 +79,16 @@ send_and_allow_reentry (DBusConnection * bus, DBusMessage * message) DBusPendingCall *pending; SpiReentrantCallClosure closure; - if (!dbus_connection_send_with_reply (bus, message, &pending, -1)) - return NULL; - dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL); - closure.loop = g_main_loop_new (NULL, FALSE); + closure.loop = g_main_loop_new (spi_global_app_data->main_context, FALSE); + switch_main_context (spi_global_app_data->main_context); - /* TODO: Remove old AT_SPI_CLIENT name */ - if (getenv ("AT_SPI_CLIENT") || getenv ("AT_SPI_REENTER_G_MAIN_LOOP")) - { - g_main_loop_run (closure.loop); - } - else + if (!dbus_connection_send_with_reply (bus, message, &pending, -1)) { - closure.reply = NULL; - while (!closure.reply) - { - if (!dbus_connection_read_write_dispatch (spi_global_app_data->bus, 1000)) - return NULL; - } + switch_main_context (NULL); + return NULL; } + dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL); + g_main_loop_run (closure.loop); g_main_loop_unref (closure.loop); return closure.reply; diff --git a/atk-adaptor/introspection.c b/atk-adaptor/introspection.c index 6a17cf0..22c3115 100644 --- a/atk-adaptor/introspection.c +++ b/atk-adaptor/introspection.c @@ -26,10 +26,12 @@ const char *spi_org_a11y_atspi_Accessible = " " " " " " +" " " " "" " " " " +" " " " "" " " @@ -118,6 +120,10 @@ const char *spi_org_a11y_atspi_Application = " " " " "" +" " +" " +" " +"" "" ""; @@ -321,7 +327,7 @@ const char *spi_org_a11y_atspi_Image = const char *spi_org_a11y_atspi_Selection = "" "" -" " +" " "" " " " " @@ -375,9 +381,9 @@ const char *spi_org_a11y_atspi_Table = " " " " "" -" " +" " "" -" " +" " "" " " " " diff --git a/droute/droute.c b/droute/droute.c index a6fe157..321144e 100644 --- a/droute/droute.c +++ b/droute/droute.c @@ -39,7 +39,6 @@ struct _DRouteContext { - DBusConnection *bus; GPtrArray *registered_paths; gchar *introspect_string; @@ -48,6 +47,8 @@ struct _DRouteContext struct _DRoutePath { DRouteContext *cnx; + gchar *path; + gboolean prefix; GStringChunk *chunks; GPtrArray *interfaces; GPtrArray *introspection; @@ -80,6 +81,8 @@ droute_object_does_not_exist_error (DBusMessage *message); static DRoutePath * path_new (DRouteContext *cnx, + const char *path, + gboolean prefix, void *user_data, DRouteIntrospectChildrenFunction introspect_children_cb, void *introspect_children_data, @@ -89,6 +92,8 @@ path_new (DRouteContext *cnx, new_path = g_new0 (DRoutePath, 1); new_path->cnx = cnx; + new_path->path = g_strdup (path); + new_path->prefix = prefix; new_path->chunks = g_string_chunk_new (CHUNKS_DEFAULT); new_path->interfaces = g_ptr_array_new (); new_path->introspection = g_ptr_array_new (); @@ -114,6 +119,7 @@ path_new (DRouteContext *cnx, static void path_free (DRoutePath *path, gpointer user_data) { + g_free (path->path); g_string_chunk_free (path->chunks); g_ptr_array_free (path->interfaces, TRUE); g_ptr_array_free (path->introspection, FALSE); @@ -133,12 +139,11 @@ path_get_datum (DRoutePath *path, const gchar *pathstr) /*---------------------------------------------------------------------------*/ DRouteContext * -droute_new (DBusConnection *bus) +droute_new () { DRouteContext *cnx; cnx = g_new0 (DRouteContext, 1); - cnx->bus = bus; cnx->registered_paths = g_ptr_array_new (); return cnx; @@ -153,12 +158,6 @@ droute_free (DRouteContext *cnx) /*---------------------------------------------------------------------------*/ -DBusConnection * -droute_get_bus (DRouteContext *cnx) -{ - return cnx->bus; -} - /*---------------------------------------------------------------------------*/ static DBusObjectPathVTable droute_vtable = @@ -176,14 +175,7 @@ droute_add_one (DRouteContext *cnx, DRoutePath *new_path; gboolean registered; - new_path = path_new (cnx, (void *)data, NULL, NULL, NULL); - - registered = dbus_connection_register_object_path (cnx->bus, path, &droute_vtable, new_path); - if (!registered) - { - path_free (new_path, NULL); - return NULL; - } + new_path = path_new (cnx, path, FALSE, (void *)data, NULL, NULL, NULL); g_ptr_array_add (cnx->registered_paths, new_path); return new_path; @@ -199,10 +191,9 @@ droute_add_many (DRouteContext *cnx, { DRoutePath *new_path; - new_path = path_new (cnx, (void *) data, introspect_children_cb, introspect_children_data, get_datum); - - if (!dbus_connection_register_fallback (cnx->bus, path, &droute_vtable, new_path)) - oom(); + new_path = path_new (cnx, path, TRUE, (void *) data, + introspect_children_cb, introspect_children_data, + get_datum); g_ptr_array_add (cnx->registered_paths, new_path); return new_path; @@ -378,6 +369,32 @@ impl_prop_GetSet (DBusMessage *message, } static DBusHandlerResult +handle_dbus (DBusConnection *bus, + DBusMessage *message, + const gchar *iface, + const gchar *member, + const gchar *pathstr) +{ + static int id = 1; + char *id_str = (char *) g_malloc(40); + DBusMessage *reply; + + if (strcmp (iface, DBUS_INTERFACE_DBUS) != 0 || + strcmp (member, "Hello") != 0) + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + + /* TODO: Fix this hack (we don't handle wrap-around, for instance) */ + sprintf (id_str, ":1.%d", id++); + reply = dbus_message_new_method_return (message); + dbus_message_append_args (reply, DBUS_TYPE_STRING, &id_str, DBUS_TYPE_INVALID); + dbus_connection_send (bus, reply, NULL); + dbus_connection_flush (bus); + dbus_message_unref (reply); + g_free (id_str); + return DBUS_HANDLER_RESULT_HANDLED; +} + +static DBusHandlerResult handle_properties (DBusConnection *bus, DBusMessage *message, DRoutePath *path, @@ -545,7 +562,9 @@ handle_message (DBusConnection *bus, DBusMessage *message, void *user_data) iface == NULL) return result; - if (!strcmp (iface, "org.freedesktop.DBus.Properties")) + if (!strcmp (pathstr, DBUS_PATH_DBUS)) + result = handle_dbus (bus, message, iface, member, pathstr); + else if (!strcmp (iface, "org.freedesktop.DBus.Properties")) result = handle_properties (bus, message, path, iface, member, pathstr); else if (!strcmp (iface, "org.freedesktop.DBus.Introspectable")) result = handle_introspection (bus, message, path, iface, member, pathstr); @@ -636,4 +655,27 @@ droute_invalid_arguments_error (DBusMessage *message) return reply; } +void +droute_path_register (DRoutePath *path, DBusConnection *bus) +{ + if (path->prefix) + dbus_connection_register_fallback (bus, path->path, &droute_vtable, path); + else + dbus_connection_register_object_path (bus, path->path, + &droute_vtable, path); +} + +void +droute_context_register (DRouteContext *cnx, DBusConnection *bus) +{ + g_ptr_array_foreach (cnx->registered_paths, (GFunc) droute_path_register, + bus); +} + +void +droute_intercept_dbus (DBusConnection *bus) +{ + dbus_connection_register_object_path (bus, DBUS_PATH_DBUS, + &droute_vtable, NULL); +} /*END------------------------------------------------------------------------*/ diff --git a/droute/droute.h b/droute/droute.h index 3fdfacb..766340e 100644 --- a/droute/droute.h +++ b/droute/droute.h @@ -59,7 +59,7 @@ typedef struct _DRoutePath DRoutePath; /*---------------------------------------------------------------------------*/ DRouteContext * -droute_new (DBusConnection *bus); +droute_new (); void droute_free (DRouteContext *cnx); @@ -93,7 +93,12 @@ droute_invalid_arguments_error (DBusMessage *message); DBusMessage * droute_out_of_memory_error (DBusMessage *message); -DBusConnection * -droute_get_bus (DRouteContext *cnx); +void +droute_path_register (DRoutePath *path, DBusConnection *bus); + +void +droute_context_register (DRouteContext *cnx, DBusConnection *bus); +void +droute_intercept_dbus (DBusConnection *connection); #endif /* _DROUTE_H */