/* AUTOMATICALLY GENERATED by qapi-gen.py DO NOT MODIFY */

/*
 * Schema-defined QAPI/QMP commands
 *
 * Copyright IBM, Corp. 2011
 * Copyright (C) 2014-2018 Red Hat, Inc.
 *
 * 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.
 */

#include "qemu/osdep.h"
#include "qapi/compat-policy.h"
#include "qapi/visitor.h"
#include "qapi/qmp/qdict.h"
#include "qapi/dealloc-visitor.h"
#include "qapi/error.h"
#include "qapi-visit-ebpf.h"
#include "qapi-commands-ebpf.h"
#include "qapi/qmp/qjson.h"
#include "trace/trace-qapi_commands_ebpf_trace_events.h"

#if defined(CONFIG_EBPF)
static void qmp_marshal_output_EbpfObject(EbpfObject *ret_in,
                                QObject **ret_out, Error **errp)
{
    Visitor *v;

    v = qobject_output_visitor_new_qmp(ret_out);
    if (visit_type_EbpfObject(v, "unused", &ret_in, errp)) {
        visit_complete(v, ret_out);
    }
    visit_free(v);
    v = qapi_dealloc_visitor_new();
    visit_type_EbpfObject(v, "unused", &ret_in, NULL);
    visit_free(v);
}
#endif /* defined(CONFIG_EBPF) */

#if defined(CONFIG_EBPF)
void qmp_marshal_request_ebpf(QDict *args, QObject **ret, Error **errp)
{
    Error *err = NULL;
    bool ok = false;
    Visitor *v;
    EbpfObject *retval;
    q_obj_request_ebpf_arg arg = {0};

    v = qobject_input_visitor_new_qmp(QOBJECT(args));
    if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
        goto out;
    }
    if (visit_type_q_obj_request_ebpf_arg_members(v, &arg, errp)) {
        ok = visit_check_struct(v, errp);
    }
    visit_end_struct(v, NULL);
    if (!ok) {
        goto out;
    }

    if (trace_event_get_state_backends(TRACE_QMP_ENTER_REQUEST_EBPF)) {
        g_autoptr(GString) req_json = qobject_to_json(QOBJECT(args));

        trace_qmp_enter_request_ebpf(req_json->str);
    }

    retval = qmp_request_ebpf(arg.id, &err);
    if (err) {
        trace_qmp_exit_request_ebpf(error_get_pretty(err), false);
        error_propagate(errp, err);
        goto out;
    }

    qmp_marshal_output_EbpfObject(retval, ret, errp);

    if (trace_event_get_state_backends(TRACE_QMP_EXIT_REQUEST_EBPF)) {
        g_autoptr(GString) ret_json = qobject_to_json(*ret);

        trace_qmp_exit_request_ebpf(ret_json->str, true);
    }

out:
    visit_free(v);
    v = qapi_dealloc_visitor_new();
    visit_start_struct(v, NULL, NULL, 0, NULL);
    visit_type_q_obj_request_ebpf_arg_members(v, &arg, NULL);
    visit_end_struct(v, NULL);
    visit_free(v);
}
#endif /* defined(CONFIG_EBPF) */

/* Dummy declaration to prevent empty .o file */
char qapi_dummy_qapi_commands_ebpf_c;
