qmp: Convert QMP code to use object property iterators
[qemu/ar7.git] / qobject / qbool.c
blobbc6535fa49a5ab2af39732d44c8a22fe751a7036
1 /*
2 * QBool Module
4 * Copyright IBM, Corp. 2009
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
10 * See the COPYING.LIB file in the top-level directory.
14 #include "qapi/qmp/qbool.h"
15 #include "qapi/qmp/qobject.h"
16 #include "qemu-common.h"
18 static void qbool_destroy_obj(QObject *obj);
20 static const QType qbool_type = {
21 .code = QTYPE_QBOOL,
22 .destroy = qbool_destroy_obj,
25 /**
26 * qbool_from_bool(): Create a new QBool from a bool
28 * Return strong reference.
30 QBool *qbool_from_bool(bool value)
32 QBool *qb;
34 qb = g_malloc(sizeof(*qb));
35 qb->value = value;
36 QOBJECT_INIT(qb, &qbool_type);
38 return qb;
41 /**
42 * qbool_get_bool(): Get the stored bool
44 bool qbool_get_bool(const QBool *qb)
46 return qb->value;
49 /**
50 * qobject_to_qbool(): Convert a QObject into a QBool
52 QBool *qobject_to_qbool(const QObject *obj)
54 if (!obj || qobject_type(obj) != QTYPE_QBOOL) {
55 return NULL;
57 return container_of(obj, QBool, base);
60 /**
61 * qbool_destroy_obj(): Free all memory allocated by a
62 * QBool object
64 static void qbool_destroy_obj(QObject *obj)
66 assert(obj != NULL);
67 g_free(qobject_to_qbool(obj));