#include "qwayland-shm-emulation-server-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_shm_emulation_server_buffer::qt_shm_emulation_server_buffer(struct ::wl_registry *registry, int id, int version)
    {
        init(registry, id, version);
    }

    qt_shm_emulation_server_buffer::qt_shm_emulation_server_buffer(struct ::qt_shm_emulation_server_buffer *obj)
        : m_qt_shm_emulation_server_buffer(obj)
    {
        init_listener();
    }

    qt_shm_emulation_server_buffer::qt_shm_emulation_server_buffer()
        : m_qt_shm_emulation_server_buffer(nullptr)
    {
    }

    qt_shm_emulation_server_buffer::~qt_shm_emulation_server_buffer()
    {
    }

    void qt_shm_emulation_server_buffer::init(struct ::wl_registry *registry, int id, int version)
    {
        m_qt_shm_emulation_server_buffer = static_cast<struct ::qt_shm_emulation_server_buffer *>(wlRegistryBind(registry, id, &qt_shm_emulation_server_buffer_interface, version));
        init_listener();
    }

    void qt_shm_emulation_server_buffer::init(struct ::qt_shm_emulation_server_buffer *obj)
    {
        m_qt_shm_emulation_server_buffer = obj;
        init_listener();
    }

    qt_shm_emulation_server_buffer *qt_shm_emulation_server_buffer::fromObject(struct ::qt_shm_emulation_server_buffer *object)
    {
        if (wl_proxy_get_listener((struct ::wl_proxy *)object) != (void *)&m_qt_shm_emulation_server_buffer_listener)
            return nullptr;
        return static_cast<qt_shm_emulation_server_buffer *>(qt_shm_emulation_server_buffer_get_user_data(object));
    }

    bool qt_shm_emulation_server_buffer::isInitialized() const
    {
        return m_qt_shm_emulation_server_buffer != nullptr;
    }

    const struct wl_interface *qt_shm_emulation_server_buffer::interface()
    {
        return &::qt_shm_emulation_server_buffer_interface;
    }

    void qt_shm_emulation_server_buffer::shm_emulation_server_buffer_server_buffer_created(struct ::qt_server_buffer *, const QString &, int32_t , int32_t , int32_t , int32_t )
    {
    }

    void qt_shm_emulation_server_buffer::handle_server_buffer_created(
        void *data,
        struct ::qt_shm_emulation_server_buffer *object,
        struct ::qt_server_buffer *id,
        const char *key,
        int32_t width,
        int32_t height,
        int32_t bytes_per_line,
        int32_t format)
    {
        Q_UNUSED(object);
        static_cast<qt_shm_emulation_server_buffer *>(data)->shm_emulation_server_buffer_server_buffer_created(
            id,
            QString::fromUtf8(key),
            width,
            height,
            bytes_per_line,
            format);
    }

    const struct qt_shm_emulation_server_buffer_listener qt_shm_emulation_server_buffer::m_qt_shm_emulation_server_buffer_listener = {
        qt_shm_emulation_server_buffer::handle_server_buffer_created
    };

    void qt_shm_emulation_server_buffer::init_listener()
    {
        qt_shm_emulation_server_buffer_add_listener(m_qt_shm_emulation_server_buffer, &m_qt_shm_emulation_server_buffer_listener, this);
    }
}

QT_WARNING_POP
QT_END_NAMESPACE
