blob: 1e8c24a48e32079510fb551268a78e8f76ecb7a0 [file] [log] [blame]
Marc-André Lureau142ca622021-07-15 11:53:53 +04001/*
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
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
Markus Armbruster9c092802022-05-06 15:49:09 +020024
25#ifndef UI_DBUS_H
26#define UI_DBUS_H
Marc-André Lureau142ca622021-07-15 11:53:53 +040027
Marc-André Lureau3e301c82021-07-22 19:43:29 +040028#include "chardev/char-socket.h"
Marc-André Lureau142ca622021-07-15 11:53:53 +040029#include "qemu/dbus.h"
30#include "qom/object.h"
31#include "ui/console.h"
Marc-André Lureauff1a5812021-07-20 16:02:52 +040032#include "ui/clipboard.h"
Marc-André Lureau142ca622021-07-15 11:53:53 +040033
Paolo Bonzini0e902f52022-07-27 12:19:03 +020034#include "ui/dbus-display1.h"
Marc-André Lureau142ca622021-07-15 11:53:53 +040035
Marc-André Lureauff1a5812021-07-20 16:02:52 +040036typedef struct DBusClipboardRequest {
37 GDBusMethodInvocation *invocation;
38 QemuClipboardType type;
39 guint timeout_id;
40} DBusClipboardRequest;
41
Marc-André Lureau142ca622021-07-15 11:53:53 +040042struct DBusDisplay {
43 Object parent;
44
45 DisplayGLMode gl_mode;
Marc-André Lureau99997822021-10-10 00:16:57 +040046 bool p2p;
Marc-André Lureau142ca622021-07-15 11:53:53 +040047 char *dbus_addr;
Marc-André Lureau739362d2021-03-09 17:15:28 +040048 char *audiodev;
Marc-André Lureau142ca622021-07-15 11:53:53 +040049 DisplayGLCtx glctx;
50
51 GDBusConnection *bus;
52 GDBusObjectManagerServer *server;
53 QemuDBusDisplay1VM *iface;
54 GPtrArray *consoles;
Marc-André Lureau99997822021-10-10 00:16:57 +040055 GCancellable *add_client_cancellable;
Marc-André Lureauff1a5812021-07-20 16:02:52 +040056
57 QemuClipboardPeer clipboard_peer;
58 QemuDBusDisplay1Clipboard *clipboard;
59 QemuDBusDisplay1Clipboard *clipboard_proxy;
60 DBusClipboardRequest clipboard_request[QEMU_CLIPBOARD_SELECTION__COUNT];
Marc-André Lureau3e301c82021-07-22 19:43:29 +040061
62 Notifier notifier;
Marc-André Lureau142ca622021-07-15 11:53:53 +040063};
64
Marc-André Lureau6cc5a612023-06-06 15:56:42 +040065#ifdef WIN32
66bool
67dbus_win32_import_socket(GDBusMethodInvocation *invocation,
68 GVariant *arg_listener, int *socket);
69#endif
70
Marc-André Lureau142ca622021-07-15 11:53:53 +040071#define TYPE_DBUS_DISPLAY "dbus-display"
72OBJECT_DECLARE_SIMPLE_TYPE(DBusDisplay, DBUS_DISPLAY)
73
Marc-André Lureau3e301c82021-07-22 19:43:29 +040074void dbus_display_notifier_add(Notifier *notifier);
75
Marc-André Lureau142ca622021-07-15 11:53:53 +040076#define DBUS_DISPLAY_TYPE_CONSOLE dbus_display_console_get_type()
77G_DECLARE_FINAL_TYPE(DBusDisplayConsole,
78 dbus_display_console,
79 DBUS_DISPLAY,
80 CONSOLE,
81 GDBusObjectSkeleton)
82
83DBusDisplayConsole *
84dbus_display_console_new(DBusDisplay *display, QemuConsole *con);
85
86int
87dbus_display_console_get_index(DBusDisplayConsole *ddc);
88
Marc-André Lureau417a2312022-02-16 22:52:14 +040089
90extern const DisplayChangeListenerOps dbus_console_dcl_ops;
91
Marc-André Lureau142ca622021-07-15 11:53:53 +040092#define DBUS_DISPLAY_TYPE_LISTENER dbus_display_listener_get_type()
93G_DECLARE_FINAL_TYPE(DBusDisplayListener,
94 dbus_display_listener,
95 DBUS_DISPLAY,
96 LISTENER,
97 GObject)
98
99DBusDisplayListener *
100dbus_display_listener_new(const char *bus_name,
101 GDBusConnection *conn,
102 DBusDisplayConsole *console);
103
104DBusDisplayConsole *
105dbus_display_listener_get_console(DBusDisplayListener *ddl);
106
107const char *
108dbus_display_listener_get_bus_name(DBusDisplayListener *ddl);
109
110extern const DisplayChangeListenerOps dbus_gl_dcl_ops;
111extern const DisplayChangeListenerOps dbus_dcl_ops;
112
Marc-André Lureau3e301c82021-07-22 19:43:29 +0400113#define TYPE_CHARDEV_DBUS "chardev-dbus"
114
115typedef struct DBusChardevClass {
116 SocketChardevClass parent_class;
117
118 void (*parent_chr_be_event)(Chardev *s, QEMUChrEvent event);
119} DBusChardevClass;
120
121DECLARE_CLASS_CHECKERS(DBusChardevClass, DBUS_CHARDEV,
122 TYPE_CHARDEV_DBUS)
123
124typedef struct DBusChardev {
125 SocketChardev parent;
126
127 bool exported;
128 QemuDBusDisplay1Chardev *iface;
129} DBusChardev;
130
131DECLARE_INSTANCE_CHECKER(DBusChardev, DBUS_CHARDEV, TYPE_CHARDEV_DBUS)
132
133#define CHARDEV_IS_DBUS(chr) \
134 object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_DBUS)
135
136typedef enum {
137 DBUS_DISPLAY_CHARDEV_OPEN,
138 DBUS_DISPLAY_CHARDEV_CLOSE,
139} DBusDisplayEventType;
140
141typedef struct DBusDisplayEvent {
142 DBusDisplayEventType type;
143 union {
144 DBusChardev *chardev;
145 };
146} DBusDisplayEvent;
147
148void dbus_display_notify(DBusDisplayEvent *event);
149
150void dbus_chardev_init(DBusDisplay *dpy);
151
Marc-André Lureauff1a5812021-07-20 16:02:52 +0400152void dbus_clipboard_init(DBusDisplay *dpy);
153
Markus Armbruster9c092802022-05-06 15:49:09 +0200154#endif /* UI_DBUS_H */