Changeset 9656 in orxonox.OLD for trunk/src/lib/network/monitor/network_stats_widget.cc
- Timestamp:
- Aug 4, 2006, 11:01:28 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/network/monitor/network_stats_widget.cc
r9494 r9656 18 18 #include "network_stats_widget.h" 19 19 #include "network_monitor.h" 20 #include "peer_info.h" 20 21 21 22 #include "multi_type.h" … … 23 24 #include "shell_command.h" 24 25 25 // SHELL_COMMAND(gui, NetworkMonitor, toggleGUI) 26 // ->setAlias("ProxyGui"); 26 #include "loading/resource_manager.h" 27 28 // this fcuk does not work! 29 // SHELL_COMMAND(gui, NetworkStatsWidget, toggleGUI) 30 // ->setAlias("ProxyGui"); 27 31 28 32 … … 30 34 : GLGuiBox(OrxGui::Horizontal) 31 35 { 36 this->init(); 37 32 38 this->setName(name); 33 39 this->setIP(ip); 34 40 41 } 42 43 HostWidget::HostWidget(const PeerInfo* peerInfo) 44 : GLGuiBox(OrxGui::Horizontal) 45 { 46 this->init(); 47 if (peerInfo == NULL) 48 { 49 this->setName("INVALID"); 50 return; 51 } 52 this->setName(peerInfo->getNodeTypeString() + "ID: " + MultiType(peerInfo->userId).getString()); 53 this->setIP(peerInfo->ip); 54 } 55 56 void HostWidget::init() 57 { 58 if(_font == NULL) 59 _font = new Font(ResourceManager::getInstance()->getDataDir() + "/fonts/arial.ttf", 20); 60 61 //this->_name.setFont(*_font); 62 this->_name.setTextSize(15); 63 //this->_ip.setFont(*_font); 64 this->_ip.setTextSize(15); 65 35 66 this->pack(&this->_name); 36 67 this->pack(&this->_ip); … … 49 80 } 50 81 82 Font* HostWidget::_font = NULL; 83 84 51 85 52 86 … … 54 88 55 89 56 ProxyWidget::ProxyWidget(const std::string& proxyName, const IP& ip)90 NodeWidget::NodeWidget(const std::string& proxyName, const IP& ip) 57 91 : _proxyWidget(proxyName, ip) 58 92 { 59 this->_ clientNameWidth = 100.0f;93 this->_nodeNameWidth = 100.0f; 60 94 this->pack(&_proxyWidget); 61 95 } 62 96 63 void ProxyWidget::addClient(const std::string& name, const IP& ip) 97 NodeWidget::NodeWidget(const NetworkNode* node) 98 : _proxyWidget(node->getPeerInfo())// "node", node->getPeerInfo()->ip) 99 { 100 this->_nodeNameWidth = 100.0f; 101 this->pack(&_proxyWidget); 102 103 std::list<NetworkNode*> list = node->getMasterServers(); 104 std::list<NetworkNode*>::const_iterator it; 105 106 for(it = list.begin(); it != list.end(); it++) 107 this->addNode(*it); 108 109 list = node->getActiveProxyServers(); 110 for(it = list.begin(); it != list.end(); it++) 111 this->addNode(*it); 112 113 list = node->getPassiveProxyServers(); 114 for(it = list.begin(); it != list.end(); it++) 115 this->addNode(*it); 116 117 list = node->getClients(); 118 for(it = list.begin(); it != list.end(); it++) 119 this->addNode(*it); 120 } 121 122 123 void NodeWidget::addNode(const NetworkNode* node) 124 { 125 this->_nodes.push_back(new NodeWidget(node)); 126 this->pack(this->_nodes.back()); 127 this->_nodes.back()->show(); 128 } 129 130 131 void NodeWidget::addNode(const std::string& name, const IP& ip) 64 132 { 65 133 HostWidget* newClient = new HostWidget(name, ip); 66 newClient->setNameWidth(this->_ clientNameWidth);134 newClient->setNameWidth(this->_nodeNameWidth); 67 135 68 136 this->pack(newClient); … … 72 140 } 73 141 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()142 bool NodeWidget::removeNode(const IP& ip) 143 { 144 // std::vector<HostWidget*>::iterator rmIt; 145 // for(rmIt = this->_nodes.begin(); rmIt != this->_nodes.end(); ++rmIt) 146 // { 147 // if (*(*rmIt) == ip) 148 // { 149 // delete (*rmIt); 150 // this->_nodes.erase(rmIt); 151 // return true; 152 // } 153 // } 154 // return false; 155 } 156 157 bool NodeWidget::removeNode(const std::string& name) 158 { 159 // std::vector<HostWidget*>::iterator rmIt; 160 // for(rmIt = this->_nodes.begin(); rmIt != this->_nodes.end(); ++rmIt) 161 // { 162 // if (*(*rmIt) == name) 163 // { 164 // delete (*rmIt); 165 // this->_nodes.erase(rmIt); 166 // return true; 167 // } 168 // } 169 // return false; 170 171 } 172 173 bool NodeWidget::removeNode(const std::string& name, const IP& ip) 174 { 175 // std::vector<HostWidget*>::iterator rmIt; 176 // for(rmIt = this->_nodes.begin(); rmIt != this->_nodes.end(); ++rmIt) 177 // { 178 // if (*(*rmIt) == ip && *(*rmIt) == name) 179 // { 180 // delete (*rmIt); 181 // this->_nodes.erase(rmIt); 182 // return true; 183 // } 184 // } 185 // return false; 186 } 187 188 189 void NodeWidget::setNodeNameWidths(float width) 190 { 191 /* this->_nodeNameWidth = width; 192 for (unsigned int i = 0; i < this->_nodes.size(); ++i) 193 this->_nodes[i]->setNameWidth(width);*/ 194 } 195 196 void NodeWidget::hiding() 129 197 { 130 198 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()199 for (unsigned int i = 0; i < this->_nodes.size(); ++i) 200 this->_nodes[i]->hide(); 201 } 202 203 void NodeWidget::showing() 136 204 { 137 205 this->_proxyWidget.show(); 138 for (unsigned int i = 0; i < this->_ clients.size(); ++i)139 this->_ clients[i]->show();206 for (unsigned int i = 0; i < this->_nodes.size(); ++i) 207 this->_nodes[i]->show(); 140 208 } 141 209 … … 147 215 */ 148 216 NetworkStatsWidget::NetworkStatsWidget(const NetworkMonitor* monitor) 149 : GLGuiBox(OrxGui::Vertical), _thisHost("myName", IP(127, 0, 0 , 1))217 : OrxGui::GLGuiFixedpositionBox(OrxGui::Center, OrxGui::Vertical), _thisHost("myName", IP(127, 0, 0 , 1)) 150 218 { 151 219 this->_monitor = monitor; 220 this->_passedTime = 0.0f; 152 221 153 222 /* … … 169 238 this->_bar.setChangedValueColor(Color::black); 170 239 */ 240 this->_thisHostIs.setText(std::string("I am ") + _monitor->getLocalNode()->getPeerInfo()->getNodeTypeString()); 241 242 this->pack(&this->_thisHostIs); 243 171 244 this->pack(&this->_thisHost); 245 246 this->pack(&this->_serverBox); 172 247 173 248 this->pack(&this->_upstreamText); 174 249 this->pack(&this->_downstreamText); 175 250 176 this->pack(&this->_serverIP); 251 252 this->rebuild(); 177 253 } 178 254 … … 183 259 NetworkStatsWidget::~NetworkStatsWidget () 184 260 {} 261 262 263 void NetworkStatsWidget::addNode(const NetworkNode* node) 264 { 265 this->_proxies.push_back(new NodeWidget(node)); 266 this->_serverBox.pack(this->_proxies.back()); 267 this->_proxies.back()->show(); 268 } 269 270 271 272 273 NetworkStatsWidget* NetworkStatsWidget::_statsWidget = NULL; 274 275 #include "class_list.h" 276 277 void NetworkStatsWidget::toggleGUI() 278 { 279 BaseObject* bo = NULL; 280 const std::list<BaseObject*>* ls = ClassList::getList(CL_NETWORK_MONITOR); 281 if (ls != NULL && !ls->empty()) 282 bo = ls->front(); 283 284 if (bo != NULL && NetworkStatsWidget::_statsWidget == NULL) 285 { 286 NetworkStatsWidget::_statsWidget = new NetworkStatsWidget(dynamic_cast<NetworkMonitor*> (bo)); 287 NetworkStatsWidget::_statsWidget->showAll(); 288 } 289 else 290 { 291 delete NetworkStatsWidget::_statsWidget; 292 NetworkStatsWidget::_statsWidget = NULL; 293 } 294 } 185 295 186 296 … … 204 314 205 315 316 void NetworkStatsWidget::addProxy(const std::string& name, const IP& proxy) 317 {} 318 319 void NetworkStatsWidget::clearProxies() 320 {} 321 322 323 void NetworkStatsWidget::rebuild() 324 { 325 while (!this->_proxies.empty()) 326 { 327 delete this->_proxies.back(); 328 this->_proxies.pop_back(); 329 } 330 331 const NetworkNode* node = this->_monitor->getLocalNode(); 332 if (node == NULL) 333 { 334 printf("NO NODE\n"); 335 return; 336 } 337 338 this->addNode(node); 339 } 340 341 342 206 343 void NetworkStatsWidget::tick(float dt) 207 344 { 345 346 if ((_passedTime+= dt) > 1.0f) 347 { 348 this->_passedTime = 0.0f; 349 this->rebuild(); 350 } 351 208 352 assert (this->_monitor->getLocalNode() != NULL); 209 353 assert(this->_monitor->getLocalNode()->getPeerInfo() != NULL); … … 220 364 void NetworkStatsWidget::resize() 221 365 { 222 GLGui Box::resize();366 GLGuiFixedpositionBox::resize(); 223 367 } 224 368
Note: See TracChangeset
for help on using the changeset viewer.