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, NetworkMonitor, 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 | : GLGuiBox(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->pack(&this->_thisHost); |
---|
172 | |
---|
173 | this->pack(&this->_upstreamText); |
---|
174 | this->pack(&this->_downstreamText); |
---|
175 | |
---|
176 | this->pack(&this->_serverIP); |
---|
177 | } |
---|
178 | |
---|
179 | |
---|
180 | /** |
---|
181 | * @brief standard deconstructor |
---|
182 | */ |
---|
183 | NetworkStatsWidget::~NetworkStatsWidget () |
---|
184 | {} |
---|
185 | |
---|
186 | |
---|
187 | void NetworkStatsWidget::setMaximum(float max) |
---|
188 | { |
---|
189 | // this->_bar.setMaximum(max); |
---|
190 | } |
---|
191 | |
---|
192 | void NetworkStatsWidget::setValue(float value) |
---|
193 | { |
---|
194 | MultiType val(value); |
---|
195 | val.setType(MT_INT); |
---|
196 | /* |
---|
197 | |
---|
198 | this->_bar.setValue(value); |
---|
199 | this->_bar.setForegroundColor(Color::slerpHSVColor(Color::red, Color::green, value/this->_bar.maximum())); |
---|
200 | this->_bar.setFrontColor(Color(1,1,1,1), true); |
---|
201 | this->_valueText.setText(val.getString()); |
---|
202 | */ |
---|
203 | } |
---|
204 | |
---|
205 | |
---|
206 | void NetworkStatsWidget::tick(float dt) |
---|
207 | { |
---|
208 | assert (this->_monitor->getLocalNode() != NULL); |
---|
209 | assert(this->_monitor->getLocalNode()->getPeerInfo() != NULL); |
---|
210 | |
---|
211 | if(this->_monitor->getLocalNode()->getPeerInfo()->connectionMonitor != NULL) |
---|
212 | { |
---|
213 | ConnectionMonitor* mon = this->_monitor->getLocalNode()->getPeerInfo()->connectionMonitor; |
---|
214 | |
---|
215 | this->_upstreamText.setText(MultiType(mon->getOutgoingZippedBandWidth()).getString()); |
---|
216 | this->_downstreamText.setText(MultiType(mon->getIncomingZippedBandWidth()).getString()); |
---|
217 | } |
---|
218 | } |
---|
219 | |
---|
220 | void NetworkStatsWidget::resize() |
---|
221 | { |
---|
222 | GLGuiBox::resize(); |
---|
223 | } |
---|
224 | |
---|
225 | |
---|
226 | void NetworkStatsWidget::showing() |
---|
227 | {} |
---|
228 | |
---|
229 | void NetworkStatsWidget::hiding() |
---|
230 | {} |
---|