forked from xen-project/xen
-
Notifications
You must be signed in to change notification settings - Fork 2
/
xl_vkb.c
162 lines (134 loc) · 4.23 KB
/
xl_vkb.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
* Copyright (C) 2016 EPAM Systems Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; version 2.1 only. with the special
* exception on linking described in file LICENSE.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*/
#include <stdlib.h>
#include <libxl.h>
#include <libxl_utils.h>
#include <libxlutil.h>
#include <xen/io/kbdif.h>
#include "xl.h"
#include "xl_utils.h"
#include "xl_parse.h"
int main_vkbattach(int argc, char **argv)
{
int opt;
int rc;
uint32_t domid;
libxl_device_vkb vkb;
SWITCH_FOREACH_OPT(opt, "", NULL, "vkb-attach", 2) {
/* No options */
}
libxl_device_vkb_init(&vkb);
domid = find_domain(argv[optind++]);
for (argv += optind, argc -= optind; argc > 0; ++argv, --argc) {
rc = parse_vkb_config(&vkb, *argv);
if (rc) goto out;
}
if (vkb.backend_type == LIBXL_VKB_BACKEND_UNKNOWN) {
fprintf(stderr, "backend-type should be set\n");
rc = ERROR_FAIL; goto out;
}
if (vkb.multi_touch_height || vkb.multi_touch_width ||
vkb.multi_touch_num_contacts) {
vkb.feature_multi_touch = true;
}
if (vkb.feature_multi_touch && !(vkb.multi_touch_height ||
vkb.multi_touch_width || vkb.multi_touch_num_contacts)) {
fprintf(stderr, XENKBD_FIELD_MT_WIDTH", "XENKBD_FIELD_MT_HEIGHT", "
XENKBD_FIELD_MT_NUM_CONTACTS" should be set\n");
rc = ERROR_FAIL; goto out;
}
if (dryrun_only) {
char *json = libxl_device_vkb_to_json(ctx, &vkb);
printf("vkb: %s\n", json);
free(json);
goto done;
}
if (libxl_device_vkb_add(ctx, domid, &vkb, 0)) {
fprintf(stderr, "libxl_device_vkb_add failed.\n");
rc = ERROR_FAIL; goto out;
}
done:
rc = 0;
out:
libxl_device_vkb_dispose(&vkb);
return rc;
}
int main_vkblist(int argc, char **argv)
{
int opt;
libxl_device_vkb *vkbs;
libxl_vkbinfo vkbinfo;
int nb, i;
SWITCH_FOREACH_OPT(opt, "", NULL, "vkb-list", 1) {
/* No options */
}
/* Idx BE Hdl Sta evch ref ID BE-type BE-path */
printf("%-3s %-2s %-6s %-5s %-6s %6s %-10s %-10s %-30s\n",
"Idx", "BE", "handle", "state", "evt-ch", "ref",
"ID", "BE-type", "BE-path");
for (argv += optind, argc -= optind; argc > 0; --argc, ++argv) {
uint32_t domid = find_domain(*argv);
vkbs = libxl_device_vkb_list(ctx, domid, &nb);
if (!vkbs) {
continue;
}
for (i = 0; i < nb; ++i) {
if (libxl_device_vkb_getinfo(ctx, domid, &vkbs[i], &vkbinfo) == 0) {
printf("%-3d %-2d %6d %5d %6d %6d %-10s %-10s %-30s\n",
vkbinfo.devid, vkbinfo.backend_id,
vkbinfo.devid, vkbinfo.state, vkbinfo.evtch,
vkbinfo.rref, vkbs[i].unique_id,
libxl_vkb_backend_to_string(vkbs[i].backend_type),
vkbinfo.backend);
libxl_vkbinfo_dispose(&vkbinfo);
}
}
libxl_device_vkb_list_free(vkbs, nb);
}
return 0;
}
int main_vkbdetach(int argc, char **argv)
{
uint32_t domid, devid;
int opt, rc;
libxl_device_vkb vkb;
SWITCH_FOREACH_OPT(opt, "", NULL, "vkb-detach", 2) {
/* No options */
}
domid = find_domain(argv[optind++]);
devid = atoi(argv[optind++]);
libxl_device_vkb_init(&vkb);
if (libxl_devid_to_device_vkb(ctx, domid, devid, &vkb)) {
fprintf(stderr, "Error: Device %d not connected.\n", devid);
rc = ERROR_FAIL;
goto out;
}
rc = libxl_device_vkb_remove(ctx, domid, &vkb, 0);
if (rc) {
fprintf(stderr, "libxl_device_vkb_remove failed.\n");
rc = ERROR_FAIL;
goto out;
}
rc = 0;
out:
libxl_device_vkb_dispose(&vkb);
return rc;
}
/*
* Local variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/