]> git.proxmox.com Git - mirror_qemu.git/blob - qobject/qbool.c
Merge remote-tracking branch 'remotes/stsquad/tags/pull-travis-speedup-090218-1'...
[mirror_qemu.git] / qobject / qbool.c
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 "qemu-common.h"
17
18 /**
19 * qbool_from_bool(): Create a new QBool from a bool
20 *
21 * Return strong reference.
22 */
23 QBool *qbool_from_bool(bool value)
24 {
25 QBool *qb;
26
27 qb = g_malloc(sizeof(*qb));
28 qobject_init(QOBJECT(qb), QTYPE_QBOOL);
29 qb->value = value;
30
31 return qb;
32 }
33
34 /**
35 * qbool_get_bool(): Get the stored bool
36 */
37 bool qbool_get_bool(const QBool *qb)
38 {
39 return qb->value;
40 }
41
42 /**
43 * qobject_to_qbool(): Convert a QObject into a QBool
44 */
45 QBool *qobject_to_qbool(const QObject *obj)
46 {
47 if (!obj || qobject_type(obj) != QTYPE_QBOOL) {
48 return NULL;
49 }
50 return container_of(obj, QBool, base);
51 }
52
53 /**
54 * qbool_is_equal(): Test whether the two QBools are equal
55 */
56 bool qbool_is_equal(const QObject *x, const QObject *y)
57 {
58 return qobject_to_qbool(x)->value == qobject_to_qbool(y)->value;
59 }
60
61 /**
62 * qbool_destroy_obj(): Free all memory allocated by a
63 * QBool object
64 */
65 void qbool_destroy_obj(QObject *obj)
66 {
67 assert(obj != NULL);
68 g_free(qobject_to_qbool(obj));
69 }