1 /*
2  *  Copyright (C) 2009-2014 Red Hat, Inc.
3  *
4  *  This library is free software; you can redistribute it and/or
5  *  modify it under the terms of the GNU Lesser General Public
6  *  License as published by the Free Software Foundation; either
7  *  version 2.1 of the License, or (at your option) any later version.
8  *
9  *  This library 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 GNU
12  *  Lesser General Public License for more details.
13  *
14  *  You should have received a copy of the GNU Lesser General Public
15  *  License along with this library; if not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef SPICE_CORE_H_
19 #define SPICE_CORE_H_
20 
21 #if !defined(SPICE_H_INSIDE) && !defined(SPICE_SERVER_INTERNAL)
22 #error "Only spice.h can be included directly."
23 #endif
24 
25 #include <stdint.h>
26 #ifndef _WIN32
27 #include <sys/socket.h>
28 #else
29 #include <winsock2.h>
30 #include <windows.h>
31 typedef int socklen_t;
32 #endif
33 #include <spice/qxl_dev.h>
34 #include <spice/vd_agent.h>
35 #include <spice/macros.h>
36 
37 #ifdef SPICE_SERVER_INTERNAL
38 #undef SPICE_GNUC_DEPRECATED
39 #define SPICE_GNUC_DEPRECATED
40 #endif
41 
42 /* interface base type */
43 
44 typedef struct SpiceBaseInterface SpiceBaseInterface;
45 typedef struct SpiceBaseInstance SpiceBaseInstance;
46 
47 struct SpiceBaseInterface {
48     const char *type;
49     const char *description;
50     uint32_t major_version;
51     uint32_t minor_version;
52 };
53 struct SpiceBaseInstance {
54     const SpiceBaseInterface *sif;
55 };
56 
57 /* core interface */
58 
59 #define SPICE_INTERFACE_CORE "core"
60 #define SPICE_INTERFACE_CORE_MAJOR 1
61 #define SPICE_INTERFACE_CORE_MINOR 3
62 typedef struct SpiceCoreInterface SpiceCoreInterface;
63 
64 #define SPICE_WATCH_EVENT_READ  (1 << 0)
65 #define SPICE_WATCH_EVENT_WRITE (1 << 1)
66 
67 #define SPICE_CHANNEL_EVENT_CONNECTED     1
68 #define SPICE_CHANNEL_EVENT_INITIALIZED   2
69 #define SPICE_CHANNEL_EVENT_DISCONNECTED  3
70 
71 #define SPICE_CHANNEL_EVENT_FLAG_TLS      (1 << 0)
72 #define SPICE_CHANNEL_EVENT_FLAG_ADDR_EXT (1 << 1)
73 
74 typedef struct SpiceWatch SpiceWatch;
75 typedef void (*SpiceWatchFunc)(int fd, int event, void *opaque);
76 
77 typedef struct SpiceTimer SpiceTimer;
78 typedef void (*SpiceTimerFunc)(void *opaque);
79 
80 typedef struct SpiceChannelEventInfo {
81     int connection_id;
82     int type;
83     int id;
84     int flags;
85     /* deprecated, can't hold ipv6 addresses, kept for backward compatibility */
86     struct sockaddr laddr SPICE_GNUC_DEPRECATED;
87     struct sockaddr paddr SPICE_GNUC_DEPRECATED;
88     socklen_t llen SPICE_GNUC_DEPRECATED;
89     socklen_t plen SPICE_GNUC_DEPRECATED;
90     /* should be used if (flags & SPICE_CHANNEL_EVENT_FLAG_ADDR_EXT) */
91     struct sockaddr_storage laddr_ext;
92     struct sockaddr_storage paddr_ext;
93     socklen_t llen_ext, plen_ext;
94 } SpiceChannelEventInfo;
95 
96 struct SpiceCoreInterface {
97     SpiceBaseInterface base;
98 
99     SpiceTimer *(*timer_add)(SpiceTimerFunc func, void *opaque);
100     void (*timer_start)(SpiceTimer *timer, uint32_t ms);
101     void (*timer_cancel)(SpiceTimer *timer);
102     void (*timer_remove)(SpiceTimer *timer);
103 
104     SpiceWatch *(*watch_add)(int fd, int event_mask, SpiceWatchFunc func, void *opaque);
105     void (*watch_update_mask)(SpiceWatch *watch, int event_mask);
106     void (*watch_remove)(SpiceWatch *watch);
107 
108     void (*channel_event)(int event, SpiceChannelEventInfo *info);
109 };
110 
111 #endif /* SPICE_CORE_H_ */
112