void ibus_connection_set_connection (IBusConnection *connection, DBusConnection *dbus_connection, gboolean shared) { gboolean result; IBusConnectionPrivate *priv; g_assert (IBUS_IS_CONNECTION (connection)); g_assert (dbus_connection != NULL); g_assert (dbus_connection_get_is_connected (dbus_connection)); priv = IBUS_CONNECTION_GET_PRIVATE (connection); g_assert (priv->connection == NULL); priv->connection = dbus_connection_ref (dbus_connection); priv->shared = shared; dbus_connection_set_data (priv->connection, _get_slot(), connection, NULL); dbus_connection_set_unix_user_function (priv->connection, (DBusAllowUnixUserFunction) _connection_allow_unix_user_cb, connection, NULL); result = dbus_connection_add_filter (priv->connection, (DBusHandleMessageFunction) _connection_handle_message_cb, connection, NULL); ibus_dbus_connection_setup (priv->connection); g_warn_if_fail (result); }
static void ibus_connection_destroy (IBusConnection *connection) { IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); if (priv->connection) { dbus_connection_remove_filter (priv->connection, (DBusHandleMessageFunction) _connection_handle_message_cb, connection); } if (!priv->shared && priv->connection) { dbus_connection_close (priv->connection); dbus_connection_unref (priv->connection); priv->connection = NULL; goto _out; } if (priv->shared && priv->connection) { g_warn_if_fail (_connections != NULL); if (_connections != NULL) { g_hash_table_remove (_connections, priv->connection); } dbus_connection_unref (priv->connection); priv->connection = NULL; goto _out; } _out: parent_class->destroy (IBUS_OBJECT (connection)); }
gboolean ibus_connection_register_object_path (IBusConnection *connection, const gchar *path, IBusMessageFunc message_func, gpointer user_data) { g_assert (IBUS_IS_CONNECTION (connection)); g_assert (path != NULL); g_assert (message_func != NULL); IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); gboolean retval; DBusObjectPathVTable vtable = {0}; VTableCallData *data; vtable.unregister_function = (DBusObjectPathUnregisterFunction) _unregister_function; vtable.message_function = (DBusObjectPathMessageFunction) _message_function; data = g_slice_new (VTableCallData); data->message_func = message_func; data->user_data = user_data; retval = dbus_connection_register_object_path (priv->connection, path, &vtable, data); if (!retval) { g_warning ("Out of memory!"); return FALSE; } return TRUE; }
DBusConnection * ibus_connection_get_connection (IBusConnection *connection) { IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); return priv->connection; }
gboolean ibus_connection_read_write_dispatch (IBusConnection *connection, gint timeout) { IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); return dbus_connection_read_write_dispatch (priv->connection, timeout); }
static void ibus_connection_init (IBusConnection *connection) { IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); priv->connection = NULL; priv->shared = FALSE; }
void ibus_connection_close (IBusConnection *connection) { g_assert (IBUS_IS_CONNECTION (connection)); IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); dbus_connection_close (priv->connection); }
gboolean ibus_connection_is_authenticated (IBusConnection *connection) { IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); if (priv->connection == NULL) { return FALSE; } return dbus_connection_get_is_authenticated (priv->connection); }
static gboolean ibus_connection_ibus_signal (IBusConnection *connection, IBusMessage *message) { IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); if (ibus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected")) { g_signal_emit (connection, connection_signals[DISCONNECTED], 0); return FALSE; } return FALSE; }
glong ibus_connection_get_unix_user (IBusConnection *connection) { IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); gulong uid; if (priv->connection && dbus_connection_get_unix_user (priv->connection, &uid)) return uid; return -1; }
void ibus_connection_flush (IBusConnection *connection) { g_assert (IBUS_IS_CONNECTION (connection)); g_assert (ibus_connection_is_connected (connection)); IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); dbus_connection_flush (priv->connection); }
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; }
gboolean ibus_connection_unregister_object_path (IBusConnection *connection, const gchar *path) { g_assert (IBUS_IS_CONNECTION (connection)); g_assert (path != NULL); IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); gboolean retval; retval = dbus_connection_unregister_object_path (priv->connection, path); if (!retval) { g_warning ("Out of memory!"); return FALSE; } return TRUE; }
IBusMessage * ibus_connection_send_with_reply_and_block (IBusConnection *connection, IBusMessage *message, gint timeout_milliseconds, IBusError **error) { g_assert (IBUS_IS_CONNECTION (connection)); g_assert (message != NULL); g_assert (timeout_milliseconds > 0 || timeout_milliseconds == -1); IBusError *_error; IBusMessage *reply; IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); _error = ibus_error_new (); reply = dbus_connection_send_with_reply_and_block (priv->connection, message, timeout_milliseconds, _error); if (reply != NULL) { g_signal_emit (connection, connection_signals[IBUS_MESSAGE_SENT], 0, message); ibus_error_free (_error); } else { if (error != NULL) { *error = _error; } else { ibus_error_free (_error); } } return reply; }
gboolean ibus_connection_send (IBusConnection *connection, IBusMessage *message) { g_assert (IBUS_IS_CONNECTION (connection)); g_assert (message != NULL); gboolean retval; IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); retval = dbus_connection_send (priv->connection, message, NULL); if (retval) { g_signal_emit (connection, connection_signals[IBUS_MESSAGE_SENT], 0, message); } return retval; }
gboolean ibus_connection_send_with_reply (IBusConnection *connection, IBusMessage *message, IBusPendingCall **pending_return, gint timeout_milliseconds) { g_assert (IBUS_IS_CONNECTION (connection)); g_assert (message != NULL); g_assert (pending_return != NULL); g_assert (timeout_milliseconds > 0 || timeout_milliseconds == -1); IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); gboolean retval; retval = dbus_connection_send_with_reply (priv->connection, message, pending_return, timeout_milliseconds); return retval; }
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; }