// // Created by grimmauld on 25.02.24. // #ifndef SWAYMUX_PSTREE_H #define SWAYMUX_PSTREE_H #define PROCFS_ROOT "/proc" #include #include #include #include #include #include #include #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) {} ProcessRecord() : name("rootItem"), pid(0), ppid(-1) {} [[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 { public: 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 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 static matchingRecord(const ProcessRecord &other) { return [&other](const ProcessTreeNode &node) { return node.proc == other; }; }; }; ProcessTreeNode * get_process_records(); void insert_process_record(const std::filesystem::path &status_path, std::map &buff); std::set update_process_records(ProcessTreeNode *node); #endif //SWAYMUX_PSTREE_H