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