qapi-dealloc-visitor.c 3.55 KB
Newer Older
1 2 3
/*
 * Dealloc Visitor
 *
4
 * Copyright (C) 2012-2016 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14
 * Copyright IBM, Corp. 2011
 *
 * Authors:
 *  Michael Roth   <mdroth@linux.vnet.ibm.com>
 *
 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
 * See the COPYING.LIB file in the top-level directory.
 *
 */

Peter Maydell's avatar
Peter Maydell committed
15
#include "qemu/osdep.h"
16
#include "qapi/dealloc-visitor.h"
17
#include "qemu/queue.h"
18
#include "qemu-common.h"
19 20
#include "qapi/qmp/types.h"
#include "qapi/visitor-impl.h"
21 22 23 24 25 26

struct QapiDeallocVisitor
{
    Visitor visitor;
};

27
static void qapi_dealloc_start_struct(Visitor *v, const char *name, void **obj,
28
                                      size_t unused, Error **errp)
29 30 31
{
}

32
static void qapi_dealloc_end_struct(Visitor *v, void **obj)
33 34
{
    if (obj) {
35
        g_free(*obj);
36 37 38
    }
}

39 40 41
static void qapi_dealloc_start_alternate(Visitor *v, const char *name,
                                         GenericAlternate **obj, size_t size,
                                         bool promote_int, Error **errp)
42 43 44
{
}

45
static void qapi_dealloc_end_alternate(Visitor *v, void **obj)
46 47 48 49 50 51
{
    if (obj) {
        g_free(*obj);
    }
}

52 53 54
static void qapi_dealloc_start_list(Visitor *v, const char *name,
                                    GenericList **list, size_t size,
                                    Error **errp)
55 56 57
{
}

58
static GenericList *qapi_dealloc_next_list(Visitor *v, GenericList *tail,
59
                                           size_t size)
60
{
61 62 63
    GenericList *next = tail->next;
    g_free(tail);
    return next;
64 65
}

66
static void qapi_dealloc_end_list(Visitor *v, void **obj)
67 68 69
{
}

70
static void qapi_dealloc_type_str(Visitor *v, const char *name, char **obj,
71 72
                                  Error **errp)
{
73 74 75
    if (obj) {
        g_free(*obj);
    }
76 77
}

78
static void qapi_dealloc_type_int64(Visitor *v, const char *name, int64_t *obj,
79
                                    Error **errp)
80 81 82
{
}

83 84
static void qapi_dealloc_type_uint64(Visitor *v, const char *name,
                                     uint64_t *obj, Error **errp)
85 86 87
{
}

88
static void qapi_dealloc_type_bool(Visitor *v, const char *name, bool *obj,
89 90 91 92
                                   Error **errp)
{
}

93
static void qapi_dealloc_type_number(Visitor *v, const char *name, double *obj,
94 95 96 97
                                     Error **errp)
{
}

98 99
static void qapi_dealloc_type_anything(Visitor *v, const char *name,
                                       QObject **obj, Error **errp)
100 101 102 103 104 105
{
    if (obj) {
        qobject_decref(*obj);
    }
}

106 107 108 109
static void qapi_dealloc_type_null(Visitor *v, const char *name, Error **errp)
{
}

110
static void qapi_dealloc_free(Visitor *v)
111
{
112
    g_free(container_of(v, QapiDeallocVisitor, visitor));
113 114
}

115
Visitor *qapi_dealloc_visitor_new(void)
116 117 118
{
    QapiDeallocVisitor *v;

119
    v = g_malloc0(sizeof(*v));
120

121
    v->visitor.type = VISITOR_DEALLOC;
122 123
    v->visitor.start_struct = qapi_dealloc_start_struct;
    v->visitor.end_struct = qapi_dealloc_end_struct;
124 125
    v->visitor.start_alternate = qapi_dealloc_start_alternate;
    v->visitor.end_alternate = qapi_dealloc_end_alternate;
126 127 128
    v->visitor.start_list = qapi_dealloc_start_list;
    v->visitor.next_list = qapi_dealloc_next_list;
    v->visitor.end_list = qapi_dealloc_end_list;
129
    v->visitor.type_int64 = qapi_dealloc_type_int64;
130
    v->visitor.type_uint64 = qapi_dealloc_type_uint64;
131 132 133
    v->visitor.type_bool = qapi_dealloc_type_bool;
    v->visitor.type_str = qapi_dealloc_type_str;
    v->visitor.type_number = qapi_dealloc_type_number;
134
    v->visitor.type_any = qapi_dealloc_type_anything;
135
    v->visitor.type_null = qapi_dealloc_type_null;
136
    v->visitor.free = qapi_dealloc_free;
137

138
    return &v->visitor;
139
}