Debian Codegraph @

src/hostinfo.h

raw
1 /*
2 This file is part of Icecream.
3
4 Copyright (c) 2004 Cornelius Schumacher <[email protected]>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program 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
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20 #ifndef ICEMON_HOSTINFO_H
21 #define ICEMON_HOSTINFO_H
22
23 #include <QString>
24 #include <QColor>
25 #include <QMap>
26 #include <QObject>
27 #include <QtCore/QVector>
28
29 class HostInfo
30 {
31 public:
32 explicit HostInfo(unsigned int id = 0);
33
34 unsigned int id() const { return mId; }
35
36 void setName(const QString &name) { mName = name; }
37 QString name() const { return mName; }
38
39 void setColor(const QColor &color) { mColor = color; }
40 QColor color() const { return mColor; }
41
42 void setIp(const QString &ip) { mIp = ip; }
43 QString ip() const { return mIp; }
44
45 void setPlatform(const QString &platform) { mPlatform = platform; }
46 QString platform() const { return mPlatform; }
47
48 void setMaxJobs(unsigned int jobs) { mMaxJobs = jobs; }
49 unsigned int maxJobs() const { return mMaxJobs; }
50 void incJobs() { mNumJobs++; }
51 void decJobs() { if (mNumJobs) mNumJobs--; }
52 unsigned int numJobs() const { return mNumJobs; }
53
54 void setOffline(bool offline) { mOffline = offline; }
55 bool isOffline() const { return mOffline; }
56
57 void setNoRemote(bool noRemote) { mNoRemote = noRemote; }
58 bool noRemote() const { return mNoRemote; }
59
60 using StatsMap = QMap<QString, QString>;
61 void updateFromStatsMap(const StatsMap &stats);
62
63 static void initColorTable();
64 static QString colorName(const QColor &);
65
66 void setServerSpeed(float serverSpeed) { mServerSpeed = serverSpeed; }
67 float serverSpeed() const { return mServerSpeed; }
68
69 void setServerLoad(unsigned int load) { mServerLoad = load; }
70 unsigned int serverLoad() const { return mServerLoad; }
71
72 void setProtocol(unsigned int protocol) { mProtocol = protocol; }
73 int protocol() const { return mProtocol; }
74
75 void setFeatures(const QString& features) { mFeatures = features; }
76 QString features() const { return mFeatures; }
77
78 QString toolTip() const;
79
80 bool operator==(const HostInfo &rhs) const { return mId == rhs.mId; }
81 bool operator!=(const HostInfo &rhs) const { return mId != rhs.mId; }
82 int operator<(const HostInfo &rhs) const { return mId < rhs.mId; }
83
84 protected:
85 // TODO: Move the whole color managing feature into a separate class
86 friend class FakeMonitor;
87 static void initColor(const QString &value, const QString &name);
88
89 QColor createColor();
90 QColor createColor(const QString &name);
91
92 private:
93 unsigned int mId = 0;
94 QString mName;
95 QColor mColor;
96 QString mPlatform;
97
98 QString mIp;
99
100 unsigned int mMaxJobs = 0;
101 unsigned int mNumJobs = 0;
102 bool mOffline = false;
103 bool mNoRemote = true;
104 int mProtocol = 0;
105 QString mFeatures;
106
107 float mServerSpeed = 0.0;
108 unsigned int mServerLoad = 0;
109
110 static QVector<QColor> mColorTable;
111 static QMap<int, QString> mColorNameMap;
112 };
113
114 class HostInfoManager
115 : public QObject
116 {
117 Q_OBJECT
118
119 public:
120 HostInfoManager();
121 ~HostInfoManager() override;
122
123 HostInfo *find(unsigned int hostid) const;
124
125 using HostMap = QMap<unsigned int, HostInfo *>;
126
127 HostMap hostMap() const;
128
129 void checkNode(const HostInfo &info);
130 HostInfo *checkNode(unsigned int hostid,
131 const HostInfo::StatsMap &statmsg);
132
133 QString nameForHost(unsigned int id) const;
134 QColor hostColor(unsigned int id) const;
135 unsigned int maxJobs(unsigned int id) const;
136
137 QString schedulerName() const { return mSchedulerName; }
138 void setSchedulerName(const QString &schedulerName);
139 QString networkName() const { return mNetworkName; }
140 void setNetworkName(const QString &networkName);
141
142 signals:
143 void hostMapChanged();
144
145 private:
146 HostMap mHostMap;
147 QString mSchedulerName;
148 QString mNetworkName;
149 };
150
151 #endif
152 // vim:ts=4:sw=4:noet