Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/lib/network/network_manager.cc @ 7559

Last change on this file since 7559 was 7540, checked in by rennerc, 18 years ago

implemented udp sockets

File size: 3.6 KB
RevLine 
[5530]1/*
[5520]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   co-programmer: ...
14*/
15
16
[5525]17/* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_NETWORK module
[5530]18   For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput
[5525]19*/
[5530]20#define DEBUG_MODULE_NETWORK
[5525]21
[5572]22#include "class_list.h"
[5605]23#include "debug.h"
[6695]24#include "shell_command.h"
[5566]25
[5525]26/* include your own header */
[5520]27#include "network_manager.h"
[6695]28#include "shared_network_data.h"
29#include "network_stream.h"
[5520]30
[5530]31
[5525]32/* using namespace std is default, this needs to be here */
[5520]33using namespace std;
34
[6695]35SHELL_COMMAND(debug, NetworkManager, debug);
[5520]36
[6695]37
[5996]38NetworkManager* NetworkManager::singletonRef = NULL;
[5520]39
40/**
41 *  standard constructor
42 */
43NetworkManager::NetworkManager()
[5566]44{
[5572]45  /* set the class id for the base object */
[5575]46  this->setClassID(CL_NETWORK_MANAGER, "NetworkManager");
[6341]47  PRINTF(0)("START\n");
[5804]48
[5572]49  /* initialize the references */
50  this->netStreamList = NULL;
51  this->syncList = NULL;
[6695]52  this->defaultSyncStream = NULL;
53  this->sharedNetworkData = SharedNetworkData::getInstance();
[6341]54
[5605]55  PRINTF(0)("NetworkManager created\n");
[5566]56}
[5520]57
58
59/**
60 *  standard deconstructor
61 */
62NetworkManager::~NetworkManager()
63{}
64
[5522]65
66/**
67 *  initializes the network manager
68 */
69void NetworkManager::initialize()
[5572]70{
71  /* get the synchronizeable list from the class list */
[5575]72  this->netStreamList = ClassList::getList(CL_SYNCHRONIZEABLE);
[5605]73  PRINTF(0)("NetworkManager initzalized\n");
[5572]74}
[5522]75
[5530]76
[5522]77/**
78 *  shutsdown the network manager
79 */
80void NetworkManager::shutdown()
[5578]81{
[5522]82
[5578]83}
[5522]84
[5578]85
[5522]86/**
87 *  creates a connection from one object to a host
[5647]88 * @param hostName: the name of the destination host
89 */
[7256]90int NetworkManager::establishConnection(const std::string & name, unsigned int port)
[5996]91{
[7540]92  this->defaultSyncStream = new NetworkStream( name, port );
[6695]93  this->sharedNetworkData->setDefaultSyncStream(this->defaultSyncStream);
94  this->defaultSyncStream->startHandshake();
[5996]95  return 1;
96}
[5647]97
[5996]98
[5647]99/**
[5996]100 *  creates a new NetworkStream of server type
101 * @param port: number of the TCP port
102 */
103int NetworkManager::createServer(unsigned int port)
104{
[6695]105  this->sharedNetworkData->setHostID(0);
106  this->sharedNetworkData->setGameServer(true);
107  this->defaultSyncStream = new NetworkStream(port);
108  this->sharedNetworkData->setDefaultSyncStream(this->defaultSyncStream);
109  this->defaultSyncStream->createNetworkGameManager();
110  PRINTF(0)("CREATE SERVER\n");
[5996]111  SDL_Delay(20);
112  return 1;
113}
114
115
116void NetworkManager::connectSynchronizeable(Synchronizeable& sync)
117{
[6695]118  if( this->defaultSyncStream)
119    this->defaultSyncStream->connectSynchronizeable(sync);
[5996]120}
[5522]121
[5996]122
[5522]123/**
124 *  sync the network
125 */
126void NetworkManager::synchronize()
[5578]127{
128  if (this->netStreamList != NULL || (this->netStreamList = ClassList::getList(CL_NETWORK_STREAM)) != NULL)
129  {
[5885]130    std::list<BaseObject*>::const_iterator stream;
[5822]131    for (stream = this->netStreamList->begin(); stream != this->netStreamList->end(); ++stream)
[5996]132      if( static_cast<NetworkStream*>(*stream)->isActive())
133        static_cast<NetworkStream*>(*stream)->processData();
[5578]134  }
135}
[5997]136
[6695]137
138
[5997]139/**
[6695]140 * debug output
[5997]141 */
[6695]142 void NetworkManager::debug()
[5997]143{
[6695]144  PRINT(0)("=================Network::debug()=========\n");
145  this->defaultSyncStream->debug();
146  PRINT(0)("===========================================\n");
[5997]147}
Note: See TracBrowser for help on using the repository browser.