summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHuang Peng <shawn.p.huang@gmail.com>2009-03-09 17:21:45 +0800
committerHuang Peng <shawn.p.huang@gmail.com>2009-03-09 17:21:45 +0800
commit21b79630873c79ced591cf5e909660cf4c1bda69 (patch)
treead1cd539a7ff1d6ad8b0e836492a79482f92846e /src
parenta1ac8682c81051518ad0ff613958a0b96054091c (diff)
downloadibus-21b79630873c79ced591cf5e909660cf4c1bda69.tar.gz
ibus-21b79630873c79ced591cf5e909660cf4c1bda69.tar.xz
ibus-21b79630873c79ced591cf5e909660cf4c1bda69.zip
Implement ibus_bus_get_config function.
Diffstat (limited to 'src')
-rw-r--r--src/ibusbus.c42
-rw-r--r--src/ibusbus.h2
-rw-r--r--src/ibusproxy.c158
-rw-r--r--src/ibusproxy.h1
-rw-r--r--src/test-proxy.c24
5 files changed, 181 insertions, 46 deletions
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;
}
@@ -452,6 +509,35 @@ ibus_proxy_get_name (IBusProxy *proxy)
}
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)
{
IBusProxyPrivate *priv;
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;
}