~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to libs/ksysguard/processcore/processes_base_p.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  This file is part of the KDE project
 
2
 
 
3
    Copyright (C) 2007 John Tapsell <tapsell@kde.org>
 
4
 
 
5
    This library is free software; you can redistribute it and/or
 
6
    modify it under the terms of the GNU Library General Public
 
7
    License as published by the Free Software Foundation; either
 
8
    version 2 of the License, or (at your option) any later version.
 
9
 
 
10
    This library is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
    Library General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU Library General Public License
 
16
    along with this library; see the file COPYING.LIB.  If not, write to
 
17
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
    Boston, MA 02110-1301, USA.
 
19
 
 
20
*/
 
21
 
 
22
#ifndef PROCESSES_BASE_P_H
 
23
#define PROCESSES_BASE_P_H
 
24
 
 
25
#include <QSet>
 
26
#include <QObject>
 
27
#include "processes.h"
 
28
 
 
29
namespace KSysGuard
 
30
{
 
31
    class Process;
 
32
    /**
 
33
     * This class contains the specific code to get the processes from the given host.
 
34
     *
 
35
     * To port this to other operating systems you need to make a processes_(osname).cpp  file
 
36
     * which implements all of the function below.  If you need private functions/variables etc put them in
 
37
     * the Private class.
 
38
     *
 
39
     * @author John Tapsell <tapsell@kde.org>
 
40
     */
 
41
    class AbstractProcesses : public QObject
 
42
    {
 
43
        Q_OBJECT
 
44
 
 
45
        public:
 
46
 
 
47
            AbstractProcesses() { errorCode = Processes::Unknown; }
 
48
            virtual ~AbstractProcesses() {}
 
49
 
 
50
            /** \brief Get a set of the currently running process PIDs.
 
51
             *
 
52
             *  To get information about processes, this will be the first function called.
 
53
             */
 
54
            virtual QSet<long> getAllPids() = 0;
 
55
 
 
56
            /** \brief Return the parent PID for the given process PID.
 
57
             *
 
58
             *  For each of the PIDs that getAllPids() returns, getParentPid will be called.
 
59
             *  This is used to setup the tree structure.
 
60
             *  For a particular PID, this is guaranteed to be called before updateProcessInfo for that PID.
 
61
             *  However this may be called several times in a row before the updateProcessInfo is called, so be careful
 
62
             *  if you want to try to preserve state in Private.
 
63
             */
 
64
            virtual long getParentPid(long pid) = 0;
 
65
 
 
66
            /** \brief Fill in the given Process class with information for given PID.
 
67
             *
 
68
             *  This will be called for every PID, after getParentPid() has been called for the same parameter.
 
69
             *
 
70
             *  The process->pid process->ppid and process->parent  are all guaranteed
 
71
             *  to be filled in correctly and process->parent will be non null.
 
72
             */
 
73
            virtual bool updateProcessInfo(long pid, Process *process) = 0;
 
74
 
 
75
            /** \brief Send the specified named POSIX signal to the process given.
 
76
             *
 
77
             *  For example, to indicate for process 324 to STOP do:
 
78
             *  \code
 
79
             *    #include <signals.h>
 
80
             *     ...
 
81
             *
 
82
             *    KSysGuard::Processes::sendSignal(324, SIGSTOP);
 
83
             *  \endcode
 
84
             *
 
85
             */
 
86
            virtual bool sendSignal(long pid, int sig) = 0;
 
87
 
 
88
            /** \brief Set the priority for a process.
 
89
             *
 
90
             *  For the normal scheduler, this is usually from 19
 
91
             *  (very nice, lowest priority) to -20 (highest priority).  The default value for a process is 0.
 
92
             *
 
93
             *  This has no effect if the scheduler is not the normal one (SCHED_OTHER in Linux).
 
94
             *
 
95
             *  @return false if you do not have permission to set the priority.
 
96
             */
 
97
            virtual bool setNiceness(long pid, int priority) = 0;
 
98
 
 
99
            /** \brief Set the scheduler for a process.
 
100
             *
 
101
             * This is defined according to POSIX.1-2001
 
102
             *  See "man sched_setscheduler" for more information.
 
103
             *
 
104
             *  @p priorityClass One of SCHED_FIFO, SCHED_RR, SCHED_OTHER, and SCHED_BATCH
 
105
             *  @p priority Set to 0 for SCHED_OTHER and SCHED_BATCH.  Between 1 and 99 for SCHED_FIFO and SCHED_RR
 
106
             *  @return false if you do not have permission to set the priority
 
107
             */
 
108
            virtual bool setScheduler(long pid, int priorityClass, int priority) = 0;
 
109
 
 
110
            /** \brief Return the total amount of physical memory in KiB.
 
111
             *
 
112
             *  This is fast (just a system call in most OSes)
 
113
             *  Returns 0 on error
 
114
             */
 
115
            virtual long long totalPhysicalMemory() = 0;
 
116
 
 
117
            /** \brief Set the i/o priority for a process.
 
118
             *
 
119
             *  This is from 7 (very nice, lowest i/o priority) to
 
120
             *  0 (highest priority).  The default value is determined as: io_nice = (cpu_nice + 20) / 5.
 
121
             *
 
122
             *  @return false if you do not have permission to set the priority
 
123
             */
 
124
            virtual bool setIoNiceness(long pid, int priorityClass, int priority) = 0;
 
125
 
 
126
            /** \brief Returns true if ionice is supported on this system
 
127
             */
 
128
            virtual bool supportsIoNiceness() = 0;
 
129
 
 
130
            /** \brief Return the number of processor cores enabled.
 
131
             *
 
132
             *  (A system can disable processors.  Disabled processors are not counted here).
 
133
             *  This is fast (just a system call on most OSes) */
 
134
            virtual long numberProcessorCores() = 0;
 
135
 
 
136
            /** \brief Update the process information for all processes.
 
137
             *
 
138
             *  Get all the current process information from the machine.  When done, emit updateAllProcesses().
 
139
             */
 
140
            virtual void updateAllProcesses( Processes::UpdateFlags updateFlags ) = 0;
 
141
 
 
142
            Processes::Error errorCode;
 
143
Q_SIGNALS:
 
144
            /** \brief This is emitted when the processes have been updated, and the view should be refreshed.
 
145
             */
 
146
            void processesUpdated();
 
147
    };
 
148
}
 
149
 
 
150
#endif // PROCESSES_BASE_P_H