summaryrefslogtreecommitdiffstats
path: root/ksim/monitors/cpu/ksimcpu.h
blob: a520b7b019ffc47c0aba964d844f39355bbbf7af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*  ksim - a system monitor for kde
 *
 *  Copyright (C) 2001  Robbie Ward <linuxphreak@gmx.co.uk>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef KSIMCPU_H
#define KSIMCPU_H

#include <pluginmodule.h>
#include <chart.h>
#include <progress.h>

#include <stdio.h>

class TQPushButton;
class TQTextStream;
class TQVBoxLayout;
class TQHBoxLayout;
class TQCheckBox;
class TQLabel;
class TQGroupBox;
class TQTimer;
class TQListViewItem;
class KListView;

class CpuPlugin : public KSim::PluginObject
{
  public:
    CpuPlugin(const char *name);
    ~CpuPlugin();

    virtual KSim::PluginView *createView(const char *);
    virtual KSim::PluginPage *createConfigPage(const char *);

    virtual void showAbout();
};

class CpuView : public KSim::PluginView
{
  Q_OBJECT
  TQ_OBJECT
  public:
    CpuView(KSim::PluginObject *parent, const char *name);
    ~CpuView();

    virtual void reparseConfig();

  private slots:
    void updateView();

  private:
    class CpuData
    {
      public:
        CpuData() { user = nice = sys = idle = 0; }

        TQString name;
        unsigned long user;
        unsigned long nice;
        unsigned long sys;
        unsigned long idle;

        CpuData &operator-=(const CpuData &rhs)
        {
          if (name != rhs.name)
            return *this;

          user -= rhs.user;
          nice -= rhs.nice;
          sys -= rhs.sys;
          idle -= rhs.idle;
          return *this;
        }
    };

    class Cpu
    {
      public:
        Cpu()
        {
          m_num = 0;
          m_chart = 0;
          m_label = 0;
        }

        Cpu(const TQString &name,
           const TQString &format,
           int number)
           : m_name(name),
           m_format(format),
           m_num(number)
        {
          m_chart = 0;
          m_label = 0;
        }

        ~Cpu()
        {
        }

        bool operator==(const Cpu &rhs) const
        {
          return m_name == rhs.m_name &&
             m_format == rhs.m_format;
        }

        bool operator!=(const Cpu &rhs) const
        {
          return !operator==(rhs);
        }

        void cleanup()
        {
          delete m_chart;
          delete m_label;
        }

        void setData(const CpuData &data)
        {
          m_old = m_data;
          m_data = data;
        }

        const CpuData &oldData() const
        {
          return m_old;
        }

        const TQString &format() const
        {
          return m_format;
        }

        int number() const
        {
          return m_num;
        }

        void setDisplay(KSim::Chart *chart, KSim::Progress *label)
        {
          m_chart = chart;
          m_label = label;
          m_label->setText(m_name);
        }

        KSim::Chart *chart()
        {
          return m_chart;
        }

        KSim::Progress *label()
        {
          return m_label;
        }

      private:
        CpuData m_data;
        CpuData m_old;
        TQString m_name;
        TQString m_format;
        KSim::Chart *m_chart;
        KSim::Progress *m_label;
        int m_num;
    };

    typedef TQValueList<Cpu> CpuList;
    void updateCpu(CpuData &cpu, int cpuNumber);
    CpuList createList();

    void addDisplay();
    void cleanup(CpuList &);

    KSim::Chart *addChart();
    KSim::Progress *addLabel();

    TQTimer *m_timer;
    TQVBoxLayout *m_mainLayout;
    bool m_firstTime;
    CpuList m_cpus;

#ifdef __linux__
    FILE *m_procFile;
    TQTextStream *m_procStream;
#endif
};

class CpuConfig : public KSim::PluginPage
{
  Q_OBJECT
  TQ_OBJECT
  public:
    CpuConfig(KSim::PluginObject *parent, const char *name);
    ~CpuConfig();

    virtual void saveConfig();
    virtual void readConfig();

  private slots:
    void modify( TQListViewItem * );
    void modify();

  private:
    uint addCpus();

    KListView *m_listView;
    TQGroupBox *m_legendBox;
    TQLabel *m_totalNiceLabel;
    TQLabel *m_totalLabel;
    TQLabel *m_sysLabel;
    TQLabel *m_userLabel;
    TQLabel *m_niceLabel;
    TQVBoxLayout *m_legendLayout;

    TQPushButton * m_modify;
};
#endif