gboolean bus_dbus_impl_register_object (BusDBusImpl *dbus, IBusService *object) { g_assert (BUS_IS_DBUS_IMPL (dbus)); g_assert (IBUS_IS_SERVICE (object)); const gchar *path; if (G_UNLIKELY (IBUS_OBJECT_DESTROYED (dbus))) { return FALSE; } path = ibus_service_get_path (object); g_return_val_if_fail (path, FALSE); g_return_val_if_fail (g_hash_table_lookup (dbus->objects, path) == NULL, FALSE); g_object_ref (object); g_hash_table_insert (dbus->objects, (gpointer)path, object); g_signal_connect (object, "destroy", G_CALLBACK (_object_destroy_cb), dbus); return TRUE; }
gboolean bus_dbus_impl_unregister_object (BusDBusImpl *dbus, IBusService *object) { g_assert (BUS_IS_DBUS_IMPL (dbus)); g_assert (IBUS_IS_SERVICE (object)); const gchar *path; if (G_UNLIKELY (IBUS_OBJECT_DESTROYED (dbus))) { return FALSE; } path = ibus_service_get_path (object); g_return_val_if_fail (path, FALSE); g_return_val_if_fail (g_hash_table_lookup (dbus->objects, path) == object, FALSE); g_signal_handlers_disconnect_by_func (object, G_CALLBACK (_object_destroy_cb), dbus); g_hash_table_remove (dbus->objects, path); g_object_unref (object); return TRUE; }
gboolean ibus_service_remove_from_all_connections (IBusService *service) { g_return_val_if_fail (IBUS_IS_SERVICE (service), FALSE); IBusServicePrivate *priv; priv = IBUS_SERVICE_GET_PRIVATE (service); GList *element = priv->connections; while (element != NULL) { IBusConnection *connection = IBUS_CONNECTION (element->data); gboolean retval; retval = ibus_connection_unregister_object_path (connection, priv->path); g_signal_handlers_disconnect_by_func (connection, (GCallback) _connection_destroy_cb, service); g_object_unref (connection); element = element->next; } g_list_free (priv->connections); priv->connections = NULL; return TRUE; }
gboolean ibus_service_send_signal (IBusService *service, const gchar *interface, const gchar *name, GType first_arg_type, ...) { g_assert (IBUS_IS_SERVICE (service)); g_assert (name != NULL); gboolean retval; va_list args; GList *p; IBusServicePrivate *priv; priv = IBUS_SERVICE_GET_PRIVATE (service); for (p = priv->connections; p != NULL; p = p->next) { va_start (args, first_arg_type); retval = ibus_connection_send_signal_valist ((IBusConnection *) p->data, priv->path, interface, name, first_arg_type, args); va_end (args); } return retval; }
gboolean ibus_service_remove_from_connection (IBusService *service, IBusConnection *connection) { g_return_val_if_fail (IBUS_IS_SERVICE (service), FALSE); g_return_val_if_fail (IBUS_IS_CONNECTION (connection), FALSE); IBusServicePrivate *priv; priv = IBUS_SERVICE_GET_PRIVATE (service); g_assert (priv->path != NULL); g_assert (g_list_find (priv->connections, connection) != NULL); gboolean retval; retval = ibus_connection_unregister_object_path (connection, priv->path); if (!retval) { return FALSE; } g_signal_handlers_disconnect_by_func (connection, (GCallback) _connection_destroy_cb, service); priv->connections = g_list_remove (priv->connections, connection); g_object_unref (connection); return TRUE; }
gboolean ibus_service_add_to_connection (IBusService *service, IBusConnection *connection) { g_assert (IBUS_IS_SERVICE (service)); g_assert (IBUS_IS_CONNECTION (connection)); gboolean retval; IBusServicePrivate *priv; priv = IBUS_SERVICE_GET_PRIVATE (service); g_return_val_if_fail (priv->path != NULL, FALSE); g_return_val_if_fail (g_list_find (priv->connections, connection) == NULL, FALSE); g_object_ref (connection); retval = ibus_connection_register_object_path (connection, priv->path, (IBusMessageFunc) _service_message_function, service); if (!retval) { g_object_unref (connection); return FALSE; } priv->connections = g_list_append (priv->connections, connection); g_signal_connect (connection, "destroy", (GCallback) _connection_destroy_cb, service); return retval; }
static void _connection_destroy_cb (IBusConnection *connection, IBusService *service) { g_assert (IBUS_IS_CONNECTION (connection)); g_assert (IBUS_IS_SERVICE (service)); ibus_service_remove_from_connection (service, connection); }
const gchar * ibus_service_get_path (IBusService *service) { g_assert (IBUS_IS_SERVICE (service)); IBusServicePrivate *priv; priv = IBUS_SERVICE_GET_PRIVATE (service); return priv->path; }
GList * ibus_service_get_connections (IBusService *service) { g_assert (IBUS_IS_SERVICE (service)); IBusServicePrivate *priv; priv = IBUS_SERVICE_GET_PRIVATE (service); GList *l; l = g_list_copy (priv->connections); g_list_foreach (l, (GFunc) g_object_ref, NULL); return l; }