Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

implemented udp sockets

File size: 3.6 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#include "class_list.h"
23#include "debug.h"
24#include "shell_command.h"
25
26/* include your own header */
27#include "network_manager.h"
28#include "shared_network_data.h"
29#include "network_stream.h"
30
31
32/* using namespace std is default, this needs to be here */
33using namespace std;
34
35SHELL_COMMAND(debug, NetworkManager, debug);
36
37
38NetworkManager* NetworkManager::singletonRef = NULL;
39
40/**
41 *  standard constructor
42 */
43NetworkManager::NetworkManager()
44{
45  /* set the class id for the base object */
46  this->setClassID(CL_NETWORK_MANAGER, "NetworkManager");
47  PRINTF(0)("START\n");
48
49  /* initialize the references */
50  this->netStreamList = NULL;
51  this->syncList = NULL;
52  this->defaultSyncStream = NULL;
53  this->sharedNetworkData = SharedNetworkData::getInstance();
54
55  PRINTF(0)("NetworkManager created\n");
56}
57
58
59/**
60 *  standard deconstructor
61 */
62NetworkManager::~NetworkManager()
63{}
64
65
66/**
67 *  initializes the network manager
68 */
69void NetworkManager::initialize()
70{
71  /* get the synchronizeable list from the class list */
72  this->netStreamList = ClassList::getList(CL_SYNCHRONIZEABLE);
73  PRINTF(0)("NetworkManager initzalized\n");
74}
75
76
77/**
78 *  shutsdown the network manager
79 */
80void NetworkManager::shutdown()
81{
82
83}
84
85
86/**
87 *  creates a connection from one object to a host
88 * @param hostName: the name of the destination host
89 */
90int NetworkManager::establishConnection(const std::string & name, unsigned int port)
91{
92  this->defaultSyncStream = new NetworkStream( name, port );
93  this->sharedNetworkData->setDefaultSyncStream(this->defaultSyncStream);
94  this->defaultSyncStream->startHandshake();
95  return 1;
96}
97
98
99/**
100 *  creates a new NetworkStream of server type
101 * @param port: number of the TCP port
102 */
103int NetworkManager::createServer(unsigned int port)
104{
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");
111  SDL_Delay(20);
112  return 1;
113}
114
115
116void NetworkManager::connectSynchronizeable(Synchronizeable& sync)
117{
118  if( this->defaultSyncStream)
119    this->defaultSyncStream->connectSynchronizeable(sync);
120}
121
122
123/**
124 *  sync the network
125 */
126void NetworkManager::synchronize()
127{
128  if (this->netStreamList != NULL || (this->netStreamList = ClassList::getList(CL_NETWORK_STREAM)) != NULL)
129  {
130    std::list<BaseObject*>::const_iterator stream;
131    for (stream = this->netStreamList->begin(); stream != this->netStreamList->end(); ++stream)
132      if( static_cast<NetworkStream*>(*stream)->isActive())
133        static_cast<NetworkStream*>(*stream)->processData();
134  }
135}
136
137
138
139/**
140 * debug output
141 */
142 void NetworkManager::debug()
143{
144  PRINT(0)("=================Network::debug()=========\n");
145  this->defaultSyncStream->debug();
146  PRINT(0)("===========================================\n");
147}
Note: See TracBrowser for help on using the repository browser.