Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/lib/network/monitor/network_stats_widget.cc @ 9443

Last change on this file since 9443 was 9443, checked in by bensch, 18 years ago

ip-bug fixed

File size: 5.0 KB
Line 
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
23HostWidget::HostWidget(const std::string& name, const IP& ip)
24    : GLGuiBox(OrxGui::Horizontal)
25{
26  this->setName(name);
27  this->setIP(ip);
28
29  this->pack(&this->_name);
30  this->pack(&this->_ip);
31}
32
33void HostWidget::showing()
34{
35  this->_name.show();
36  this->_ip.show();
37}
38
39void HostWidget::hiding()
40{
41  this->_name.hide();
42  this->_ip.hide();
43}
44
45
46
47//======================================================//
48
49
50ProxyWidget::ProxyWidget(const std::string& proxyName, const IP& ip)
51    : _proxyWidget(proxyName, ip)
52{
53  this->_clientNameWidth = 100.0f;
54  this->pack(&_proxyWidget);
55}
56
57void ProxyWidget::addClient(const std::string& name, const IP& ip)
58{
59  HostWidget* newClient = new HostWidget(name, ip);
60  newClient->setNameWidth(this->_clientNameWidth);
61
62  this->pack(newClient);
63
64  if (this->isVisible())
65    newClient->show();
66}
67
68bool ProxyWidget::removeClient(const IP& ip)
69{
70  std::vector<HostWidget*>::iterator rmIt;
71  for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
72  {
73    if (*(*rmIt) == ip)
74    {
75      delete (*rmIt);
76      this->_clients.erase(rmIt);
77      return true;
78    }
79  }
80  return false;
81}
82
83bool ProxyWidget::removeClient(const std::string& name)
84{
85  std::vector<HostWidget*>::iterator rmIt;
86  for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
87  {
88    if (*(*rmIt) == name)
89    {
90      delete (*rmIt);
91      this->_clients.erase(rmIt);
92      return true;
93    }
94  }
95  return false;
96
97}
98
99bool ProxyWidget::removeClient(const std::string& name, const IP& ip)
100{
101  std::vector<HostWidget*>::iterator rmIt;
102  for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
103  {
104    if (*(*rmIt) == ip && *(*rmIt) == name)
105    {
106      delete (*rmIt);
107      this->_clients.erase(rmIt);
108      return true;
109    }
110  }
111  return false;
112}
113
114
115void ProxyWidget::setClientNameWidths(float width)
116{
117  this->_clientNameWidth = width;
118  for (unsigned int i = 0; i < this->_clients.size(); ++i)
119    this->_clients[i]->setNameWidth(width);
120}
121
122void ProxyWidget::hiding()
123{
124  this->_proxyWidget.hide();
125  for (unsigned int i = 0; i < this->_clients.size(); ++i)
126    this->_clients[i]->hide();
127}
128
129void ProxyWidget::showing()
130{
131  this->_proxyWidget.show();
132  for (unsigned int i = 0; i < this->_clients.size(); ++i)
133    this->_clients[i]->show();
134}
135
136
137//======================================================//
138
139/**
140 * @brief standard constructor
141 */
142NetworkStatsWidget::NetworkStatsWidget(const NetworkMonitor* monitor)
143    : GLGuiBox(OrxGui::Vertical), _thisHost("myName", IP(127, 0, 0 , 1))
144{
145  this->_monitor = monitor;
146
147  /*
148  this->_bar.setSize2D(100, 30);
149  this->pack(&this->_valueText);
150  this->_bar.setParent2D(&this->_valueText);
151
152  this->_valueText.setChangedTextColor(Color::white);
153
154  //this->setBackgroundTexture("maps/gui_element_background_2.png");
155  this->setBackgroundColor(Color(.5,.5,.5,1));
156
157  //this->_name.setBackgroundTexture(Texture());
158  //this->_valueText.setBackgroundTexture("maps/gui_element_background_2.png");
159  this->_bar.setBackgroundTexture(Texture());
160  this->_bar.setBackgroundColor(Color(0,0,0,0));
161  this->_bar.setForegroundTexture("maps/gui_element_background_faded.png");
162  this->_bar.setForegroundColor(Color(.5, .5, .5, 1));
163  this->_bar.setChangedValueColor(Color::black);
164  */
165  this->pack(&this->_thisHost);
166
167  this->pack(&this->_upstreamText);
168  this->pack(&this->_downstreamText);
169
170  this->pack(&this->_serverIP);
171}
172
173
174/**
175 * @brief standard deconstructor
176 */
177NetworkStatsWidget::~NetworkStatsWidget ()
178{}
179
180
181void NetworkStatsWidget::setMaximum(float max)
182{
183  // this->_bar.setMaximum(max);
184}
185
186void NetworkStatsWidget::setValue(float value)
187{
188  MultiType val(value);
189  val.setType(MT_INT);
190  /*
191
192  this->_bar.setValue(value);
193  this->_bar.setForegroundColor(Color::slerpHSVColor(Color::red, Color::green, value/this->_bar.maximum()));
194  this->_bar.setFrontColor(Color(1,1,1,1), true);
195  this->_valueText.setText(val.getString());
196  */
197}
198
199
200void NetworkStatsWidget::tick(float dt)
201{
202  assert (this->_monitor->getLocalNode() != NULL);
203  assert(this->_monitor->getLocalNode()->getPeerInfo() != NULL);
204
205  if(this->_monitor->getLocalNode()->getPeerInfo()->connectionMonitor != NULL)
206  {
207    ConnectionMonitor* mon = this->_monitor->getLocalNode()->getPeerInfo()->connectionMonitor;
208
209    this->_upstreamText.setText(MultiType(mon->getOutgoingZippedBandWidth()).getString());
210    this->_downstreamText.setText(MultiType(mon->getIncomingZippedBandWidth()).getString());
211  }
212}
213
214void NetworkStatsWidget::resize()
215{
216  GLGuiBox::resize();
217}
218
219
220void NetworkStatsWidget::showing()
221{}
222
223void NetworkStatsWidget::hiding()
224{}
Note: See TracBrowser for help on using the repository browser.