Beispiel #1
0
/**
 * virSysinfoFormat:
 * @buf: buffer to append output to (may use auto-indentation)
 * @def: structure to convert to xml string
 *
 * Returns 0 on success, -1 on failure after generating an error message.
 */
int
virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
{
    const char *type = virSysinfoTypeToString(def->type);

    if (!type) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("unexpected sysinfo type model %d"),
                       def->type);
        virBufferFreeAndReset(buf);
        return -1;
    }

    virBufferAsprintf(buf, "<sysinfo type='%s'>\n", type);

    virSysinfoBIOSFormat(buf, def);
    virSysinfoSystemFormat(buf, def);
    virSysinfoProcessorFormat(buf, def);
    virSysinfoMemoryFormat(buf, def);

    virBufferAddLit(buf, "</sysinfo>\n");

    if (virBufferError(buf)) {
        virReportOOMError();
        return -1;
    }

    return 0;
}
Beispiel #2
0
/**
 * virSysinfoFormat:
 * @buf: buffer to append output to (may use auto-indentation)
 * @def: structure to convert to xml string
 *
 * Returns 0 on success, -1 on failure after generating an error message.
 */
int
virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
{
    virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
    const char *type = virSysinfoTypeToString(def->type);
    int indent = virBufferGetIndent(buf, false);
    int ret = -1;

    if (!type) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("unexpected sysinfo type model %d"),
                       def->type);
        virBufferFreeAndReset(buf);
        goto cleanup;
    }

    virBufferAdjustIndent(&childrenBuf, indent + 2);

    virSysinfoBIOSFormat(&childrenBuf, def->bios);
    virSysinfoSystemFormat(&childrenBuf, def->system);
    virSysinfoBaseBoardFormat(&childrenBuf, def->baseBoard, def->nbaseBoard);
    virSysinfoProcessorFormat(&childrenBuf, def);
    virSysinfoMemoryFormat(&childrenBuf, def);

    virBufferAsprintf(buf, "<sysinfo type='%s'", type);
    if (virBufferUse(&childrenBuf)) {
        virBufferAddLit(buf, ">\n");
        virBufferAddBuffer(buf, &childrenBuf);
        virBufferAddLit(buf, "</sysinfo>\n");
    } else {
        virBufferAddLit(buf, "/>\n");
    }

    if (virBufferCheckError(buf) < 0)
        goto cleanup;

    ret = 0;
 cleanup:
    virBufferFreeAndReset(&childrenBuf);
    return ret;
}