}
if (priv->connection) {
- ibus_bus_hello (bus);
+ g_free (ibus_bus_hello (bus));
g_signal_connect (priv->connection,
"destroy",
(GCallback) _connection_destroy_cb,
return context;
}
-static gboolean
-ibus_bus_call (IBusBus *bus,
- const gchar *name,
- const gchar *path,
- const gchar *interface,
- const gchar *member,
- GType first_arg_type,
- ...)
+IBusMessage *
+ibus_bus_call_with_reply_valist (IBusBus *bus,
+ const gchar *name,
+ const gchar *path,
+ const gchar *interface,
+ const gchar *member,
+ GType first_arg_type,
+ va_list va_args)
{
g_assert (IBUS_IS_BUS (bus));
g_assert (name != NULL);
IBusMessage *message, *reply;
IBusError *error;
- va_list args;
- GType type;
gboolean retval;
IBusBusPrivate *priv;
message = ibus_message_new_method_call (name, path, interface, member);
- va_start (args, first_arg_type);
- ibus_message_append_args_valist (message, first_arg_type, args);
- va_end (args);
+ ibus_message_append_args_valist (message, first_arg_type, va_args);
reply = ibus_connection_send_with_reply_and_block (
priv->connection,
if (reply == NULL) {
g_warning ("%s : %s", error->name, error->message);
ibus_error_free (error);
- return FALSE;
+ return NULL;
}
if ((error = ibus_error_new_from_message (reply)) != NULL) {
g_warning ("%s : %s", error->name, error->message);
ibus_error_free (error);
ibus_message_unref (reply);
- return FALSE;
+ return NULL;
}
- va_start (args, first_arg_type);
+ return reply;
+}
- type = first_arg_type;
+IBusMessage *
+ibus_bus_call_with_reply (IBusBus *bus,
+ const gchar *name,
+ const gchar *path,
+ const gchar *interface,
+ const gchar *member,
+ GType first_arg_type,
+ ...)
+{
+ IBusMessage *reply;
+ va_list va_args;
- while (type != G_TYPE_INVALID) {
- va_arg (args, gpointer);
- type = va_arg (args, GType);
- }
+ va_start (va_args, first_arg_type);
+ reply = ibus_bus_call_with_reply_valist (
+ bus, name, path, interface, member, first_arg_type, va_args);
+ va_end (va_args);
- type = va_arg (args, GType);
- if (type != G_TYPE_INVALID) {
- retval = ibus_message_get_args_valist (reply, &error, type, args);
- }
- else {
- retval = TRUE;
- }
- va_end (args);
+ return reply;
+}
- ibus_message_unref (reply);
+gboolean
+ibus_bus_call (IBusBus *bus,
+ const gchar *name,
+ const gchar *path,
+ const gchar *interface,
+ const gchar *member,
+ GType first_arg_type,
+ ...)
+{
+ IBusMessage *reply;
+ va_list va_args;
- if (!retval) {
- g_warning ("%s: %s", error->name, error->message);
- ibus_error_free (error);
- return FALSE;
+ va_start (va_args, first_arg_type);
+ reply = ibus_bus_call_with_reply_valist (
+ bus, name, path, interface, member, first_arg_type, va_args);
+ va_end (va_args);
+
+ if (reply) {
+ ibus_message_unref (reply);
+ return TRUE;
}
- return TRUE;
+ return FALSE;
}
-const gchar *
+gchar *
ibus_bus_current_input_context(IBusBus *bus)
{
g_assert (IBUS_IS_BUS (bus));
+ g_return_val_if_fail (ibus_bus_is_connected (bus), NULL);
gchar *name = NULL;
- gboolean result;
-
- result = ibus_bus_call (bus,
- IBUS_SERVICE_IBUS,
- IBUS_PATH_IBUS,
- IBUS_INTERFACE_IBUS,
- "CurrentInputContext",
- G_TYPE_INVALID,
- G_TYPE_STRING, &name,
- G_TYPE_INVALID);
+ IBusMessage *reply = NULL;
+ IBusError *error = NULL;
+
+ reply = ibus_bus_call_with_reply (bus,
+ IBUS_SERVICE_IBUS,
+ IBUS_PATH_IBUS,
+ IBUS_INTERFACE_IBUS,
+ "CurrentInputContext",
+ G_TYPE_INVALID);
+
+ if (reply) {
+ if (ibus_message_get_args (reply, &error, G_TYPE_STRING, &name,
+ G_TYPE_INVALID)) {
+ name = g_strdup (name);
+ } else {
+ g_warning ("%s: %s", error->name, error->message);
+ ibus_error_free (error);
+ }
- if (result)
- return name;
+ ibus_message_unref (reply);
+ }
- return NULL;
+ return name;
}
static void
}
}
-const gchar *
+gchar *
ibus_bus_hello (IBusBus *bus)
{
g_assert (IBUS_IS_BUS (bus));
gchar *unique_name = NULL;
- gboolean result;
-
- result = ibus_bus_call (bus,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS,
- "Hello",
- G_TYPE_INVALID,
- G_TYPE_STRING, &unique_name,
- G_TYPE_INVALID);
+ IBusMessage *reply = NULL;
+ IBusError *error = NULL;
+
+ reply = ibus_bus_call_with_reply (bus,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS,
+ "Hello",
+ G_TYPE_INVALID);
+
+ if (reply) {
+ if (ibus_message_get_args (reply, &error, G_TYPE_STRING, &unique_name,
+ G_TYPE_INVALID)) {
+ unique_name = g_strdup (unique_name);
+ } else {
+ g_warning ("%s: %s", error->name, error->message);
+ ibus_error_free (error);
+ }
- if (result)
- return unique_name;
+ ibus_message_unref (reply);
+ }
- return NULL;
+ return unique_name;
}
guint
{
g_assert (IBUS_IS_BUS (bus));
- guint retval;
- gboolean result;
-
- result = ibus_bus_call (bus,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS,
- "RequestName",
- G_TYPE_STRING, &name,
- G_TYPE_UINT, &flags,
- G_TYPE_INVALID,
- G_TYPE_UINT, &retval,
- G_TYPE_INVALID);
+ IBusMessage *reply = NULL;
+ IBusError *error = NULL;
+ guint retval = 0;
+
+ reply = ibus_bus_call_with_reply (bus,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS,
+ "RequestName",
+ G_TYPE_STRING, &name,
+ G_TYPE_UINT, &flags,
+ G_TYPE_INVALID);
+
+ if (reply) {
+ if (!ibus_message_get_args (reply, &error, G_TYPE_UINT, &retval,
+ G_TYPE_INVALID)) {
+ g_warning ("%s: %s", error->name, error->message);
+ ibus_error_free (error);
+ }
- if (result)
- return retval;
+ ibus_message_unref (reply);
+ }
- return 0;
+ return retval;
}
guint
{
g_assert (IBUS_IS_BUS (bus));
- guint retval;
- gboolean result;
-
- result = ibus_bus_call (bus,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS,
- "ReleaseName",
- G_TYPE_STRING, &name,
- G_TYPE_INVALID,
- G_TYPE_UINT, &retval,
- G_TYPE_INVALID);
+ IBusMessage *reply = NULL;
+ IBusError *error = NULL;
+ guint retval = 0;
+
+ reply = ibus_bus_call_with_reply (bus,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS,
+ "ReleaseName",
+ G_TYPE_STRING, &name,
+ G_TYPE_INVALID);
+
+ if (reply) {
+ if (!ibus_message_get_args (reply, &error, G_TYPE_UINT, &retval,
+ G_TYPE_INVALID)) {
+ g_warning ("%s: %s", error->name, error->message);
+ ibus_error_free (error);
+ }
- if (result)
- return retval;
+ ibus_message_unref (reply);
+ }
- return 0;
+ return retval;
}
gboolean
ibus_bus_name_has_owner (IBusBus *bus,
const gchar *name)
{
- gboolean retval;
- gboolean result;
+ g_assert (IBUS_IS_BUS (bus));
- result = ibus_bus_call (bus,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS,
- "NameHasOwner",
- G_TYPE_STRING, &name,
- G_TYPE_INVALID,
- G_TYPE_BOOLEAN, &retval,
- G_TYPE_INVALID);
+ IBusMessage *reply = NULL;
+ IBusError *error = NULL;
+ gboolean retval = FALSE;
+
+ reply = ibus_bus_call_with_reply (bus,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS,
+ "NameHasOwner",
+ G_TYPE_STRING, &name,
+ G_TYPE_INVALID);
+
+ if (reply) {
+ if (!ibus_message_get_args (reply, &error, G_TYPE_BOOLEAN, &retval,
+ G_TYPE_INVALID)) {
+ g_warning ("%s: %s", error->name, error->message);
+ ibus_error_free (error);
+ }
- if (result)
- return retval;
+ ibus_message_unref (reply);
+ }
- return FALSE;
+ return retval;
}
GList *
{
g_assert (IBUS_IS_BUS (bus));
- gboolean result;
-
- result = ibus_bus_call (bus,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS,
- "AddMatch",
- G_TYPE_STRING, &rule,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
+ ibus_bus_call (bus,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS,
+ "AddMatch",
+ G_TYPE_STRING, &rule,
+ G_TYPE_INVALID);
}
void
{
g_assert (IBUS_IS_BUS (bus));
- gboolean result;
-
- result = ibus_bus_call (bus,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS,
- "RemoveMatch",
- G_TYPE_STRING, &rule,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
+ ibus_bus_call (bus,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS,
+ "RemoveMatch",
+ G_TYPE_STRING, &rule,
+ G_TYPE_INVALID);
}
-const gchar *
+gchar *
ibus_bus_get_name_owner (IBusBus *bus,
const gchar *name)
{
g_assert (IBUS_IS_BUS (bus));
gchar *owner = NULL;
- gboolean result;
-
- result = ibus_bus_call (bus,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS,
- "GetNameOwner",
- G_TYPE_STRING, &name,
- G_TYPE_INVALID,
- G_TYPE_STRING, &owner,
- G_TYPE_INVALID);
+ IBusMessage *reply = NULL;
+ IBusError *error = NULL;
+
+ reply = ibus_bus_call_with_reply (bus,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS,
+ "GetNameOwner",
+ G_TYPE_STRING, &owner,
+ G_TYPE_INVALID);
+
+ if (reply) {
+ if (ibus_message_get_args (reply, &error, G_TYPE_STRING, &owner,
+ G_TYPE_INVALID)) {
+ owner = g_strdup (owner);
+ } else {
+ g_warning ("%s: %s", error->name, error->message);
+ ibus_error_free (error);
+ }
- if (result)
- return owner;
+ ibus_message_unref (reply);
+ }
- return NULL;
+ return owner;
}
IBusConnection *
IBUS_INTERFACE_IBUS,
"Exit",
G_TYPE_BOOLEAN, &restart,
- G_TYPE_INVALID,
G_TYPE_INVALID);
return result;
}
IBUS_INTERFACE_IBUS,
"RegisterComponent",
IBUS_TYPE_COMPONENT, &component,
- G_TYPE_INVALID,
G_TYPE_INVALID);
return result;
-
-
-#if 0
- IBusMessage *message, *reply;
- IBusError *error;
-
- IBusBusPrivate *priv;
- priv = IBUS_BUS_GET_PRIVATE (bus);
-
- message = ibus_message_new_method_call (IBUS_SERVICE_IBUS,
- IBUS_PATH_IBUS,
- IBUS_INTERFACE_IBUS,
- "RegisterComponent");
-
- ibus_message_append_args (message,
- IBUS_TYPE_COMPONENT, &component,
- G_TYPE_INVALID);
-
- reply = ibus_connection_send_with_reply_and_block (
- priv->connection,
- message,
- -1,
- &error);
- ibus_message_unref (message);
-
- if (reply == NULL) {
- g_warning ("%s : %s", error->name, error->message);
- ibus_error_free (error);
- return FALSE;
- }
-
- if ((error = ibus_error_from_message (reply)) != NULL) {
- g_warning ("%s : %s", error->name, error->message);
- ibus_error_free (error);
- ibus_message_unref (reply);
- return FALSE;
- }
-
- return TRUE;
-#endif
}
static GList *