xref: /openbmc/qemu/qobject/qbool.c (revision 406d2aa2)
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_is_equal(): Test whether the two QBools are equal
56  */
57 bool qbool_is_equal(const QObject *x, const QObject *y)
58 {
59     return qobject_to_qbool(x)->value == qobject_to_qbool(y)->value;
60 }
61 
62 /**
63  * qbool_destroy_obj(): Free all memory allocated by a
64  * QBool object
65  */
66 void qbool_destroy_obj(QObject *obj)
67 {
68     assert(obj != NULL);
69     g_free(qobject_to_qbool(obj));
70 }
71