Lines Matching refs:vd

139 static void vdagent_send_buf(VDAgentChardev *vd)  in vdagent_send_buf()  argument
143 while (vd->outbuf->len) { in vdagent_send_buf()
144 len = qemu_chr_be_can_write(CHARDEV(vd)); in vdagent_send_buf()
148 if (len > vd->outbuf->len) { in vdagent_send_buf()
149 len = vd->outbuf->len; in vdagent_send_buf()
151 qemu_chr_be_write(CHARDEV(vd), vd->outbuf->data, len); in vdagent_send_buf()
152 g_byte_array_remove_range(vd->outbuf, 0, len); in vdagent_send_buf()
156 static void vdagent_send_msg(VDAgentChardev *vd, VDAgentMessage *msg) in vdagent_send_msg() argument
167 if (vd->outbuf->len + msgsize > VDAGENT_BUFFER_LIMIT) { in vdagent_send_msg()
178 g_byte_array_append(vd->outbuf, (void *)&chunk, sizeof(chunk)); in vdagent_send_msg()
179 g_byte_array_append(vd->outbuf, msgbuf + msgoff, chunk.size); in vdagent_send_msg()
182 vdagent_send_buf(vd); in vdagent_send_msg()
185 static void vdagent_send_caps(VDAgentChardev *vd, bool request) in vdagent_send_caps() argument
194 if (vd->mouse) { in vdagent_send_caps()
197 if (vd->clipboard) { in vdagent_send_caps()
206 vdagent_send_msg(vd, msg); in vdagent_send_caps()
212 static bool have_mouse(VDAgentChardev *vd) in have_mouse() argument
214 return vd->mouse && in have_mouse()
215 (vd->caps & (1 << VD_AGENT_CAP_MOUSE_STATE)); in have_mouse()
218 static void vdagent_send_mouse(VDAgentChardev *vd) in vdagent_send_mouse() argument
227 mouse->x = vd->mouse_x; in vdagent_send_mouse()
228 mouse->y = vd->mouse_y; in vdagent_send_mouse()
229 mouse->buttons = vd->mouse_btn; in vdagent_send_mouse()
230 mouse->display_id = vd->mouse_display; in vdagent_send_mouse()
232 vdagent_send_msg(vd, msg); in vdagent_send_mouse()
250 VDAgentChardev *vd = container_of(dev, struct VDAgentChardev, mouse_dev); in vdagent_pointer_event() local
261 vd->mouse_x = qemu_input_scale_axis(move->value, in vdagent_pointer_event()
266 vd->mouse_y = qemu_input_scale_axis(move->value, in vdagent_pointer_event()
271 vd->mouse_display = qemu_console_get_index(src); in vdagent_pointer_event()
277 vd->mouse_btn |= bmap[btn->button]; in vdagent_pointer_event()
279 vd->mouse_btn &= ~bmap[btn->button]; in vdagent_pointer_event()
291 VDAgentChardev *vd = container_of(dev, struct VDAgentChardev, mouse_dev); in vdagent_pointer_sync() local
293 if (vd->caps & (1 << VD_AGENT_CAP_MOUSE_STATE)) { in vdagent_pointer_sync()
294 vdagent_send_mouse(vd); in vdagent_pointer_sync()
308 static bool have_clipboard(VDAgentChardev *vd) in have_clipboard() argument
310 return vd->clipboard && in have_clipboard()
311 (vd->caps & (1 << VD_AGENT_CAP_CLIPBOARD_BY_DEMAND)); in have_clipboard()
314 static bool have_selection(VDAgentChardev *vd) in have_selection() argument
316 return vd->caps & (1 << VD_AGENT_CAP_CLIPBOARD_SELECTION); in have_selection()
329 static void vdagent_send_clipboard_grab(VDAgentChardev *vd, in vdagent_send_clipboard_grab() argument
340 if (have_selection(vd)) { in vdagent_send_clipboard_grab()
349 if (vd->caps & (1 << VD_AGENT_CAP_CLIPBOARD_GRAB_SERIAL)) { in vdagent_send_clipboard_grab()
352 info->serial = vd->last_serial[info->selection]++; in vdagent_send_clipboard_grab()
371 vdagent_send_msg(vd, msg); in vdagent_send_clipboard_grab()
374 static void vdagent_send_clipboard_release(VDAgentChardev *vd, in vdagent_send_clipboard_release() argument
380 if (have_selection(vd)) { in vdagent_send_clipboard_release()
389 vdagent_send_msg(vd, msg); in vdagent_send_clipboard_release()
392 static void vdagent_send_clipboard_data(VDAgentChardev *vd, in vdagent_send_clipboard_data() argument
403 if (have_selection(vd)) { in vdagent_send_clipboard_data()
419 vdagent_send_msg(vd, msg); in vdagent_send_clipboard_data()
422 static void vdagent_send_empty_clipboard_data(VDAgentChardev *vd, in vdagent_send_empty_clipboard_data() argument
426 g_autoptr(QemuClipboardInfo) info = qemu_clipboard_info_new(&vd->cbpeer, selection); in vdagent_send_empty_clipboard_data()
429 vdagent_send_clipboard_data(vd, info, type); in vdagent_send_empty_clipboard_data()
432 static void vdagent_clipboard_update_info(VDAgentChardev *vd, in vdagent_clipboard_update_info() argument
437 bool self_update = info->owner == &vd->cbpeer; in vdagent_clipboard_update_info()
440 vd->cbpending[s] = 0; in vdagent_clipboard_update_info()
443 vdagent_send_clipboard_grab(vd, info); in vdagent_clipboard_update_info()
445 vdagent_send_clipboard_release(vd, info); in vdagent_clipboard_update_info()
456 if (vd->cbpending[s] & (1 << type)) { in vdagent_clipboard_update_info()
457 vd->cbpending[s] &= ~(1 << type); in vdagent_clipboard_update_info()
458 vdagent_send_clipboard_data(vd, info, type); in vdagent_clipboard_update_info()
463 static void vdagent_clipboard_reset_serial(VDAgentChardev *vd) in vdagent_clipboard_reset_serial() argument
465 Chardev *chr = CHARDEV(vd); in vdagent_clipboard_reset_serial()
474 VDAgentChardev *vd = in vdagent_clipboard_notify() local
480 vdagent_clipboard_update_info(vd, notify->info); in vdagent_clipboard_notify()
483 vdagent_clipboard_reset_serial(vd); in vdagent_clipboard_notify()
491 VDAgentChardev *vd = container_of(info->owner, VDAgentChardev, cbpeer); in vdagent_clipboard_request() local
502 if (have_selection(vd)) { in vdagent_clipboard_request()
512 vdagent_send_msg(vd, msg); in vdagent_clipboard_request()
515 static void vdagent_clipboard_recv_grab(VDAgentChardev *vd, uint8_t s, uint32_t size, void *data) in vdagent_clipboard_recv_grab() argument
520 info = qemu_clipboard_info_new(&vd->cbpeer, s); in vdagent_clipboard_recv_grab()
522 if (vd->caps & (1 << VD_AGENT_CAP_CLIPBOARD_GRAB_SERIAL)) { in vdagent_clipboard_recv_grab()
530 if (info->serial < vd->last_serial[s]) { in vdagent_clipboard_recv_grab()
532 vd->last_serial[s], info->serial); in vdagent_clipboard_recv_grab()
536 vd->last_serial[s] = info->serial; in vdagent_clipboard_recv_grab()
563 static void vdagent_clipboard_recv_request(VDAgentChardev *vd, uint8_t s, uint32_t size, void *data) in vdagent_clipboard_recv_request() argument
580 if (info && info->types[type].available && info->owner != &vd->cbpeer) { in vdagent_clipboard_recv_request()
582 vdagent_send_clipboard_data(vd, info, type); in vdagent_clipboard_recv_request()
584 vd->cbpending[s] |= (1 << type); in vdagent_clipboard_recv_request()
588 vdagent_send_empty_clipboard_data(vd, s, type); in vdagent_clipboard_recv_request()
592 static void vdagent_clipboard_recv_data(VDAgentChardev *vd, uint8_t s, uint32_t size, void *data) in vdagent_clipboard_recv_data() argument
609 if (qemu_clipboard_peer_owns(&vd->cbpeer, s)) { in vdagent_clipboard_recv_data()
610 qemu_clipboard_set_data(&vd->cbpeer, qemu_clipboard_info(s), in vdagent_clipboard_recv_data()
615 static void vdagent_clipboard_recv_release(VDAgentChardev *vd, uint8_t s) in vdagent_clipboard_recv_release() argument
617 qemu_clipboard_peer_release(&vd->cbpeer, s); in vdagent_clipboard_recv_release()
620 static void vdagent_chr_recv_clipboard(VDAgentChardev *vd, VDAgentMessage *msg) in vdagent_chr_recv_clipboard() argument
626 if (have_selection(vd)) { in vdagent_chr_recv_clipboard()
640 return vdagent_clipboard_recv_grab(vd, s, size, data); in vdagent_chr_recv_clipboard()
642 return vdagent_clipboard_recv_request(vd, s, size, data); in vdagent_chr_recv_clipboard()
644 return vdagent_clipboard_recv_data(vd, s, size, data); in vdagent_chr_recv_clipboard()
646 return vdagent_clipboard_recv_release(vd, s); in vdagent_chr_recv_clipboard()
660 VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(chr); in vdagent_chr_open() local
672 vd->mouse = VDAGENT_MOUSE_DEFAULT; in vdagent_chr_open()
674 vd->mouse = cfg->mouse; in vdagent_chr_open()
677 vd->clipboard = VDAGENT_CLIPBOARD_DEFAULT; in vdagent_chr_open()
679 vd->clipboard = cfg->clipboard; in vdagent_chr_open()
682 if (vd->mouse) { in vdagent_chr_open()
683 vd->mouse_hs = qemu_input_handler_register(&vd->mouse_dev, in vdagent_chr_open()
690 static void vdagent_clipboard_peer_register(VDAgentChardev *vd) in vdagent_clipboard_peer_register() argument
692 if (vd->cbpeer.notifier.notify != NULL) { in vdagent_clipboard_peer_register()
696 vd->cbpeer.name = "vdagent"; in vdagent_clipboard_peer_register()
697 vd->cbpeer.notifier.notify = vdagent_clipboard_notify; in vdagent_clipboard_peer_register()
698 vd->cbpeer.request = vdagent_clipboard_request; in vdagent_clipboard_peer_register()
699 qemu_clipboard_peer_register(&vd->cbpeer); in vdagent_clipboard_peer_register()
702 static void vdagent_chr_recv_caps(VDAgentChardev *vd, VDAgentMessage *msg) in vdagent_chr_recv_caps() argument
718 vd->caps = caps->caps[0]; in vdagent_chr_recv_caps()
720 vdagent_send_caps(vd, false); in vdagent_chr_recv_caps()
722 if (have_mouse(vd) && vd->mouse_hs) { in vdagent_chr_recv_caps()
723 qemu_input_handler_activate(vd->mouse_hs); in vdagent_chr_recv_caps()
726 memset(vd->last_serial, 0, sizeof(vd->last_serial)); in vdagent_chr_recv_caps()
728 if (have_clipboard(vd)) { in vdagent_chr_recv_caps()
730 vdagent_clipboard_peer_register(vd); in vdagent_chr_recv_caps()
734 static void vdagent_chr_recv_msg(VDAgentChardev *vd, VDAgentMessage *msg) in vdagent_chr_recv_msg() argument
740 vdagent_chr_recv_caps(vd, msg); in vdagent_chr_recv_msg()
746 if (have_clipboard(vd)) { in vdagent_chr_recv_msg()
747 vdagent_chr_recv_clipboard(vd, msg); in vdagent_chr_recv_msg()
755 static void vdagent_reset_xbuf(VDAgentChardev *vd) in vdagent_reset_xbuf() argument
757 g_clear_pointer(&vd->xbuf, g_free); in vdagent_reset_xbuf()
758 vd->xoff = 0; in vdagent_reset_xbuf()
759 vd->xsize = 0; in vdagent_reset_xbuf()
762 static void vdagent_chr_recv_chunk(VDAgentChardev *vd) in vdagent_chr_recv_chunk() argument
764 VDAgentMessage *msg = (void *)vd->msgbuf; in vdagent_chr_recv_chunk()
766 if (!vd->xsize) { in vdagent_chr_recv_chunk()
767 if (vd->msgsize < sizeof(*msg)) { in vdagent_chr_recv_chunk()
769 vd->msgsize, sizeof(*msg)); in vdagent_chr_recv_chunk()
772 if (vd->msgsize == msg->size + sizeof(*msg)) { in vdagent_chr_recv_chunk()
773 vdagent_chr_recv_msg(vd, msg); in vdagent_chr_recv_chunk()
778 if (!vd->xsize) { in vdagent_chr_recv_chunk()
779 vd->xsize = msg->size + sizeof(*msg); in vdagent_chr_recv_chunk()
780 vd->xbuf = g_malloc0(vd->xsize); in vdagent_chr_recv_chunk()
783 if (vd->xoff + vd->msgsize > vd->xsize) { in vdagent_chr_recv_chunk()
785 vd->xoff, vd->msgsize, vd->xsize); in vdagent_chr_recv_chunk()
786 vdagent_reset_xbuf(vd); in vdagent_chr_recv_chunk()
790 memcpy(vd->xbuf + vd->xoff, vd->msgbuf, vd->msgsize); in vdagent_chr_recv_chunk()
791 vd->xoff += vd->msgsize; in vdagent_chr_recv_chunk()
792 if (vd->xoff < vd->xsize) { in vdagent_chr_recv_chunk()
796 msg = (void *)vd->xbuf; in vdagent_chr_recv_chunk()
797 vdagent_chr_recv_msg(vd, msg); in vdagent_chr_recv_chunk()
798 vdagent_reset_xbuf(vd); in vdagent_chr_recv_chunk()
801 static void vdagent_reset_bufs(VDAgentChardev *vd) in vdagent_reset_bufs() argument
803 memset(&vd->chunk, 0, sizeof(vd->chunk)); in vdagent_reset_bufs()
804 vd->chunksize = 0; in vdagent_reset_bufs()
805 g_free(vd->msgbuf); in vdagent_reset_bufs()
806 vd->msgbuf = NULL; in vdagent_reset_bufs()
807 vd->msgsize = 0; in vdagent_reset_bufs()
812 VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(chr); in vdagent_chr_write() local
816 if (vd->chunksize < sizeof(vd->chunk)) { in vdagent_chr_write()
817 copy = sizeof(vd->chunk) - vd->chunksize; in vdagent_chr_write()
821 memcpy((void *)(&vd->chunk) + vd->chunksize, buf, copy); in vdagent_chr_write()
822 vd->chunksize += copy; in vdagent_chr_write()
825 if (vd->chunksize < sizeof(vd->chunk)) { in vdagent_chr_write()
829 assert(vd->msgbuf == NULL); in vdagent_chr_write()
830 vd->msgbuf = g_malloc0(vd->chunk.size); in vdagent_chr_write()
833 copy = vd->chunk.size - vd->msgsize; in vdagent_chr_write()
837 memcpy(vd->msgbuf + vd->msgsize, buf, copy); in vdagent_chr_write()
838 vd->msgsize += copy; in vdagent_chr_write()
842 if (vd->msgsize == vd->chunk.size) { in vdagent_chr_write()
843 trace_vdagent_recv_chunk(vd->chunk.size); in vdagent_chr_write()
844 vdagent_chr_recv_chunk(vd); in vdagent_chr_write()
845 vdagent_reset_bufs(vd); in vdagent_chr_write()
854 VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(chr); in vdagent_chr_accept_input() local
856 vdagent_send_buf(vd); in vdagent_chr_accept_input()
859 static void vdagent_disconnect(VDAgentChardev *vd) in vdagent_disconnect() argument
863 vd->connected = false; in vdagent_disconnect()
864 g_byte_array_set_size(vd->outbuf, 0); in vdagent_disconnect()
865 vdagent_reset_bufs(vd); in vdagent_disconnect()
866 vd->caps = 0; in vdagent_disconnect()
867 if (vd->mouse_hs) { in vdagent_disconnect()
868 qemu_input_handler_deactivate(vd->mouse_hs); in vdagent_disconnect()
870 if (vd->cbpeer.notifier.notify) { in vdagent_disconnect()
871 qemu_clipboard_peer_unregister(&vd->cbpeer); in vdagent_disconnect()
872 memset(&vd->cbpeer, 0, sizeof(vd->cbpeer)); in vdagent_disconnect()
878 VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(chr); in vdagent_chr_set_fe_open() local
882 if (vd->connected == fe_open) { in vdagent_chr_set_fe_open()
888 vdagent_disconnect(vd); in vdagent_chr_set_fe_open()
895 vd->connected = true; in vdagent_chr_set_fe_open()
896 vdagent_send_caps(vd, true); in vdagent_chr_set_fe_open()
928 VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(opaque); in post_load() local
930 if (have_mouse(vd) && vd->mouse_hs) { in post_load()
931 qemu_input_handler_activate(vd->mouse_hs); in post_load()
934 if (have_clipboard(vd)) { in post_load()
935 vdagent_clipboard_peer_register(vd); in post_load()
981 VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(pv); in put_cbinfo() local
985 if (!have_clipboard(vd)) { in put_cbinfo()
990 if (qemu_clipboard_peer_owns(&vd->cbpeer, i)) { in put_cbinfo()
1001 VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(pv); in get_cbinfo() local
1005 if (!have_clipboard(vd)) { in get_cbinfo()
1009 vdagent_clipboard_peer_register(vd); in get_cbinfo()
1018 qemu_clipboard_info_new(&vd->cbpeer, cbinfo.cbinfo[i].selection); in get_cbinfo()
1068 VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(obj); in vdagent_chr_init() local
1070 vd->outbuf = g_byte_array_new(); in vdagent_chr_init()
1071 vmstate_register_any(NULL, &vmstate_vdagent, vd); in vdagent_chr_init()
1076 VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(obj); in vdagent_chr_fini() local
1078 vdagent_disconnect(vd); in vdagent_chr_fini()
1079 if (vd->mouse_hs) { in vdagent_chr_fini()
1080 qemu_input_handler_unregister(vd->mouse_hs); in vdagent_chr_fini()
1082 g_clear_pointer(&vd->outbuf, g_byte_array_unref); in vdagent_chr_fini()