• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Konsole

ProcessInfo.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2007 by Robert Knight <robertknight@gmail.com>
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301  USA.
00018 */
00019 
00020 #ifndef PROCESSINFO_H
00021 #define PROCESSINFO_H
00022 
00023 // Qt
00024 #include <QtCore/QFile>
00025 #include <QtCore/QMap>
00026 #include <QtCore/QString>
00027 #include <QtCore/QVector>
00028 
00029 namespace Konsole
00030 {
00031 
00079 class ProcessInfo
00080 {
00081 public:
00093     static ProcessInfo* newInstance(int pid,bool readEnvironment = false);
00094 
00095     virtual ~ProcessInfo() {}
00096 
00101     void update();
00102 
00104     bool isValid() const;
00110     int pid(bool* ok) const;
00116     int parentPid(bool* ok) const;
00117     
00127     int foregroundPid(bool* ok) const;
00128     
00130     QString name(bool* ok) const;
00131    
00140     QVector<QString> arguments(bool* ok) const;
00149     QMap<QString,QString> environment(bool* ok) const;
00150 
00156     QString currentDir(bool* ok) const;
00157 
00176     QString format(const QString& text) const;
00177 
00182     enum Error
00183     {
00185         NoError,
00187         UnknownError,
00189         PermissionsError
00190     };
00191 
00195     Error error() const;
00196 
00197 protected:
00204     explicit ProcessInfo(int pid , bool readEnvironment = false);
00205 
00206 
00225     virtual bool readProcessInfo(int pid , bool readEnvironment) = 0;
00226 
00228     void setPid(int pid);
00230     void setParentPid(int pid);
00232     void setForegroundPid(int pid);
00234     void setName(const QString& name);
00236     void setCurrentDir(const QString& dir);
00237 
00239     void setError( Error error );
00240 
00242     void setFileError( QFile::FileError error ); 
00243 
00248     void addArgument(const QString& argument);
00256     void addEnvironmentBinding(const QString& name , const QString& value);
00257 
00258 
00259 
00260 private:
00261     // takes a full directory path and returns a
00262     // shortened version suitable for display in 
00263     // space-constrained UI elements (eg. tabs)
00264     QString formatShortDir(const QString& dirPath) const;
00265 
00266     enum CommandFormat
00267     {
00268         ShortCommandFormat,
00269         LongCommandFormat
00270     };
00271     // takes a process name and its arguments and produces formatted output
00272     QString formatCommand(const QString& name , const QVector<QString>& arguments , 
00273                           CommandFormat format) const;
00274 
00275     // valid bits for _fields variable, ensure that
00276     // _fields is changed to an int if more than 8 fields are added
00277     enum FIELD_BITS
00278     {
00279         PROCESS_ID          = 1,
00280         PARENT_PID          = 2,
00281         FOREGROUND_PID      = 4,
00282         ARGUMENTS           = 8,
00283         ENVIRONMENT         = 16,
00284         NAME                = 32,
00285         CURRENT_DIR         = 64
00286     };
00287 
00288 
00289     char _fields; // a bitmap indicating which fields are valid
00290                   // used to set the "ok" parameters for the public
00291                   // accessor functions
00292 
00293     bool _enableEnvironmentRead; // specifies whether to read the environment
00294                                  // bindings when update() is called
00295     int _pid;  
00296     int _parentPid;
00297     int _foregroundPid;
00298 
00299     Error _lastError;
00300 
00301     QString _name;
00302     QString _currentDir;
00303 
00304     QVector<QString> _arguments;
00305     QMap<QString,QString> _environment;
00306 
00307 
00308     static QSet<QString> commonDirNames();
00309     static QSet<QString> _commonDirNames;
00310 };
00311 
00319 class NullProcessInfo : public ProcessInfo
00320 {
00321 public:
00326     explicit NullProcessInfo(int pid,bool readEnvironment = false);
00327 protected:
00328     virtual bool readProcessInfo(int pid,bool readEnvironment);
00329 };
00330 
00335 class UnixProcessInfo : public ProcessInfo
00336 {
00337 public:
00342     explicit UnixProcessInfo(int pid,bool readEnvironment = false);
00343 protected:
00344     // reads the /proc/<pid>/stat file to get status information
00345     // about the process, also uses readEnvironment() and readArguments()
00346     // to read other files in /proc/<pid>
00347     virtual bool readProcessInfo(int pid , bool readEnvironment);
00348 
00349 private:
00350     bool readEnvironment(int pid);  // read the /proc/<pid/environ file
00351                                     // to get environment bindings
00352     bool readArguments(int pid);    // read the /proc/<pid>/cmdline file
00353                                     // to get command-line arguments
00354 
00355     bool readCurrentDir(int pid);   // read the /proc/<pid>/cwd symlink to
00356                                     // get the current working directory of the process
00357 };
00358 
00362 class SSHProcessInfo
00363 {
00364 public:
00371     SSHProcessInfo(const ProcessInfo& process);
00372 
00377     QString userName() const;
00378 
00382     QString host() const;
00383 
00388     QString command() const;
00389 
00403     QString format(const QString& input) const;
00404 
00405 private:
00406     const ProcessInfo& _process;
00407     QString _user;
00408     QString _host;
00409     QString _command;
00410 };
00411 
00412 }
00413 #endif //PROCESSINFO_H

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • Konsole
  • Libraries
  •   libkonq
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal