dbus-clipboard.c (6a50f64ca01d0a7b97f14f069762bfd88160f31e) dbus-clipboard.c (b289bb301a037a2bf98c07269f5cb40561e03357)
1/*
2 * QEMU DBus display
3 *
4 * Copyright (c) 2021 Marc-André Lureau <marcandre.lureau@redhat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 190 unchanged lines hidden (view full) ---

199 return;
200 }
201
202 name = g_dbus_proxy_get_name(G_DBUS_PROXY(dpy->clipboard_proxy));
203 trace_dbus_clipboard_unregister(name);
204 g_clear_object(&dpy->clipboard_proxy);
205}
206
1/*
2 * QEMU DBus display
3 *
4 * Copyright (c) 2021 Marc-André Lureau <marcandre.lureau@redhat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 190 unchanged lines hidden (view full) ---

199 return;
200 }
201
202 name = g_dbus_proxy_get_name(G_DBUS_PROXY(dpy->clipboard_proxy));
203 trace_dbus_clipboard_unregister(name);
204 g_clear_object(&dpy->clipboard_proxy);
205}
206
207static void
208dbus_on_clipboard_proxy_name_owner_changed(
209 DBusDisplay *dpy,
210 GObject *object,
211 GParamSpec *pspec)
212{
213 dbus_clipboard_unregister_proxy(dpy);
214}
215
216static gboolean
217dbus_clipboard_register(
218 DBusDisplay *dpy,
219 GDBusMethodInvocation *invocation)
220{
221 g_autoptr(GError) err = NULL;
222 const char *name = NULL;
207static gboolean
208dbus_clipboard_register(
209 DBusDisplay *dpy,
210 GDBusMethodInvocation *invocation)
211{
212 g_autoptr(GError) err = NULL;
213 const char *name = NULL;
214 GDBusConnection *connection = g_dbus_method_invocation_get_connection(invocation);
223
224 if (dpy->clipboard_proxy) {
225 g_dbus_method_invocation_return_error(
226 invocation,
227 DBUS_DISPLAY_ERROR,
228 DBUS_DISPLAY_ERROR_FAILED,
229 "Clipboard peer already registered!");
230 return DBUS_METHOD_INVOCATION_HANDLED;
231 }
232
233 dpy->clipboard_proxy =
234 qemu_dbus_display1_clipboard_proxy_new_sync(
215
216 if (dpy->clipboard_proxy) {
217 g_dbus_method_invocation_return_error(
218 invocation,
219 DBUS_DISPLAY_ERROR,
220 DBUS_DISPLAY_ERROR_FAILED,
221 "Clipboard peer already registered!");
222 return DBUS_METHOD_INVOCATION_HANDLED;
223 }
224
225 dpy->clipboard_proxy =
226 qemu_dbus_display1_clipboard_proxy_new_sync(
235 g_dbus_method_invocation_get_connection(invocation),
227 connection,
236 G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
237 g_dbus_method_invocation_get_sender(invocation),
238 "/org/qemu/Display1/Clipboard",
239 NULL,
240 &err);
241 if (!dpy->clipboard_proxy) {
242 g_dbus_method_invocation_return_error(
243 invocation,
244 DBUS_DISPLAY_ERROR,
245 DBUS_DISPLAY_ERROR_FAILED,
246 "Failed to setup proxy: %s", err->message);
247 return DBUS_METHOD_INVOCATION_HANDLED;
248 }
249
250 name = g_dbus_proxy_get_name(G_DBUS_PROXY(dpy->clipboard_proxy));
251 trace_dbus_clipboard_register(name);
252
253 g_object_connect(dpy->clipboard_proxy,
254 "swapped-signal::notify::g-name-owner",
228 G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
229 g_dbus_method_invocation_get_sender(invocation),
230 "/org/qemu/Display1/Clipboard",
231 NULL,
232 &err);
233 if (!dpy->clipboard_proxy) {
234 g_dbus_method_invocation_return_error(
235 invocation,
236 DBUS_DISPLAY_ERROR,
237 DBUS_DISPLAY_ERROR_FAILED,
238 "Failed to setup proxy: %s", err->message);
239 return DBUS_METHOD_INVOCATION_HANDLED;
240 }
241
242 name = g_dbus_proxy_get_name(G_DBUS_PROXY(dpy->clipboard_proxy));
243 trace_dbus_clipboard_register(name);
244
245 g_object_connect(dpy->clipboard_proxy,
246 "swapped-signal::notify::g-name-owner",
255 dbus_on_clipboard_proxy_name_owner_changed, dpy,
247 dbus_clipboard_unregister_proxy, dpy,
256 NULL);
248 NULL);
249 g_object_connect(connection,
250 "swapped-signal::closed",
251 dbus_clipboard_unregister_proxy, dpy,
252 NULL);
257 qemu_clipboard_reset_serial();
258
259 qemu_dbus_display1_clipboard_complete_register(dpy->clipboard, invocation);
260 return DBUS_METHOD_INVOCATION_HANDLED;
261}
262
263static gboolean
264dbus_clipboard_check_caller(DBusDisplay *dpy, GDBusMethodInvocation *invocation)

--- 194 unchanged lines hidden ---
253 qemu_clipboard_reset_serial();
254
255 qemu_dbus_display1_clipboard_complete_register(dpy->clipboard, invocation);
256 return DBUS_METHOD_INVOCATION_HANDLED;
257}
258
259static gboolean
260dbus_clipboard_check_caller(DBusDisplay *dpy, GDBusMethodInvocation *invocation)

--- 194 unchanged lines hidden ---