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 | /** |
Max Reitz | b38dd67 | 2017-11-14 19:01:25 +0100 | [diff] [blame] | 43 | * qbool_is_equal(): Test whether the two QBools are equal |
| 44 | */ |
| 45 | bool qbool_is_equal(const QObject *x, const QObject *y) |
| 46 | { |
Max Reitz | 7dc847e | 2018-02-24 16:40:29 +0100 | [diff] [blame] | 47 | return qobject_to(QBool, x)->value == qobject_to(QBool, y)->value; |
Max Reitz | b38dd67 | 2017-11-14 19:01:25 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /** |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 51 | * qbool_destroy_obj(): Free all memory allocated by a |
| 52 | * QBool object |
| 53 | */ |
Eric Blake | 55e1819 | 2015-12-01 22:20:45 -0700 | [diff] [blame] | 54 | void qbool_destroy_obj(QObject *obj) |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 55 | { |
| 56 | assert(obj != NULL); |
Max Reitz | 7dc847e | 2018-02-24 16:40:29 +0100 | [diff] [blame] | 57 | g_free(qobject_to(QBool, obj)); |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 58 | } |