gboolean ibus_bus_register_component (IBusBus *bus, IBusComponent *component) { g_assert (IBUS_IS_BUS (bus)); g_assert (IBUS_IS_COMPONENT (component)); gboolean result; result = ibus_bus_call (bus, IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, 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 }
IBusInputContext * ibus_bus_create_input_context (IBusBus *bus, const gchar *client_name) { g_assert (IBUS_IS_BUS (bus)); g_assert (client_name != NULL); g_return_val_if_fail (ibus_bus_is_connected (bus), NULL); gchar *path; DBusMessage *call = NULL; DBusMessage *reply = NULL; IBusError *error; IBusInputContext *context = NULL; IBusBusPrivate *priv; priv = IBUS_BUS_GET_PRIVATE (bus); call = ibus_message_new_method_call (IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, IBUS_INTERFACE_IBUS, "CreateInputContext"); ibus_message_append_args (call, G_TYPE_STRING, &client_name, G_TYPE_INVALID); reply = ibus_connection_send_with_reply_and_block (priv->connection, call, -1, &error); ibus_message_unref (call); if (reply == NULL) { g_warning ("%s: %s", error->name, error->message); ibus_error_free (error); return NULL; } if ((error = ibus_error_new_from_message (reply)) != NULL) { g_warning ("%s: %s", error->name, error->message); ibus_message_unref (reply); ibus_error_free (error); return NULL; } if (!ibus_message_get_args (reply, &error, IBUS_TYPE_OBJECT_PATH, &path, G_TYPE_INVALID)) { g_warning ("%s: %s", error->name, error->message); ibus_message_unref (reply); ibus_error_free (error); return NULL; } context = ibus_input_context_new (path, priv->connection); ibus_message_unref (reply); return context; }
static IBusMessage * ibus_connection_call_with_reply_valist (IBusConnection *connection, const gchar *name, const gchar *path, const gchar *interface, const gchar *member, IBusError **error, GType first_arg_type, va_list va_args) { g_assert (IBUS_IS_CONNECTION (connection)); g_assert (name != NULL); g_assert (path != NULL); g_assert (interface != NULL); g_assert (member != NULL); g_assert (ibus_connection_is_connected (connection)); IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); IBusMessage *message, *reply; IBusError *tmp_error; message = ibus_message_new_method_call (name, path, interface, member); ibus_message_append_args_valist (message, first_arg_type, va_args); reply = ibus_connection_send_with_reply_and_block ( connection, message, -1, error); ibus_message_unref (message); if (reply == NULL) { return NULL; } if ((tmp_error = ibus_error_new_from_message (reply)) != NULL) { if (error) { *error = tmp_error; } else { ibus_error_free (tmp_error); } ibus_message_unref (reply); return NULL; } return reply; }
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); g_assert (path != NULL); g_assert (interface != NULL); g_assert (member); IBusMessage *message, *reply; IBusError *error; IBusBusPrivate *priv; g_return_val_if_fail (ibus_bus_is_connected (bus), FALSE); priv = IBUS_BUS_GET_PRIVATE (bus); message = ibus_message_new_method_call (name, path, interface, member); ibus_message_append_args_valist (message, first_arg_type, va_args); 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 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 NULL; } return reply; }
IBusMessage * ibus_proxy_call_with_reply_and_block (IBusProxy *proxy, const gchar *method, gint timeout_milliseconds, IBusError **error, GType first_arg_type, ...) { g_assert (IBUS_IS_PROXY (proxy)); g_assert (method != NULL); va_list args; gboolean retval; DBusMessage *message; DBusMessage *reply_message; IBusProxyPrivate *priv; priv = IBUS_PROXY_GET_PRIVATE (proxy); if (priv->connection == NULL || !ibus_connection_is_connected (priv->connection)) { if (error) { *error = ibus_error_new_from_printf (DBUS_ERROR_DISCONNECTED, "Connection of %s was disconnected.", G_OBJECT_TYPE_NAME (proxy)); } return NULL; } message = ibus_message_new_method_call (priv->name, priv->path, priv->interface, method); va_start (args, first_arg_type); retval = ibus_message_append_args_valist (message, first_arg_type, args); va_end (args); reply_message = ibus_connection_send_with_reply_and_block ( priv->connection, message, timeout_milliseconds, error); ibus_message_unref (message); return reply_message; }
static GList * ibus_bus_do_list_engines (IBusBus *bus, gboolean active_engines_only) { g_assert (IBUS_IS_BUS (bus)); IBusMessage *message, *reply; IBusError *error; gboolean retval; IBusBusPrivate *priv; IBusMessageIter iter, subiter; GList *engines; const gchar* member = active_engines_only ? "ListActiveEngines" : "ListEngines"; priv = IBUS_BUS_GET_PRIVATE (bus); message = ibus_message_new_method_call (IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, IBUS_INTERFACE_IBUS, member); 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 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 NULL; } retval = ibus_message_iter_init (reply, &iter); if (!retval) { error = ibus_error_new_from_printf (DBUS_ERROR_INVALID_ARGS, "Message does not have arguments!"); g_warning ("%s : %s", error->name, error->message); ibus_error_free (error); ibus_message_unref (reply); return NULL; } if (!ibus_message_iter_recurse (&iter, IBUS_TYPE_ARRAY, &subiter)) { ibus_message_unref (reply); return NULL; } engines = NULL; while (ibus_message_iter_get_arg_type (&subiter) != G_TYPE_INVALID) { IBusSerializable *object = NULL; if (!ibus_message_iter_get (&subiter, IBUS_TYPE_ENGINE_DESC, &object) || !object) { g_warning ("Unexpected type is returned from %s", member); continue; } engines = g_list_append (engines, object); ibus_message_iter_next (&subiter); }; ibus_message_unref (reply); return engines; }
static gboolean ibus_bus_call (IBusBus *bus, const gchar *name, const gchar *path, const gchar *interface, const gchar *member, GType first_arg_type, ...) { g_assert (IBUS_IS_BUS (bus)); g_assert (name != NULL); g_assert (path != NULL); g_assert (interface != NULL); g_assert (member); IBusMessage *message, *reply; IBusError *error; va_list args; GType type; gboolean retval; IBusBusPrivate *priv; g_return_val_if_fail (ibus_bus_is_connected (bus), FALSE); priv = IBUS_BUS_GET_PRIVATE (bus); 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); 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_new_from_message (reply)) != NULL) { g_warning ("%s : %s", error->name, error->message); ibus_error_free (error); ibus_message_unref (reply); return FALSE; } va_start (args, first_arg_type); type = first_arg_type; while (type != G_TYPE_INVALID) { va_arg (args, gpointer); type = va_arg (args, GType); } 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); ibus_message_unref (reply); if (!retval) { g_warning ("%s: %s", error->name, error->message); ibus_error_free (error); return FALSE; } return TRUE; }
gboolean ibus_connection_call (IBusConnection *connection, const gchar *name, const gchar *path, const gchar *interface, const gchar *member, IBusError **error, GType first_arg_type, ...) { g_assert (IBUS_IS_CONNECTION (connection)); g_assert (name != NULL); g_assert (path != NULL); g_assert (interface != NULL); g_assert (member != NULL); IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); g_assert (dbus_connection_get_is_connected (priv->connection)); IBusMessage *message, *reply; IBusError *tmp_error; va_list args; GType type; gboolean retval; 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); reply = ibus_connection_send_with_reply_and_block ( connection, message, -1, error); ibus_message_unref (message); if (reply == NULL) { return FALSE; } if ((tmp_error = ibus_error_new_from_message (reply)) != NULL) { if (error) { *error = tmp_error; } else { ibus_error_free (tmp_error); } ibus_message_unref (reply); return FALSE; } va_start (args, first_arg_type); type = first_arg_type; while (type != G_TYPE_INVALID) { va_arg (args, gpointer); type = va_arg (args, GType); } 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); ibus_message_unref (reply); return retval; }