mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 15:36:17 +01:00
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:
parent
c3371efcaa
commit
ee945d8f62
@ -122,8 +122,8 @@ struct _GDBusServerClass
|
||||
|
||||
/*< public >*/
|
||||
/* Signals */
|
||||
void (*new_connection) (GDBusServer *server,
|
||||
GDBusConnection *connection);
|
||||
gboolean (*new_connection) (GDBusServer *server,
|
||||
GDBusConnection *connection);
|
||||
};
|
||||
|
||||
enum
|
||||
@ -391,10 +391,12 @@ g_dbus_server_class_init (GDBusServerClass *klass)
|
||||
* g_dbus_connection_get_peer_credentials() to figure out what
|
||||
* identity (if any), was authenticated.
|
||||
*
|
||||
* If you want to accept the connection, simply ref the @connection
|
||||
* object. Then call g_dbus_connection_close() and unref it when you
|
||||
* are done with it. A typical thing to do when accepting a
|
||||
* connection is to listen to the #GDBusConnection::closed signal.
|
||||
* If you want to accept the connection, take a reference to the
|
||||
* @connection object and return %TRUE. When you are done with the
|
||||
* connection call g_dbus_connection_close() and give up your
|
||||
* 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
|
||||
* 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
|
||||
* similar from the signal handler.
|
||||
*
|
||||
* Returns: %TRUE to claim @connection, %FALSE to let other handlers
|
||||
* run.
|
||||
*
|
||||
* Since: 2.26
|
||||
*/
|
||||
_signals[NEW_CONNECTION_SIGNAL] = g_signal_new ("new-connection",
|
||||
G_TYPE_DBUS_SERVER,
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (GDBusServerClass, new_connection),
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_VOID__OBJECT,
|
||||
G_TYPE_NONE,
|
||||
g_signal_accumulator_true_handled,
|
||||
NULL, /* accu_data */
|
||||
_gio_marshal_BOOLEAN__OBJECT,
|
||||
G_TYPE_BOOLEAN,
|
||||
1,
|
||||
G_TYPE_DBUS_CONNECTION);
|
||||
}
|
||||
@ -922,12 +927,17 @@ static gboolean
|
||||
emit_new_connection_in_idle (gpointer user_data)
|
||||
{
|
||||
EmitIdleData *data = user_data;
|
||||
gboolean claimed;
|
||||
|
||||
claimed = FALSE;
|
||||
g_signal_emit (data->server,
|
||||
_signals[NEW_CONNECTION_SIGNAL],
|
||||
0,
|
||||
data->connection);
|
||||
g_dbus_connection_start_message_processing (data->connection);
|
||||
data->connection,
|
||||
&claimed);
|
||||
|
||||
if (claimed)
|
||||
g_dbus_connection_start_message_processing (data->connection);
|
||||
g_object_unref (data->connection);
|
||||
|
||||
return FALSE;
|
||||
|
@ -21,3 +21,4 @@ VOID:STRING,STRING,VARIANT
|
||||
VOID:STRING
|
||||
VOID:STRING,STRING
|
||||
VOID:STRING,BOOLEAN
|
||||
BOOL:OBJECT
|
||||
|
@ -121,7 +121,7 @@ static const GDBusInterfaceVTable interface_vtable =
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
static gboolean
|
||||
on_new_connection (GDBusServer *server,
|
||||
GDBusConnection *connection,
|
||||
gpointer user_data)
|
||||
@ -152,6 +152,8 @@ on_new_connection (GDBusServer *server,
|
||||
NULL, /* user_data_free_func */
|
||||
NULL); /* GError** */
|
||||
g_assert (registration_id > 0);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------- */
|
||||
|
@ -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) */
|
||||
static void
|
||||
static gboolean
|
||||
on_new_connection (GDBusServer *server,
|
||||
GDBusConnection *connection,
|
||||
gpointer user_data)
|
||||
@ -311,6 +311,8 @@ on_new_connection (GDBusServer *server,
|
||||
g_assert (reg_id > 0);
|
||||
|
||||
g_main_loop_quit (loop);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
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) */
|
||||
static void
|
||||
static gboolean
|
||||
dmp_on_new_connection (GDBusServer *server,
|
||||
GDBusConnection *connection,
|
||||
gpointer user_data)
|
||||
@ -984,6 +986,8 @@ dmp_on_new_connection (GDBusServer *server,
|
||||
NULL,
|
||||
&error);
|
||||
g_dbus_node_info_unref (node);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
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) */
|
||||
static void
|
||||
static gboolean
|
||||
nonce_tcp_on_new_connection (GDBusServer *server,
|
||||
GDBusConnection *connection,
|
||||
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_main_loop_quit (loop);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gpointer
|
||||
|
Loading…
Reference in New Issue
Block a user