xref: /openbmc/qemu/include/ui/qemu-spice.h (revision 406d2aa2)
1 /*
2  * Copyright (C) 2010 Red Hat, Inc.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 or
7  * (at your option) version 3 of the License.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef QEMU_SPICE_H
19 #define QEMU_SPICE_H
20 
21 #include "qapi/error.h"
22 
23 #ifdef CONFIG_SPICE
24 
25 #include <spice.h>
26 #include "qemu/option.h"
27 #include "qemu/config-file.h"
28 
29 extern int using_spice;
30 
31 void qemu_spice_init(void);
32 void qemu_spice_input_init(void);
33 void qemu_spice_audio_init(void);
34 void qemu_spice_display_init(void);
35 int qemu_spice_display_add_client(int csock, int skipauth, int tls);
36 int qemu_spice_add_interface(SpiceBaseInstance *sin);
37 bool qemu_spice_have_display_interface(QemuConsole *con);
38 int qemu_spice_add_display_interface(QXLInstance *qxlin, QemuConsole *con);
39 int qemu_spice_set_passwd(const char *passwd,
40                           bool fail_if_connected, bool disconnect_if_connected);
41 int qemu_spice_set_pw_expire(time_t expires);
42 int qemu_spice_migrate_info(const char *hostname, int port, int tls_port,
43                             const char *subject);
44 
45 #if !defined(SPICE_SERVER_VERSION) || (SPICE_SERVER_VERSION < 0xc06)
46 #define SPICE_NEEDS_SET_MM_TIME 1
47 #else
48 #define SPICE_NEEDS_SET_MM_TIME 0
49 #endif
50 
51 #if SPICE_SERVER_VERSION >= 0x000c02
52 void qemu_spice_register_ports(void);
53 #else
54 static inline Chardev *qemu_chr_open_spice_port(const char *name)
55 { return NULL; }
56 #endif
57 
58 #else  /* CONFIG_SPICE */
59 
60 #include "qemu/error-report.h"
61 
62 #define using_spice 0
63 #define spice_displays 0
64 static inline int qemu_spice_set_passwd(const char *passwd,
65                                         bool fail_if_connected,
66                                         bool disconnect_if_connected)
67 {
68     return -1;
69 }
70 static inline int qemu_spice_set_pw_expire(time_t expires)
71 {
72     return -1;
73 }
74 static inline int qemu_spice_migrate_info(const char *h, int p, int t,
75                                           const char *s)
76 {
77     return -1;
78 }
79 
80 static inline int qemu_spice_display_add_client(int csock, int skipauth,
81                                                 int tls)
82 {
83     return -1;
84 }
85 
86 static inline void qemu_spice_display_init(void)
87 {
88     /* This must never be called if CONFIG_SPICE is disabled */
89     error_report("spice support is disabled");
90     abort();
91 }
92 
93 static inline void qemu_spice_init(void)
94 {
95 }
96 
97 #endif /* CONFIG_SPICE */
98 
99 static inline bool qemu_using_spice(Error **errp)
100 {
101     if (!using_spice) {
102         error_set(errp, ERROR_CLASS_DEVICE_NOT_ACTIVE,
103                   "SPICE is not in use");
104         return false;
105     }
106     return true;
107 }
108 
109 #endif /* QEMU_SPICE_H */
110