2 KSysGuard, the KDE System Guard
4 Copyright (c) 2008 John Tapsell <tapsell@kde.org>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
23 #ifndef _KMonitorProcessIO_h_
24 #define _KMonitorProcessIO_h_
26 #include <QtCore/QTimer>
27 #include "KTextEditVT.h"
30 #include "processes.h"
32 class KDE_EXPORT KMonitorProcessIO
: public KTextEditVT
35 Q_PROPERTY( bool includeChildProcesses READ includeChildProcesses WRITE setIncludeChildProcesses
)
36 Q_PROPERTY( bool updateInterval READ updateInterval WRITE setUpdateInterval
)
37 Q_PROPERTY( int attachedPid READ attachedPid WRITE attach
)
38 Q_PROPERTY( State status READ state WRITE setState
)
42 KMonitorProcessIO(QWidget
* parent
, int pid
= -1);
45 /** Whether to include the output from child processes. If true, forks and clones will be monitored */
46 bool includeChildProcesses() const;
48 /** Interval to poll for new ptrace input. Recommended around 20 (milliseconds). Note that the process
49 * being monitored cannot do anything if it is waiting for us to update.
52 int updateInterval() const;
53 /** Set interval to poll for new ptrace input. Recommended around 20 (milliseconds). Note that the process
54 * being monitored cannot do anything if it is waiting for us to update.
57 void setUpdateInterval(int msecs
);
59 /** Detached state indicates that we are not connected to the process and not monitoring it.
61 * AttachedRunning state indicates that we are attached to the process and displaying its output.
63 * AttachedPaused state indicates that we are attached but not reading its output. This will block the process until we resume or detach.
65 enum State
{ Detached
, AttachedRunning
, AttachedPaused
};
67 /** Return the current state. */
68 KMonitorProcessIO::State
state() const;
71 /** Set whether to include the output from child processes. If true, forks and clones will be monitored */
72 void setIncludeChildProcesses(bool include
);
73 /** If the state is in AttachedRunning, change to AttachedPaused. This will block the process until we resume or detach.*/
74 void pauseProcesses();
75 /** If the state is in AttachedPaused, change to AttachedRunning. This will allow the process to run again. */
76 void resumeProcesses();
77 /** Stop monitoring all processes*/
79 /** Stop monitoring the given process */
81 /** Start monitoring the given process. If this is the first process being monitored, the state is set to
82 * AttachedRunning if possible and attachedPid() will return @p pid
83 * @return true if successfully reattached. Can fail if process has disappeared or we do not have the right to attach. */
85 /** Reattach the pid that was first attached.
86 * @return true if successfully reattached. Can fail if process has disappeared or we do not have the right to attach. */
88 /** Return the main pid that we are monitoring.*/
89 int attachedPid() const;
90 /** Attempts to set the state. Check status() to confirm whether the state has changed successfully. */
91 void setState(State new_state
);
96 /** Read in the next bit of data and display it. This should be called very frequently. */
97 void update(bool modified
=false);
101 KTextEditVT
*mTextEdit
;
104 QList
<int> attached_pids
;
107 bool mIncludeChildProcesses
;
108 bool remove_duplicates
;
110 unsigned int lastdir
;