Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5809 was 5805, checked in by patrick, 19 years ago

network: added some simulated network delay - this helps a lot for debugging :D

File size: 4.4 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
22
[5566]23#include "network_stream.h"
24#include "list.h"
[5572]25#include "class_list.h"
[5566]26
[5605]27#include "debug.h"
[5566]28
[5605]29
[5525]30/* include your own header */
[5520]31#include "network_manager.h"
32
[5530]33
[5525]34/* using namespace std is default, this needs to be here */
[5520]35using namespace std;
36
37
[5525]38/************************************
39  What you will see here are the function definitions from the header file (network_manager.h) with doxygen documentation. Here is an example:
[5520]40
[5530]41
42 In file network_manager.h
43
[5525]44 class NetworkManager
45 {
46   int doSomeStuff(float argument, float* pointer);
[5530]47 }
[5520]48
[5525]49 will be implemented in the source file as follows:
50
51 In file network_manager.cc
52
53 / **
54  *  this is the short description for this function: it just does some stuff
55  * @param argument: this is the first argument, stuff...
[5530]56  * @param pointer:  this is the pointer to nowhereland
57  * return: whatever the function returns: for example an index, number, etc.
58  * /
[5525]59 int NetworkManager::doSomeStuff(float argument, float* pointer)
60 {
[5530]61   // whaterver you want to do
62 }
[5525]63
[5530]64
[5525]65 if you want to make automake compile your files: you will want to add the file names to the local Makefile.am
[5530]66
[5525]67 ************************************/
68
[5530]69
[5605]70
[5520]71/**
72 *  standard constructor
73 */
74NetworkManager::NetworkManager()
[5566]75{
[5572]76  /* set the class id for the base object */
[5575]77  this->setClassID(CL_NETWORK_MANAGER, "NetworkManager");
[5804]78
[5572]79  /* initialize the references */
80  this->netStreamList = NULL;
81  this->syncList = NULL;
[5804]82
[5605]83  PRINTF(0)("NetworkManager created\n");
[5566]84}
[5520]85
86
87/**
88 *  standard deconstructor
89 */
90NetworkManager::~NetworkManager()
91{}
92
[5522]93
94/**
95 *  initializes the network manager
96 */
97void NetworkManager::initialize()
[5572]98{
99  /* get the synchronizeable list from the class list */
[5575]100  this->netStreamList = ClassList::getList(CL_SYNCHRONIZEABLE);
[5605]101  PRINTF(0)("NetworkManager initzalized\n");
[5572]102}
[5522]103
[5530]104
[5522]105/**
106 *  shutsdown the network manager
107 */
108void NetworkManager::shutdown()
[5578]109{
[5522]110
[5578]111}
[5522]112
[5578]113
[5522]114/**
115 *  creates a connection from one object to a host
[5647]116 * @param hostName: the name of the destination host
117 * @param synchronizeable: reference to the sync object
118 */
119NetworkStream& establishConnection(const char& hostName, const Synchronizeable& sync)
120{}
121
122
123/**
124 *  creates a connection from one object to a host
[5522]125 * @param address: the address of the destination host
126 * @param synchronizeable: reference to the sync object
127 */
[5648]128NetworkStream& NetworkManager::establishConnection(IPaddress& address, Synchronizeable& sync)
[5572]129{
[5804]130  printf("Establish connection to server %s, on port %u\n", SDLNet_ResolveIP(&address), address.port);
[5578]131  /* creating a new network stream, it will register itself automaticaly to the class list */
[5649]132  NetworkStream* netStream = new NetworkStream(address, sync, NET_CLIENT);
[5572]133}
[5522]134
[5649]135/**
136 *  creates a new NetworkStream of server type
137 * @param sync: the listener
138 */
[5804]139NetworkStream& NetworkManager::createServer(Synchronizeable& sync, unsigned int port)
[5649]140{
[5805]141  PRINTF(0)("Create a new server socket\n");
[5649]142  /* creating a new network stream, it will register itself automaticaly to the class list */
143  NetworkStream* netStream = new NetworkStream(sync, port, NET_SERVER);
144}
[5522]145
[5649]146
[5522]147/**
148 *  teardown a connection
149 */
150void NetworkManager::shutdownConnection()
[5605]151{
152  PRINTF(0)("Shutdown connection\n");
153}
[5522]154
[5530]155
[5522]156
157/**
158 *  sync the network
159 */
160void NetworkManager::synchronize()
[5578]161{
162  if (this->netStreamList != NULL || (this->netStreamList = ClassList::getList(CL_NETWORK_STREAM)) != NULL)
163  {
[5649]164    tIterator<BaseObject>* iterator = this->netStreamList->getIterator();
165    NetworkStream* stream = (NetworkStream*)(iterator->firstElement());
166    while( stream)
167    {
168      stream->processData();
169      stream = (NetworkStream*)(iterator->nextElement());
170    }
171    delete iterator;
[5578]172  }
[5522]173
[5578]174}
[5522]175
[5578]176
Note: See TracBrowser for help on using the repository browser.