xref: /openbmc/qemu/qobject/qbool.c (revision 09a274d8)
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 
17 /**
18  * qbool_from_bool(): Create a new QBool from a bool
19  *
20  * Return strong reference.
21  */
22 QBool *qbool_from_bool(bool value)
23 {
24     QBool *qb;
25 
26     qb = g_malloc(sizeof(*qb));
27     qobject_init(QOBJECT(qb), QTYPE_QBOOL);
28     qb->value = value;
29 
30     return qb;
31 }
32 
33 /**
34  * qbool_get_bool(): Get the stored bool
35  */
36 bool qbool_get_bool(const QBool *qb)
37 {
38     return qb->value;
39 }
40 
41 /**
42  * qbool_is_equal(): Test whether the two QBools are equal
43  */
44 bool qbool_is_equal(const QObject *x, const QObject *y)
45 {
46     return qobject_to(QBool, x)->value == qobject_to(QBool, y)->value;
47 }
48 
49 /**
50  * qbool_destroy_obj(): Free all memory allocated by a
51  * QBool object
52  */
53 void qbool_destroy_obj(QObject *obj)
54 {
55     assert(obj != NULL);
56     g_free(qobject_to(QBool, obj));
57 }
58