#ifdef G_OS_UNIX
#include "gkdbus.h"
-#include "gkdbusconnection.h"
#include "gunixconnection.h"
#include "gunixfdmessage.h"
#endif
* hold @init_lock or check for initialization first.
*/
GDBusWorker *worker;
+ GKDBusWorker *kdbus_worker;
/* If connected to a message bus, this contains the unique name assigned to
* us by the bus (e.g. ":1.42").
if (!check_initialized (connection))
return;
- g_assert (connection->worker != NULL);
- _g_dbus_worker_unfreeze (connection->worker);
+ g_assert (connection->worker || connection->kdbus_worker);
+
+ if (connection->kdbus_worker)
+ g_kdbus_worker_unfreeze (connection->kdbus_worker);
+ else
+ _g_dbus_worker_unfreeze (connection->worker);
}
/**
g_return_val_if_fail (g_dbus_is_name (name) && !g_dbus_is_unique_name (name), G_BUS_RELEASE_NAME_FLAGS_ERROR);
g_return_val_if_fail (error == NULL || *error == NULL, G_BUS_RELEASE_NAME_FLAGS_ERROR);
- if (G_IS_KDBUS_CONNECTION (connection->stream))
- result = _g_kdbus_RequestName (connection, name, flags, error);
+ if (connection->kdbus_worker)
+ result = _g_kdbus_RequestName (connection->kdbus_worker, name, flags, error);
else
result = g_dbus_connection_call_sync (connection, "org.freedesktop.DBus", "/org/freedesktop/DBus",
"org.freedesktop.DBus", "RequestName",
g_return_val_if_fail (g_dbus_is_name (name) && !g_dbus_is_unique_name (name), G_BUS_RELEASE_NAME_FLAGS_ERROR);
g_return_val_if_fail (error == NULL || *error == NULL, G_BUS_RELEASE_NAME_FLAGS_ERROR);
- if (G_IS_KDBUS_CONNECTION (connection->stream))
- result = _g_kdbus_ReleaseName (connection, name, error);
+ if (connection->kdbus_worker)
+ result = _g_kdbus_ReleaseName (connection->kdbus_worker, name, error);
else
result = g_dbus_connection_call_sync (connection, "org.freedesktop.DBus", "/org/freedesktop/DBus",
"org.freedesktop.DBus", "ReleaseName",
result = NULL;
bus_id = NULL;
- if (G_IS_KDBUS_CONNECTION (connection->stream))
+ if (connection->kdbus_worker)
{
- result = _g_kdbus_GetBusId (connection, error);
+ result = _g_kdbus_GetBusId (connection->kdbus_worker, error);
}
else
{
if (list_name_type == LIST_QUEUED_OWNERS)
{
- if (G_IS_KDBUS_CONNECTION (connection->stream))
- result = _g_kdbus_GetListQueuedOwners (connection, name, error);
+ if (connection->kdbus_worker)
+ result = _g_kdbus_GetListQueuedOwners (connection->kdbus_worker, name, error);
else
result = g_dbus_connection_call_sync (connection, "org.freedesktop.DBus", "/",
"org.freedesktop.DBus", "ListQueuedOwners",
else
method_name = "ListActivatableNames";
- if (G_IS_KDBUS_CONNECTION (connection->stream))
- result = _g_kdbus_GetListNames (connection, list_name_type, error);
+ if (connection->kdbus_worker)
+ result = _g_kdbus_GetListNames (connection->kdbus_worker, list_name_type, error);
else
result = g_dbus_connection_call_sync (connection, "org.freedesktop.DBus", "/",
"org.freedesktop.DBus", method_name,
name_owner = NULL;
result = NULL;
- if (G_IS_KDBUS_CONNECTION (connection->stream))
- result = _g_kdbus_GetNameOwner (connection, name, error);
+ if (connection->kdbus_worker)
+ result = _g_kdbus_GetNameOwner (connection->kdbus_worker, name, error);
else
result = g_dbus_connection_call_sync (connection, "org.freedesktop.DBus", "/",
"org.freedesktop.DBus", "GetNameOwner",
}
/**
- * g_dbus_name_has_owner:
- * @connection: a #GDBusConnection
- * @name: a unique or well-known bus name
- * @error: return location for error or %NULL
- *
- * Synchronously checks if the specified name exists (currently has an owner).
- *
- * If @name contains a value not compatible with the D-Bus syntax and naming
- * conventions for bus names, the operation returns %NULL and @error is set.
- *
- * The calling thread is blocked until a reply is received.
- *
- * Returns: %TRUE if specified name exists (currently has an owner)
- * If the requested name doesn't have an owner or @error is set,
- * function returns %FALSE.
- *
- * Since: 2.4x
- */
-gboolean
-g_dbus_name_has_owner (GDBusConnection *connection,
- const gchar *name,
- GError **error)
-{
- GVariant *result;
- gboolean ret;
-
- g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
- g_return_val_if_fail (name == NULL || g_dbus_is_name (name), NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
-
- result = NULL;
-
- if (G_IS_KDBUS_CONNECTION (connection->stream))
- result = _g_kdbus_NameHasOwner (connection, name, error);
- else
- result = g_dbus_connection_call_sync (connection, "org.freedesktop.DBus", "/",
- "org.freedesktop.DBus", "NameHasOwner",
- g_variant_new ("(s)", name), G_VARIANT_TYPE ("(b)"),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
- if (result != NULL)
- {
- g_variant_get (result, "(b)", &ret);
- g_variant_unref (result);
- }
- else
- ret = FALSE;
-
- return ret;
-}
-
-/**
* g_dbus_get_connection_pid:
* @connection: a #GDBusConnection
* @name: a unique or well-known bus name of the connection to query
result = NULL;
pid = -1;
- if (G_IS_KDBUS_CONNECTION (connection->stream))
- result = _g_kdbus_GetConnectionUnixProcessID (connection, name, error);
+ if (connection->kdbus_worker)
+ result = _g_kdbus_GetConnectionUnixProcessID (connection->kdbus_worker, name, error);
else
result = g_dbus_connection_call_sync (connection, "org.freedesktop.DBus", "/",
"org.freedesktop.DBus", "GetConnectionUnixProcessID",
result = NULL;
uid = -1;
- if (G_IS_KDBUS_CONNECTION (connection->stream))
- result = _g_kdbus_GetConnectionUnixUser (connection, name, error);
+ if (connection->kdbus_worker)
+ result = _g_kdbus_GetConnectionUnixUser (connection->kdbus_worker, name, error);
else
result = g_dbus_connection_call_sync (connection, "org.freedesktop.DBus", "/",
"org.freedesktop.DBus", "GetConnectionUnixUser",
}
/* ---------------------------------------------------------------------------------------------------- */
-
+#include "gkdbus.h"
/* Can be called by any thread, with the connection lock held */
static gboolean
g_dbus_connection_send_message_unlocked (GDBusConnection *connection,
error))
goto out;
- blob = g_dbus_message_to_blob (message,
- &blob_size,
- connection->capabilities,
- error);
- if (blob == NULL)
- goto out;
+ if (!(flags & G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL))
+ g_dbus_message_set_serial (message, ++connection->last_serial);
- if (flags & G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL)
- serial_to_use = g_dbus_message_get_serial (message);
- else
- serial_to_use = ++connection->last_serial; /* TODO: handle overflow */
+ serial_to_use = g_dbus_message_get_serial (message);
- switch (blob[0])
+ /*
+ * serializes message to a blob
+ */
+ if (connection->worker)
{
- case 'l':
- ((guint32 *) blob)[2] = GUINT32_TO_LE (serial_to_use);
- break;
- case 'B':
- ((guint32 *) blob)[2] = GUINT32_TO_BE (serial_to_use);
- break;
- default:
- g_assert_not_reached ();
- break;
+ blob = g_dbus_message_to_blob (message,
+ &blob_size,
+ connection->capabilities,
+ error);
+ if (blob == NULL)
+ goto out;
+
+ switch (blob[0])
+ {
+ case 'l':
+ ((guint32 *) blob)[2] = GUINT32_TO_LE (serial_to_use);
+ break;
+ case 'B':
+ ((guint32 *) blob)[2] = GUINT32_TO_BE (serial_to_use);
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
}
+ g_dbus_message_lock (message);
+
#if 0
g_printerr ("Writing message of %" G_GSIZE_FORMAT " bytes (serial %d) on %p:\n",
blob_size, serial_to_use, connection);
g_thread_self (),
GUINT_TO_POINTER (serial_to_use));
- if (!(flags & G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL))
- g_dbus_message_set_serial (message, serial_to_use);
+ ret = TRUE;
- g_dbus_message_lock (message);
- _g_dbus_worker_send_message (connection->worker,
- message,
- (gchar*) blob,
- blob_size);
- blob = NULL; /* since _g_dbus_worker_send_message() steals the blob */
+ if (connection->worker)
+ _g_dbus_worker_send_message (connection->worker,
+ message,
+ (gchar*) blob,
+ blob_size);
+ else
+ ret = g_kdbus_worker_send_message (connection->kdbus_worker, message, error);
- ret = TRUE;
+ blob = NULL; /* since _g_dbus_worker_send_message() steals the blob */
out:
g_free (blob);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
data = g_new0 (SendMessageSyncData, 1);
- data->context = g_main_context_new ();
+
+ if (connection->kdbus_worker)
+ data->context = g_main_context_ref_thread_default ();
+ else
+ data->context = g_main_context_new ();
+
data->loop = g_main_loop_new (data->context, FALSE);
g_main_context_push_thread_default (data->context);
/* Called in GDBusWorker's thread - we must not block - with no lock held */
static void
-on_worker_message_received (GDBusWorker *worker,
- GDBusMessage *message,
+on_worker_message_received (GDBusMessage *message,
gpointer user_data)
{
GDBusConnection *connection;
/* Called in GDBusWorker's thread, lock is not held */
static GDBusMessage *
-on_worker_message_about_to_be_sent (GDBusWorker *worker,
- GDBusMessage *message,
+on_worker_message_about_to_be_sent (GDBusMessage *message,
gpointer user_data)
{
GDBusConnection *connection;
/* Called in GDBusWorker's thread - we must not block - without lock held */
static void
-on_worker_closed (GDBusWorker *worker,
- gboolean remote_peer_vanished,
- GError *error,
- gpointer user_data)
+on_worker_closed (gboolean remote_peer_vanished,
+ GError *error,
+ gpointer user_data)
{
GDBusConnection *connection;
gboolean alive;
GError **error)
{
GDBusConnection *connection = G_DBUS_CONNECTION (initable);
+ gboolean initially_frozen;
gboolean ret;
/* This method needs to be idempotent to work with the singleton
*/
if (connection->address != NULL)
{
+ GObject *ret;
+
g_assert (connection->stream == NULL);
if ((connection->flags & G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_SERVER) ||
goto out;
}
- connection->stream = g_dbus_address_get_stream_sync (connection->address,
- NULL, /* TODO: out_guid */
- cancellable,
- &connection->initialization_error);
- if (connection->stream == NULL)
+ ret = g_dbus_address_get_stream_internal (connection->address, TRUE,
+ NULL, /* TODO: out_guid */
+ cancellable, &connection->initialization_error);
+ if (ret == NULL)
goto out;
+
+ if (G_IS_IO_STREAM (ret))
+ connection->stream = G_IO_STREAM (ret);
+ else if (G_IS_KDBUS_WORKER (ret))
+ connection->kdbus_worker = G_KDBUS_WORKER (ret);
+ else
+ g_assert_not_reached ();
}
else if (connection->stream != NULL)
{
}
/* [KDBUS] Skip authentication process for kdbus transport */
- if (G_IS_KDBUS_CONNECTION (connection->stream))
+ if (connection->kdbus_worker)
{
goto authenticated;
}
g_hash_table_insert (alive_connections, connection, connection);
G_UNLOCK (message_bus_lock);
- connection->worker = _g_dbus_worker_new (connection->stream,
- connection->capabilities,
- ((connection->flags & G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING) != 0),
- on_worker_message_received,
- on_worker_message_about_to_be_sent,
- on_worker_closed,
- connection);
+ initially_frozen = (connection->flags & G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING) != 0;
+
+ if (connection->kdbus_worker)
+ g_kdbus_worker_associate (connection->kdbus_worker,
+ connection->capabilities,
+ on_worker_message_received,
+ on_worker_message_about_to_be_sent,
+ on_worker_closed,
+ connection);
+ else
+ connection->worker = _g_dbus_worker_new (connection->stream,
+ connection->capabilities,
+ initially_frozen,
+ on_worker_message_received,
+ on_worker_message_about_to_be_sent,
+ on_worker_closed,
+ connection);
/* if a bus connection, call org.freedesktop.DBus.Hello - this is how we're getting a name */
if (connection->flags & G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION)
goto out;
}
- if (G_IS_KDBUS_CONNECTION (connection->stream))
+ if (connection->kdbus_worker)
{
- hello_result = _g_kdbus_Hello (connection->stream, &connection->initialization_error);
+ hello_result = _g_kdbus_Hello (connection->kdbus_worker, &connection->initialization_error);
}
else
{
//g_debug ("unique name is '%s'", connection->bus_unique_name);
}
+ if (connection->kdbus_worker && !initially_frozen)
+ g_kdbus_worker_unfreeze (connection->kdbus_worker);
+
ret = TRUE;
out:
if (!ret)
if (connection->flags & G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION)
{
if (!is_signal_data_for_name_lost_or_acquired (signal_data))
- add_match_rule (connection, signal_data->rule);
+ if (connection->kdbus_worker)
+ _g_kdbus_AddMatch (connection->kdbus_worker, signal_data->rule, subscriber.id);
+ else
+ add_match_rule (connection, signal_data->rule);
else
{
- if (G_IS_KDBUS_CONNECTION (connection->stream))
+ if (connection->kdbus_worker)
{
if (g_strcmp0 (signal_data->member, "NameAcquired") == 0)
- _g_kdbus_subscribe_name_acquired (connection, arg0);
+ _g_kdbus_subscribe_name_acquired (connection->kdbus_worker, arg0);
else if (g_strcmp0 (signal_data->member, "NameLost") == 0)
- _g_kdbus_subscribe_name_lost (connection, arg0);
+ _g_kdbus_subscribe_name_lost (connection->kdbus_worker, arg0);
}
}
}
* so on_worker_closed() can't happen between the check we just
* did, and releasing the lock later.
*/
- remove_match_rule (connection, signal_data->rule);
+ if (connection->kdbus_worker)
+ _g_kdbus_RemoveMatch (connection->kdbus_worker, subscription_id);
+ else
+ remove_match_rule (connection, signal_data->rule);
}
else
{
- if (G_IS_KDBUS_CONNECTION (connection->stream))
+ if (connection->kdbus_worker)
{
- //_g_kdbus_unsubscribe_name_lost_and_acquired (connection, arg0);
+ if (g_strcmp0 (signal_data->member, "NameAcquired") == 0)
+ _g_kdbus_unsubscribe_name_acquired (connection->kdbus_worker);
+ else if (g_strcmp0 (signal_data->member, "NameLost") == 0)
+ _g_kdbus_unsubscribe_name_lost (connection->kdbus_worker);
}
}