not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / libs / ksysguard / processui / KMonitorProcessIO.h
blob9a06f2c1a79d1e31d725565bf1f43bfa257d65ae
1 /*
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"
28 #include <kdialog.h>
29 #include <kprocess.h>
30 #include "processes.h"
32 class KDE_EXPORT KMonitorProcessIO : public KTextEditVT
34 Q_OBJECT
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 )
39 Q_ENUMS( State )
41 public:
42 KMonitorProcessIO(QWidget* parent, int pid = -1);
43 ~KMonitorProcessIO();
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.
50 * Default is 20 (ms)
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.
55 * Default is 20 (ms)
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;
70 public Q_SLOTS:
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*/
78 void detach();
79 /** Stop monitoring the given process */
80 void detach(int pid);
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. */
84 bool attach(int pid);
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. */
87 bool reattach();
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);
93 Q_SIGNALS:
94 void finished();
95 private Q_SLOTS:
96 /** Read in the next bit of data and display it. This should be called very frequently. */
97 void update(bool modified=false);
99 private:
100 KProcess mIOProcess;
101 KTextEditVT *mTextEdit;
102 QTimer mTimer;
103 int mPid;
104 QList<int> attached_pids;
106 int mUpdateInterval;
107 bool mIncludeChildProcesses;
108 bool remove_duplicates;
110 unsigned int lastdir;
111 QTextCursor mCursor;
114 #endif