1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
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, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Benjamin Grauer |
---|
13 | co-programmer: ... |
---|
14 | */ |
---|
15 | |
---|
16 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ |
---|
17 | |
---|
18 | #include "network_stats_widget.h" |
---|
19 | #include "network_monitor.h" |
---|
20 | |
---|
21 | #include "multi_type.h" |
---|
22 | |
---|
23 | #include "shell_command.h" |
---|
24 | |
---|
25 | SHELL_COMMAND(gui, NetworkStatsWidget, toggleGUI) |
---|
26 | ->setAlias("ProxyGui"); |
---|
27 | |
---|
28 | |
---|
29 | HostWidget::HostWidget(const std::string& name, const IP& ip) |
---|
30 | : GLGuiBox(OrxGui::Horizontal) |
---|
31 | { |
---|
32 | this->setName(name); |
---|
33 | this->setIP(ip); |
---|
34 | |
---|
35 | this->pack(&this->_name); |
---|
36 | this->pack(&this->_ip); |
---|
37 | } |
---|
38 | |
---|
39 | void HostWidget::showing() |
---|
40 | { |
---|
41 | this->_name.show(); |
---|
42 | this->_ip.show(); |
---|
43 | } |
---|
44 | |
---|
45 | void HostWidget::hiding() |
---|
46 | { |
---|
47 | this->_name.hide(); |
---|
48 | this->_ip.hide(); |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | //======================================================// |
---|
54 | |
---|
55 | |
---|
56 | ProxyWidget::ProxyWidget(const std::string& proxyName, const IP& ip) |
---|
57 | : _proxyWidget(proxyName, ip) |
---|
58 | { |
---|
59 | this->_clientNameWidth = 100.0f; |
---|
60 | this->pack(&_proxyWidget); |
---|
61 | } |
---|
62 | |
---|
63 | void ProxyWidget::addClient(const std::string& name, const IP& ip) |
---|
64 | { |
---|
65 | HostWidget* newClient = new HostWidget(name, ip); |
---|
66 | newClient->setNameWidth(this->_clientNameWidth); |
---|
67 | |
---|
68 | this->pack(newClient); |
---|
69 | |
---|
70 | if (this->isVisible()) |
---|
71 | newClient->show(); |
---|
72 | } |
---|
73 | |
---|
74 | bool ProxyWidget::removeClient(const IP& ip) |
---|
75 | { |
---|
76 | std::vector<HostWidget*>::iterator rmIt; |
---|
77 | for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt) |
---|
78 | { |
---|
79 | if (*(*rmIt) == ip) |
---|
80 | { |
---|
81 | delete (*rmIt); |
---|
82 | this->_clients.erase(rmIt); |
---|
83 | return true; |
---|
84 | } |
---|
85 | } |
---|
86 | return false; |
---|
87 | } |
---|
88 | |
---|
89 | bool ProxyWidget::removeClient(const std::string& name) |
---|
90 | { |
---|
91 | std::vector<HostWidget*>::iterator rmIt; |
---|
92 | for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt) |
---|
93 | { |
---|
94 | if (*(*rmIt) == name) |
---|
95 | { |
---|
96 | delete (*rmIt); |
---|
97 | this->_clients.erase(rmIt); |
---|
98 | return true; |
---|
99 | } |
---|
100 | } |
---|
101 | return false; |
---|
102 | |
---|
103 | } |
---|
104 | |
---|
105 | bool ProxyWidget::removeClient(const std::string& name, const IP& ip) |
---|
106 | { |
---|
107 | std::vector<HostWidget*>::iterator rmIt; |
---|
108 | for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt) |
---|
109 | { |
---|
110 | if (*(*rmIt) == ip && *(*rmIt) == name) |
---|
111 | { |
---|
112 | delete (*rmIt); |
---|
113 | this->_clients.erase(rmIt); |
---|
114 | return true; |
---|
115 | } |
---|
116 | } |
---|
117 | return false; |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | void ProxyWidget::setClientNameWidths(float width) |
---|
122 | { |
---|
123 | this->_clientNameWidth = width; |
---|
124 | for (unsigned int i = 0; i < this->_clients.size(); ++i) |
---|
125 | this->_clients[i]->setNameWidth(width); |
---|
126 | } |
---|
127 | |
---|
128 | void ProxyWidget::hiding() |
---|
129 | { |
---|
130 | this->_proxyWidget.hide(); |
---|
131 | for (unsigned int i = 0; i < this->_clients.size(); ++i) |
---|
132 | this->_clients[i]->hide(); |
---|
133 | } |
---|
134 | |
---|
135 | void ProxyWidget::showing() |
---|
136 | { |
---|
137 | this->_proxyWidget.show(); |
---|
138 | for (unsigned int i = 0; i < this->_clients.size(); ++i) |
---|
139 | this->_clients[i]->show(); |
---|
140 | } |
---|
141 | |
---|
142 | |
---|
143 | //======================================================// |
---|
144 | |
---|
145 | /** |
---|
146 | * @brief standard constructor |
---|
147 | */ |
---|
148 | NetworkStatsWidget::NetworkStatsWidget(const NetworkMonitor* monitor) |
---|
149 | : OrxGui::GLGuiFixedpositionBox(OrxGui::Center, OrxGui::Vertical), _thisHost("myName", IP(127, 0, 0 , 1)) |
---|
150 | { |
---|
151 | this->_monitor = monitor; |
---|
152 | |
---|
153 | /* |
---|
154 | this->_bar.setSize2D(100, 30); |
---|
155 | this->pack(&this->_valueText); |
---|
156 | this->_bar.setParent2D(&this->_valueText); |
---|
157 | |
---|
158 | this->_valueText.setChangedTextColor(Color::white); |
---|
159 | |
---|
160 | //this->setBackgroundTexture("maps/gui_element_background_2.png"); |
---|
161 | this->setBackgroundColor(Color(.5,.5,.5,1)); |
---|
162 | |
---|
163 | //this->_name.setBackgroundTexture(Texture()); |
---|
164 | //this->_valueText.setBackgroundTexture("maps/gui_element_background_2.png"); |
---|
165 | this->_bar.setBackgroundTexture(Texture()); |
---|
166 | this->_bar.setBackgroundColor(Color(0,0,0,0)); |
---|
167 | this->_bar.setForegroundTexture("maps/gui_element_background_faded.png"); |
---|
168 | this->_bar.setForegroundColor(Color(.5, .5, .5, 1)); |
---|
169 | this->_bar.setChangedValueColor(Color::black); |
---|
170 | */ |
---|
171 | this->_thisHostIs.setText(std::string("I am ") + _monitor->getLocalNode()->getPeerInfo()->getNodeTypeString()); |
---|
172 | |
---|
173 | this->pack(&this->_thisHostIs); |
---|
174 | |
---|
175 | this->pack(&this->_thisHost); |
---|
176 | |
---|
177 | this->pack(&this->_upstreamText); |
---|
178 | this->pack(&this->_downstreamText); |
---|
179 | |
---|
180 | |
---|
181 | this->pack(&this->_serverBox); |
---|
182 | |
---|
183 | |
---|
184 | this->_refreshButton.setLabel("refresh"); |
---|
185 | this->_refreshButton.released.connect(this, &NetworkStatsWidget::rebuild); |
---|
186 | this->pack(&this->_refreshButton); |
---|
187 | } |
---|
188 | |
---|
189 | |
---|
190 | /** |
---|
191 | * @brief standard deconstructor |
---|
192 | */ |
---|
193 | NetworkStatsWidget::~NetworkStatsWidget () |
---|
194 | {} |
---|
195 | |
---|
196 | NetworkStatsWidget* NetworkStatsWidget::_statsWidget = NULL; |
---|
197 | |
---|
198 | #include "class_list.h" |
---|
199 | |
---|
200 | void NetworkStatsWidget::toggleGUI() |
---|
201 | { |
---|
202 | BaseObject* bo = NULL; |
---|
203 | const std::list<BaseObject*>* ls = ClassList::getList(CL_NETWORK_MONITOR); |
---|
204 | if (ls != NULL && !ls->empty()) |
---|
205 | bo = ls->front(); |
---|
206 | |
---|
207 | printf("==== %p\n", bo); |
---|
208 | |
---|
209 | if (bo != NULL && NetworkStatsWidget::_statsWidget == NULL) |
---|
210 | { |
---|
211 | NetworkStatsWidget::_statsWidget = new NetworkStatsWidget(dynamic_cast<NetworkMonitor*> (bo)); |
---|
212 | NetworkStatsWidget::_statsWidget->showAll(); |
---|
213 | } |
---|
214 | else |
---|
215 | { |
---|
216 | delete NetworkStatsWidget::_statsWidget; |
---|
217 | NetworkStatsWidget::_statsWidget = NULL; |
---|
218 | } |
---|
219 | } |
---|
220 | |
---|
221 | |
---|
222 | void NetworkStatsWidget::setMaximum(float max) |
---|
223 | { |
---|
224 | // this->_bar.setMaximum(max); |
---|
225 | } |
---|
226 | |
---|
227 | void NetworkStatsWidget::setValue(float value) |
---|
228 | { |
---|
229 | MultiType val(value); |
---|
230 | val.setType(MT_INT); |
---|
231 | /* |
---|
232 | |
---|
233 | this->_bar.setValue(value); |
---|
234 | this->_bar.setForegroundColor(Color::slerpHSVColor(Color::red, Color::green, value/this->_bar.maximum())); |
---|
235 | this->_bar.setFrontColor(Color(1,1,1,1), true); |
---|
236 | this->_valueText.setText(val.getString()); |
---|
237 | */ |
---|
238 | } |
---|
239 | |
---|
240 | |
---|
241 | void NetworkStatsWidget::addProxy(const std::string& name, const IP& proxy) |
---|
242 | {} |
---|
243 | |
---|
244 | void clearProxies(); |
---|
245 | |
---|
246 | |
---|
247 | void NetworkStatsWidget::rebuild() |
---|
248 | { |
---|
249 | while (!this->_proxies.empty()) |
---|
250 | { |
---|
251 | delete this->_proxies.back(); |
---|
252 | this->_proxies.pop_back(); |
---|
253 | } |
---|
254 | |
---|
255 | |
---|
256 | |
---|
257 | } |
---|
258 | |
---|
259 | |
---|
260 | |
---|
261 | void NetworkStatsWidget::tick(float dt) |
---|
262 | { |
---|
263 | assert (this->_monitor->getLocalNode() != NULL); |
---|
264 | assert(this->_monitor->getLocalNode()->getPeerInfo() != NULL); |
---|
265 | |
---|
266 | if(this->_monitor->getLocalNode()->getPeerInfo()->connectionMonitor != NULL) |
---|
267 | { |
---|
268 | ConnectionMonitor* mon = this->_monitor->getLocalNode()->getPeerInfo()->connectionMonitor; |
---|
269 | |
---|
270 | this->_upstreamText.setText(MultiType(mon->getOutgoingZippedBandWidth()).getString()); |
---|
271 | this->_downstreamText.setText(MultiType(mon->getIncomingZippedBandWidth()).getString()); |
---|
272 | } |
---|
273 | } |
---|
274 | |
---|
275 | void NetworkStatsWidget::resize() |
---|
276 | { |
---|
277 | GLGuiFixedpositionBox::resize(); |
---|
278 | } |
---|
279 | |
---|
280 | |
---|
281 | void NetworkStatsWidget::showing() |
---|
282 | {} |
---|
283 | |
---|
284 | void NetworkStatsWidget::hiding() |
---|
285 | {} |
---|