File indexing completed on 2024-05-12 17:00:15
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "GpuPlugin.h" 0008 0009 #include <KPluginFactory> 0010 #include <KLocalizedString> 0011 0012 #include <systemstats/SensorContainer.h> 0013 0014 #include "GpuDevice.h" 0015 #include "LinuxBackend.h" 0016 #include "AllGpus.h" 0017 0018 class GpuPlugin::Private 0019 { 0020 public: 0021 std::unique_ptr<KSysGuard::SensorContainer> container; 0022 std::unique_ptr<GpuBackend> backend; 0023 0024 AllGpus *allGpus = nullptr; 0025 }; 0026 0027 GpuPlugin::GpuPlugin(QObject *parent, const QVariantList &args) 0028 : SensorPlugin(parent, args) 0029 , d(std::make_unique<Private>()) 0030 { 0031 d->container = std::make_unique<KSysGuard::SensorContainer>(QStringLiteral("gpu"), i18nc("@title", "GPU"), this); 0032 0033 #ifdef Q_OS_LINUX 0034 d->backend = std::make_unique<LinuxBackend>(); 0035 #endif 0036 0037 if (d->backend) { 0038 connect(d->backend.get(), &GpuBackend::deviceAdded, this, [this](GpuDevice* device) { 0039 d->container->addObject(device); 0040 }); 0041 connect(d->backend.get(), &GpuBackend::deviceRemoved, this, [this](GpuDevice* device) { 0042 d->container->removeObject(device); 0043 }); 0044 d->backend->start(); 0045 0046 if (d->backend->deviceCount() > 0) { 0047 d->allGpus = new AllGpus(d->container.get()); 0048 } 0049 } 0050 } 0051 0052 GpuPlugin::~GpuPlugin() 0053 { 0054 d->container.reset(); 0055 if (d->backend) { 0056 d->backend->stop(); 0057 } 0058 } 0059 0060 void GpuPlugin::update() 0061 { 0062 if (d->backend) { 0063 d->backend->update(); 0064 } 0065 } 0066 0067 K_PLUGIN_CLASS_WITH_JSON(GpuPlugin, "metadata.json") 0068 0069 #include "GpuPlugin.moc"