From 21b79630873c79ced591cf5e909660cf4c1bda69 Mon Sep 17 00:00:00 2001 From: Huang Peng Date: Mon, 9 Mar 2009 17:21:45 +0800 Subject: Implement ibus_bus_get_config function. --- bus/dbusimpl.c | 17 ++++-- bus/matchrule.c | 3 ++ src/ibusbus.c | 42 ++++++++++++++- src/ibusbus.h | 2 + src/ibusproxy.c | 158 ++++++++++++++++++++++++++++++++++++++++++------------- src/ibusproxy.h | 1 + src/test-proxy.c | 24 ++++++--- 7 files changed, 197 insertions(+), 50 deletions(-) diff --git a/bus/dbusimpl.c b/bus/dbusimpl.c index 3cc51dc..f51ab96 100644 --- a/bus/dbusimpl.c +++ b/bus/dbusimpl.c @@ -828,6 +828,16 @@ _connection_ibus_message_cb (BusConnection *connection, ibus_message_get_error_message (message)); break; #endif +#if 0 + case DBUS_MESSAGE_TYPE_SIGNAL: + g_debug ("From :%s to %s, Signal: %s @ %s", + ibus_message_get_sender (message), + ibus_message_get_destination (message), + ibus_message_get_member (message), + ibus_message_get_path (message) + ); + break; +#endif #if 0 case DBUS_MESSAGE_TYPE_METHOD_CALL: g_debug("From %s to %s, Method %s on %s", @@ -1068,10 +1078,9 @@ bus_dbus_impl_dispatch_message_by_rule (BusDBusImpl *dbus, #endif for (link = dbus->rules; link != NULL; link = link->next) { - recipients = bus_match_rule_get_recipients (BUS_MATCH_RULE (link->data), - message); - if (recipients != NULL) - break; + GList *list = bus_match_rule_get_recipients (BUS_MATCH_RULE (link->data), + message); + recipients = g_list_concat (recipients, list); } for (link = recipients; link != NULL; link = link->next) { diff --git a/bus/matchrule.c b/bus/matchrule.c index f40147a..039602e 100644 --- a/bus/matchrule.c +++ b/bus/matchrule.c @@ -270,6 +270,8 @@ bus_match_rule_new (const gchar *text) { g_assert (text != NULL); + g_debug ("new rule=%s", text); + Token *tokens, *p; BusMatchRule *rule; @@ -499,6 +501,7 @@ bus_match_rule_match (BusMatchRule *rule, ibus_message_iter_next (&iter); } } + return TRUE; } diff --git a/src/ibusbus.c b/src/ibusbus.c index 52631e8..4115689 100644 --- a/src/ibusbus.c +++ b/src/ibusbus.c @@ -23,6 +23,7 @@ #include "ibusinternal.h" #include "ibusshare.h" #include "ibusconnection.h" +#include "ibusconfig.h" #define IBUS_BUS_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), IBUS_TYPE_BUS, IBusBusPrivate)) @@ -40,6 +41,7 @@ struct _IBusBusPrivate { GFileMonitor *monitor; IBusConnection *connection; gboolean watch_dbus_signal; + IBusConfig *config; }; typedef struct _IBusBusPrivate IBusBusPrivate; @@ -210,6 +212,7 @@ ibus_bus_init (IBusBus *bus) IBusBusPrivate *priv; priv = IBUS_BUS_GET_PRIVATE (bus); + priv->config = NULL; priv->connection = NULL; priv->watch_dbus_signal = FALSE; @@ -239,8 +242,13 @@ ibus_bus_destroy (IBusObject *object) priv->monitor = NULL; } + if (priv->config) { + ibus_object_destroy ((IBusObject *) priv->config); + priv->config = NULL; + } + if (priv->connection) { - ibus_object_destroy (IBUS_OBJECT (priv->connection)); + ibus_object_destroy ((IBusObject *) priv->connection); priv->connection = NULL; } @@ -613,7 +621,7 @@ ibus_bus_get_name_owner (IBusBus *bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, - "RemoveMatch", + "GetNameOwner", G_TYPE_STRING, &name, G_TYPE_INVALID, G_TYPE_STRING, &owner, @@ -729,3 +737,33 @@ ibus_bus_list_active_engines (IBusBus *bus) { return NULL; } + +static void +_config_destroy_cb (IBusConfig *config, + IBusBus *bus) +{ + IBusBusPrivate *priv; + priv = IBUS_BUS_GET_PRIVATE (bus); + + g_assert (priv->config == config); + + g_object_unref (config); + priv->config = NULL; +} + +IBusConfig * +ibus_bus_get_config (IBusBus *bus) +{ + g_assert (IBUS_IS_BUS (bus)); + IBusBusPrivate *priv; + priv = IBUS_BUS_GET_PRIVATE (bus); + + if (priv->config == NULL && priv->connection) { + priv->config = ibus_config_new (priv->connection); + if (priv->config) { + g_signal_connect (priv->config, "destroy", G_CALLBACK (_config_destroy_cb), bus); + } + } + + return priv->config; +} diff --git a/src/ibusbus.h b/src/ibusbus.h index be1fba8..e02c193 100644 --- a/src/ibusbus.h +++ b/src/ibusbus.h @@ -92,6 +92,8 @@ gboolean ibus_bus_register_component(IBusBus *bus, GList *ibus_bus_list_engines (IBusBus *bus); GList *ibus_bus_list_active_engines (IBusBus *bus); +/* declare config apis */ +IBusConfig *ibus_bus_get_config (IBusBus *bus); G_END_DECLS #endif diff --git a/src/ibusproxy.c b/src/ibusproxy.c index 5ef3b40..9abf8f6 100644 --- a/src/ibusproxy.c +++ b/src/ibusproxy.c @@ -43,6 +43,7 @@ enum { /* IBusProxyPriv */ struct _IBusProxyPrivate { gchar *name; + gchar *unique_name; gchar *path; gchar *interface; IBusConnection *connection; @@ -187,6 +188,12 @@ _connection_ibus_signal_cb (IBusConnection *connection, IBusMessage *message, IBusProxy *proxy) { + IBusProxyPrivate *priv; + priv = IBUS_PROXY_GET_PRIVATE (proxy); + + if (g_strcmp0 (ibus_message_get_path (message), priv->path) != 0) + return FALSE; + if (ibus_proxy_handle_signal (proxy, message)) { g_signal_stop_emission_by_name (connection, "ibus-signal"); return TRUE; @@ -224,45 +231,71 @@ ibus_proxy_constructor (GType type, proxy = IBUS_PROXY (obj); priv = IBUS_PROXY_GET_PRIVATE (proxy); - if (priv->connection != NULL) { - if (priv->name != NULL) { + if (priv->connection == NULL) { + g_object_unref (proxy); + return NULL; + } - IBusError *error; - gchar *rule; + if (priv->name != NULL) { + IBusError *error; + gchar *rule; - rule = g_strdup_printf ("type='signal'," - "sender='" DBUS_SERVICE_DBUS "'," - "path='" DBUS_PATH_DBUS "'," - "interface='" DBUS_INTERFACE_DBUS "'," - "member='NameOwnerChanged'," - "arg0='%s'", - priv->name); + if (ibus_proxy_get_unique_name (proxy) == NULL) { + g_object_unref (proxy); + return NULL; + } - if (!ibus_connection_call (priv->connection, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "AddMatch", - &error, - G_TYPE_STRING, &rule, - G_TYPE_INVALID, - G_TYPE_INVALID)) { - g_warning ("%s: %s", error->name, error->message); - ibus_error_free (error); - } - g_free (rule); + rule = g_strdup_printf ("type='signal'," + "sender='" DBUS_SERVICE_DBUS "'," + "path='" DBUS_PATH_DBUS "'," + "interface='" DBUS_INTERFACE_DBUS "'," + "member='NameOwnerChanged'," + "arg0='%s'", + priv->unique_name); + + if (!ibus_connection_call (priv->connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "AddMatch", + &error, + G_TYPE_STRING, &rule, + G_TYPE_INVALID, + G_TYPE_INVALID)) { + g_warning ("%s: %s", error->name, error->message); + ibus_error_free (error); + } + g_free (rule); + + rule = g_strdup_printf ("type='signal'," + "sender='%s'," + "path='%s'", + priv->unique_name, + priv->path); + + if (!ibus_connection_call (priv->connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "AddMatch", + &error, + G_TYPE_STRING, &rule, + G_TYPE_INVALID, + G_TYPE_INVALID)) { + g_warning ("%s: %s", error->name, error->message); + ibus_error_free (error); } - g_signal_connect (priv->connection, - "ibus-signal", - (GCallback) _connection_ibus_signal_cb, - proxy); - - g_signal_connect (priv->connection, - "destroy", - (GCallback) _connection_destroy_cb, - proxy); + g_free (rule); } - + g_signal_connect (priv->connection, + "ibus-signal", + (GCallback) _connection_ibus_signal_cb, + proxy); + + g_signal_connect (priv->connection, + "destroy", + (GCallback) _connection_destroy_cb, + proxy); return obj; } @@ -273,6 +306,7 @@ ibus_proxy_init (IBusProxy *proxy) priv = IBUS_PROXY_GET_PRIVATE (proxy); priv->name = NULL; + priv->unique_name = NULL; priv->path = NULL; priv->interface = NULL; priv->connection = NULL; @@ -304,7 +338,28 @@ ibus_proxy_destroy (IBusProxy *proxy) "interface='" DBUS_INTERFACE_DBUS "'," "member='NameOwnerChanged'," "arg0='%s'", - priv->name); + priv->unique_name); + + if (!ibus_connection_call (priv->connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "RemoveMatch", + &error, + G_TYPE_STRING, &rule, + G_TYPE_INVALID, + G_TYPE_INVALID)) { + + g_warning ("%s: %s", error->name, error->message); + ibus_error_free (error); + } + g_free (rule); + + rule = g_strdup_printf ("type='signal'," + "sender='%s'," + "path='%s'", + priv->unique_name, + priv->path); if (!ibus_connection_call (priv->connection, DBUS_SERVICE_DBUS, @@ -320,10 +375,12 @@ ibus_proxy_destroy (IBusProxy *proxy) ibus_error_free (error); } g_free (rule); + } } g_free (priv->name); + g_free (priv->unique_name); g_free (priv->path); g_free (priv->interface); @@ -421,7 +478,7 @@ ibus_proxy_handle_signal (IBusProxy *proxy, ibus_error_free (error); } - if (g_strcmp0 (priv->name, old_name) == 0) { + if (g_strcmp0 (priv->unique_name, old_name) == 0) { ibus_object_destroy (IBUS_OBJECT (proxy)); return FALSE; } @@ -451,6 +508,35 @@ ibus_proxy_get_name (IBusProxy *proxy) return priv->name; } +const gchar * +ibus_proxy_get_unique_name (IBusProxy *proxy) +{ + + IBusProxyPrivate *priv; + priv = IBUS_PROXY_GET_PRIVATE (proxy); + + if (priv->unique_name == NULL && priv->connection != NULL) { + IBusError *error; + gchar *owner; + if (!ibus_connection_call (priv->connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "GetNameOwner", + &error, + G_TYPE_STRING, &(priv->name), + G_TYPE_INVALID, + G_TYPE_STRING, &owner, + G_TYPE_INVALID)) { + g_warning ("%s: %s", error->name, error->message); + ibus_error_free (error); + } + priv->unique_name = g_strdup (owner); + } + + return priv->unique_name; +} + const gchar * ibus_proxy_get_path (IBusProxy *proxy) { diff --git a/src/ibusproxy.h b/src/ibusproxy.h index 0cc22d4..ce85b4d 100644 --- a/src/ibusproxy.h +++ b/src/ibusproxy.h @@ -98,6 +98,7 @@ IBusMessage *ibus_proxy_send_with_reply_and_block gboolean ibus_proxy_handle_signal (IBusProxy *proxy, IBusMessage *message); const gchar *ibus_proxy_get_name (IBusProxy *proxy); +const gchar *ibus_proxy_get_unique_name (IBusProxy *proxy); const gchar *ibus_proxy_get_path (IBusProxy *proxy); const gchar *ibus_proxy_get_interface (IBusProxy *proxy); IBusConnection *ibus_proxy_get_connection (IBusProxy *proxy); diff --git a/src/test-proxy.c b/src/test-proxy.c index 31866f1..aedd732 100644 --- a/src/test-proxy.c +++ b/src/test-proxy.c @@ -1,18 +1,26 @@ #include "ibus.h" +static +_value_changed_cb (IBusConfig *config, gchar *section, gchar *name, GValue *value, gpointer data) +{ + g_debug ("value-changed %s %s", section, name); +} + int main() { g_type_init (); - IBusConnection *connection; - IBusProxy *proxy; + IBusBus *bus; + IBusConfig *config; + + bus = ibus_bus_new (); + config = ibus_bus_get_config (bus); - connection = ibus_connection_new (); - proxy = ibus_proxy_new ("a", "/a", connection); - GValue value = {0}; - g_value_init (&value, G_TYPE_STRING); - g_value_set_static_string (&value, "aaa"); - g_object_set_property (G_OBJECT (proxy), "name", &value); + g_signal_connect (config, + "value-changed", + G_CALLBACK (_value_changed_cb), + NULL); + g_main_loop_run (g_main_loop_new (NULL, FALSE)); return 0; } -- cgit