Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/lib/network/monitor/network_monitor.cc @ 9286

Last change on this file since 9286 was 9286, checked in by patrick, 18 years ago

first network monitor debug session

File size: 3.7 KB
RevLine 
[9263]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: Patrick Boenzli
13*/
14
15#include "glgui.h"
16#include "shell_command.h"
17
18#include "network_stream.h"
[9266]19#include "debug.h"
[9263]20
21#include "network_monitor.h"
[9276]22#include "network_node.h"
[9279]23#include "network_stream.h"
[9263]24
[9276]25
[9266]26SHELL_COMMAND(showGUI, NetworkMonitor, showGUI);
27SHELL_COMMAND(hideGUI, NetworkMonitor, hideGUI);
[9263]28// SHELL_COMMAND(output, MappedWater, saveParams);
29
30
31
32/**
33 * starts a network monitor
34 */
35NetworkMonitor::NetworkMonitor(NetworkStream* networkStream)
[9281]36  : Synchronizeable()
[9263]37{
[9281]38  this->setClassID(CL_NETWORK_MONITOR, "NetworkMonitor");
39
[9279]40  this->networkStream = networkStream;
[9272]41  this->playerNumber = 0;
[9284]42  this->localNode = new NetworkNode( this->networkStream->getPeerInfo());
[9283]43
[9281]44  this->setSynchronized(false);
[9263]45}
46
47
[9264]48/**
49 * deconstructor
50 */
51NetworkMonitor::~NetworkMonitor()
[9283]52{
53  if( this->localNode)
54    delete this->localNode;
55}
[9263]56
57
[9266]58/**
[9277]59 * add the network node
60 * @param node to add
[9266]61 */
[9277]62void NetworkMonitor::addNetworkNode(NetworkNode* node)
[9266]63{
[9277]64  this->nodeList.push_back(node);
[9266]65}
[9263]66
[9266]67
68/**
[9277]69 * add the network node
70 * @param node to add
[9266]71 */
[9277]72void NetworkMonitor::removeNetworkNode(NetworkNode* node)
[9266]73{
[9277]74  std::list<NetworkNode*>::iterator it = this->nodeList.begin();
75  for(; it != this->nodeList.end(); it++)
[9266]76  {
77    if( *it == node)
78    {
[9277]79      this->nodeList.erase(it);
[9272]80      this->playerNumber--;
[9266]81      return;
82    }
83  }
84}
85
86
[9283]87/**
88 * adds a network node to the local node
89 *  @param pInfo node information
90 */
[9282]91void NetworkMonitor::addNode(PeerInfo* pInfo)
92{
[9283]93  if( this->localNode == NULL)
94    return;
[9282]95
96  if( pInfo->isClient())
97    this->localNode->addClient(pInfo);
98  else if( pInfo->isProxyServer())
99    this->localNode->addProxyServer(pInfo);
100  else if( pInfo->isMasterServer())
101    this->localNode->addMasterServer(pInfo);
102}
103
[9266]104/**
[9265]105 * this displays the network monitor gui
106 */
107void NetworkMonitor::showGUI()
108{
[9263]109  if (this->box == NULL)
110  {
[9265]111    this->box = new OrxGui::GLGuiBox(OrxGui::Vertical);
[9263]112    {
[9265]113      OrxGui::GLGuiBox* waterColorBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
114      {
115        OrxGui::GLGuiText* waterColorText = new OrxGui::GLGuiText();
116        waterColorText->setText("NetworkMonitor");
117        waterColorBox->pack(waterColorText);
118      }
119      this->box->pack(waterColorBox);
[9263]120    }
121
[9265]122    this->box->showAll();
123    this->box->setAbsCoor2D(300, 40);
124    OrxGui::GLGuiHandler::getInstance()->activate();
[9266]125//     OrxGui::GLGuiHandler::getInstance()->activateCursor();
[9265]126  }
127}
[9263]128
129
[9265]130/**
[9266]131 * hides the network monitor gui again
132 */
133void NetworkMonitor::hideGUI()
134{
135  if( this->box == NULL)
136    return;
137
138  OrxGui::GLGuiHandler::getInstance()->deactivate();
139//   OrxGui::GLGuiHandler::getInstance()->deactivateCursor();
140
141  delete this->box;
142  this->box = NULL;
143}
144
145
146/**
[9265]147 * processes the network monitor data
148 */
149void NetworkMonitor::process()
150{
[9280]151  this->playerNumber = 0;
[9279]152  std::list<NetworkNode*>::iterator it = this->nodeList.begin();
153  for(; it != this->nodeList.end(); it++)
154  {
[9280]155    this->playerNumber += (*it)->getPlayerNumber();
[9279]156  }
[9286]157
158  this->debug();
[9265]159}
[9263]160
[9286]161/**
162 * prints out the debug informations
163 */
[9285]164void NetworkMonitor::debug()
165{
166  PRINTF(0)("================================= Network Monitor ========\n");
[9286]167  PRINTF(0)(" I am: %s\n", this->localNode->getPeerInfo()->getNodeTypeString().c_str());
[9285]168  PRINTF(0)(" Total count of network nodes: %i\n", this->playerNumber);
[9286]169  PRINTF(0)("==========================================================\n");
170//   PRINTF(0)(" Currently got %i");
[9285]171}
172
Note: See TracBrowser for help on using the repository browser.