// This file was generated by qtwaylandscanner
// source file is /build/qt6-wayland/src/qtwayland-everywhere-src-6.4.0/src/compositor/../3rdparty/protocol/presentation-time.xml

#include <QtWaylandCompositor/private/qwayland-server-presentation-time.h>

QT_BEGIN_NAMESPACE
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wmissing-field-initializers")

namespace QtWaylandServer {
    wp_presentation::wp_presentation(struct ::wl_client *client, uint32_t id, int version)
        : m_resource_map()
        , m_resource(nullptr)
        , m_global(nullptr)
    {
        init(client, id, version);
    }

    wp_presentation::wp_presentation(struct ::wl_display *display, int version)
        : m_resource_map()
        , m_resource(nullptr)
        , m_global(nullptr)
    {
        init(display, version);
    }

    wp_presentation::wp_presentation(struct ::wl_resource *resource)
        : m_resource_map()
        , m_resource(nullptr)
        , m_global(nullptr)
    {
        init(resource);
    }

    wp_presentation::wp_presentation()
        : m_resource_map()
        , m_resource(nullptr)
        , m_global(nullptr)
    {
    }

    wp_presentation::~wp_presentation()
    {
        for (auto resource : qAsConst(m_resource_map))
            resource->wp_presentation_object = nullptr;

        if (m_resource)
            m_resource->wp_presentation_object = nullptr;

        if (m_global) {
            wl_global_destroy(m_global);
            wl_list_remove(&m_displayDestroyedListener.link);
        }
    }

    void wp_presentation::init(struct ::wl_client *client, uint32_t id, int version)
    {
        m_resource = bind(client, id, version);
    }

    void wp_presentation::init(struct ::wl_resource *resource)
    {
        m_resource = bind(resource);
    }

    wp_presentation::Resource *wp_presentation::add(struct ::wl_client *client, int version)
    {
        Resource *resource = bind(client, 0, version);
        m_resource_map.insert(client, resource);
        return resource;
    }

    wp_presentation::Resource *wp_presentation::add(struct ::wl_client *client, uint32_t id, int version)
    {
        Resource *resource = bind(client, id, version);
        m_resource_map.insert(client, resource);
        return resource;
    }

    void wp_presentation::init(struct ::wl_display *display, int version)
    {
        m_global = wl_global_create(display, &::wp_presentation_interface, version, this, bind_func);
        m_displayDestroyedListener.notify = wp_presentation::display_destroy_func;
        m_displayDestroyedListener.parent = this;
        wl_display_add_destroy_listener(display, &m_displayDestroyedListener);
    }

    const struct wl_interface *wp_presentation::interface()
    {
        return &::wp_presentation_interface;
    }

    wp_presentation::Resource *wp_presentation::wp_presentation_allocate()
    {
        return new Resource;
    }

    void wp_presentation::wp_presentation_bind_resource(Resource *)
    {
    }

    void wp_presentation::wp_presentation_destroy_resource(Resource *)
    {
    }

    void wp_presentation::bind_func(struct ::wl_client *client, void *data, uint32_t version, uint32_t id)
    {
        wp_presentation *that = static_cast<wp_presentation *>(data);
        that->add(client, id, version);
    }

    void wp_presentation::display_destroy_func(struct ::wl_listener *listener, void *data)
    {
        Q_UNUSED(data);
        wp_presentation *that = static_cast<wp_presentation::DisplayDestroyedListener *>(listener)->parent;
        that->m_global = nullptr;
    }

    void wp_presentation::destroy_func(struct ::wl_resource *client_resource)
    {
        Resource *resource = Resource::fromResource(client_resource);
        Q_ASSERT(resource);
        wp_presentation *that = resource->wp_presentation_object;
        if (Q_LIKELY(that)) {
            that->m_resource_map.remove(resource->client(), resource);
            that->wp_presentation_destroy_resource(resource);

            that = resource->wp_presentation_object;
            if (that && that->m_resource == resource)
                that->m_resource = nullptr;
        }
        delete resource;
    }

    wp_presentation::Resource *wp_presentation::bind(struct ::wl_client *client, uint32_t id, int version)
    {
        Q_ASSERT_X(!wl_client_get_object(client, id), "QWaylandObject bind", QStringLiteral("binding to object %1 more than once").arg(id).toLocal8Bit().constData());
        struct ::wl_resource *handle = wl_resource_create(client, &::wp_presentation_interface, version, id);
        return bind(handle);
    }

    wp_presentation::Resource *wp_presentation::bind(struct ::wl_resource *handle)
    {
        Resource *resource = wp_presentation_allocate();
        resource->wp_presentation_object = this;

        wl_resource_set_implementation(handle, &m_wp_presentation_interface, resource, destroy_func);
        resource->handle = handle;
        wp_presentation_bind_resource(resource);
        return resource;
    }
    wp_presentation::Resource *wp_presentation::Resource::fromResource(struct ::wl_resource *resource)
    {
        if (Q_UNLIKELY(!resource))
            return nullptr;
        if (wl_resource_instance_of(resource, &::wp_presentation_interface, &m_wp_presentation_interface))
            return static_cast<Resource *>(wl_resource_get_user_data(resource));
        return nullptr;
    }

    const struct ::wp_presentation_interface wp_presentation::m_wp_presentation_interface = {
        wp_presentation::handle_destroy,
        wp_presentation::handle_feedback
    };

    void wp_presentation::wp_presentation_destroy(Resource *)
    {
    }

    void wp_presentation::wp_presentation_feedback(Resource *, struct ::wl_resource *, uint32_t)
    {
    }


    void wp_presentation::handle_destroy(
        ::wl_client *client,
        struct wl_resource *resource)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->wp_presentation_object)) {
            wl_resource_destroy(resource);
            return;
        }
        static_cast<wp_presentation *>(r->wp_presentation_object)->wp_presentation_destroy(
            r);
    }

    void wp_presentation::handle_feedback(
        ::wl_client *client,
        struct wl_resource *resource,
        struct ::wl_resource *surface,
        uint32_t callback)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->wp_presentation_object)) {
            return;
        }
        static_cast<wp_presentation *>(r->wp_presentation_object)->wp_presentation_feedback(
            r,
            surface,
            callback);
    }

    void wp_presentation::send_clock_id(uint32_t clk_id)
    {
        Q_ASSERT_X(m_resource, "wp_presentation::clock_id", "Uninitialised resource");
        if (Q_UNLIKELY(!m_resource)) {
            qWarning("could not call wp_presentation::clock_id as it's not initialised");
            return;
        }
        send_clock_id(
            m_resource->handle,
            clk_id);
    }

    void wp_presentation::send_clock_id(struct ::wl_resource *resource, uint32_t clk_id)
    {
        wp_presentation_send_clock_id(
            resource,
            clk_id);
    }


    wp_presentation_feedback::wp_presentation_feedback(struct ::wl_client *client, uint32_t id, int version)
        : m_resource_map()
        , m_resource(nullptr)
        , m_global(nullptr)
    {
        init(client, id, version);
    }

    wp_presentation_feedback::wp_presentation_feedback(struct ::wl_display *display, int version)
        : m_resource_map()
        , m_resource(nullptr)
        , m_global(nullptr)
    {
        init(display, version);
    }

    wp_presentation_feedback::wp_presentation_feedback(struct ::wl_resource *resource)
        : m_resource_map()
        , m_resource(nullptr)
        , m_global(nullptr)
    {
        init(resource);
    }

    wp_presentation_feedback::wp_presentation_feedback()
        : m_resource_map()
        , m_resource(nullptr)
        , m_global(nullptr)
    {
    }

    wp_presentation_feedback::~wp_presentation_feedback()
    {
        for (auto resource : qAsConst(m_resource_map))
            resource->wp_presentation_feedback_object = nullptr;

        if (m_resource)
            m_resource->wp_presentation_feedback_object = nullptr;

        if (m_global) {
            wl_global_destroy(m_global);
            wl_list_remove(&m_displayDestroyedListener.link);
        }
    }

    void wp_presentation_feedback::init(struct ::wl_client *client, uint32_t id, int version)
    {
        m_resource = bind(client, id, version);
    }

    void wp_presentation_feedback::init(struct ::wl_resource *resource)
    {
        m_resource = bind(resource);
    }

    wp_presentation_feedback::Resource *wp_presentation_feedback::add(struct ::wl_client *client, int version)
    {
        Resource *resource = bind(client, 0, version);
        m_resource_map.insert(client, resource);
        return resource;
    }

    wp_presentation_feedback::Resource *wp_presentation_feedback::add(struct ::wl_client *client, uint32_t id, int version)
    {
        Resource *resource = bind(client, id, version);
        m_resource_map.insert(client, resource);
        return resource;
    }

    void wp_presentation_feedback::init(struct ::wl_display *display, int version)
    {
        m_global = wl_global_create(display, &::wp_presentation_feedback_interface, version, this, bind_func);
        m_displayDestroyedListener.notify = wp_presentation_feedback::display_destroy_func;
        m_displayDestroyedListener.parent = this;
        wl_display_add_destroy_listener(display, &m_displayDestroyedListener);
    }

    const struct wl_interface *wp_presentation_feedback::interface()
    {
        return &::wp_presentation_feedback_interface;
    }

    wp_presentation_feedback::Resource *wp_presentation_feedback::wp_presentation_feedback_allocate()
    {
        return new Resource;
    }

    void wp_presentation_feedback::wp_presentation_feedback_bind_resource(Resource *)
    {
    }

    void wp_presentation_feedback::wp_presentation_feedback_destroy_resource(Resource *)
    {
    }

    void wp_presentation_feedback::bind_func(struct ::wl_client *client, void *data, uint32_t version, uint32_t id)
    {
        wp_presentation_feedback *that = static_cast<wp_presentation_feedback *>(data);
        that->add(client, id, version);
    }

    void wp_presentation_feedback::display_destroy_func(struct ::wl_listener *listener, void *data)
    {
        Q_UNUSED(data);
        wp_presentation_feedback *that = static_cast<wp_presentation_feedback::DisplayDestroyedListener *>(listener)->parent;
        that->m_global = nullptr;
    }

    void wp_presentation_feedback::destroy_func(struct ::wl_resource *client_resource)
    {
        Resource *resource = Resource::fromResource(client_resource);
        Q_ASSERT(resource);
        wp_presentation_feedback *that = resource->wp_presentation_feedback_object;
        if (Q_LIKELY(that)) {
            that->m_resource_map.remove(resource->client(), resource);
            that->wp_presentation_feedback_destroy_resource(resource);

            that = resource->wp_presentation_feedback_object;
            if (that && that->m_resource == resource)
                that->m_resource = nullptr;
        }
        delete resource;
    }

    wp_presentation_feedback::Resource *wp_presentation_feedback::bind(struct ::wl_client *client, uint32_t id, int version)
    {
        Q_ASSERT_X(!wl_client_get_object(client, id), "QWaylandObject bind", QStringLiteral("binding to object %1 more than once").arg(id).toLocal8Bit().constData());
        struct ::wl_resource *handle = wl_resource_create(client, &::wp_presentation_feedback_interface, version, id);
        return bind(handle);
    }

    wp_presentation_feedback::Resource *wp_presentation_feedback::bind(struct ::wl_resource *handle)
    {
        Resource *resource = wp_presentation_feedback_allocate();
        resource->wp_presentation_feedback_object = this;

        wl_resource_set_implementation(handle, nullptr, resource, destroy_func);
        resource->handle = handle;
        wp_presentation_feedback_bind_resource(resource);
        return resource;
    }
    wp_presentation_feedback::Resource *wp_presentation_feedback::Resource::fromResource(struct ::wl_resource *resource)
    {
        if (Q_UNLIKELY(!resource))
            return nullptr;
        if (wl_resource_instance_of(resource, &::wp_presentation_feedback_interface, nullptr))
            return static_cast<Resource *>(wl_resource_get_user_data(resource));
        return nullptr;
    }

    void wp_presentation_feedback::send_sync_output(struct ::wl_resource *output)
    {
        Q_ASSERT_X(m_resource, "wp_presentation_feedback::sync_output", "Uninitialised resource");
        if (Q_UNLIKELY(!m_resource)) {
            qWarning("could not call wp_presentation_feedback::sync_output as it's not initialised");
            return;
        }
        send_sync_output(
            m_resource->handle,
            output);
    }

    void wp_presentation_feedback::send_sync_output(struct ::wl_resource *resource, struct ::wl_resource *output)
    {
        wp_presentation_feedback_send_sync_output(
            resource,
            output);
    }


    void wp_presentation_feedback::send_presented(uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec, uint32_t refresh, uint32_t seq_hi, uint32_t seq_lo, uint32_t flags)
    {
        Q_ASSERT_X(m_resource, "wp_presentation_feedback::presented", "Uninitialised resource");
        if (Q_UNLIKELY(!m_resource)) {
            qWarning("could not call wp_presentation_feedback::presented as it's not initialised");
            return;
        }
        send_presented(
            m_resource->handle,
            tv_sec_hi,
            tv_sec_lo,
            tv_nsec,
            refresh,
            seq_hi,
            seq_lo,
            flags);
    }

    void wp_presentation_feedback::send_presented(struct ::wl_resource *resource, uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec, uint32_t refresh, uint32_t seq_hi, uint32_t seq_lo, uint32_t flags)
    {
        wp_presentation_feedback_send_presented(
            resource,
            tv_sec_hi,
            tv_sec_lo,
            tv_nsec,
            refresh,
            seq_hi,
            seq_lo,
            flags);
    }


    void wp_presentation_feedback::send_discarded()
    {
        Q_ASSERT_X(m_resource, "wp_presentation_feedback::discarded", "Uninitialised resource");
        if (Q_UNLIKELY(!m_resource)) {
            qWarning("could not call wp_presentation_feedback::discarded as it's not initialised");
            return;
        }
        send_discarded(
            m_resource->handle);
    }

    void wp_presentation_feedback::send_discarded(struct ::wl_resource *resource)
    {
        wp_presentation_feedback_send_discarded(
            resource);
    }

}

QT_WARNING_POP
QT_END_NAMESPACE
