[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" |
---|
[9656] | 20 | #include "peer_info.h" |
---|
[1853] | 21 | |
---|
[9869] | 22 | #include "loading/resource_manager.h" |
---|
| 23 | |
---|
[9369] | 24 | #include "multi_type.h" |
---|
| 25 | |
---|
[9444] | 26 | #include "shell_command.h" |
---|
| 27 | |
---|
[9656] | 28 | // this fcuk does not work! |
---|
| 29 | // SHELL_COMMAND(gui, NetworkStatsWidget, toggleGUI) |
---|
| 30 | // ->setAlias("ProxyGui"); |
---|
[9444] | 31 | |
---|
[9437] | 32 | HostWidget::HostWidget(const std::string& name, const IP& ip) |
---|
[9442] | 33 | : GLGuiBox(OrxGui::Horizontal) |
---|
[9437] | 34 | { |
---|
[9656] | 35 | this->init(); |
---|
| 36 | |
---|
[9437] | 37 | this->setName(name); |
---|
| 38 | this->setIP(ip); |
---|
[9383] | 39 | |
---|
[9656] | 40 | } |
---|
| 41 | |
---|
| 42 | HostWidget::HostWidget(const PeerInfo* peerInfo) |
---|
| 43 | : GLGuiBox(OrxGui::Horizontal) |
---|
| 44 | { |
---|
| 45 | this->init(); |
---|
| 46 | if (peerInfo == NULL) |
---|
| 47 | { |
---|
| 48 | this->setName("INVALID"); |
---|
| 49 | return; |
---|
| 50 | } |
---|
| 51 | this->setName(peerInfo->getNodeTypeString() + "ID: " + MultiType(peerInfo->userId).getString()); |
---|
| 52 | this->setIP(peerInfo->ip); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | void HostWidget::init() |
---|
| 56 | { |
---|
| 57 | if(_font == NULL) |
---|
[10320] | 58 | _font = new Font(Resources::ResourceManager::getInstance()->mainGlobalPath().name() + "/fonts/final_frontier.ttf", 20); |
---|
[9656] | 59 | |
---|
| 60 | //this->_name.setFont(*_font); |
---|
| 61 | this->_name.setTextSize(15); |
---|
| 62 | //this->_ip.setFont(*_font); |
---|
| 63 | this->_ip.setTextSize(15); |
---|
| 64 | |
---|
[9437] | 65 | this->pack(&this->_name); |
---|
| 66 | this->pack(&this->_ip); |
---|
| 67 | } |
---|
[9383] | 68 | |
---|
[9437] | 69 | void HostWidget::showing() |
---|
| 70 | { |
---|
| 71 | this->_name.show(); |
---|
| 72 | this->_ip.show(); |
---|
| 73 | } |
---|
[9383] | 74 | |
---|
[9437] | 75 | void HostWidget::hiding() |
---|
| 76 | { |
---|
| 77 | this->_name.hide(); |
---|
| 78 | this->_ip.hide(); |
---|
| 79 | } |
---|
[9383] | 80 | |
---|
[9656] | 81 | Font* HostWidget::_font = NULL; |
---|
[9383] | 82 | |
---|
| 83 | |
---|
[9656] | 84 | |
---|
| 85 | |
---|
[9437] | 86 | //======================================================// |
---|
[9383] | 87 | |
---|
| 88 | |
---|
[9656] | 89 | NodeWidget::NodeWidget(const std::string& proxyName, const IP& ip) |
---|
[9437] | 90 | : _proxyWidget(proxyName, ip) |
---|
| 91 | { |
---|
[9656] | 92 | this->_nodeNameWidth = 100.0f; |
---|
[9437] | 93 | this->pack(&_proxyWidget); |
---|
| 94 | } |
---|
[9383] | 95 | |
---|
[9656] | 96 | NodeWidget::NodeWidget(const NetworkNode* node) |
---|
| 97 | : _proxyWidget(node->getPeerInfo())// "node", node->getPeerInfo()->ip) |
---|
[9437] | 98 | { |
---|
[9656] | 99 | this->_nodeNameWidth = 100.0f; |
---|
| 100 | this->pack(&_proxyWidget); |
---|
| 101 | |
---|
| 102 | std::list<NetworkNode*> list = node->getMasterServers(); |
---|
| 103 | std::list<NetworkNode*>::const_iterator it; |
---|
| 104 | |
---|
| 105 | for(it = list.begin(); it != list.end(); it++) |
---|
| 106 | this->addNode(*it); |
---|
| 107 | |
---|
| 108 | list = node->getActiveProxyServers(); |
---|
| 109 | for(it = list.begin(); it != list.end(); it++) |
---|
| 110 | this->addNode(*it); |
---|
| 111 | |
---|
| 112 | list = node->getPassiveProxyServers(); |
---|
| 113 | for(it = list.begin(); it != list.end(); it++) |
---|
| 114 | this->addNode(*it); |
---|
| 115 | |
---|
| 116 | list = node->getClients(); |
---|
| 117 | for(it = list.begin(); it != list.end(); it++) |
---|
| 118 | this->addNode(*it); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | void NodeWidget::addNode(const NetworkNode* node) |
---|
| 123 | { |
---|
| 124 | this->_nodes.push_back(new NodeWidget(node)); |
---|
| 125 | this->pack(this->_nodes.back()); |
---|
| 126 | this->_nodes.back()->show(); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | void NodeWidget::addNode(const std::string& name, const IP& ip) |
---|
| 131 | { |
---|
[9437] | 132 | HostWidget* newClient = new HostWidget(name, ip); |
---|
[9656] | 133 | newClient->setNameWidth(this->_nodeNameWidth); |
---|
[9383] | 134 | |
---|
[9437] | 135 | this->pack(newClient); |
---|
[9383] | 136 | |
---|
[9437] | 137 | if (this->isVisible()) |
---|
| 138 | newClient->show(); |
---|
| 139 | } |
---|
[9383] | 140 | |
---|
[9656] | 141 | bool NodeWidget::removeNode(const IP& ip) |
---|
[9437] | 142 | { |
---|
[9656] | 143 | // std::vector<HostWidget*>::iterator rmIt; |
---|
| 144 | // for(rmIt = this->_nodes.begin(); rmIt != this->_nodes.end(); ++rmIt) |
---|
| 145 | // { |
---|
| 146 | // if (*(*rmIt) == ip) |
---|
| 147 | // { |
---|
| 148 | // delete (*rmIt); |
---|
| 149 | // this->_nodes.erase(rmIt); |
---|
| 150 | // return true; |
---|
| 151 | // } |
---|
| 152 | // } |
---|
| 153 | // return false; |
---|
[9437] | 154 | } |
---|
[9383] | 155 | |
---|
[9656] | 156 | bool NodeWidget::removeNode(const std::string& name) |
---|
[9437] | 157 | { |
---|
[9656] | 158 | // std::vector<HostWidget*>::iterator rmIt; |
---|
| 159 | // for(rmIt = this->_nodes.begin(); rmIt != this->_nodes.end(); ++rmIt) |
---|
| 160 | // { |
---|
| 161 | // if (*(*rmIt) == name) |
---|
| 162 | // { |
---|
| 163 | // delete (*rmIt); |
---|
| 164 | // this->_nodes.erase(rmIt); |
---|
| 165 | // return true; |
---|
| 166 | // } |
---|
| 167 | // } |
---|
| 168 | // return false; |
---|
[9383] | 169 | |
---|
[9437] | 170 | } |
---|
| 171 | |
---|
[9656] | 172 | bool NodeWidget::removeNode(const std::string& name, const IP& ip) |
---|
[9437] | 173 | { |
---|
[9656] | 174 | // std::vector<HostWidget*>::iterator rmIt; |
---|
| 175 | // for(rmIt = this->_nodes.begin(); rmIt != this->_nodes.end(); ++rmIt) |
---|
| 176 | // { |
---|
| 177 | // if (*(*rmIt) == ip && *(*rmIt) == name) |
---|
| 178 | // { |
---|
| 179 | // delete (*rmIt); |
---|
| 180 | // this->_nodes.erase(rmIt); |
---|
| 181 | // return true; |
---|
| 182 | // } |
---|
| 183 | // } |
---|
| 184 | // return false; |
---|
[9437] | 185 | } |
---|
[9383] | 186 | |
---|
| 187 | |
---|
[9656] | 188 | void NodeWidget::setNodeNameWidths(float width) |
---|
[9437] | 189 | { |
---|
[9656] | 190 | /* this->_nodeNameWidth = width; |
---|
| 191 | for (unsigned int i = 0; i < this->_nodes.size(); ++i) |
---|
| 192 | this->_nodes[i]->setNameWidth(width);*/ |
---|
[9437] | 193 | } |
---|
[9385] | 194 | |
---|
[9656] | 195 | void NodeWidget::hiding() |
---|
[9437] | 196 | { |
---|
| 197 | this->_proxyWidget.hide(); |
---|
[9656] | 198 | for (unsigned int i = 0; i < this->_nodes.size(); ++i) |
---|
| 199 | this->_nodes[i]->hide(); |
---|
[9437] | 200 | } |
---|
[9383] | 201 | |
---|
[9656] | 202 | void NodeWidget::showing() |
---|
[9437] | 203 | { |
---|
| 204 | this->_proxyWidget.show(); |
---|
[9656] | 205 | for (unsigned int i = 0; i < this->_nodes.size(); ++i) |
---|
| 206 | this->_nodes[i]->show(); |
---|
[9437] | 207 | } |
---|
[9383] | 208 | |
---|
| 209 | |
---|
[9437] | 210 | //======================================================// |
---|
[9383] | 211 | |
---|
[9869] | 212 | |
---|
| 213 | ObjectListDefinition(NetworkStatsWidget); |
---|
[9437] | 214 | /** |
---|
| 215 | * @brief standard constructor |
---|
| 216 | */ |
---|
[9439] | 217 | NetworkStatsWidget::NetworkStatsWidget(const NetworkMonitor* monitor) |
---|
[9656] | 218 | : OrxGui::GLGuiFixedpositionBox(OrxGui::Center, OrxGui::Vertical), _thisHost("myName", IP(127, 0, 0 , 1)) |
---|
[9437] | 219 | { |
---|
[9439] | 220 | this->_monitor = monitor; |
---|
[9656] | 221 | this->_passedTime = 0.0f; |
---|
[8983] | 222 | |
---|
[9438] | 223 | /* |
---|
[9437] | 224 | this->_bar.setSize2D(100, 30); |
---|
| 225 | this->pack(&this->_valueText); |
---|
| 226 | this->_bar.setParent2D(&this->_valueText); |
---|
[8973] | 227 | |
---|
[9437] | 228 | this->_valueText.setChangedTextColor(Color::white); |
---|
[8991] | 229 | |
---|
[9437] | 230 | //this->setBackgroundTexture("maps/gui_element_background_2.png"); |
---|
| 231 | this->setBackgroundColor(Color(.5,.5,.5,1)); |
---|
[8980] | 232 | |
---|
[9437] | 233 | //this->_name.setBackgroundTexture(Texture()); |
---|
| 234 | //this->_valueText.setBackgroundTexture("maps/gui_element_background_2.png"); |
---|
| 235 | this->_bar.setBackgroundTexture(Texture()); |
---|
| 236 | this->_bar.setBackgroundColor(Color(0,0,0,0)); |
---|
| 237 | this->_bar.setForegroundTexture("maps/gui_element_background_faded.png"); |
---|
| 238 | this->_bar.setForegroundColor(Color(.5, .5, .5, 1)); |
---|
| 239 | this->_bar.setChangedValueColor(Color::black); |
---|
[9438] | 240 | */ |
---|
[9656] | 241 | this->_thisHostIs.setText(std::string("I am ") + _monitor->getLocalNode()->getPeerInfo()->getNodeTypeString()); |
---|
| 242 | |
---|
| 243 | this->pack(&this->_thisHostIs); |
---|
| 244 | |
---|
[9438] | 245 | this->pack(&this->_thisHost); |
---|
| 246 | |
---|
[9656] | 247 | this->pack(&this->_serverBox); |
---|
| 248 | |
---|
[9438] | 249 | this->pack(&this->_upstreamText); |
---|
| 250 | this->pack(&this->_downstreamText); |
---|
| 251 | |
---|
[9656] | 252 | |
---|
| 253 | this->rebuild(); |
---|
[9437] | 254 | } |
---|
[4320] | 255 | |
---|
| 256 | |
---|
[9437] | 257 | /** |
---|
| 258 | * @brief standard deconstructor |
---|
| 259 | */ |
---|
| 260 | NetworkStatsWidget::~NetworkStatsWidget () |
---|
| 261 | {} |
---|
[8974] | 262 | |
---|
| 263 | |
---|
[9656] | 264 | void NetworkStatsWidget::addNode(const NetworkNode* node) |
---|
| 265 | { |
---|
| 266 | this->_proxies.push_back(new NodeWidget(node)); |
---|
| 267 | this->_serverBox.pack(this->_proxies.back()); |
---|
| 268 | this->_proxies.back()->show(); |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | |
---|
| 272 | |
---|
| 273 | |
---|
| 274 | NetworkStatsWidget* NetworkStatsWidget::_statsWidget = NULL; |
---|
| 275 | |
---|
| 276 | void NetworkStatsWidget::toggleGUI() |
---|
| 277 | { |
---|
[9869] | 278 | NetworkMonitor* monitor; |
---|
| 279 | if (!NetworkMonitor::objectList().empty()) |
---|
| 280 | monitor = NetworkMonitor::objectList().front(); |
---|
[9656] | 281 | |
---|
[9869] | 282 | if (monitor != NULL && NetworkStatsWidget::_statsWidget == NULL) |
---|
[9656] | 283 | { |
---|
[9869] | 284 | NetworkStatsWidget::_statsWidget = new NetworkStatsWidget(monitor); |
---|
[9656] | 285 | NetworkStatsWidget::_statsWidget->showAll(); |
---|
| 286 | } |
---|
| 287 | else |
---|
| 288 | { |
---|
| 289 | delete NetworkStatsWidget::_statsWidget; |
---|
| 290 | NetworkStatsWidget::_statsWidget = NULL; |
---|
| 291 | } |
---|
| 292 | } |
---|
| 293 | |
---|
| 294 | |
---|
[9437] | 295 | void NetworkStatsWidget::setMaximum(float max) |
---|
| 296 | { |
---|
[9442] | 297 | // this->_bar.setMaximum(max); |
---|
[9437] | 298 | } |
---|
[8974] | 299 | |
---|
[9437] | 300 | void NetworkStatsWidget::setValue(float value) |
---|
| 301 | { |
---|
| 302 | MultiType val(value); |
---|
| 303 | val.setType(MT_INT); |
---|
[9438] | 304 | /* |
---|
[8974] | 305 | |
---|
[9437] | 306 | this->_bar.setValue(value); |
---|
| 307 | this->_bar.setForegroundColor(Color::slerpHSVColor(Color::red, Color::green, value/this->_bar.maximum())); |
---|
| 308 | this->_bar.setFrontColor(Color(1,1,1,1), true); |
---|
| 309 | this->_valueText.setText(val.getString()); |
---|
[9438] | 310 | */ |
---|
[9437] | 311 | } |
---|
[8974] | 312 | |
---|
[9439] | 313 | |
---|
[9656] | 314 | void NetworkStatsWidget::addProxy(const std::string& name, const IP& proxy) |
---|
| 315 | {} |
---|
| 316 | |
---|
| 317 | void NetworkStatsWidget::clearProxies() |
---|
| 318 | {} |
---|
| 319 | |
---|
| 320 | |
---|
| 321 | void NetworkStatsWidget::rebuild() |
---|
| 322 | { |
---|
| 323 | while (!this->_proxies.empty()) |
---|
| 324 | { |
---|
| 325 | delete this->_proxies.back(); |
---|
| 326 | this->_proxies.pop_back(); |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | const NetworkNode* node = this->_monitor->getLocalNode(); |
---|
| 330 | if (node == NULL) |
---|
| 331 | { |
---|
| 332 | printf("NO NODE\n"); |
---|
| 333 | return; |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | this->addNode(node); |
---|
| 337 | } |
---|
| 338 | |
---|
| 339 | |
---|
| 340 | |
---|
[9439] | 341 | void NetworkStatsWidget::tick(float dt) |
---|
| 342 | { |
---|
[9656] | 343 | |
---|
| 344 | if ((_passedTime+= dt) > 1.0f) |
---|
| 345 | { |
---|
| 346 | this->_passedTime = 0.0f; |
---|
| 347 | this->rebuild(); |
---|
| 348 | } |
---|
| 349 | |
---|
[9442] | 350 | assert (this->_monitor->getLocalNode() != NULL); |
---|
| 351 | assert(this->_monitor->getLocalNode()->getPeerInfo() != NULL); |
---|
[9439] | 352 | |
---|
[9442] | 353 | if(this->_monitor->getLocalNode()->getPeerInfo()->connectionMonitor != NULL) |
---|
| 354 | { |
---|
| 355 | ConnectionMonitor* mon = this->_monitor->getLocalNode()->getPeerInfo()->connectionMonitor; |
---|
[9439] | 356 | |
---|
[9442] | 357 | this->_upstreamText.setText(MultiType(mon->getOutgoingZippedBandWidth()).getString()); |
---|
| 358 | this->_downstreamText.setText(MultiType(mon->getIncomingZippedBandWidth()).getString()); |
---|
| 359 | } |
---|
[9439] | 360 | } |
---|
| 361 | |
---|
[9437] | 362 | void NetworkStatsWidget::resize() |
---|
| 363 | { |
---|
[9656] | 364 | GLGuiFixedpositionBox::resize(); |
---|
[9437] | 365 | } |
---|
[8974] | 366 | |
---|
[8981] | 367 | |
---|
[9437] | 368 | void NetworkStatsWidget::showing() |
---|
[9442] | 369 | {} |
---|
[8974] | 370 | |
---|
[9437] | 371 | void NetworkStatsWidget::hiding() |
---|
[9442] | 372 | {} |
---|