remote-desktop/session: Add API to acquire new mapping ID

They are guaranteed to be unique per session, and never reused.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3228>
This commit is contained in:
Jonas Ådahl 2023-08-29 20:31:30 +02:00 committed by Marge Bot
parent b3ba8aedcb
commit 7faac2aef4
2 changed files with 27 additions and 0 deletions

View File

@ -102,6 +102,8 @@ struct _MetaRemoteDesktopSession
MetaSelectionSourceRemote *current_source;
GHashTable *transfer_requests;
guint transfer_request_timeout_id;
GHashTable *mapping_ids;
};
static void initable_init_iface (GInitableIface *iface);
@ -296,6 +298,25 @@ meta_remote_desktop_session_register_screen_cast (MetaRemoteDesktopSession *ses
return TRUE;
}
const char *
meta_remote_desktop_session_acquire_mapping_id (MetaRemoteDesktopSession *session)
{
while (TRUE)
{
char *mapping_id;
mapping_id = g_uuid_string_random ();
if (g_hash_table_contains (session->mapping_ids, mapping_id))
{
g_free (mapping_id);
continue;
}
g_hash_table_add (session->mapping_ids, mapping_id);
return mapping_id;
}
}
static gboolean
check_permission (MetaRemoteDesktopSession *session,
GDBusMethodInvocation *invocation)
@ -1731,6 +1752,8 @@ meta_remote_desktop_session_initable_init (GInitable *initable,
session, "num-lock-state",
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
session->mapping_ids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
return TRUE;
}
@ -1784,6 +1807,8 @@ meta_remote_desktop_session_finalize (GObject *object)
cancel_selection_read (session);
g_hash_table_unref (session->transfer_requests);
g_clear_pointer (&session->mapping_ids, g_hash_table_unref);
g_clear_object (&session->handle);
g_free (session->peer_name);
g_free (session->session_id);

View File

@ -42,6 +42,8 @@ gboolean meta_remote_desktop_session_register_screen_cast (MetaRemoteDesktopSess
MetaScreenCastSession *screen_cast_session,
GError **error);
const char * meta_remote_desktop_session_acquire_mapping_id (MetaRemoteDesktopSession *session);
void meta_remote_desktop_session_request_transfer (MetaRemoteDesktopSession *session,
const char *mime_type,
GTask *task);