]>
Commit | Line | Data |
---|---|---|
cc04455b DM |
1 | #include <stdlib.h> |
2 | #include <math.h> | |
3 | #include <string.h> | |
4 | #include <stdio.h> | |
5 | #include <unistd.h> | |
6 | #include <signal.h> | |
7 | #include <wait.h> | |
8 | #include <sys/select.h> | |
9 | #include <sys/types.h> | |
10 | #include <getopt.h> | |
11 | ||
4219b121 | 12 | #include "glyphs.h" |
cc04455b | 13 | #include <spice.h> |
474762d8 | 14 | #include <spice/enums.h> |
cc04455b DM |
15 | #include <spice/macros.h> |
16 | #include <spice/qxl_dev.h> | |
17 | ||
18 | #include "test_display_base.h" | |
cc04455b DM |
19 | |
20 | #define MEM_SLOT_GROUP_ID 0 | |
21 | ||
22 | #define NOTIFY_DISPLAY_BATCH (SINGLE_PART/2) | |
23 | #define NOTIFY_CURSOR_BATCH 10 | |
24 | ||
65007123 DM |
25 | /* these colours are from linux kernel drivers/char/vt.c */ |
26 | /* the default colour table, for VGA+ colour systems */ | |
27 | int default_red[] = {0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa, | |
28 | 0x55,0xff,0x55,0xff,0x55,0xff,0x55,0xff}; | |
29 | int default_grn[] = {0x00,0x00,0xaa,0x55,0x00,0x00,0xaa,0xaa, | |
30 | 0x55,0x55,0xff,0xff,0x55,0x55,0xff,0xff}; | |
31 | int default_blu[] = {0x00,0x00,0x00,0x00,0xaa,0xaa,0xaa,0xaa, | |
32 | 0x55,0x55,0x55,0x55,0xff,0xff,0xff,0xff}; | |
33 | ||
cc04455b DM |
34 | /* Parts cribbed from spice-display.h/.c/qxl.c */ |
35 | ||
36 | typedef struct SimpleSpiceUpdate { | |
37 | QXLCommandExt ext; // first | |
38 | QXLDrawable drawable; | |
39 | QXLImage image; | |
40 | uint8_t *bitmap; | |
41 | } SimpleSpiceUpdate; | |
42 | ||
cc04455b DM |
43 | static void test_spice_destroy_update(SimpleSpiceUpdate *update) |
44 | { | |
45 | if (!update) { | |
46 | return; | |
47 | } | |
48 | if (update->drawable.clip.type != SPICE_CLIP_TYPE_NONE) { | |
49 | uint8_t *ptr = (uint8_t*)update->drawable.clip.data; | |
50 | free(ptr); | |
51 | } | |
9f9c8d83 DM |
52 | g_free(update->bitmap); |
53 | g_free(update); | |
cc04455b DM |
54 | } |
55 | ||
56 | #define DEFAULT_WIDTH 640 | |
57 | #define DEFAULT_HEIGHT 320 | |
58 | ||
59 | #define SINGLE_PART 4 | |
60 | static const int angle_parts = 64 / SINGLE_PART; | |
61 | static int unique = 1; | |
62 | static int color = -1; | |
63 | static int c_i = 0; | |
64 | ||
cc04455b DM |
65 | __attribute__((noreturn)) |
66 | static void sigchld_handler(int signal_num) // wait for the child process and exit | |
67 | { | |
68 | int status; | |
69 | wait(&status); | |
70 | exit(0); | |
71 | } | |
72 | ||
cc04455b DM |
73 | static void set_cmd(QXLCommandExt *ext, uint32_t type, QXLPHYSICAL data) |
74 | { | |
75 | ext->cmd.type = type; | |
76 | ext->cmd.data = data; | |
77 | ext->cmd.padding = 0; | |
78 | ext->group_id = MEM_SLOT_GROUP_ID; | |
79 | ext->flags = 0; | |
80 | } | |
81 | ||
82 | static void simple_set_release_info(QXLReleaseInfo *info, intptr_t ptr) | |
83 | { | |
84 | info->id = ptr; | |
85 | //info->group_id = MEM_SLOT_GROUP_ID; | |
86 | } | |
87 | ||
9f9c8d83 | 88 | /* bitmap are freed, so they must be allocated with g_malloc */ |
cc04455b DM |
89 | SimpleSpiceUpdate *test_spice_create_update_from_bitmap(uint32_t surface_id, |
90 | QXLRect bbox, | |
4219b121 | 91 | uint8_t *bitmap) |
cc04455b DM |
92 | { |
93 | SimpleSpiceUpdate *update; | |
94 | QXLDrawable *drawable; | |
95 | QXLImage *image; | |
96 | uint32_t bw, bh; | |
97 | ||
98 | bh = bbox.bottom - bbox.top; | |
99 | bw = bbox.right - bbox.left; | |
100 | ||
9f9c8d83 | 101 | update = g_new0(SimpleSpiceUpdate, 1); |
cc04455b DM |
102 | update->bitmap = bitmap; |
103 | drawable = &update->drawable; | |
104 | image = &update->image; | |
105 | ||
106 | drawable->surface_id = surface_id; | |
107 | ||
108 | drawable->bbox = bbox; | |
4219b121 | 109 | drawable->clip.type = SPICE_CLIP_TYPE_NONE; |
cc04455b DM |
110 | drawable->effect = QXL_EFFECT_OPAQUE; |
111 | simple_set_release_info(&drawable->release_info, (intptr_t)update); | |
112 | drawable->type = QXL_DRAW_COPY; | |
113 | drawable->surfaces_dest[0] = -1; | |
114 | drawable->surfaces_dest[1] = -1; | |
115 | drawable->surfaces_dest[2] = -1; | |
116 | ||
117 | drawable->u.copy.rop_descriptor = SPICE_ROPD_OP_PUT; | |
118 | drawable->u.copy.src_bitmap = (intptr_t)image; | |
119 | drawable->u.copy.src_area.right = bw; | |
120 | drawable->u.copy.src_area.bottom = bh; | |
121 | ||
122 | QXL_SET_IMAGE_ID(image, QXL_IMAGE_GROUP_DEVICE, unique); | |
123 | image->descriptor.type = SPICE_IMAGE_TYPE_BITMAP; | |
124 | image->bitmap.flags = QXL_BITMAP_DIRECT | QXL_BITMAP_TOP_DOWN; | |
125 | image->bitmap.stride = bw * 4; | |
126 | image->descriptor.width = image->bitmap.x = bw; | |
127 | image->descriptor.height = image->bitmap.y = bh; | |
128 | image->bitmap.data = (intptr_t)bitmap; | |
129 | image->bitmap.palette = 0; | |
130 | image->bitmap.format = SPICE_BITMAP_FMT_32BIT; | |
131 | ||
132 | set_cmd(&update->ext, QXL_CMD_DRAW, (intptr_t)drawable); | |
133 | ||
134 | return update; | |
135 | } | |
136 | ||
65007123 | 137 | static SimpleSpiceUpdate *test_draw_char(Test *test, int x, int y, int c, int fg, int bg) |
cc04455b DM |
138 | { |
139 | int top, left; | |
140 | uint8_t *dst; | |
141 | uint8_t *bitmap; | |
142 | int bw, bh; | |
9462ba15 | 143 | int i, j; |
cc04455b DM |
144 | QXLRect bbox; |
145 | ||
8a22eb4f DM |
146 | left = x*8; |
147 | top = y*16; | |
26c64941 | 148 | |
77133eee | 149 | // printf("DRAWCHAR %d %d %d\n", left, top, c); |
8a22eb4f | 150 | |
cc04455b DM |
151 | unique++; |
152 | ||
26c64941 DM |
153 | bw = 8; |
154 | bh = 16; | |
cc04455b | 155 | |
9f9c8d83 | 156 | bitmap = dst = g_malloc(bw * bh * 4); |
cc04455b | 157 | |
9462ba15 DM |
158 | unsigned char *data = vt_font_data + c*16; |
159 | unsigned char d = *data; | |
160 | ||
65007123 DM |
161 | g_assert(fg >= 0 && fg < 16); |
162 | g_assert(bg >= 0 && bg < 16); | |
163 | ||
164 | unsigned char fgc_red = default_red[fg]; | |
165 | unsigned char fgc_blue = default_blu[fg]; | |
166 | unsigned char fgc_green = default_grn[fg]; | |
167 | unsigned char bgc_red = default_red[bg]; | |
168 | unsigned char bgc_blue = default_blu[bg]; | |
169 | unsigned char bgc_green = default_grn[bg]; | |
9f9c8d83 | 170 | |
9462ba15 DM |
171 | for (j = 0; j < 16; j++) { |
172 | for (i = 0; i < 8; i++) { | |
173 | if ((i&7) == 0) { | |
174 | d=*data; | |
175 | data++; | |
176 | } | |
177 | if (d&0x80) { | |
9f9c8d83 DM |
178 | *(dst) = fgc_blue; |
179 | *(dst+1) = fgc_green; | |
180 | *(dst+2) = fgc_red; | |
181 | *(dst+3) = 0; | |
182 | } else { | |
183 | *(dst) = bgc_blue; | |
184 | *(dst+1) = bgc_green; | |
185 | *(dst+2) = bgc_red; | |
9462ba15 DM |
186 | *(dst+3) = 0; |
187 | } | |
188 | d<<=1; | |
189 | dst += 4; | |
190 | } | |
cc04455b DM |
191 | } |
192 | ||
193 | bbox.left = left; bbox.top = top; | |
194 | bbox.right = left + bw; bbox.bottom = top + bh; | |
9462ba15 | 195 | |
8a22eb4f | 196 | return test_spice_create_update_from_bitmap(0, bbox, bitmap); |
cc04455b DM |
197 | } |
198 | ||
cc04455b DM |
199 | static void create_primary_surface(Test *test, uint32_t width, |
200 | uint32_t height) | |
201 | { | |
202 | QXLWorker *qxl_worker = test->qxl_worker; | |
203 | QXLDevSurfaceCreate surface = { 0, }; | |
204 | ||
205 | g_assert(height <= MAX_HEIGHT); | |
206 | g_assert(width <= MAX_WIDTH); | |
207 | g_assert(height > 0); | |
208 | g_assert(width > 0); | |
209 | ||
210 | surface.format = SPICE_SURFACE_FMT_32_xRGB; | |
211 | surface.width = test->primary_width = width; | |
212 | surface.height = test->primary_height = height; | |
213 | surface.stride = -width * 4; /* negative? */ | |
214 | surface.mouse_mode = TRUE; /* unused by red_worker */ | |
215 | surface.flags = 0; | |
216 | surface.type = 0; /* unused by red_worker */ | |
217 | surface.position = 0; /* unused by red_worker */ | |
218 | surface.mem = (uint64_t)&test->primary_surface; | |
219 | surface.group_id = MEM_SLOT_GROUP_ID; | |
220 | ||
221 | test->width = width; | |
222 | test->height = height; | |
223 | ||
224 | qxl_worker->create_primary_surface(qxl_worker, 0, &surface); | |
225 | } | |
226 | ||
227 | QXLDevMemSlot slot = { | |
228 | .slot_group_id = MEM_SLOT_GROUP_ID, | |
229 | .slot_id = 0, | |
230 | .generation = 0, | |
231 | .virt_start = 0, | |
232 | .virt_end = ~0, | |
233 | .addr_delta = 0, | |
234 | .qxl_ram_size = ~0, | |
235 | }; | |
236 | ||
237 | static void attache_worker(QXLInstance *qin, QXLWorker *_qxl_worker) | |
238 | { | |
239 | Test *test = SPICE_CONTAINEROF(qin, Test, qxl_instance); | |
240 | ||
241 | if (test->qxl_worker) { | |
242 | if (test->qxl_worker != _qxl_worker) | |
243 | printf("%s ignored, %p is set, ignoring new %p\n", __func__, | |
244 | test->qxl_worker, _qxl_worker); | |
245 | else | |
246 | printf("%s ignored, redundant\n", __func__); | |
247 | return; | |
248 | } | |
249 | printf("%s\n", __func__); | |
250 | test->qxl_worker = _qxl_worker; | |
251 | test->qxl_worker->add_memslot(test->qxl_worker, &slot); | |
252 | create_primary_surface(test, DEFAULT_WIDTH, DEFAULT_HEIGHT); | |
253 | test->qxl_worker->start(test->qxl_worker); | |
254 | } | |
255 | ||
256 | static void set_compression_level(QXLInstance *qin, int level) | |
257 | { | |
258 | printf("%s\n", __func__); | |
259 | } | |
260 | ||
261 | static void set_mm_time(QXLInstance *qin, uint32_t mm_time) | |
262 | { | |
263 | } | |
cc04455b DM |
264 | static void get_init_info(QXLInstance *qin, QXLDevInitInfo *info) |
265 | { | |
266 | memset(info, 0, sizeof(*info)); | |
267 | info->num_memslots = 1; | |
268 | info->num_memslots_groups = 1; | |
269 | info->memslot_id_bits = 1; | |
270 | info->memslot_gen_bits = 1; | |
aae93060 | 271 | info->n_surfaces = 1; |
cc04455b DM |
272 | } |
273 | ||
aae93060 | 274 | |
cc04455b DM |
275 | // We shall now have a ring of commands, so that we can update |
276 | // it from a separate thread - since get_command is called from | |
277 | // the worker thread, and we need to sometimes do an update_area, | |
278 | // which cannot be done from red_worker context (not via dispatcher, | |
279 | // since you get a deadlock, and it isn't designed to be done | |
280 | // any other way, so no point testing that). | |
281 | int commands_end = 0; | |
282 | int commands_start = 0; | |
283 | struct QXLCommandExt* commands[1024]; | |
284 | ||
285 | #define COMMANDS_SIZE COUNT(commands) | |
286 | ||
287 | static void push_command(QXLCommandExt *ext) | |
288 | { | |
289 | g_assert(commands_end - commands_start < COMMANDS_SIZE); | |
290 | commands[commands_end % COMMANDS_SIZE] = ext; | |
291 | commands_end++; | |
292 | } | |
293 | ||
294 | static struct QXLCommandExt *get_simple_command(void) | |
295 | { | |
296 | struct QXLCommandExt *ret = commands[commands_start % COMMANDS_SIZE]; | |
297 | g_assert(commands_start < commands_end); | |
298 | commands_start++; | |
299 | return ret; | |
300 | } | |
301 | ||
302 | static int get_num_commands(void) | |
303 | { | |
304 | return commands_end - commands_start; | |
305 | } | |
306 | ||
307 | // called from spice_server thread (i.e. red_worker thread) | |
308 | static int get_command(QXLInstance *qin, struct QXLCommandExt *ext) | |
309 | { | |
310 | if (get_num_commands() == 0) { | |
311 | return FALSE; | |
312 | } | |
313 | *ext = *get_simple_command(); | |
314 | return TRUE; | |
315 | } | |
316 | ||
cc04455b DM |
317 | static int req_cmd_notification(QXLInstance *qin) |
318 | { | |
319 | Test *test = SPICE_CONTAINEROF(qin, Test, qxl_instance); | |
320 | ||
8a22eb4f | 321 | //test->core->timer_start(test->wakeup_timer, test->wakeup_ms); |
cc04455b DM |
322 | return TRUE; |
323 | } | |
f6cb554c | 324 | |
cc04455b DM |
325 | static void release_resource(QXLInstance *qin, struct QXLReleaseInfoExt release_info) |
326 | { | |
327 | QXLCommandExt *ext = (QXLCommandExt*)(unsigned long)release_info.info->id; | |
328 | //printf("%s\n", __func__); | |
329 | g_assert(release_info.group_id == MEM_SLOT_GROUP_ID); | |
330 | switch (ext->cmd.type) { | |
331 | case QXL_CMD_DRAW: | |
332 | test_spice_destroy_update((void*)ext); | |
333 | break; | |
334 | case QXL_CMD_SURFACE: | |
335 | free(ext); | |
336 | break; | |
337 | case QXL_CMD_CURSOR: { | |
338 | QXLCursorCmd *cmd = (QXLCursorCmd *)(unsigned long)ext->cmd.data; | |
339 | if (cmd->type == QXL_CURSOR_SET) { | |
340 | free(cmd); | |
341 | } | |
342 | free(ext); | |
343 | break; | |
344 | } | |
345 | default: | |
346 | abort(); | |
347 | } | |
348 | } | |
349 | ||
350 | #define CURSOR_WIDTH 32 | |
351 | #define CURSOR_HEIGHT 32 | |
352 | ||
353 | static struct { | |
354 | QXLCursor cursor; | |
355 | uint8_t data[CURSOR_WIDTH * CURSOR_HEIGHT * 4]; // 32bit per pixel | |
356 | } cursor; | |
357 | ||
358 | static void cursor_init() | |
359 | { | |
360 | cursor.cursor.header.unique = 0; | |
361 | cursor.cursor.header.type = SPICE_CURSOR_TYPE_COLOR32; | |
362 | cursor.cursor.header.width = CURSOR_WIDTH; | |
363 | cursor.cursor.header.height = CURSOR_HEIGHT; | |
364 | cursor.cursor.header.hot_spot_x = 0; | |
365 | cursor.cursor.header.hot_spot_y = 0; | |
366 | cursor.cursor.data_size = CURSOR_WIDTH * CURSOR_HEIGHT * 4; | |
367 | ||
368 | // X drivers addes it to the cursor size because it could be | |
369 | // cursor data information or another cursor related stuffs. | |
370 | // Otherwise, the code will break in client/cursor.cpp side, | |
371 | // that expect the data_size plus cursor information. | |
372 | // Blame cursor protocol for this. :-) | |
373 | cursor.cursor.data_size += 128; | |
374 | cursor.cursor.chunk.data_size = cursor.cursor.data_size; | |
375 | cursor.cursor.chunk.prev_chunk = cursor.cursor.chunk.next_chunk = 0; | |
376 | } | |
377 | ||
378 | static int get_cursor_command(QXLInstance *qin, struct QXLCommandExt *ext) | |
379 | { | |
380 | Test *test = SPICE_CONTAINEROF(qin, Test, qxl_instance); | |
381 | static int color = 0; | |
382 | static int set = 1; | |
383 | static int x = 0, y = 0; | |
384 | QXLCursorCmd *cursor_cmd; | |
385 | QXLCommandExt *cmd; | |
386 | ||
387 | if (!test->cursor_notify) { | |
388 | return FALSE; | |
389 | } | |
390 | ||
391 | test->cursor_notify--; | |
392 | cmd = calloc(sizeof(QXLCommandExt), 1); | |
393 | cursor_cmd = calloc(sizeof(QXLCursorCmd), 1); | |
394 | ||
395 | cursor_cmd->release_info.id = (unsigned long)cmd; | |
396 | ||
397 | if (set) { | |
398 | cursor_cmd->type = QXL_CURSOR_SET; | |
399 | cursor_cmd->u.set.position.x = 0; | |
400 | cursor_cmd->u.set.position.y = 0; | |
401 | cursor_cmd->u.set.visible = TRUE; | |
402 | cursor_cmd->u.set.shape = (unsigned long)&cursor; | |
403 | // Only a white rect (32x32) as cursor | |
404 | memset(cursor.data, 255, sizeof(cursor.data)); | |
405 | set = 0; | |
406 | } else { | |
407 | cursor_cmd->type = QXL_CURSOR_MOVE; | |
408 | cursor_cmd->u.position.x = x++ % test->primary_width; | |
409 | cursor_cmd->u.position.y = y++ % test->primary_height; | |
410 | } | |
411 | ||
412 | cmd->cmd.data = (unsigned long)cursor_cmd; | |
413 | cmd->cmd.type = QXL_CMD_CURSOR; | |
414 | cmd->group_id = MEM_SLOT_GROUP_ID; | |
415 | cmd->flags = 0; | |
416 | *ext = *cmd; | |
417 | //printf("%s\n", __func__); | |
418 | return TRUE; | |
419 | } | |
420 | ||
421 | static int req_cursor_notification(QXLInstance *qin) | |
422 | { | |
423 | printf("%s\n", __func__); | |
424 | return TRUE; | |
425 | } | |
426 | ||
427 | static void notify_update(QXLInstance *qin, uint32_t update_id) | |
428 | { | |
429 | printf("%s\n", __func__); | |
430 | } | |
431 | ||
432 | static int flush_resources(QXLInstance *qin) | |
433 | { | |
434 | printf("%s\n", __func__); | |
435 | return TRUE; | |
436 | } | |
437 | ||
438 | static int client_monitors_config(QXLInstance *qin, | |
439 | VDAgentMonitorsConfig *monitors_config) | |
440 | { | |
441 | if (!monitors_config) { | |
442 | printf("%s: NULL monitors_config\n", __func__); | |
443 | } else { | |
444 | printf("%s: %d\n", __func__, monitors_config->num_of_monitors); | |
445 | } | |
446 | return 0; | |
447 | } | |
448 | ||
449 | static void set_client_capabilities(QXLInstance *qin, | |
450 | uint8_t client_present, | |
451 | uint8_t caps[58]) | |
452 | { | |
453 | Test *test = SPICE_CONTAINEROF(qin, Test, qxl_instance); | |
454 | ||
455 | printf("%s: present %d caps %d\n", __func__, client_present, caps[0]); | |
456 | if (test->on_client_connected && client_present) { | |
457 | test->on_client_connected(test); | |
458 | } | |
459 | if (test->on_client_disconnected && !client_present) { | |
460 | test->on_client_disconnected(test); | |
461 | } | |
462 | } | |
463 | ||
6faab5d5 DM |
464 | static int client_count = 0; |
465 | ||
466 | static void client_connected(Test *test) | |
467 | { | |
468 | printf("Client connected\n"); | |
469 | client_count++; | |
470 | } | |
471 | ||
472 | static void client_disconnected(Test *test) | |
473 | { | |
474 | ||
475 | if (client_count > 0) { | |
476 | client_count--; | |
477 | printf("Client disconnected\n"); | |
478 | exit(0); // fixme: cleanup? | |
479 | } | |
480 | } | |
481 | ||
f6cb554c DM |
482 | static void do_conn_timeout(void *opaque) |
483 | { | |
484 | Test *test = opaque; | |
485 | ||
486 | if (client_count <= 0) { | |
487 | printf("do_conn_timeout\n"); | |
488 | exit (0); // fixme: cleanup? | |
489 | } | |
490 | } | |
491 | ||
492 | ||
cc04455b DM |
493 | QXLInterface display_sif = { |
494 | .base = { | |
495 | .type = SPICE_INTERFACE_QXL, | |
496 | .description = "test", | |
497 | .major_version = SPICE_INTERFACE_QXL_MAJOR, | |
498 | .minor_version = SPICE_INTERFACE_QXL_MINOR | |
499 | }, | |
500 | .attache_worker = attache_worker, | |
501 | .set_compression_level = set_compression_level, | |
502 | .set_mm_time = set_mm_time, | |
503 | .get_init_info = get_init_info, | |
504 | ||
505 | /* the callbacks below are called from spice server thread context */ | |
506 | .get_command = get_command, | |
507 | .req_cmd_notification = req_cmd_notification, | |
508 | .release_resource = release_resource, | |
509 | .get_cursor_command = get_cursor_command, | |
510 | .req_cursor_notification = req_cursor_notification, | |
511 | .notify_update = notify_update, | |
512 | .flush_resources = flush_resources, | |
513 | .client_monitors_config = client_monitors_config, | |
514 | .set_client_capabilities = set_client_capabilities, | |
515 | }; | |
516 | ||
517 | /* interface for tests */ | |
518 | void test_add_display_interface(Test* test) | |
519 | { | |
520 | spice_server_add_interface(test->server, &test->qxl_instance.base); | |
521 | } | |
522 | ||
523 | static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len) | |
524 | { | |
6faab5d5 | 525 | // printf("%s: %d\n", __func__, len); |
cc04455b DM |
526 | return len; |
527 | } | |
528 | ||
529 | static int vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len) | |
530 | { | |
6faab5d5 | 531 | // printf("%s: %d\n", __func__, len); |
cc04455b DM |
532 | return 0; |
533 | } | |
534 | ||
535 | static void vmc_state(SpiceCharDeviceInstance *sin, int connected) | |
536 | { | |
6faab5d5 | 537 | // printf("%s: %d\n", __func__, connected); |
cc04455b DM |
538 | } |
539 | ||
540 | static SpiceCharDeviceInterface vdagent_sif = { | |
541 | .base.type = SPICE_INTERFACE_CHAR_DEVICE, | |
542 | .base.description = "test spice virtual channel char device", | |
543 | .base.major_version = SPICE_INTERFACE_CHAR_DEVICE_MAJOR, | |
544 | .base.minor_version = SPICE_INTERFACE_CHAR_DEVICE_MINOR, | |
545 | .state = vmc_state, | |
546 | .write = vmc_write, | |
547 | .read = vmc_read, | |
548 | }; | |
549 | ||
550 | SpiceCharDeviceInstance vdagent_sin = { | |
551 | .base = { | |
552 | .sif = &vdagent_sif.base, | |
553 | }, | |
554 | .subtype = "vdagent", | |
555 | }; | |
556 | ||
557 | void test_add_agent_interface(SpiceServer *server) | |
558 | { | |
559 | spice_server_add_interface(server, &vdagent_sin.base); | |
560 | } | |
561 | ||
8a22eb4f DM |
562 | static int my_charcode = 65; |
563 | static int my_posx = 0; | |
474762d8 DM |
564 | static void kbd_push_key(SpiceKbdInstance *sin, uint8_t frag) |
565 | { | |
8a22eb4f DM |
566 | Test *test = SPICE_CONTAINEROF(sin, Test, keyboard_sin); |
567 | ||
568 | printf("KEYCODE %u %p\n", frag, test); | |
569 | ||
474762d8 DM |
570 | } |
571 | ||
22e5ba02 DM |
572 | void test_draw_update_char(Test *test, int x, int y, int c, TextAttributes attrib) |
573 | { | |
574 | int fg, bg; | |
575 | ||
576 | if (attrib.invers) { | |
577 | bg = attrib.fgcol; | |
578 | fg = attrib.bgcol; | |
579 | } else { | |
580 | bg = attrib.bgcol; | |
581 | fg = attrib.fgcol; | |
582 | } | |
583 | ||
584 | if (attrib.bold) { | |
585 | fg += 8; | |
586 | } | |
587 | ||
588 | // unsuported attributes = (attrib.blink || attrib.unvisible) | |
589 | ||
590 | //if (attrib.uline) { | |
591 | //rfbDrawLine (vt->screen, rx, ry + 14, rxe, ry + 14, fg); | |
592 | //} | |
593 | ||
594 | SimpleSpiceUpdate *update; | |
65007123 | 595 | update = test_draw_char(test, x, y, c, fg, bg); |
22e5ba02 DM |
596 | push_command(&update->ext); |
597 | ||
598 | test->qxl_worker->wakeup(test->qxl_worker); | |
599 | } | |
600 | ||
474762d8 DM |
601 | static uint8_t kbd_get_leds(SpiceKbdInstance *sin) |
602 | { | |
603 | return 0; | |
604 | } | |
605 | ||
606 | static SpiceKbdInterface keyboard_sif = { | |
607 | .base.type = SPICE_INTERFACE_KEYBOARD , | |
608 | .base.description = "spiceterm keyboard device", | |
609 | .base.major_version = SPICE_INTERFACE_KEYBOARD_MAJOR, | |
610 | .base.minor_version = SPICE_INTERFACE_KEYBOARD_MINOR, | |
611 | .push_scan_freg = kbd_push_key, | |
612 | .get_leds = kbd_get_leds, | |
613 | }; | |
614 | ||
8a22eb4f | 615 | void test_add_keyboard_interface(Test* test) |
474762d8 | 616 | { |
8a22eb4f | 617 | spice_server_add_interface(test->server, &test->keyboard_sin.base); |
474762d8 DM |
618 | } |
619 | ||
cc04455b DM |
620 | Test *test_new(SpiceCoreInterface *core) |
621 | { | |
622 | int port = 5912; | |
623 | Test *test = g_new0(Test, 1); | |
624 | SpiceServer* server = spice_server_new(); | |
625 | ||
6faab5d5 DM |
626 | test->on_client_connected = client_connected, |
627 | test->on_client_disconnected = client_disconnected, | |
628 | ||
cc04455b DM |
629 | test->qxl_instance.base.sif = &display_sif.base; |
630 | test->qxl_instance.id = 0; | |
631 | ||
8a22eb4f DM |
632 | test->keyboard_sin.base.sif = &keyboard_sif.base; |
633 | ||
cc04455b DM |
634 | test->core = core; |
635 | test->server = server; | |
8a22eb4f | 636 | |
cc04455b DM |
637 | test->cursor_notify = NOTIFY_CURSOR_BATCH; |
638 | // some common initialization for all display tests | |
639 | printf("TESTER: listening on port %d (unsecure)\n", port); | |
640 | spice_server_set_port(server, port); | |
641 | spice_server_set_noauth(server); | |
1d7f2da4 DM |
642 | int res = spice_server_init(server, core); |
643 | if (res != 0) { | |
644 | g_error("spice_server_init failed, res = %d\n", res); | |
645 | } | |
cc04455b DM |
646 | |
647 | cursor_init(); | |
cc04455b | 648 | test->has_secondary = 0; |
f6cb554c DM |
649 | |
650 | int timeout = 10; // max time to wait for client connection | |
651 | test->conn_timeout_timer = core->timer_add(do_conn_timeout, test); | |
652 | test->core->timer_start(test->conn_timeout_timer, timeout*1000); | |
653 | ||
cc04455b DM |
654 | return test; |
655 | } | |
656 | ||
cc04455b DM |
657 | |
658 | __attribute__((noreturn)) | |
659 | void usage(const char *argv0, const int exitcode) | |
660 | { | |
cc04455b | 661 | |
7f30e760 | 662 | printf("usage: %s\n", argv0); |
cc04455b DM |
663 | exit(exitcode); |
664 | } | |
665 | ||
666 | void spice_test_config_parse_args(int argc, char **argv) | |
667 | { | |
668 | struct option options[] = { | |
7f30e760 | 669 | // {"automated-tests", no_argument, &has_automated_tests, 1}, |
cc04455b DM |
670 | {NULL, 0, NULL, 0}, |
671 | }; | |
672 | int option_index; | |
673 | int val; | |
674 | ||
675 | while ((val = getopt_long(argc, argv, "", options, &option_index)) != -1) { | |
676 | switch (val) { | |
677 | case '?': | |
678 | printf("unrecognized option '%s'\n", argv[optind - 1]); | |
679 | usage(argv[0], EXIT_FAILURE); | |
680 | case 0: | |
681 | break; | |
682 | } | |
683 | } | |
684 | ||
685 | if (argc > optind) { | |
686 | printf("unknown argument '%s'\n", argv[optind]); | |
687 | usage(argv[0], EXIT_FAILURE); | |
688 | } | |
cc04455b DM |
689 | return; |
690 | } |