summaryrefslogtreecommitdiffstats
path: root/ksim/monitors/net/netdevices.h
blob: 2a5a680966a7033aed9d3e50354cf5e50e6b1695 (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
/*  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 NETDEVICES_H
#define NETDEVICES_H

#include <chart.h>
#include <led.h>

class NetData
{
  public:
    NetData() : in(0), out(0) {}
    NetData &operator=( const NetData & rhs )
    {
      in = rhs.in;
      out = rhs.out;

      return *this;
    }

    unsigned long in;
    unsigned long out;
};

class Network
{
  public:
    typedef QValueList<Network> List;

    Network()
    {
      m_chart = 0;
      m_led = 0;
      m_label = 0;
      m_popup = 0;

      m_max = 0;
    }

    Network( const QString & name,
       const QString & format,
       bool timer,
       bool commands,
       const QString & cCommand,
       const QString & dCommand )
       : m_name( name ),
       m_format( format ),
       m_timer( timer ),
       m_commands( commands ),
       m_cCommand( cCommand ),
       m_dCommand( dCommand )
    {
      m_chart = 0;
      m_led = 0;
      m_label = 0;
      m_popup = 0;

      m_max = 0;
    }

    bool operator==( const Network & rhs ) const
    {
      return m_name == rhs.m_name &&
         m_format == rhs.m_format &&
         m_timer == rhs.m_timer &&
         m_commands == rhs.m_commands &&
         m_cCommand == rhs.m_cCommand &&
         m_dCommand == rhs.m_dCommand;
    }

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

    bool operator<( const Network & rhs ) const
    {
      return m_name < rhs.m_name;
    }

    bool operator>( const Network & rhs ) const
    {
      return m_name > rhs.m_name;
    }

    bool operator<=( const Network & rhs ) const
    {
      return !( *this > rhs );
    }

    void cleanup()
    {
      delete m_chart;
      delete m_label;
      delete m_led;
      delete m_popup;

      m_chart = 0;
      m_label = 0;
      m_led = 0;
      m_popup = 0;
    }

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

    const NetData & data() const
    {
      return m_data;
    }

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

    void setMaxValue( int max )
    {
      m_max = max;
    }

    int maxValue() const
    {
      return m_max;
    }

    const QString & name() const
    {
      return m_name;
    }

    bool showTimer() const
    {
      return m_timer;
    }

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

    bool commandsEnabled() const
    {
      return m_commands;
    }

    const QString & connectCommand() const
    {
      return m_cCommand;
    }

    const QString & disconnectCommand() const
    {
      return m_dCommand;
    }

    void setDisplay( KSim::Chart * chart, KSim::LedLabel * led,
       KSim::Label * label, QPopupMenu * popup )
    {
      m_chart = chart;
      m_led = led;
      m_label = label;
      m_popup = popup;
    }

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

    KSim::LedLabel * led()
    {
      return m_led;
    }

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

  private:
    NetData m_data;
    NetData m_old;
    QString m_name;
    QString m_format;
    bool m_timer;
    bool m_commands;
    QString m_cCommand;
    QString m_dCommand;

    KSim::Chart * m_chart;
    KSim::LedLabel * m_led;
    KSim::Label * m_label;
    QPopupMenu * m_popup;

    int m_max;
};
#endif