]>
Commit | Line | Data |
---|---|---|
6b8d1ece | 1 | /* |
41836a9f | 2 | * QInt Module |
6b8d1ece LC |
3 | * |
4 | * Copyright (C) 2009 Red Hat Inc. | |
5 | * | |
6 | * Authors: | |
7 | * Luiz Capitulino <[email protected]> | |
8 | * | |
41836a9f LC |
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. | |
6b8d1ece | 11 | */ |
41836a9f | 12 | |
7b1b5d19 PB |
13 | #include "qapi/qmp/qint.h" |
14 | #include "qapi/qmp/qobject.h" | |
6b8d1ece LC |
15 | #include "qemu-common.h" |
16 | ||
6b8d1ece LC |
17 | /** |
18 | * qint_from_int(): Create a new QInt from an int64_t | |
19 | * | |
20 | * Return strong reference. | |
21 | */ | |
22 | QInt *qint_from_int(int64_t value) | |
23 | { | |
24 | QInt *qi; | |
25 | ||
7267c094 | 26 | qi = g_malloc(sizeof(*qi)); |
55e1819c | 27 | qobject_init(QOBJECT(qi), QTYPE_QINT); |
6b8d1ece | 28 | qi->value = value; |
6b8d1ece LC |
29 | |
30 | return qi; | |
31 | } | |
32 | ||
33 | /** | |
34 | * qint_get_int(): Get the stored integer | |
35 | */ | |
36 | int64_t qint_get_int(const QInt *qi) | |
37 | { | |
38 | return qi->value; | |
39 | } | |
40 | ||
41 | /** | |
42 | * qobject_to_qint(): Convert a QObject into a QInt | |
43 | */ | |
44 | QInt *qobject_to_qint(const QObject *obj) | |
45 | { | |
fcf73f66 | 46 | if (!obj || qobject_type(obj) != QTYPE_QINT) { |
6b8d1ece | 47 | return NULL; |
fcf73f66 | 48 | } |
6b8d1ece LC |
49 | return container_of(obj, QInt, base); |
50 | } | |
51 | ||
52 | /** | |
53 | * qint_destroy_obj(): Free all memory allocated by a | |
54 | * QInt object | |
55 | */ | |
55e1819c | 56 | void qint_destroy_obj(QObject *obj) |
6b8d1ece LC |
57 | { |
58 | assert(obj != NULL); | |
7267c094 | 59 | g_free(qobject_to_qint(obj)); |
6b8d1ece | 60 | } |