]>
Commit | Line | Data |
---|---|---|
f7e6b192 AL |
1 | /* |
2 | * QBool Module | |
3 | * | |
f7e6b192 AL |
4 | * Copyright IBM, Corp. 2009 |
5 | * | |
6 | * Authors: | |
7 | * Anthony Liguori <[email protected]> | |
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 | ||
f2ad72b3 | 14 | #include "qemu/osdep.h" |
7b1b5d19 PB |
15 | #include "qapi/qmp/qbool.h" |
16 | #include "qapi/qmp/qobject.h" | |
f7e6b192 AL |
17 | #include "qemu-common.h" |
18 | ||
f7e6b192 | 19 | /** |
fc48ffc3 | 20 | * qbool_from_bool(): Create a new QBool from a bool |
f7e6b192 AL |
21 | * |
22 | * Return strong reference. | |
23 | */ | |
fc48ffc3 | 24 | QBool *qbool_from_bool(bool value) |
f7e6b192 AL |
25 | { |
26 | QBool *qb; | |
27 | ||
7267c094 | 28 | qb = g_malloc(sizeof(*qb)); |
55e1819c | 29 | qobject_init(QOBJECT(qb), QTYPE_QBOOL); |
f7e6b192 | 30 | qb->value = value; |
f7e6b192 AL |
31 | |
32 | return qb; | |
33 | } | |
34 | ||
35 | /** | |
fc48ffc3 | 36 | * qbool_get_bool(): Get the stored bool |
f7e6b192 | 37 | */ |
fc48ffc3 | 38 | bool qbool_get_bool(const QBool *qb) |
f7e6b192 AL |
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 | { | |
14b61600 | 48 | if (!obj || qobject_type(obj) != QTYPE_QBOOL) { |
f7e6b192 | 49 | return NULL; |
14b61600 | 50 | } |
f7e6b192 AL |
51 | return container_of(obj, QBool, base); |
52 | } | |
53 | ||
54 | /** | |
55 | * qbool_destroy_obj(): Free all memory allocated by a | |
56 | * QBool object | |
57 | */ | |
55e1819c | 58 | void qbool_destroy_obj(QObject *obj) |
f7e6b192 AL |
59 | { |
60 | assert(obj != NULL); | |
7267c094 | 61 | g_free(qobject_to_qbool(obj)); |
f7e6b192 | 62 | } |