// Copyright (C) 2022 JiDe Zhang <zccrs@live.com>.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#pragma once

#include <qwglobal.h>
#include <QObject>

struct wlr_ABC;

QW_BEGIN_NAMESPACE

class QWABCPrivate;
class QW_EXPORT QWABC : public QWWrapObject
{
    Q_OBJECT
    QW_DECLARE_PRIVATE(QWABC)
public:
    inline wlr_ABC *handle() const {
        return QWObject::handle<wlr_ABC>();
    }

    static QWABC *get(wlr_ABC *handle);
    static QWABC *from(wlr_ABC *handle);

private:
    QWABC(wlr_ABC *handle, bool isOwner);
};

QW_END_NAMESPACE

// Copyright (C) 2022 JiDe Zhang <zccrs@live.com>.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qwabc.h"
#include "private/qwglobal_p.h"

#include <QHash>

extern "C" {
#include <wlr/types/wlr_abc.h>
}

QW_BEGIN_NAMESPACE

class QWABCPrivate : public QWWrapObjectPrivate
{
public:
    QWABCPrivate(wlr_ABC *handle, bool isOwner, QWABC *qq)
        : QWWrapObjectPrivate(handle, isOwner, qq, &handle->events.destroy,
                              toDestroyFunction(wlr_ABC_destroy))
    {

    }

    QW_DECLARE_PUBLIC(QWABC)
};

QWABC::QWABC(wlr_ABC *handle, bool isOwner)
    : QWWrapObject(*new QWABCPrivate(handle, isOwner, this))
{

}

QWABC *QWABC::get(wlr_ABC *handle)
{
    return static_cast<QWABC*>(QWABCPrivate::map.value(handle));
}

QWABC *QWABC::from(wlr_ABC *handle)
{
    if (auto o = get(handle))
        return o;
    return new QWABC(handle, false);
}

QW_END_NAMESPACE
