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