File indexing completed on 2024-04-28 16:49:52
0001 /* 0002 SPDX-FileCopyrightText: 2019 David Edmundson <davidedmundson@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QScopedPointer> 0010 #include <QString> 0011 #include <QVector> 0012 0013 #include <KService> 0014 0015 namespace KSysGuard 0016 { 0017 class Process; 0018 class CGroupPrivate; 0019 0020 /** 0021 * @brief The CGroup class represents a cgroup. This could be a 0022 * service, slice or scope 0023 */ 0024 class Q_DECL_EXPORT CGroup 0025 { 0026 public: 0027 virtual ~CGroup(); 0028 /** 0029 * @brief id 0030 * @return The cgroup ID passed from the constructor 0031 */ 0032 QString id() const; 0033 0034 /** 0035 * @brief Returns metadata about the given service 0036 * Only applicable for .service entries and really only useful for applications. 0037 * This KService object is always valid, but may not correspond to a real desktop entry 0038 * @return 0039 */ 0040 KService::Ptr service() const; 0041 0042 /** 0043 * @brief The list of pids contained in this group. 0044 * @return A Vector of pids 0045 */ 0046 QVector<pid_t> pids() const; 0047 0048 /** 0049 * @internal 0050 */ 0051 void setPids(const QVector<pid_t> &pids); 0052 0053 /** 0054 * Request fetching the list of processes associated with this cgroup. 0055 * 0056 * This is done in a separate thread. Once it has completed, \p callback is 0057 * called with the list of pids of this cgroup. 0058 * 0059 * It is the callers responsibility to call setPids in response. 0060 * 0061 * \param context An object that is used to track if the caller still exists. 0062 * \param callback A callback that gets called once the list of pids has 0063 * been retrieved. 0064 */ 0065 void requestPids(QObject *context, std::function<void(QVector<pid_t>)> callback); 0066 0067 /** 0068 * Returns the base path to exposed cgroup information. Either /sys/fs/cgroup or /sys/fs/cgroup/unified as applicable 0069 * If cgroups are unavailable this will be an empty string 0070 */ 0071 static QString cgroupSysBasePath(); 0072 0073 private: 0074 /** 0075 * Create a new cgroup object for a given cgroup entry 0076 * The id is the fully formed separated path, such as 0077 * "system.slice/dbus.service" 0078 */ 0079 CGroup(const QString &id); 0080 0081 QScopedPointer<CGroupPrivate> d; 0082 friend class CGroupDataModel; 0083 friend class CGroupDataModelPrivate; 0084 }; 0085 0086 }