master
h 159 lines 4.62 KB
Raw
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
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 */
24
25 #ifndef UI_DBUS_H
26 #define UI_DBUS_H
27
28 #include "chardev/char-socket.h"
29 #include "qemu/dbus.h"
30 #include "qom/object.h"
31 #include "ui/console.h"
32 #include "ui/clipboard.h"
33
34 #include "ui/dbus-display1.h"
35
36 typedef struct DBusClipboardRequest {
37 GDBusMethodInvocation *invocation;
38 QemuClipboardType type;
39 guint timeout_id;
40 } DBusClipboardRequest;
41
42 struct DBusDisplay {
43 Object parent;
44
45 DisplayGLMode gl_mode;
46 bool p2p;
47 char *dbus_addr;
48 char *audiodev;
49 DisplayGLCtx glctx;
50
51 GDBusConnection *bus;
52 GDBusObjectManagerServer *server;
53 QemuDBusDisplay1VM *iface;
54 GPtrArray *consoles;
55 GCancellable *add_client_cancellable;
56
57 QemuClipboardPeer clipboard_peer;
58 QemuDBusDisplay1Clipboard *clipboard;
59 QemuDBusDisplay1Clipboard *clipboard_proxy;
60 DBusClipboardRequest clipboard_request[QEMU_CLIPBOARD_SELECTION__COUNT];
61
62 Notifier notifier;
63 Notifier console_notifier;
64 };
65
66 #ifdef WIN32
67 bool
68 dbus_win32_import_socket(GDBusMethodInvocation *invocation,
69 GVariant *arg_listener, int *socket);
70 #endif
71
72 #define TYPE_DBUS_DISPLAY "dbus-display"
73 OBJECT_DECLARE_SIMPLE_TYPE(DBusDisplay, DBUS_DISPLAY)
74
75 void dbus_display_notifier_add(Notifier *notifier);
76
77 #define DBUS_DISPLAY_TYPE_CONSOLE dbus_display_console_get_type()
78 G_DECLARE_FINAL_TYPE(DBusDisplayConsole,
79 dbus_display_console,
80 DBUS_DISPLAY,
81 CONSOLE,
82 GDBusObjectSkeleton)
83
84 DBusDisplayConsole *
85 dbus_display_console_new(DBusDisplay *display, QemuConsole *con);
86
87 int
88 dbus_display_console_get_index(DBusDisplayConsole *ddc);
89
90 QemuConsole *
91 dbus_display_console_get_qemu_console(DBusDisplayConsole *ddc);
92
93 extern const DisplayChangeListenerOps dbus_console_dcl_ops;
94
95 #define DBUS_DISPLAY_TYPE_LISTENER dbus_display_listener_get_type()
96 G_DECLARE_FINAL_TYPE(DBusDisplayListener,
97 dbus_display_listener,
98 DBUS_DISPLAY,
99 LISTENER,
100 GObject)
101
102 DBusDisplayListener *
103 dbus_display_listener_new(const char *bus_name,
104 GDBusConnection *conn,
105 DBusDisplayConsole *console);
106
107 DBusDisplayConsole *
108 dbus_display_listener_get_console(DBusDisplayListener *ddl);
109
110 const char *
111 dbus_display_listener_get_bus_name(DBusDisplayListener *ddl);
112
113 extern const DisplayChangeListenerOps dbus_gl_dcl_ops;
114 extern const DisplayChangeListenerOps dbus_dcl_ops;
115
116 #define TYPE_CHARDEV_DBUS "chardev-dbus"
117
118 typedef struct DBusChardevClass {
119 SocketChardevClass parent_class;
120
121 void (*parent_chr_be_event)(Chardev *s, QEMUChrEvent event);
122 } DBusChardevClass;
123
124 DECLARE_CLASS_CHECKERS(DBusChardevClass, DBUS_CHARDEV,
125 TYPE_CHARDEV_DBUS)
126
127 typedef struct DBusChardev {
128 SocketChardev parent;
129
130 bool exported;
131 QemuDBusDisplay1Chardev *iface;
132 QemuDBusDisplay1ChardevVCEncoding *iface_vc_encoding;
133 } DBusChardev;
134
135 DECLARE_INSTANCE_CHECKER(DBusChardev, DBUS_CHARDEV, TYPE_CHARDEV_DBUS)
136
137 #define CHARDEV_IS_DBUS(chr) \
138 object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_DBUS)
139
140 typedef enum {
141 DBUS_DISPLAY_CHARDEV_OPEN,
142 DBUS_DISPLAY_CHARDEV_CLOSE,
143 } DBusDisplayEventType;
144
145 typedef struct DBusDisplayEvent {
146 DBusDisplayEventType type;
147 union {
148 DBusChardev *chardev;
149 };
150 } DBusDisplayEvent;
151
152 void dbus_display_notify(DBusDisplayEvent *event);
153
154 void dbus_chardev_init(DBusDisplay *dpy);
155
156 void dbus_clipboard_init(DBusDisplay *dpy);
157 void dbus_clipboard_fini(DBusDisplay *dpy);
158
159 #endif /* UI_DBUS_H */