#include "qwayland-share-buffer.h"

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

namespace QtWayland {

static inline void *wlRegistryBind(struct ::wl_registry *registry, uint32_t name, const struct ::wl_interface *interface, uint32_t version)
{
    const uint32_t bindOpCode = 0;
#if (WAYLAND_VERSION_MAJOR == 1 && WAYLAND_VERSION_MINOR > 10) || WAYLAND_VERSION_MAJOR > 1
    return (void *) wl_proxy_marshal_constructor_versioned((struct wl_proxy *) registry,
        bindOpCode, interface, version, name, interface->name, version, nullptr);
#else
    return (void *) wl_proxy_marshal_constructor((struct wl_proxy *) registry,
        bindOpCode, interface, name, interface->name, version, nullptr);
#endif
}

    qt_share_buffer::qt_share_buffer(struct ::wl_registry *registry, int id, int version)
    {
        init(registry, id, version);
    }

    qt_share_buffer::qt_share_buffer(struct ::qt_share_buffer *obj)
        : m_qt_share_buffer(obj)
    {
        init_listener();
    }

    qt_share_buffer::qt_share_buffer()
        : m_qt_share_buffer(nullptr)
    {
    }

    qt_share_buffer::~qt_share_buffer()
    {
    }

    void qt_share_buffer::init(struct ::wl_registry *registry, int id, int version)
    {
        m_qt_share_buffer = static_cast<struct ::qt_share_buffer *>(wlRegistryBind(registry, id, &qt_share_buffer_interface, version));
        init_listener();
    }

    void qt_share_buffer::init(struct ::qt_share_buffer *obj)
    {
        m_qt_share_buffer = obj;
        init_listener();
    }

    qt_share_buffer *qt_share_buffer::fromObject(struct ::qt_share_buffer *object)
    {
        if (wl_proxy_get_listener((struct ::wl_proxy *)object) != (void *)&m_qt_share_buffer_listener)
            return nullptr;
        return static_cast<qt_share_buffer *>(qt_share_buffer_get_user_data(object));
    }

    bool qt_share_buffer::isInitialized() const
    {
        return m_qt_share_buffer != nullptr;
    }

    const struct wl_interface *qt_share_buffer::interface()
    {
        return &::qt_share_buffer_interface;
    }

    void qt_share_buffer::share_buffer_cross_buffer(struct ::qt_server_buffer *)
    {
    }

    void qt_share_buffer::handle_cross_buffer(
        void *data,
        struct ::qt_share_buffer *object,
        struct ::qt_server_buffer *buffer)
    {
        Q_UNUSED(object);
        static_cast<qt_share_buffer *>(data)->share_buffer_cross_buffer(
            buffer);
    }

    const struct qt_share_buffer_listener qt_share_buffer::m_qt_share_buffer_listener = {
        qt_share_buffer::handle_cross_buffer
    };

    void qt_share_buffer::init_listener()
    {
        qt_share_buffer_add_listener(m_qt_share_buffer, &m_qt_share_buffer_listener, this);
    }
}

QT_WARNING_POP
QT_END_NAMESPACE
