libDwm-0.9.45
DwmProcessTree.hh
Go to the documentation of this file.
1//===========================================================================
2// @(#) $DwmPath$
3//===========================================================================
4// Copyright (c) Daniel W. McRobb 2024
5// All rights reserved.
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions
9// are met:
10//
11// 1. Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// 2. Redistributions in binary form must reproduce the above copyright
14// notice, this list of conditions and the following disclaimer in the
15// documentation and/or other materials provided with the distribution.
16// 3. The names of the authors and copyright holders may not be used to
17// endorse or promote products derived from this software without
18// specific prior written permission.
19//
20// IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
21// DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
22// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
23// EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
24// DAMAGE.
25//
26// THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
27// DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
28// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
29// REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
30// IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31// WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
32// OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
33// TRADEMARK OR OTHER RIGHTS.
34//===========================================================================
35
36//---------------------------------------------------------------------------
40//---------------------------------------------------------------------------
41
42#include "DwmProcessTable.hh"
43
44namespace Dwm {
45
46 //--------------------------------------------------------------------------
48 //--------------------------------------------------------------------------
50 {
51 public:
52 //------------------------------------------------------------------------
54 //------------------------------------------------------------------------
55 ProcessTree() = default;
56 ProcessTree(const ProcessTree &) = default;
57 ProcessTree(ProcessTree &&) = default;
58 ProcessTree & operator = (const ProcessTree &) = default;
59 ProcessTree & operator = (ProcessTree &&) = default;
60
61 //------------------------------------------------------------------------
63 //------------------------------------------------------------------------
64 ProcessTree(pid_t pid);
65
66 //------------------------------------------------------------------------
68 //------------------------------------------------------------------------
69 inline const ProcessInfo & ProcInfo() const
70 { return _processInfo; }
71
72 //------------------------------------------------------------------------
74 //------------------------------------------------------------------------
75 inline const std::map<pid_t,ProcessTree> & Children() const
76 { return _children; }
77
78 //------------------------------------------------------------------------
81 //------------------------------------------------------------------------
82 friend std::ostream &
83 operator << (std::ostream & os, const ProcessTree & pt);
84
85 //------------------------------------------------------------------------
87 //------------------------------------------------------------------------
88 nlohmann::json ToJson() const;
89
90 //------------------------------------------------------------------------
92 //------------------------------------------------------------------------
93 friend bool ToJson(const ProcessTree & processTree, nlohmann::json & json);
94
95 private:
96 ProcessInfo _processInfo;
97 std::map<pid_t,ProcessTree> _children;
98
99 ProcessTree(const ProcessTable & pt, const ProcessInfo & procInfo);
100 void AddChildren(const ProcessTable & pt);
101 std::ostream & Print(std::ostream & os, std::string indent) const;
102 };
103
104 //--------------------------------------------------------------------------
106 //--------------------------------------------------------------------------
107 bool ToJson(const ProcessTree & processTree, nlohmann::json & json);
108
109} // namespace Dwm
Dwm::ProcessTable typedef and utility function prototypes.
std::map< pid_t, Dwm::ProcessInfo > ProcessTable
We represent a process table as a map of Dwm::Process keyed by process ID.
Definition DwmProcessTable.hh:55
Encapsulate information for a single process from the process table.
Definition DwmProcessInfo.hh:62
Encapsulates a process tree, i.e. a process and its descendants.
Definition DwmProcessTree.hh:50
ProcessTree(pid_t pid)
Create a process tree rooted at the given process ID pid.
const ProcessInfo & ProcInfo() const
Returns the process info for the process.
Definition DwmProcessTree.hh:69
ProcessTree()=default
Defaulted constructors and assignment operators.
friend std::ostream & operator<<(std::ostream &os, const ProcessTree &pt)
Prints the process tree to an ostream.
const std::map< pid_t, ProcessTree > & Children() const
Returns the children of the process.
Definition DwmProcessTree.hh:75