Add support for copy paste commands to vdagentd
[vd_agent/hramrach.git] / vdagent-virtio-port.h
blob1f07070e273a6d33dd1c630a14d9439241954682
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 <stdint.h>
26 #include <sys/select.h>
27 #include <spice/vd_agent.h>
29 struct vdagent_virtio_port;
31 /* Callbacks with this type will be called when a complete message has been
32 received. Sometimes the callback may want to close the port, in this
33 case do *not* call vdagent_virtio_port_destroy from the callback. The desire
34 to close the port can be indicated be returning -1 from the callback,
35 in other cases return 0. */
36 typedef int (*vdagent_virtio_port_read_callback)(
37 struct vdagent_virtio_port *port,
38 VDIChunkHeader *chunk_header,
39 VDAgentMessage *message_header,
40 uint8_t *data);
42 /* Callbacks with this type will be called when the port is disconnected.
43 Note:
44 1) vdagent_virtio_port will destroy the port in question itself after
45 this callback has completed!
46 2) This callback is always called, even if the disconnect is initiated
47 by the vdagent_virtio_port user through returning -1 from a read
48 callback, or by explictly calling vdagent_virtio_port_destroy */
49 typedef void (*vdagent_virtio_port_disconnect_callback)(
50 struct vdagent_virtio_port *conn);
53 /* Create a vdagent virtio port object for port portname */
54 struct vdagent_virtio_port *vdagent_virtio_port_create(const char *portname,
55 vdagent_virtio_port_read_callback read_callback,
56 vdagent_virtio_port_disconnect_callback disconnect_callback);
58 /* The contents of portp will be made NULL */
59 void vdagent_virtio_port_destroy(struct vdagent_virtio_port **portp);
62 /* Given a vdagent_virtio_port fill the fd_sets pointed to by readfds and
63 writefds for select() usage.
65 Return value: value of the highest fd + 1 */
66 int vdagent_virtio_port_fill_fds(struct vdagent_virtio_port *port,
67 fd_set *readfds, fd_set *writefds);
69 /* Handle any events flagged by select for the given vdagent_virtio_port.
70 Note the port may be destroyed (when disconnected) by this call
71 in this case the disconnect calllback will get called before the
72 destruction and the contents of connp will be made NULL */
73 void vdagent_virtio_port_handle_fds(struct vdagent_virtio_port **portp,
74 fd_set *readfds, fd_set *writefds);
77 /* Queue a message for delivery
79 Returns 0 on success -1 on error (only happens when malloc fails) */
80 int vdagent_virtio_port_write(
81 struct vdagent_virtio_port *port,
82 uint32_t port_nr,
83 uint32_t message_type,
84 uint32_t message_opaque,
85 uint8_t *data,
86 uint32_t data_size);
88 #endif