File indexing completed on 2024-04-28 05:31:38
0001 /* 0002 SPDX-FileCopyrightText: 2019 David Edmundson <davidedmundson@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #pragma once 0007 0008 #include <QList> 0009 #include <QObject> 0010 #include <QVariant> 0011 0012 #include "processcore_export.h" 0013 0014 namespace KSysGuard 0015 { 0016 class Processes; 0017 class Process; 0018 class ProcessAttribute; 0019 0020 /** 0021 * Base class for a process plugin data 0022 * Plugins provide a list of additional attributes, which in turn have data about a given process 0023 */ 0024 class PROCESSCORE_EXPORT ProcessDataProvider : public QObject 0025 { 0026 Q_OBJECT 0027 0028 public: 0029 ProcessDataProvider(QObject *parent, const QVariantList &args); 0030 ~ProcessDataProvider() override; 0031 0032 /** 0033 * Accessors for process information matching 0034 */ 0035 KSysGuard::Processes *processes() const; 0036 0037 /** 0038 * Returns a new process object for a given PID 0039 * This will update the process list if this PID does not exist yet 0040 * This may return a null pointer 0041 */ 0042 KSysGuard::Process *getProcess(long pid); 0043 0044 /** 0045 * A list of all process attributes provided by this plugin 0046 * It is expected to remain constant through the lifespan of this class 0047 */ 0048 QList<ProcessAttribute *> attributes() const; 0049 0050 /** 0051 * Called when processes should be updated if manually polled 0052 * Plugins can however update at any time if enabled 0053 */ 0054 virtual void update() 0055 { 0056 } 0057 0058 /** 0059 * True when at least one attribute from this plugin is subscribed 0060 */ 0061 bool enabled() const; 0062 0063 virtual void handleEnabledChanged(bool enabled) 0064 { 0065 Q_UNUSED(enabled) 0066 } 0067 0068 // for any future compatibility 0069 virtual void virtual_hook(int id, void *data) 0070 { 0071 Q_UNUSED(id) 0072 Q_UNUSED(data) 0073 } 0074 0075 protected: 0076 /** 0077 * Register a new process attribute 0078 * Process attributes should be created in the plugin constructor and must live for the duration the plugin 0079 */ 0080 void addProcessAttribute(ProcessAttribute *attribute); 0081 0082 private: 0083 class Private; 0084 QScopedPointer<Private> d; 0085 }; 0086 0087 }