build-sys: move user/system to respective dir
[vd_agent.git] / src / vdagentd / vdagent-virtio-port.h
blobac766bdb6c9337c07042b4bf8f3d98aa0c6e0c89
1 /* vdagent-virtio-port.h virtio port communication header
3 Copyright 2010 Red Hat, Inc.
5 Red Hat Authors:
6 Hans de Goede <hdegoede@redhat.com>
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef __VIRTIO_PORT_H
23 #define __VIRTIO_PORT_H
25 #include <stdio.h>
26 #include <stdint.h>
27 #include <sys/select.h>
28 #include <spice/vd_agent.h>
30 struct vdagent_virtio_port;
32 /* Callbacks with this type will be called when a complete message has been
33 received. Sometimes the callback may want to close the port, in this
34 case do *not* call vdagent_virtio_port_destroy from the callback. The desire
35 to close the port can be indicated be returning -1 from the callback,
36 in other cases return 0. */
37 typedef int (*vdagent_virtio_port_read_callback)(
38 struct vdagent_virtio_port *vport,
39 int port_nr,
40 VDAgentMessage *message_header,
41 uint8_t *data);
43 /* Callbacks with this type will be called when the port is disconnected.
44 Note:
45 1) vdagent_virtio_port will destroy the port in question itself after
46 this callback has completed!
47 2) This callback is always called, even if the disconnect is initiated
48 by the vdagent_virtio_port user through returning -1 from a read
49 callback, or by explictly calling vdagent_virtio_port_destroy */
50 typedef void (*vdagent_virtio_port_disconnect_callback)(
51 struct vdagent_virtio_port *conn);
54 /* Create a vdagent virtio port object for port portname */
55 struct vdagent_virtio_port *vdagent_virtio_port_create(const char *portname,
56 vdagent_virtio_port_read_callback read_callback,
57 vdagent_virtio_port_disconnect_callback disconnect_callback);
59 /* The contents of portp will be made NULL */
60 void vdagent_virtio_port_destroy(struct vdagent_virtio_port **vportp);
63 /* Given a vdagent_virtio_port fill the fd_sets pointed to by readfds and
64 writefds for select() usage.
66 Return value: value of the highest fd + 1 */
67 int vdagent_virtio_port_fill_fds(struct vdagent_virtio_port *vport,
68 fd_set *readfds, fd_set *writefds);
70 /* Handle any events flagged by select for the given vdagent_virtio_port.
71 Note the port may be destroyed (when disconnected) by this call
72 in this case the disconnect calllback will get called before the
73 destruction and the contents of connp will be made NULL */
74 void vdagent_virtio_port_handle_fds(struct vdagent_virtio_port **vportp,
75 fd_set *readfds, fd_set *writefds);
78 /* Queue a message for delivery, either bit by bit, or all at once
80 Returns 0 on success -1 on error (only happens when malloc fails) */
81 int vdagent_virtio_port_write_start(
82 struct vdagent_virtio_port *vport,
83 uint32_t port_nr,
84 uint32_t message_type,
85 uint32_t message_opaque,
86 uint32_t data_size);
88 int vdagent_virtio_port_write_append(
89 struct vdagent_virtio_port *vport,
90 const uint8_t *data,
91 uint32_t size);
93 int vdagent_virtio_port_write(
94 struct vdagent_virtio_port *vport,
95 uint32_t port_nr,
96 uint32_t message_type,
97 uint32_t message_opaque,
98 const uint8_t *data,
99 uint32_t data_size);
101 void vdagent_virtio_port_flush(struct vdagent_virtio_port **vportp);
102 void vdagent_virtio_port_reset(struct vdagent_virtio_port *vport, int port);
104 #endif