blob: 9c149e7b416d2d871927946949fc53935117bf76 [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
65#define TYPE_DBUS_DISPLAY "dbus-display"
66OBJECT_DECLARE_SIMPLE_TYPE(DBusDisplay, DBUS_DISPLAY)
67
Marc-André Lureau3e301c82021-07-22 19:43:29 +040068void dbus_display_notifier_add(Notifier *notifier);
69
Marc-André Lureau142ca622021-07-15 11:53:53 +040070#define DBUS_DISPLAY_TYPE_CONSOLE dbus_display_console_get_type()
71G_DECLARE_FINAL_TYPE(DBusDisplayConsole,
72 dbus_display_console,
73 DBUS_DISPLAY,
74 CONSOLE,
75 GDBusObjectSkeleton)
76
77DBusDisplayConsole *
78dbus_display_console_new(DBusDisplay *display, QemuConsole *con);
79
80int
81dbus_display_console_get_index(DBusDisplayConsole *ddc);
82
Marc-André Lureau417a2312022-02-16 22:52:14 +040083
84extern const DisplayChangeListenerOps dbus_console_dcl_ops;
85
Marc-André Lureau142ca622021-07-15 11:53:53 +040086#define DBUS_DISPLAY_TYPE_LISTENER dbus_display_listener_get_type()
87G_DECLARE_FINAL_TYPE(DBusDisplayListener,
88 dbus_display_listener,
89 DBUS_DISPLAY,
90 LISTENER,
91 GObject)
92
93DBusDisplayListener *
94dbus_display_listener_new(const char *bus_name,
95 GDBusConnection *conn,
96 DBusDisplayConsole *console);
97
98DBusDisplayConsole *
99dbus_display_listener_get_console(DBusDisplayListener *ddl);
100
101const char *
102dbus_display_listener_get_bus_name(DBusDisplayListener *ddl);
103
104extern const DisplayChangeListenerOps dbus_gl_dcl_ops;
105extern const DisplayChangeListenerOps dbus_dcl_ops;
106
Marc-André Lureau3e301c82021-07-22 19:43:29 +0400107#define TYPE_CHARDEV_DBUS "chardev-dbus"
108
109typedef struct DBusChardevClass {
110 SocketChardevClass parent_class;
111
112 void (*parent_chr_be_event)(Chardev *s, QEMUChrEvent event);
113} DBusChardevClass;
114
115DECLARE_CLASS_CHECKERS(DBusChardevClass, DBUS_CHARDEV,
116 TYPE_CHARDEV_DBUS)
117
118typedef struct DBusChardev {
119 SocketChardev parent;
120
121 bool exported;
122 QemuDBusDisplay1Chardev *iface;
123} DBusChardev;
124
125DECLARE_INSTANCE_CHECKER(DBusChardev, DBUS_CHARDEV, TYPE_CHARDEV_DBUS)
126
127#define CHARDEV_IS_DBUS(chr) \
128 object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_DBUS)
129
130typedef enum {
131 DBUS_DISPLAY_CHARDEV_OPEN,
132 DBUS_DISPLAY_CHARDEV_CLOSE,
133} DBusDisplayEventType;
134
135typedef struct DBusDisplayEvent {
136 DBusDisplayEventType type;
137 union {
138 DBusChardev *chardev;
139 };
140} DBusDisplayEvent;
141
142void dbus_display_notify(DBusDisplayEvent *event);
143
144void dbus_chardev_init(DBusDisplay *dpy);
145
Marc-André Lureauff1a5812021-07-20 16:02:52 +0400146void dbus_clipboard_init(DBusDisplay *dpy);
147
Markus Armbruster9c092802022-05-06 15:49:09 +0200148#endif /* UI_DBUS_H */