#include "qwayland-ivi-application.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
}

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

    ivi_surface::ivi_surface(struct ::ivi_surface *obj)
        : m_ivi_surface(obj)
    {
        init_listener();
    }

    ivi_surface::ivi_surface()
        : m_ivi_surface(nullptr)
    {
    }

    ivi_surface::~ivi_surface()
    {
    }

    void ivi_surface::init(struct ::wl_registry *registry, int id, int version)
    {
        m_ivi_surface = static_cast<struct ::ivi_surface *>(wlRegistryBind(registry, id, &ivi_surface_interface, version));
        init_listener();
    }

    void ivi_surface::init(struct ::ivi_surface *obj)
    {
        m_ivi_surface = obj;
        init_listener();
    }

    ivi_surface *ivi_surface::fromObject(struct ::ivi_surface *object)
    {
        if (wl_proxy_get_listener((struct ::wl_proxy *)object) != (void *)&m_ivi_surface_listener)
            return nullptr;
        return static_cast<ivi_surface *>(ivi_surface_get_user_data(object));
    }

    bool ivi_surface::isInitialized() const
    {
        return m_ivi_surface != nullptr;
    }

    const struct wl_interface *ivi_surface::interface()
    {
        return &::ivi_surface_interface;
    }

    void ivi_surface::destroy()
    {
        ivi_surface_destroy(
            m_ivi_surface);
        m_ivi_surface = nullptr;
    }

    void ivi_surface::ivi_surface_configure(int32_t , int32_t )
    {
    }

    void ivi_surface::handle_configure(
        void *data,
        struct ::ivi_surface *object,
        int32_t width,
        int32_t height)
    {
        Q_UNUSED(object);
        static_cast<ivi_surface *>(data)->ivi_surface_configure(
            width,
            height);
    }

    const struct ivi_surface_listener ivi_surface::m_ivi_surface_listener = {
        ivi_surface::handle_configure
    };

    void ivi_surface::init_listener()
    {
        ivi_surface_add_listener(m_ivi_surface, &m_ivi_surface_listener, this);
    }

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

    ivi_application::ivi_application(struct ::ivi_application *obj)
        : m_ivi_application(obj)
    {
    }

    ivi_application::ivi_application()
        : m_ivi_application(nullptr)
    {
    }

    ivi_application::~ivi_application()
    {
    }

    void ivi_application::init(struct ::wl_registry *registry, int id, int version)
    {
        m_ivi_application = static_cast<struct ::ivi_application *>(wlRegistryBind(registry, id, &ivi_application_interface, version));
    }

    void ivi_application::init(struct ::ivi_application *obj)
    {
        m_ivi_application = obj;
    }

    ivi_application *ivi_application::fromObject(struct ::ivi_application *object)
    {
        return static_cast<ivi_application *>(ivi_application_get_user_data(object));
    }

    bool ivi_application::isInitialized() const
    {
        return m_ivi_application != nullptr;
    }

    const struct wl_interface *ivi_application::interface()
    {
        return &::ivi_application_interface;
    }

    struct ::ivi_surface *ivi_application::surface_create(uint32_t ivi_id, struct ::wl_surface *surface)
    {
        return ivi_application_surface_create(
            m_ivi_application,
            ivi_id,
            surface);
    }
}

QT_WARNING_POP
QT_END_NAMESPACE
