2024-03-02 22:33:27 +01:00
|
|
|
//
|
|
|
|
// Created by grimmauld on 25.02.24.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef SWAYMUX_PSTREE_H
|
|
|
|
#define SWAYMUX_PSTREE_H
|
|
|
|
|
|
|
|
#define PROCFS_ROOT "/proc"
|
|
|
|
|
|
|
|
|
|
|
|
#include <filesystem>
|
|
|
|
#include <set>
|
|
|
|
#include <utility>
|
|
|
|
#include <map>
|
|
|
|
#include <functional>
|
|
|
|
#include <vector>
|
|
|
|
#include <QVariant>
|
|
|
|
#include "AbstractTreeNode.h"
|
|
|
|
|
|
|
|
void printTree();
|
|
|
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
|
|
|
class ProcessRecord {
|
|
|
|
public:
|
|
|
|
const std::string name;
|
|
|
|
const pid_t pid;
|
|
|
|
const pid_t ppid;
|
|
|
|
|
|
|
|
ProcessRecord(std::string name, pid_t pid, pid_t ppid) : name(std::move(name)), pid(pid), ppid(ppid) {}
|
|
|
|
|
2024-03-04 00:27:05 +01:00
|
|
|
ProcessRecord() : name("rootItem"), pid(0), ppid(-1) {}
|
2024-03-02 22:33:27 +01:00
|
|
|
|
|
|
|
[[nodiscard]] bool operator<(const ProcessRecord &other) const {
|
|
|
|
return this->pid < other.pid;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] bool operator==(const ProcessRecord &other) const {
|
|
|
|
return this->pid == other.pid && this->ppid == other.ppid && this->name == other.name;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ProcessTreeNode : public AbstractTreeNode<ProcessTreeNode> {
|
|
|
|
public:
|
2024-03-04 00:27:05 +01:00
|
|
|
ProcessTreeNode(ProcessTreeNode& node) = delete; // default constructor to make the static asserts shut up
|
|
|
|
ProcessTreeNode(const ProcessTreeNode& node) = delete; // default constructor to make the static asserts shut up
|
|
|
|
|
2024-03-02 22:33:27 +01:00
|
|
|
explicit ProcessTreeNode(ProcessTreeNode *parent = nullptr) : proc(ProcessRecord()), AbstractTreeNode(parent) {}
|
|
|
|
|
|
|
|
const ProcessRecord proc;
|
|
|
|
|
|
|
|
explicit ProcessTreeNode(ProcessRecord proc, ProcessTreeNode *parent = nullptr) : proc(std::move(proc)),
|
|
|
|
AbstractTreeNode(parent) {}
|
|
|
|
|
|
|
|
[[nodiscard]] bool operator<(const ProcessTreeNode &other) const {
|
|
|
|
return this->proc < other.proc;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] QVariant data(int column) const override;
|
|
|
|
|
|
|
|
[[nodiscard]] QVariant headerData(int column) const override;
|
|
|
|
|
|
|
|
[[nodiscard]] int columnCount() const override { return 2; };
|
|
|
|
|
|
|
|
std::function<bool(const ProcessTreeNode &)> static matchingRecord(const ProcessRecord &other) {
|
|
|
|
return [&other](const ProcessTreeNode &node) {
|
|
|
|
return node.proc == other;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-03-04 00:27:05 +01:00
|
|
|
ProcessTreeNode * get_process_records();
|
2024-03-02 22:33:27 +01:00
|
|
|
|
|
|
|
void insert_process_record(const std::filesystem::path &status_path, std::map<pid_t, ProcessRecord> &buff);
|
|
|
|
|
|
|
|
std::set<ProcessTreeNode*> update_process_records(ProcessTreeNode *node);
|
|
|
|
|
|
|
|
#endif //SWAYMUX_PSTREE_H
|