gboolean ibus_bus_name_has_owner (IBusBus *bus, const gchar *name) { g_assert (IBUS_IS_BUS (bus)); 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); } ibus_message_unref (reply); } return retval; }
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; }
guint ibus_bus_release_name (IBusBus *bus, const gchar *name) { g_assert (IBUS_IS_BUS (bus)); 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); } ibus_message_unref (reply); } return retval; }
guint ibus_bus_request_name (IBusBus *bus, const gchar *name, guint flags) { 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); if (result) return retval; return 0; }
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 *path = NULL; 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, IBUS_TYPE_OBJECT_PATH, &path, G_TYPE_INVALID)) { path = g_strdup (path); } else { g_warning ("%s: %s", error->name, error->message); ibus_error_free (error); } ibus_message_unref (reply); } return path; }
static void _connection_destroy_cb (IBusConnection *connection, IBusBus *bus) { g_assert (IBUS_IS_BUS (bus)); g_assert (IBUS_IS_CONNECTION (connection)); IBusBusPrivate *priv; priv = IBUS_BUS_GET_PRIVATE (bus); g_assert (priv->connection == connection); g_signal_handlers_disconnect_by_func (priv->connection, G_CALLBACK (_connection_destroy_cb), bus); g_signal_handlers_disconnect_by_func (priv->connection, G_CALLBACK (_connection_ibus_signal_cb), bus); g_object_unref (priv->connection); priv->connection = NULL; g_free (priv->unique_name); priv->unique_name = NULL; g_signal_emit (bus, bus_signals[DISCONNECTED], 0); }
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 }
IBusEngineDesc * ibus_bus_get_global_engine (IBusBus *bus) { g_assert (IBUS_IS_BUS (bus)); IBusMessage *reply = NULL; IBusError *error = NULL; IBusEngineDesc *global_engine = NULL; reply = ibus_bus_call_with_reply (bus, IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, IBUS_INTERFACE_IBUS, "GetGlobalEngine", G_TYPE_INVALID); if (reply) { if (!ibus_message_get_args (reply, &error, IBUS_TYPE_ENGINE_DESC, &global_engine, G_TYPE_INVALID)) { g_warning ("%s: %s", error->name, error->message); ibus_error_free (error); } ibus_message_unref (reply); } return global_engine; }
gchar * ibus_bus_get_name_owner (IBusBus *bus, const gchar *name) { g_assert (IBUS_IS_BUS (bus)); gchar *owner = NULL; 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, &name, 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); } ibus_message_unref (reply); } return owner; }
gboolean ibus_bus_get_use_global_engine (IBusBus *bus) { g_assert (IBUS_IS_BUS (bus)); IBusMessage *reply = NULL; IBusError *error = NULL; gboolean use_global_engine = FALSE; reply = ibus_bus_call_with_reply (bus, IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, IBUS_INTERFACE_IBUS, "GetUseGlobalEngine", G_TYPE_INVALID); if (reply) { if (!ibus_message_get_args (reply, &error, G_TYPE_BOOLEAN, &use_global_engine, G_TYPE_INVALID)) { g_warning ("%s: %s", error->name, error->message); ibus_error_free (error); } ibus_message_unref (reply); } return use_global_engine; }
static void _bus_disconnected_cb (IBusBus *ibusbus, BusTestClient *client) { g_assert (IBUS_IS_BUS (ibusbus)); g_assert (BUS_IS_TEST_CLIENT (client)); IDEBUG ("%s", __FUNCTION__); client->connected = FALSE; IDEBUG ("Disconnected ibus daemon"); }
IBusConnection * ibus_bus_get_connection (IBusBus *bus) { g_assert (IBUS_IS_BUS (bus)); IBusBusPrivate *priv; priv = IBUS_BUS_GET_PRIVATE (bus); return priv->connection; }
static void ibus_bus_unwatch_dbus_signal (IBusBus *bus) { g_assert (IBUS_IS_BUS (bus)); const gchar *rule; rule = "type='signal'," \ "path='" DBUS_PATH_DBUS "'," \ "interface='" DBUS_INTERFACE_DBUS "'"; ibus_bus_remove_match (bus, rule); }
gboolean ibus_bus_is_connected (IBusBus *bus) { g_assert (IBUS_IS_BUS (bus)); IBusBusPrivate *priv; priv = IBUS_BUS_GET_PRIVATE (bus); if (priv->connection) { return ibus_connection_is_connected (priv->connection); } return FALSE; }
void ibus_bus_remove_match (IBusBus *bus, const gchar *rule) { g_assert (IBUS_IS_BUS (bus)); ibus_bus_call (bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "RemoveMatch", G_TYPE_STRING, &rule, G_TYPE_INVALID); }
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; }
void ibus_bus_add_match (IBusBus *bus, const gchar *rule) { 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); }
gboolean ibus_bus_set_global_engine (IBusBus *bus, const gchar *global_engine) { g_assert (IBUS_IS_BUS (bus)); gboolean result; result = ibus_bus_call (bus, IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, IBUS_INTERFACE_IBUS, "SetGlobalEngine", G_TYPE_STRING, &global_engine, G_TYPE_INVALID); return result; }
IBusConfig * ibus_bus_get_config (IBusBus *bus) { g_assert (IBUS_IS_BUS (bus)); g_return_val_if_fail (ibus_bus_is_connected (bus), NULL); 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; }
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); return result; }
gboolean ibus_bus_exit (IBusBus *bus, gboolean restart) { g_assert (IBUS_IS_BUS (bus)); IBusBusPrivate *priv; priv = IBUS_BUS_GET_PRIVATE (bus); gboolean result; result = ibus_bus_call (bus, IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, IBUS_INTERFACE_IBUS, "Exit", G_TYPE_BOOLEAN, &restart, G_TYPE_INVALID); return result; }
const 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); if (result) return unique_name; return NULL; }
const gchar * ibus_bus_current_input_context(IBusBus *bus) { g_assert (IBUS_IS_BUS (bus)); gchar *name = NULL; gboolean result; result = ibus_bus_call (bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "CurrentInputContext", G_TYPE_INVALID, G_TYPE_STRING, &name, G_TYPE_INVALID); if (result) return name; return NULL; }
void ibus_bus_set_watch_dbus_signal (IBusBus *bus, gboolean watch) { g_assert (IBUS_IS_BUS (bus)); IBusBusPrivate *priv; priv = IBUS_BUS_GET_PRIVATE (bus); if (priv->watch_dbus_signal == watch) return; priv->watch_dbus_signal = watch; if (ibus_bus_is_connected (bus)) { if (watch) { ibus_bus_watch_dbus_signal (bus); } else { ibus_bus_unwatch_dbus_signal (bus); } } }
gboolean ibus_bus_name_has_owner (IBusBus *bus, const gchar *name) { g_assert (IBUS_IS_BUS (bus)); gboolean retval; gboolean result; 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); if (result) return retval; return FALSE; }
const 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); if (result) return owner; return NULL; }
const gchar * ibus_bus_hello (IBusBus *bus) { g_assert (IBUS_IS_BUS (bus)); gchar *unique_name = NULL; IBusMessage *reply = NULL; IBusError *error = NULL; IBusBusPrivate *priv; priv = IBUS_BUS_GET_PRIVATE (bus); g_free (priv->unique_name); priv->unique_name = 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)) { priv->unique_name = g_strdup (unique_name); } else { g_warning ("%s: %s", error->name, error->message); ibus_error_free (error); } ibus_message_unref (reply); } return priv->unique_name; }
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; }