xref: /qemu/qobject/qbool.c (revision 7a4e543d)
1 /*
2  * QBool Module
3  *
4  * Copyright IBM, Corp. 2009
5  *
6  * Authors:
7  *  Anthony Liguori   <aliguori@us.ibm.com>
8  *
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.
11  *
12  */
13 
14 #include "qemu/osdep.h"
15 #include "qapi/qmp/qbool.h"
16 #include "qapi/qmp/qobject.h"
17 #include "qemu-common.h"
18 
19 /**
20  * qbool_from_bool(): Create a new QBool from a bool
21  *
22  * Return strong reference.
23  */
24 QBool *qbool_from_bool(bool value)
25 {
26     QBool *qb;
27 
28     qb = g_malloc(sizeof(*qb));
29     qobject_init(QOBJECT(qb), QTYPE_QBOOL);
30     qb->value = value;
31 
32     return qb;
33 }
34 
35 /**
36  * qbool_get_bool(): Get the stored bool
37  */
38 bool qbool_get_bool(const QBool *qb)
39 {
40     return qb->value;
41 }
42 
43 /**
44  * qobject_to_qbool(): Convert a QObject into a QBool
45  */
46 QBool *qobject_to_qbool(const QObject *obj)
47 {
48     if (!obj || qobject_type(obj) != QTYPE_QBOOL) {
49         return NULL;
50     }
51     return container_of(obj, QBool, base);
52 }
53 
54 /**
55  * qbool_destroy_obj(): Free all memory allocated by a
56  * QBool object
57  */
58 void qbool_destroy_obj(QObject *obj)
59 {
60     assert(obj != NULL);
61     g_free(qobject_to_qbool(obj));
62 }
63