[4744] | 1 | /* |
---|
[1853] | 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. |
---|
[1855] | 10 | |
---|
| 11 | ### File Specific: |
---|
[9014] | 12 | main-programmer: Benjamin Grauer |
---|
[1855] | 13 | co-programmer: ... |
---|
[1853] | 14 | */ |
---|
| 15 | |
---|
[3955] | 16 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ |
---|
[1853] | 17 | |
---|
[9330] | 18 | #include "network_stats_widget.h" |
---|
[9442] | 19 | #include "network_monitor.h" |
---|
[1853] | 20 | |
---|
[9369] | 21 | #include "multi_type.h" |
---|
| 22 | |
---|
[9444] | 23 | #include "shell_command.h" |
---|
| 24 | |
---|
| 25 | // SHELL_COMMAND(gui, NetworkMonitor, toggleGUI) |
---|
| 26 | // ->setAlias("ProxyGui"); |
---|
| 27 | |
---|
| 28 | |
---|
[9437] | 29 | HostWidget::HostWidget(const std::string& name, const IP& ip) |
---|
[9442] | 30 | : GLGuiBox(OrxGui::Horizontal) |
---|
[9437] | 31 | { |
---|
| 32 | this->setName(name); |
---|
| 33 | this->setIP(ip); |
---|
[9383] | 34 | |
---|
[9437] | 35 | this->pack(&this->_name); |
---|
| 36 | this->pack(&this->_ip); |
---|
| 37 | } |
---|
[9383] | 38 | |
---|
[9437] | 39 | void HostWidget::showing() |
---|
| 40 | { |
---|
| 41 | this->_name.show(); |
---|
| 42 | this->_ip.show(); |
---|
| 43 | } |
---|
[9383] | 44 | |
---|
[9437] | 45 | void HostWidget::hiding() |
---|
| 46 | { |
---|
| 47 | this->_name.hide(); |
---|
| 48 | this->_ip.hide(); |
---|
| 49 | } |
---|
[9383] | 50 | |
---|
| 51 | |
---|
| 52 | |
---|
[9437] | 53 | //======================================================// |
---|
[9383] | 54 | |
---|
| 55 | |
---|
[9437] | 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 | } |
---|
[9383] | 62 | |
---|
[9437] | 63 | void ProxyWidget::addClient(const std::string& name, const IP& ip) |
---|
| 64 | { |
---|
| 65 | HostWidget* newClient = new HostWidget(name, ip); |
---|
| 66 | newClient->setNameWidth(this->_clientNameWidth); |
---|
[9383] | 67 | |
---|
[9437] | 68 | this->pack(newClient); |
---|
[9383] | 69 | |
---|
[9437] | 70 | if (this->isVisible()) |
---|
| 71 | newClient->show(); |
---|
| 72 | } |
---|
[9383] | 73 | |
---|
[9437] | 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) |
---|
[9383] | 78 | { |
---|
[9437] | 79 | if (*(*rmIt) == ip) |
---|
[9383] | 80 | { |
---|
[9437] | 81 | delete (*rmIt); |
---|
| 82 | this->_clients.erase(rmIt); |
---|
| 83 | return true; |
---|
[9383] | 84 | } |
---|
| 85 | } |
---|
[9437] | 86 | return false; |
---|
| 87 | } |
---|
[9383] | 88 | |
---|
[9437] | 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) |
---|
[9383] | 93 | { |
---|
[9437] | 94 | if (*(*rmIt) == name) |
---|
[9383] | 95 | { |
---|
[9437] | 96 | delete (*rmIt); |
---|
| 97 | this->_clients.erase(rmIt); |
---|
| 98 | return true; |
---|
[9383] | 99 | } |
---|
| 100 | } |
---|
[9437] | 101 | return false; |
---|
[9383] | 102 | |
---|
[9437] | 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) |
---|
[9383] | 109 | { |
---|
[9437] | 110 | if (*(*rmIt) == ip && *(*rmIt) == name) |
---|
[9383] | 111 | { |
---|
[9437] | 112 | delete (*rmIt); |
---|
| 113 | this->_clients.erase(rmIt); |
---|
| 114 | return true; |
---|
[9383] | 115 | } |
---|
| 116 | } |
---|
[9437] | 117 | return false; |
---|
| 118 | } |
---|
[9383] | 119 | |
---|
| 120 | |
---|
[9437] | 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 | } |
---|
[9385] | 127 | |
---|
[9437] | 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 | } |
---|
[9383] | 134 | |
---|
[9437] | 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 | } |
---|
[9383] | 141 | |
---|
| 142 | |
---|
[9437] | 143 | //======================================================// |
---|
[9383] | 144 | |
---|
[9437] | 145 | /** |
---|
| 146 | * @brief standard constructor |
---|
| 147 | */ |
---|
[9439] | 148 | NetworkStatsWidget::NetworkStatsWidget(const NetworkMonitor* monitor) |
---|
[9554] | 149 | : OrxGui::GLGuiFixedpositionBox(OrxGui::Center, OrxGui::Vertical), _thisHost("myName", IP(127, 0, 0 , 1)) |
---|
[9437] | 150 | { |
---|
[9439] | 151 | this->_monitor = monitor; |
---|
[8983] | 152 | |
---|
[9438] | 153 | /* |
---|
[9437] | 154 | this->_bar.setSize2D(100, 30); |
---|
| 155 | this->pack(&this->_valueText); |
---|
| 156 | this->_bar.setParent2D(&this->_valueText); |
---|
[8973] | 157 | |
---|
[9437] | 158 | this->_valueText.setChangedTextColor(Color::white); |
---|
[8991] | 159 | |
---|
[9437] | 160 | //this->setBackgroundTexture("maps/gui_element_background_2.png"); |
---|
| 161 | this->setBackgroundColor(Color(.5,.5,.5,1)); |
---|
[8980] | 162 | |
---|
[9437] | 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); |
---|
[9438] | 170 | */ |
---|
[9546] | 171 | this->_thisHostIs.setText(std::string("I am ") + _monitor->getLocalNode()->getPeerInfo()->getNodeTypeString()); |
---|
[9438] | 172 | |
---|
[9546] | 173 | this->pack(&this->_thisHostIs); |
---|
| 174 | |
---|
| 175 | this->pack(&this->_thisHost); |
---|
| 176 | |
---|
[9438] | 177 | this->pack(&this->_upstreamText); |
---|
| 178 | this->pack(&this->_downstreamText); |
---|
| 179 | |
---|
[9567] | 180 | |
---|
[9569] | 181 | this->pack(&this->_serverBox); |
---|
[9567] | 182 | |
---|
| 183 | |
---|
| 184 | this->_refreshButton.setLabel("refresh"); |
---|
| 185 | this->_refreshButton.released.connect(this, &NetworkStatsWidget::rebuild); |
---|
| 186 | this->pack(&this->_refreshButton); |
---|
[9437] | 187 | } |
---|
[4320] | 188 | |
---|
| 189 | |
---|
[9437] | 190 | /** |
---|
| 191 | * @brief standard deconstructor |
---|
| 192 | */ |
---|
| 193 | NetworkStatsWidget::~NetworkStatsWidget () |
---|
| 194 | {} |
---|
[8974] | 195 | |
---|
| 196 | |
---|
[9437] | 197 | void NetworkStatsWidget::setMaximum(float max) |
---|
| 198 | { |
---|
[9442] | 199 | // this->_bar.setMaximum(max); |
---|
[9437] | 200 | } |
---|
[8974] | 201 | |
---|
[9437] | 202 | void NetworkStatsWidget::setValue(float value) |
---|
| 203 | { |
---|
| 204 | MultiType val(value); |
---|
| 205 | val.setType(MT_INT); |
---|
[9438] | 206 | /* |
---|
[8974] | 207 | |
---|
[9437] | 208 | this->_bar.setValue(value); |
---|
| 209 | this->_bar.setForegroundColor(Color::slerpHSVColor(Color::red, Color::green, value/this->_bar.maximum())); |
---|
| 210 | this->_bar.setFrontColor(Color(1,1,1,1), true); |
---|
| 211 | this->_valueText.setText(val.getString()); |
---|
[9438] | 212 | */ |
---|
[9437] | 213 | } |
---|
[8974] | 214 | |
---|
[9569] | 215 | |
---|
| 216 | void NetworkStatsWidget::addProxy(const std::string& name, const IP& proxy) |
---|
| 217 | { |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | void clearProxies(); |
---|
| 221 | |
---|
| 222 | |
---|
[9567] | 223 | void NetworkStatsWidget::rebuild() |
---|
| 224 | { |
---|
[9569] | 225 | while (!this->_proxies.empty()) |
---|
| 226 | { |
---|
| 227 | delete this->_proxies.back(); |
---|
| 228 | this->_proxies.pop_back(); |
---|
| 229 | } |
---|
[9439] | 230 | |
---|
[9569] | 231 | |
---|
| 232 | |
---|
[9567] | 233 | } |
---|
| 234 | |
---|
| 235 | |
---|
| 236 | |
---|
[9439] | 237 | void NetworkStatsWidget::tick(float dt) |
---|
| 238 | { |
---|
[9442] | 239 | assert (this->_monitor->getLocalNode() != NULL); |
---|
| 240 | assert(this->_monitor->getLocalNode()->getPeerInfo() != NULL); |
---|
[9439] | 241 | |
---|
[9442] | 242 | if(this->_monitor->getLocalNode()->getPeerInfo()->connectionMonitor != NULL) |
---|
| 243 | { |
---|
| 244 | ConnectionMonitor* mon = this->_monitor->getLocalNode()->getPeerInfo()->connectionMonitor; |
---|
[9439] | 245 | |
---|
[9442] | 246 | this->_upstreamText.setText(MultiType(mon->getOutgoingZippedBandWidth()).getString()); |
---|
| 247 | this->_downstreamText.setText(MultiType(mon->getIncomingZippedBandWidth()).getString()); |
---|
| 248 | } |
---|
[9439] | 249 | } |
---|
| 250 | |
---|
[9437] | 251 | void NetworkStatsWidget::resize() |
---|
| 252 | { |
---|
[9556] | 253 | GLGuiFixedpositionBox::resize(); |
---|
[9437] | 254 | } |
---|
[8974] | 255 | |
---|
[8981] | 256 | |
---|
[9437] | 257 | void NetworkStatsWidget::showing() |
---|
[9442] | 258 | {} |
---|
[8974] | 259 | |
---|
[9437] | 260 | void NetworkStatsWidget::hiding() |
---|
[9442] | 261 | {} |
---|