Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 1 | /* |
| 2 | * QBool Module |
| 3 | * |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 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 | |
Peter Maydell | f2ad72b | 2016-01-29 17:50:01 +0000 | [diff] [blame] | 14 | #include "qemu/osdep.h" |
Paolo Bonzini | 7b1b5d1 | 2012-12-17 18:19:43 +0100 | [diff] [blame] | 15 | #include "qapi/qmp/qbool.h" |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 16 | #include "qemu-common.h" |
| 17 | |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 18 | /** |
Eric Blake | fc48ffc | 2015-05-15 16:24:59 -0600 | [diff] [blame] | 19 | * qbool_from_bool(): Create a new QBool from a bool |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 20 | * |
| 21 | * Return strong reference. |
| 22 | */ |
Eric Blake | fc48ffc | 2015-05-15 16:24:59 -0600 | [diff] [blame] | 23 | QBool *qbool_from_bool(bool value) |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 24 | { |
| 25 | QBool *qb; |
| 26 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 27 | qb = g_malloc(sizeof(*qb)); |
Eric Blake | 55e1819 | 2015-12-01 22:20:45 -0700 | [diff] [blame] | 28 | qobject_init(QOBJECT(qb), QTYPE_QBOOL); |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 29 | qb->value = value; |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 30 | |
| 31 | return qb; |
| 32 | } |
| 33 | |
| 34 | /** |
Eric Blake | fc48ffc | 2015-05-15 16:24:59 -0600 | [diff] [blame] | 35 | * qbool_get_bool(): Get the stored bool |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 36 | */ |
Eric Blake | fc48ffc | 2015-05-15 16:24:59 -0600 | [diff] [blame] | 37 | bool qbool_get_bool(const QBool *qb) |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 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 | { |
Markus Armbruster | 14b6160 | 2015-10-15 16:15:33 +0200 | [diff] [blame] | 47 | if (!obj || qobject_type(obj) != QTYPE_QBOOL) { |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 48 | return NULL; |
Markus Armbruster | 14b6160 | 2015-10-15 16:15:33 +0200 | [diff] [blame] | 49 | } |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 50 | return container_of(obj, QBool, base); |
| 51 | } |
| 52 | |
| 53 | /** |
Max Reitz | b38dd67 | 2017-11-14 19:01:25 +0100 | [diff] [blame] | 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 | /** |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 62 | * qbool_destroy_obj(): Free all memory allocated by a |
| 63 | * QBool object |
| 64 | */ |
Eric Blake | 55e1819 | 2015-12-01 22:20:45 -0700 | [diff] [blame] | 65 | void qbool_destroy_obj(QObject *obj) |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 66 | { |
| 67 | assert(obj != NULL); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 68 | g_free(qobject_to_qbool(obj)); |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 69 | } |