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