Пример #1
0
CharDriverState *qemu_chr_open_spice(QemuOpts *opts)
{
    CharDriverState *chr;
    SpiceCharDriver *s;
    const char* name = qemu_opt_get(opts, "name");
    uint32_t debug = qemu_opt_get_number(opts, "debug", 0);
    const char** psubtype = spice_server_char_device_recognized_subtypes();
    const char *subtype = NULL;

    if (name == NULL) {
        fprintf(stderr, "spice-qemu-char: missing name parameter\n");
        print_allowed_subtypes();
        return NULL;
    }
    for(;*psubtype != NULL; ++psubtype) {
        if (strcmp(name, *psubtype) == 0) {
            subtype = *psubtype;
            break;
        }
    }
    if (subtype == NULL) {
        fprintf(stderr, "spice-qemu-char: unsupported name: %s\n", name);
        print_allowed_subtypes();
        return NULL;
    }

    chr = g_malloc0(sizeof(CharDriverState));
    s = g_malloc0(sizeof(SpiceCharDriver));
    s->chr = chr;
    s->debug = debug;
    s->active = false;
    s->sin.subtype = subtype;
    chr->opaque = s;
    chr->chr_write = spice_chr_write;
    chr->chr_close = spice_chr_close;
    chr->chr_guest_open = spice_chr_guest_open;
    chr->chr_guest_close = spice_chr_guest_close;

#if SPICE_SERVER_VERSION < 0x000901
    /* See comment in vmc_state() */
    if (strcmp(subtype, "vdagent") == 0) {
        qemu_chr_generic_open(chr);
    }
#endif

    return chr;
}
Пример #2
0
CharDriverState *qemu_chr_open_spice_vmc(const char *type)
{
    CharDriverState *chr;
    SpiceCharDriver *s;
    const char **psubtype = spice_server_char_device_recognized_subtypes();

    if (type == NULL) {
        fprintf(stderr, "spice-qemu-char: missing name parameter\n");
        print_allowed_subtypes();
        return NULL;
    }
    for (; *psubtype != NULL; ++psubtype) {
        if (strcmp(type, *psubtype) == 0) {
            break;
        }
    }
    if (*psubtype == NULL) {
        fprintf(stderr, "spice-qemu-char: unsupported type: %s\n", type);
        print_allowed_subtypes();
        return NULL;
    }

    chr = qemu_mallocz(sizeof(CharDriverState));
    s = qemu_mallocz(sizeof(SpiceCharDriver));
    s->chr = chr;
    s->active = false;
    s->sin.subtype = *psubtype;
    chr->opaque = s;
    chr->chr_write = spice_chr_write;
    chr->chr_add_watch = spice_chr_add_watch;
    chr->chr_close = spice_chr_close;
    chr->chr_guest_open = spice_chr_guest_open;
    chr->chr_guest_close = spice_chr_guest_close;

#if SPICE_SERVER_VERSION < 0x000901
    /* See comment in vmc_state() */
    if (strcmp(type, "vdagent") == 0) {
        qemu_chr_generic_open(chr);
    }
#endif

    return chr;
}