File indexing completed on 2024-04-28 16:49:55

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