Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

network: added even more interface, more function to the network_manager and sync test class

File size: 4.3 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: Patrick Boenzli
13   co-programmer: ...
14*/
15
16
17/* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_NETWORK module
18   For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput
19*/
20#define DEBUG_MODULE_NETWORK
21
22
23#include "network_stream.h"
24#include "list.h"
25#include "class_list.h"
26
27#include "debug.h"
28
29
30/* include your own header */
31#include "network_manager.h"
32
33
34/* using namespace std is default, this needs to be here */
35using namespace std;
36
37
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:
40
41
42 In file network_manager.h
43
44 class NetworkManager
45 {
46   int doSomeStuff(float argument, float* pointer);
47 }
48
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...
56  * @param pointer:  this is the pointer to nowhereland
57  * return: whatever the function returns: for example an index, number, etc.
58  * /
59 int NetworkManager::doSomeStuff(float argument, float* pointer)
60 {
61   // whaterver you want to do
62 }
63
64
65 if you want to make automake compile your files: you will want to add the file names to the local Makefile.am
66
67 ************************************/
68
69
70
71/**
72 *  standard constructor
73 */
74NetworkManager::NetworkManager()
75{
76  /* set the class id for the base object */
77  this->setClassID(CL_NETWORK_MANAGER, "NetworkManager");
78 
79  /* initialize the references */
80  this->netStreamList = NULL;
81  this->syncList = NULL;
82 
83  PRINTF(0)("NetworkManager created\n");
84}
85
86
87/**
88 *  standard deconstructor
89 */
90NetworkManager::~NetworkManager()
91{}
92
93
94/**
95 *  initializes the network manager
96 */
97void NetworkManager::initialize()
98{
99  /* get the synchronizeable list from the class list */
100  this->netStreamList = ClassList::getList(CL_SYNCHRONIZEABLE);
101  PRINTF(0)("NetworkManager initzalized\n");
102}
103
104
105/**
106 *  shutsdown the network manager
107 */
108void NetworkManager::shutdown()
109{
110
111}
112
113
114/**
115 *  creates a connection from one object to a host
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
125 * @param address: the address of the destination host
126 * @param synchronizeable: reference to the sync object
127 */
128NetworkStream& NetworkManager::establishConnection(IPaddress& address, Synchronizeable& sync)
129{
130  PRINTF(0)("Establish connection...\n");
131  /* creating a new network stream, it will register itself automaticaly to the class list */
132  NetworkStream* netStream = new NetworkStream(address, sync, NET_CLIENT);
133}
134
135/**
136 *  creates a new NetworkStream of server type
137 * @param sync: the listener
138 */
139NetworkStream& NetworkManager::createServer(Synchronizeable& sync, int port)
140{
141  PRINTF(0)("Create a new server socket...\n");
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}
145
146
147/**
148 *  teardown a connection
149 */
150void NetworkManager::shutdownConnection()
151{
152  PRINTF(0)("Shutdown connection\n");
153}
154
155
156
157/**
158 *  sync the network
159 */
160void NetworkManager::synchronize()
161{
162  PRINTF(0)("NetworkManager synchronizes\n");
163  if (this->netStreamList != NULL || (this->netStreamList = ClassList::getList(CL_NETWORK_STREAM)) != NULL)
164  {
165    tIterator<BaseObject>* iterator = this->netStreamList->getIterator();
166    NetworkStream* stream = (NetworkStream*)(iterator->firstElement());
167    while( stream)
168    {
169      stream->processData();
170      stream = (NetworkStream*)(iterator->nextElement());
171    }
172    delete iterator;
173  }
174
175}
176
177
Note: See TracBrowser for help on using the repository browser.