Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 4, 2006, 11:01:28 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the proxy bache back with no conflicts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/network/monitor/network_stats_widget.cc

    r9494 r9656  
    1818#include "network_stats_widget.h"
    1919#include "network_monitor.h"
     20#include "peer_info.h"
    2021
    2122#include "multi_type.h"
     
    2324#include "shell_command.h"
    2425
    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");
    2731
    2832
     
    3034    : GLGuiBox(OrxGui::Horizontal)
    3135{
     36  this->init();
     37
    3238  this->setName(name);
    3339  this->setIP(ip);
    3440
     41}
     42
     43HostWidget::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
     56void 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
    3566  this->pack(&this->_name);
    3667  this->pack(&this->_ip);
     
    4980}
    5081
     82Font* HostWidget::_font = NULL;
     83
     84
    5185
    5286
     
    5488
    5589
    56 ProxyWidget::ProxyWidget(const std::string& proxyName, const IP& ip)
     90NodeWidget::NodeWidget(const std::string& proxyName, const IP& ip)
    5791    : _proxyWidget(proxyName, ip)
    5892{
    59   this->_clientNameWidth = 100.0f;
     93  this->_nodeNameWidth = 100.0f;
    6094  this->pack(&_proxyWidget);
    6195}
    6296
    63 void ProxyWidget::addClient(const std::string& name, const IP& ip)
     97NodeWidget::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
     123void 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
     131void NodeWidget::addNode(const std::string& name, const IP& ip)
    64132{
    65133  HostWidget* newClient = new HostWidget(name, ip);
    66   newClient->setNameWidth(this->_clientNameWidth);
     134  newClient->setNameWidth(this->_nodeNameWidth);
    67135
    68136  this->pack(newClient);
     
    72140}
    73141
    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()
     142bool 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
     157bool 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
     173bool 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
     189void 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
     196void NodeWidget::hiding()
    129197{
    130198  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
     203void NodeWidget::showing()
    136204{
    137205  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();
    140208}
    141209
     
    147215 */
    148216NetworkStatsWidget::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))
    150218{
    151219  this->_monitor = monitor;
     220  this->_passedTime = 0.0f;
    152221
    153222  /*
     
    169238  this->_bar.setChangedValueColor(Color::black);
    170239  */
     240  this->_thisHostIs.setText(std::string("I am ") + _monitor->getLocalNode()->getPeerInfo()->getNodeTypeString());
     241
     242  this->pack(&this->_thisHostIs);
     243
    171244  this->pack(&this->_thisHost);
     245
     246  this->pack(&this->_serverBox);
    172247
    173248  this->pack(&this->_upstreamText);
    174249  this->pack(&this->_downstreamText);
    175250
    176   this->pack(&this->_serverIP);
     251
     252  this->rebuild();
    177253}
    178254
     
    183259NetworkStatsWidget::~NetworkStatsWidget ()
    184260{}
     261
     262
     263void 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
     273NetworkStatsWidget* NetworkStatsWidget::_statsWidget = NULL;
     274
     275#include "class_list.h"
     276
     277void 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}
    185295
    186296
     
    204314
    205315
     316void NetworkStatsWidget::addProxy(const std::string& name, const IP& proxy)
     317{}
     318
     319void NetworkStatsWidget::clearProxies()
     320{}
     321
     322
     323void 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
    206343void NetworkStatsWidget::tick(float dt)
    207344{
     345
     346  if ((_passedTime+= dt) > 1.0f)
     347  {
     348    this->_passedTime = 0.0f;
     349    this->rebuild();
     350  }
     351
    208352  assert (this->_monitor->getLocalNode() != NULL);
    209353  assert(this->_monitor->getLocalNode()->getPeerInfo() != NULL);
     
    220364void NetworkStatsWidget::resize()
    221365{
    222   GLGuiBox::resize();
     366  GLGuiFixedpositionBox::resize();
    223367}
    224368
Note: See TracChangeset for help on using the changeset viewer.