GDBusServer: Make ::new-connection return whether the connection was claimed

Otherwise things probably won't work in a garbage-collected world
(consider the trivial GC that never collects garbage).

This commit breaks GDBusServer ABI. No known released software is
using this code.

Signed-off-by: David Zeuthen <davidz@redhat.com>
This commit is contained in:
David Zeuthen 2010-09-09 14:00:46 -04:00
parent c3371efcaa
commit ee945d8f62
4 changed files with 35 additions and 16 deletions

View File

@ -122,7 +122,7 @@ struct _GDBusServerClass
/*< public >*/ /*< public >*/
/* Signals */ /* Signals */
void (*new_connection) (GDBusServer *server, gboolean (*new_connection) (GDBusServer *server,
GDBusConnection *connection); GDBusConnection *connection);
}; };
@ -391,10 +391,12 @@ g_dbus_server_class_init (GDBusServerClass *klass)
* g_dbus_connection_get_peer_credentials() to figure out what * g_dbus_connection_get_peer_credentials() to figure out what
* identity (if any), was authenticated. * identity (if any), was authenticated.
* *
* If you want to accept the connection, simply ref the @connection * If you want to accept the connection, take a reference to the
* object. Then call g_dbus_connection_close() and unref it when you * @connection object and return %TRUE. When you are done with the
* are done with it. A typical thing to do when accepting a * connection call g_dbus_connection_close() and give up your
* connection is to listen to the #GDBusConnection::closed signal. * reference. Note that the other peer may disconnect at any time -
* a typical thing to do when accepting a connection is to listen to
* the #GDBusConnection::closed signal.
* *
* If #GDBusServer:flags contains %G_DBUS_SERVER_FLAGS_RUN_IN_THREAD * If #GDBusServer:flags contains %G_DBUS_SERVER_FLAGS_RUN_IN_THREAD
* then the signal is emitted in a new thread dedicated to the * then the signal is emitted in a new thread dedicated to the
@ -407,16 +409,19 @@ g_dbus_server_class_init (GDBusServerClass *klass)
* that it's suitable to call g_dbus_connection_register_object() or * that it's suitable to call g_dbus_connection_register_object() or
* similar from the signal handler. * similar from the signal handler.
* *
* Returns: %TRUE to claim @connection, %FALSE to let other handlers
* run.
*
* Since: 2.26 * Since: 2.26
*/ */
_signals[NEW_CONNECTION_SIGNAL] = g_signal_new ("new-connection", _signals[NEW_CONNECTION_SIGNAL] = g_signal_new ("new-connection",
G_TYPE_DBUS_SERVER, G_TYPE_DBUS_SERVER,
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GDBusServerClass, new_connection), G_STRUCT_OFFSET (GDBusServerClass, new_connection),
NULL, g_signal_accumulator_true_handled,
NULL, NULL, /* accu_data */
g_cclosure_marshal_VOID__OBJECT, _gio_marshal_BOOLEAN__OBJECT,
G_TYPE_NONE, G_TYPE_BOOLEAN,
1, 1,
G_TYPE_DBUS_CONNECTION); G_TYPE_DBUS_CONNECTION);
} }
@ -922,11 +927,16 @@ static gboolean
emit_new_connection_in_idle (gpointer user_data) emit_new_connection_in_idle (gpointer user_data)
{ {
EmitIdleData *data = user_data; EmitIdleData *data = user_data;
gboolean claimed;
claimed = FALSE;
g_signal_emit (data->server, g_signal_emit (data->server,
_signals[NEW_CONNECTION_SIGNAL], _signals[NEW_CONNECTION_SIGNAL],
0, 0,
data->connection); data->connection,
&claimed);
if (claimed)
g_dbus_connection_start_message_processing (data->connection); g_dbus_connection_start_message_processing (data->connection);
g_object_unref (data->connection); g_object_unref (data->connection);

View File

@ -21,3 +21,4 @@ VOID:STRING,STRING,VARIANT
VOID:STRING VOID:STRING
VOID:STRING,STRING VOID:STRING,STRING
VOID:STRING,BOOLEAN VOID:STRING,BOOLEAN
BOOL:OBJECT

View File

@ -121,7 +121,7 @@ static const GDBusInterfaceVTable interface_vtable =
/* ---------------------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------------------- */
static void static gboolean
on_new_connection (GDBusServer *server, on_new_connection (GDBusServer *server,
GDBusConnection *connection, GDBusConnection *connection,
gpointer user_data) gpointer user_data)
@ -152,6 +152,8 @@ on_new_connection (GDBusServer *server,
NULL, /* user_data_free_func */ NULL, /* user_data_free_func */
NULL); /* GError** */ NULL); /* GError** */
g_assert (registration_id > 0); g_assert (registration_id > 0);
return TRUE;
} }
/* ---------------------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------------------- */

View File

@ -283,7 +283,7 @@ on_authorize_authenticated_peer (GDBusAuthObserver *observer,
} }
/* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */ /* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */
static void static gboolean
on_new_connection (GDBusServer *server, on_new_connection (GDBusServer *server,
GDBusConnection *connection, GDBusConnection *connection,
gpointer user_data) gpointer user_data)
@ -311,6 +311,8 @@ on_new_connection (GDBusServer *server,
g_assert (reg_id > 0); g_assert (reg_id > 0);
g_main_loop_quit (loop); g_main_loop_quit (loop);
return TRUE;
} }
static gpointer static gpointer
@ -943,7 +945,7 @@ static const GDBusInterfaceVTable dmp_interface_vtable =
/* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */ /* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */
static void static gboolean
dmp_on_new_connection (GDBusServer *server, dmp_on_new_connection (GDBusServer *server,
GDBusConnection *connection, GDBusConnection *connection,
gpointer user_data) gpointer user_data)
@ -984,6 +986,8 @@ dmp_on_new_connection (GDBusServer *server,
NULL, NULL,
&error); &error);
g_dbus_node_info_unref (node); g_dbus_node_info_unref (node);
return TRUE;
} }
static gpointer static gpointer
@ -1101,7 +1105,7 @@ nonce_tcp_on_authorize_authenticated_peer (GDBusAuthObserver *observer,
} }
/* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */ /* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */
static void static gboolean
nonce_tcp_on_new_connection (GDBusServer *server, nonce_tcp_on_new_connection (GDBusServer *server,
GDBusConnection *connection, GDBusConnection *connection,
gpointer user_data) gpointer user_data)
@ -1111,6 +1115,8 @@ nonce_tcp_on_new_connection (GDBusServer *server,
g_ptr_array_add (data->current_connections, g_object_ref (connection)); g_ptr_array_add (data->current_connections, g_object_ref (connection));
g_main_loop_quit (loop); g_main_loop_quit (loop);
return TRUE;
} }
static gpointer static gpointer