1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
/*
* SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "GpuPlugin.h"
#include <KPluginFactory>
#include <KLocalizedString>
#include <systemstats/SensorContainer.h>
#include "GpuDevice.h"
#include "LinuxBackend.h"
#include "FreeBSDBackend.h"
#include "AllGpus.h"
class GpuPlugin::Private
{
public:
std::unique_ptr<KSysGuard::SensorContainer> container;
std::unique_ptr<GpuBackend> backend;
AllGpus *allGpus = nullptr;
};
GpuPlugin::GpuPlugin(QObject *parent, const QVariantList &args)
: SensorPlugin(parent, args)
, d(std::make_unique<Private>())
{
d->container = std::make_unique<KSysGuard::SensorContainer>(QStringLiteral("gpu"), i18nc("@title", "GPU"), this);
#ifdef Q_OS_LINUX
d->backend = std::make_unique<LinuxBackend>();
#endif
#ifdef Q_OS_FREEBSD
d->backend = std::make_unique<FreeBSDBackend>();
#endif
if (d->backend) {
connect(d->backend.get(), &GpuBackend::deviceAdded, this, [this](GpuDevice* device) {
d->container->addObject(device);
});
connect(d->backend.get(), &GpuBackend::deviceRemoved, this, [this](GpuDevice* device) {
d->container->removeObject(device);
});
d->backend->start();
if (d->backend->deviceCount() > 0) {
d->allGpus = new AllGpus(d->container.get());
}
}
}
GpuPlugin::~GpuPlugin()
{
d->container.reset();
if (d->backend) {
d->backend->stop();
}
}
void GpuPlugin::update()
{
if (d->backend) {
d->backend->update();
}
}
K_PLUGIN_CLASS_WITH_JSON(GpuPlugin, "metadata.json")
#include "GpuPlugin.moc"
#include "moc_GpuPlugin.cpp"
|