Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging
[qemu/ar7.git] / qobject / qbool.c
blob856c7433577041982950b6ca14cbbefed9b42696
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 /**
19 * qbool_from_bool(): Create a new QBool from a bool
21 * Return strong reference.
23 QBool *qbool_from_bool(bool value)
25 QBool *qb;
27 qb = g_malloc(sizeof(*qb));
28 qobject_init(QOBJECT(qb), QTYPE_QBOOL);
29 qb->value = value;
31 return qb;
34 /**
35 * qbool_get_bool(): Get the stored bool
37 bool qbool_get_bool(const QBool *qb)
39 return qb->value;
42 /**
43 * qobject_to_qbool(): Convert a QObject into a QBool
45 QBool *qobject_to_qbool(const QObject *obj)
47 if (!obj || qobject_type(obj) != QTYPE_QBOOL) {
48 return NULL;
50 return container_of(obj, QBool, base);
53 /**
54 * qbool_destroy_obj(): Free all memory allocated by a
55 * QBool object
57 void qbool_destroy_obj(QObject *obj)
59 assert(obj != NULL);
60 g_free(qobject_to_qbool(obj));