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 | |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 17 | /** |
Eric Blake | fc48ffc | 2015-05-15 16:24:59 -0600 | [diff] [blame] | 18 | * qbool_from_bool(): Create a new QBool from a bool |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 19 | * |
| 20 | * Return strong reference. |
| 21 | */ |
Eric Blake | fc48ffc | 2015-05-15 16:24:59 -0600 | [diff] [blame] | 22 | QBool *qbool_from_bool(bool value) |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 23 | { |
| 24 | QBool *qb; |
| 25 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 26 | qb = g_malloc(sizeof(*qb)); |
Eric Blake | 55e1819 | 2015-12-01 22:20:45 -0700 | [diff] [blame] | 27 | qobject_init(QOBJECT(qb), QTYPE_QBOOL); |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 28 | qb->value = value; |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 29 | |
| 30 | return qb; |
| 31 | } |
| 32 | |
| 33 | /** |
Eric Blake | fc48ffc | 2015-05-15 16:24:59 -0600 | [diff] [blame] | 34 | * qbool_get_bool(): Get the stored bool |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 35 | */ |
Eric Blake | fc48ffc | 2015-05-15 16:24:59 -0600 | [diff] [blame] | 36 | bool qbool_get_bool(const QBool *qb) |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 37 | { |
| 38 | return qb->value; |
| 39 | } |
| 40 | |
| 41 | /** |
Max Reitz | b38dd67 | 2017-11-14 19:01:25 +0100 | [diff] [blame] | 42 | * qbool_is_equal(): Test whether the two QBools are equal |
| 43 | */ |
| 44 | bool qbool_is_equal(const QObject *x, const QObject *y) |
| 45 | { |
Max Reitz | 7dc847e | 2018-02-24 16:40:29 +0100 | [diff] [blame] | 46 | return qobject_to(QBool, x)->value == qobject_to(QBool, y)->value; |
Max Reitz | b38dd67 | 2017-11-14 19:01:25 +0100 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /** |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 50 | * qbool_destroy_obj(): Free all memory allocated by a |
| 51 | * QBool object |
| 52 | */ |
Eric Blake | 55e1819 | 2015-12-01 22:20:45 -0700 | [diff] [blame] | 53 | void qbool_destroy_obj(QObject *obj) |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 54 | { |
| 55 | assert(obj != NULL); |
Max Reitz | 7dc847e | 2018-02-24 16:40:29 +0100 | [diff] [blame] | 56 | g_free(qobject_to(QBool, obj)); |
Anthony Liguori | f7e6b19 | 2009-11-11 10:37:39 -0600 | [diff] [blame] | 57 | } |