// This file was generated by qtwaylandscanner
// source file is /usr/share/treeland-protocols/treeland-wallpaper-manager-unstable-v1.xml

#include "qwayland-server-treeland-wallpaper-manager-unstable-v1.h"

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

namespace QtWaylandServer {

    int treeland_wallpaper_manager_v1::deferred_destroy_global_func(void *data) {
        auto object = static_cast<treeland_wallpaper_manager_v1 *>(data);
        wl_global_destroy(object->m_global);
        object->m_global = nullptr;
        wl_event_source_remove(object->m_globalRemovedEvent);
        object->m_globalRemovedEvent = nullptr;
        wl_list_remove(&object->m_displayDestroyedListener.link);
        object->destroy_global();
        return 0;
    }

    treeland_wallpaper_manager_v1::treeland_wallpaper_manager_v1(struct ::wl_client *client, int id, int version)
        : m_resource_map()
        , m_resource(nullptr)
        , m_global(nullptr)
        , m_display(nullptr)
        , m_globalRemovedEvent(nullptr)
    {
        init(client, id, version);
    }

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

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

    treeland_wallpaper_manager_v1::treeland_wallpaper_manager_v1()
        : m_resource_map()
        , m_resource(nullptr)
        , m_global(nullptr)
        , m_display(nullptr)
        , m_globalRemovedEvent(nullptr)
    {
    }

    treeland_wallpaper_manager_v1::~treeland_wallpaper_manager_v1()
    {
        for (auto resource : std::as_const(m_resource_map))
            resource->treeland_wallpaper_manager_v1_object = nullptr;

        if (m_resource)
            m_resource->treeland_wallpaper_manager_v1_object = nullptr;

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

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

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

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

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

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

    const struct wl_interface *treeland_wallpaper_manager_v1::interface()
    {
        return &::treeland_wallpaper_manager_v1_interface;
    }

    treeland_wallpaper_manager_v1::Resource *treeland_wallpaper_manager_v1::allocate()
    {
        return new Resource;
    }

    void treeland_wallpaper_manager_v1::destroy_global()
    {
    }

    void treeland_wallpaper_manager_v1::bind_resource(Resource *)
    {
    }

    void treeland_wallpaper_manager_v1::destroy_resource(Resource *)
    {
    }

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

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

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

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


    void treeland_wallpaper_manager_v1::globalRemove()
    {
        if (!m_global || m_globalRemovedEvent)
            return;

        wl_global_remove(m_global);

        struct wl_event_loop *event_loop = wl_display_get_event_loop(m_display);
        m_globalRemovedEvent = wl_event_loop_add_timer(event_loop, deferred_destroy_global_func, this);
        wl_event_source_timer_update(m_globalRemovedEvent, 5000);
    }

    treeland_wallpaper_manager_v1::Resource *treeland_wallpaper_manager_v1::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, &::treeland_wallpaper_manager_v1_interface, version, id);
        return bind(handle);
    }

    treeland_wallpaper_manager_v1::Resource *treeland_wallpaper_manager_v1::bind(struct ::wl_resource *handle)
    {
        Resource *resource = allocate();
        resource->treeland_wallpaper_manager_v1_object = this;

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

    const struct ::treeland_wallpaper_manager_v1_interface treeland_wallpaper_manager_v1::m_treeland_wallpaper_manager_v1_interface = {
        treeland_wallpaper_manager_v1::handle_destroy,
        treeland_wallpaper_manager_v1::handle_get_treeland_wallpaper
    };

    void treeland_wallpaper_manager_v1::destroy(Resource *resource)
    {
        Q_UNUSED(resource);
    }

    void treeland_wallpaper_manager_v1::get_treeland_wallpaper(Resource *resource, uint32_t id, struct ::wl_resource *output, struct ::wl_resource *surface)
    {
        Q_UNUSED(resource);
        Q_UNUSED(id);
        Q_UNUSED(output);
        Q_UNUSED(surface);
    }


    void treeland_wallpaper_manager_v1::handle_destroy(
        ::wl_client *client,
        struct wl_resource *resource)
    {
        Q_UNUSED(client);
        Resource *qResource = Resource::fromResource(resource);
        if (Q_UNLIKELY(!qResource->treeland_wallpaper_manager_v1_object)) {
            wl_resource_destroy(resource);
            return;
        }
        static_cast<treeland_wallpaper_manager_v1 *>(qResource->treeland_wallpaper_manager_v1_object)->destroy(
            qResource);
    }

    void treeland_wallpaper_manager_v1::handle_get_treeland_wallpaper(
        ::wl_client *client,
        struct wl_resource *resource,
        uint32_t id,
        struct ::wl_resource *output,
        struct ::wl_resource *surface)
    {
        Q_UNUSED(client);
        Resource *qResource = Resource::fromResource(resource);
        if (Q_UNLIKELY(!qResource->treeland_wallpaper_manager_v1_object)) {
            return;
        }
        static_cast<treeland_wallpaper_manager_v1 *>(qResource->treeland_wallpaper_manager_v1_object)->get_treeland_wallpaper(
            qResource,
            id,
            output,
            surface);
    }


    int treeland_wallpaper_v1::deferred_destroy_global_func(void *data) {
        auto object = static_cast<treeland_wallpaper_v1 *>(data);
        wl_global_destroy(object->m_global);
        object->m_global = nullptr;
        wl_event_source_remove(object->m_globalRemovedEvent);
        object->m_globalRemovedEvent = nullptr;
        wl_list_remove(&object->m_displayDestroyedListener.link);
        object->destroy_global();
        return 0;
    }

    treeland_wallpaper_v1::treeland_wallpaper_v1(struct ::wl_client *client, int id, int version)
        : m_resource_map()
        , m_resource(nullptr)
        , m_global(nullptr)
        , m_display(nullptr)
        , m_globalRemovedEvent(nullptr)
    {
        init(client, id, version);
    }

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

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

    treeland_wallpaper_v1::treeland_wallpaper_v1()
        : m_resource_map()
        , m_resource(nullptr)
        , m_global(nullptr)
        , m_display(nullptr)
        , m_globalRemovedEvent(nullptr)
    {
    }

    treeland_wallpaper_v1::~treeland_wallpaper_v1()
    {
        for (auto resource : std::as_const(m_resource_map))
            resource->treeland_wallpaper_v1_object = nullptr;

        if (m_resource)
            m_resource->treeland_wallpaper_v1_object = nullptr;

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

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

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

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

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

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

    const struct wl_interface *treeland_wallpaper_v1::interface()
    {
        return &::treeland_wallpaper_v1_interface;
    }

    treeland_wallpaper_v1::Resource *treeland_wallpaper_v1::allocate()
    {
        return new Resource;
    }

    void treeland_wallpaper_v1::destroy_global()
    {
    }

    void treeland_wallpaper_v1::bind_resource(Resource *)
    {
    }

    void treeland_wallpaper_v1::destroy_resource(Resource *)
    {
    }

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

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

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

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


    void treeland_wallpaper_v1::globalRemove()
    {
        if (!m_global || m_globalRemovedEvent)
            return;

        wl_global_remove(m_global);

        struct wl_event_loop *event_loop = wl_display_get_event_loop(m_display);
        m_globalRemovedEvent = wl_event_loop_add_timer(event_loop, deferred_destroy_global_func, this);
        wl_event_source_timer_update(m_globalRemovedEvent, 5000);
    }

    treeland_wallpaper_v1::Resource *treeland_wallpaper_v1::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, &::treeland_wallpaper_v1_interface, version, id);
        return bind(handle);
    }

    treeland_wallpaper_v1::Resource *treeland_wallpaper_v1::bind(struct ::wl_resource *handle)
    {
        Resource *resource = allocate();
        resource->treeland_wallpaper_v1_object = this;

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

    const struct ::treeland_wallpaper_v1_interface treeland_wallpaper_v1::m_treeland_wallpaper_v1_interface = {
        treeland_wallpaper_v1::handle_destroy,
        treeland_wallpaper_v1::handle_set_image_source,
        treeland_wallpaper_v1::handle_set_video_source
    };

    void treeland_wallpaper_v1::destroy(Resource *resource)
    {
        Q_UNUSED(resource);
    }

    void treeland_wallpaper_v1::set_image_source(Resource *resource, const QString &file_source, uint32_t role)
    {
        Q_UNUSED(resource);
        Q_UNUSED(file_source);
        Q_UNUSED(role);
    }

    void treeland_wallpaper_v1::set_video_source(Resource *resource, const QString &file_source, uint32_t role)
    {
        Q_UNUSED(resource);
        Q_UNUSED(file_source);
        Q_UNUSED(role);
    }


    void treeland_wallpaper_v1::handle_destroy(
        ::wl_client *client,
        struct wl_resource *resource)
    {
        Q_UNUSED(client);
        Resource *qResource = Resource::fromResource(resource);
        if (Q_UNLIKELY(!qResource->treeland_wallpaper_v1_object)) {
            wl_resource_destroy(resource);
            return;
        }
        static_cast<treeland_wallpaper_v1 *>(qResource->treeland_wallpaper_v1_object)->destroy(
            qResource);
    }

    void treeland_wallpaper_v1::handle_set_image_source(
        ::wl_client *client,
        struct wl_resource *resource,
        const char *file_source,
        uint32_t role)
    {
        Q_UNUSED(client);
        Resource *qResource = Resource::fromResource(resource);
        if (Q_UNLIKELY(!qResource->treeland_wallpaper_v1_object)) {
            return;
        }
        static_cast<treeland_wallpaper_v1 *>(qResource->treeland_wallpaper_v1_object)->set_image_source(
            qResource,
            QString::fromUtf8(file_source),
            role);
    }

    void treeland_wallpaper_v1::handle_set_video_source(
        ::wl_client *client,
        struct wl_resource *resource,
        const char *file_source,
        uint32_t role)
    {
        Q_UNUSED(client);
        Resource *qResource = Resource::fromResource(resource);
        if (Q_UNLIKELY(!qResource->treeland_wallpaper_v1_object)) {
            return;
        }
        static_cast<treeland_wallpaper_v1 *>(qResource->treeland_wallpaper_v1_object)->set_video_source(
            qResource,
            QString::fromUtf8(file_source),
            role);
    }

    void treeland_wallpaper_v1::send_failed(const QString &file_source, uint32_t error)
    {
        Q_ASSERT_X(m_resource, "treeland_wallpaper_v1::failed", "Uninitialised resource");
        if (Q_UNLIKELY(!m_resource)) {
            qWarning("could not call treeland_wallpaper_v1::failed as it's not initialised");
            return;
        }
        send_failed(
            m_resource->handle,
            file_source,
            error);
    }

    void treeland_wallpaper_v1::send_failed(struct ::wl_resource *resource, const QString &file_source, uint32_t error)
    {
        treeland_wallpaper_v1_send_failed(
            resource,
            file_source.toUtf8().constData(),
            error);
    }


    void treeland_wallpaper_v1::send_changed(uint32_t role, uint32_t source_type, const QString &file_source)
    {
        Q_ASSERT_X(m_resource, "treeland_wallpaper_v1::changed", "Uninitialised resource");
        if (Q_UNLIKELY(!m_resource)) {
            qWarning("could not call treeland_wallpaper_v1::changed as it's not initialised");
            return;
        }
        send_changed(
            m_resource->handle,
            role,
            source_type,
            file_source);
    }

    void treeland_wallpaper_v1::send_changed(struct ::wl_resource *resource, uint32_t role, uint32_t source_type, const QString &file_source)
    {
        treeland_wallpaper_v1_send_changed(
            resource,
            role,
            source_type,
            file_source.toUtf8().constData());
    }

}

QT_WARNING_POP
QT_END_NAMESPACE
