]> Git Repo - qemu.git/blame - qobject/qlit.c
qapi-schema: Collect run state stuff in qapi/run-state.json
[qemu.git] / qobject / qlit.c
CommitLineData
28035bcd
MAL
1/*
2 * QLit literal qobject
3 *
4 * Copyright IBM, Corp. 2009
5 * Copyright (c) 2013, 2015, 2017 Red Hat Inc.
6 *
7 * Authors:
8 * Anthony Liguori <[email protected]>
9 * Markus Armbruster <[email protected]>
10 * Marc-André Lureau <[email protected]>
11 *
12 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
13 * See the COPYING.LIB file in the top-level directory.
14 */
15
16#include "qemu/osdep.h"
17
18#include "qapi/qmp/qlit.h"
19#include "qapi/qmp/types.h"
20
6da8a7a3
MAL
21static bool qlit_equal_qdict(const QLitObject *lhs, const QDict *qdict)
22{
23 int i;
24
25 for (i = 0; lhs->value.qdict[i].key; i++) {
26 QObject *obj = qdict_get(qdict, lhs->value.qdict[i].key);
27
28 if (!qlit_equal_qobject(&lhs->value.qdict[i].value, obj)) {
29 return false;
30 }
31 }
32
33 /* Note: the literal qdict must not contain duplicates, this is
34 * considered a programming error and it isn't checked here. */
35 if (qdict_size(qdict) != i) {
36 return false;
37 }
38
39 return true;
40}
41
cbb65405
MAL
42static bool qlit_equal_qlist(const QLitObject *lhs, const QList *qlist)
43{
44 QListEntry *e;
45 int i = 0;
46
47 QLIST_FOREACH_ENTRY(qlist, e) {
48 QObject *obj = qlist_entry_obj(e);
49
50 if (!qlit_equal_qobject(&lhs->value.qlist[i], obj)) {
51 return false;
52 }
53 i++;
54 }
55
56 return !e && lhs->value.qlist[i].type == QTYPE_NONE;
57}
58
e2346a19 59bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
28035bcd 60{
28035bcd 61 if (!rhs || lhs->type != qobject_type(rhs)) {
d9eba57a 62 return false;
28035bcd
MAL
63 }
64
65 switch (lhs->type) {
6c6084c1
MAL
66 case QTYPE_QBOOL:
67 return lhs->value.qbool == qbool_get_bool(qobject_to_qbool(rhs));
28035bcd 68 case QTYPE_QNUM:
5f4bd809 69 return lhs->value.qnum == qnum_get_int(qobject_to_qnum(rhs));
28035bcd
MAL
70 case QTYPE_QSTRING:
71 return (strcmp(lhs->value.qstr,
72 qstring_get_str(qobject_to_qstring(rhs))) == 0);
6da8a7a3
MAL
73 case QTYPE_QDICT:
74 return qlit_equal_qdict(lhs, qobject_to_qdict(rhs));
cbb65405
MAL
75 case QTYPE_QLIST:
76 return qlit_equal_qlist(lhs, qobject_to_qlist(rhs));
6c6084c1
MAL
77 case QTYPE_QNULL:
78 return true;
28035bcd
MAL
79 default:
80 break;
81 }
82
d9eba57a 83 return false;
28035bcd 84}
This page took 0.032284 seconds and 4 git commands to generate.