aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/callback__server_8cpp-source.html
blob: 4facdb6f4222c534d20a468965150bb857f37b78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
	<TITLE>nevrax.org : docs</TITLE>
	<LINK REL=stylesheet TYPE="text/css" HREF="/inc/css/nevrax.css">
	<link href="doxygen.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY MARGINHEIGHT="0" MARGINWIDTH="0">

<!-- uplinks -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0>
 <TR>
        <TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=140 BGCOLOR=#dddddd><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF=><b>Home</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
        <TD><IMG  width=6 height=14  SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF=http://www.nevrax.com><b>nevrax.com</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
 </TR>
</TABLE> 

<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0 WIDTH=100%>
 <TR><TD  BGCOLOR="#000000" BACKGROUND="/inc/img/black_banner.jpg"><A HREF=""><IMG  SRC="/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR>
</TABLE>

<!-- main table -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0 height=100%>
 <TR>
	<TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
	<TD WIDTH=140   BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">

		<!------ Begin Box ------>
		<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0  cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black>
		<FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td  colspan=2 bgcolor=#FFFFFF>
		<TABLE cellspacing=0 cellpadding=1 border=0>
			<tr><td ALIGN=middle><a  class='linkbox' href="/news/" TITLE="Rubrique news"><img width=13 height=15  hspace=5 border=0 src=/inc/img/picto-news.gif ALT=#></A></td><td><a  class='linkbox' href="/news/" TITLE="News">News</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/mail/" TITLE="Rubrique mail"><img width=15 height=11  hspace=5 border=0 src=/inc/img/picto-mail.gif ALT=#></A></td><td><a  class='linkbox' href="/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/docs/" TITLE="Rubrique docs"><img width=14 height=16  hspace=5 border=0 src=/inc/img/picto-docs.gif ALT=#></A></td><td><a  class='linkbox' href="/docs/" TITLE="Documentation">Documentation</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/cvs/" TITLE="Rubrique cvs"><img width=13 height=17  hspace=5 border=0 src=/inc/img/picto-cvs.gif ALT=#></A></td><td><a  class='linkbox' href="/cvs/" TITLE="CVS Web">CVS</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/bugs/" TITLE="Rubrique bugs"><img width=20 height=16  hspace=5 border=0 src=/inc/img/picto-bugs.gif ALT=#></A></td><td><a  class='linkbox' href="/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/GPL.php3" TITLE="Rubrique license"><img  width=18 height=12   hspace=5 border=0 src=/inc/img/picto-gpl.gif ALT=#></A></td><td><a  class='linkbox' href="/GPL.php3" TITLE="License">License</a></td></tr>
		</TABLE>
		</TD></TR></TABLE></TD></TR></TABLE>
		<!------ End Box  ------>

	</TD>
	<TD WIDTH=15><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
	<TD ALIGN=left valign=top><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">

<!-- title -->
<TABLE  background="/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0  BORDER=0 width=100%><tr><td>
<A HREF="/docs/"><img src="/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG  SRC="/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT="">
</td></tr></table>
&nbsp;

<!-- block -->
<TABLE  bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0  BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="/inc/img/reddots.gif"></TD>
	<TD><B>Documentation</B></TD>
	<TD ALIGN=RIGHT>&nbsp;</td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; <a class="qindexRef" doxygen="_cgi:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> &nbsp; </center>
<hr><h1>callback_server.cpp</h1><a href="callback__server_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 
00007 <font class="comment">/* Copyright, 2001 Nevrax Ltd.</font>
00008 <font class="comment"> *</font>
00009 <font class="comment"> * This file is part of NEVRAX NEL.</font>
00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font>
00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font>
00013 <font class="comment"> * any later version.</font>
00014 <font class="comment"></font>
00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font>
00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00018 <font class="comment"> * General Public License for more details.</font>
00019 <font class="comment"></font>
00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font>
00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font>
00023 <font class="comment"> * MA 02111-1307, USA.</font>
00024 <font class="comment"> */</font>
00025 
00026 <font class="preprocessor">#include "<a class="code" href="stdnet_8h.html">stdnet.h</a>"</font>
00027 
00028 <font class="preprocessor">#include "<a class="code" href="string__id__array_8h.html">nel/misc/string_id_array.h</a>"</font>
00029 
00030 <font class="preprocessor">#include "<a class="code" href="callback__server_8h.html">nel/net/callback_server.h</a>"</font>
00031 
00032 <font class="preprocessor">#ifdef USE_MESSAGE_RECORDER</font>
00033 <font class="preprocessor"></font><font class="preprocessor">#include "<a class="code" href="dummy__tcp__sock_8h.html">nel/net/dummy_tcp_sock.h</a>"</font>
00034 <font class="preprocessor">#endif</font>
00035 <font class="preprocessor"></font>
00036 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00037 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
00038 
00039 <font class="keyword">namespace </font>NLNET {
00040 
00041 
00042 <font class="comment">/*</font>
00043 <font class="comment"> * Connection callback (the disconnection callback is in callback_net_base.cpp</font>
00044 <font class="comment"> */</font>
<a name="l00045"></a><a class="code" href="classNLNET_1_1CCallbackServer.html#a93">00045</a> <font class="keywordtype">void</font> <a class="code" href="namespaceNLNET.html#a93">cbsNewConnection</a> (<a class="code" href="namespaceNLNET.html#a0">TSockId</a> from, <font class="keywordtype">void</font> *<a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a>)
00046 {
00047         <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a> != NULL);
00048         CCallbackServer *server = (CCallbackServer *)<a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a>;
00049 
00050         <a class="code" href="debug_8h.html#a0">nldebug</a>(<font class="stringliteral">"LNETL3S: newConnection()"</font>);
00051 
00052 <font class="preprocessor">#ifdef USE_MESSAGE_RECORDER</font>
00053 <font class="preprocessor"></font>        <font class="comment">// Record connection</font>
00054         server-&gt;noticeConnection( from );
00055 <font class="preprocessor">#endif</font>
00056 <font class="preprocessor"></font>
00057         <font class="comment">// send all my association to the new client</font>
00058 <font class="comment">// association are disactivated so we don t need to send them</font>
00059 <font class="comment">//      server-&gt;sendAllMyAssociations (from);</font>
00060 
00061         <font class="comment">// call the client callback if necessary</font>
00062         <font class="keywordflow">if</font> (server-&gt;_ConnectionCallback != NULL)
00063                 server-&gt;_ConnectionCallback (from, server-&gt;_ConnectionCbArg);
00064 }
00065 
00066 
00067 <font class="comment">/*</font>
00068 <font class="comment"> * Constructor</font>
00069 <font class="comment"> */</font>
00070 CCallbackServer::CCallbackServer( TRecordingState rec, <font class="keyword">const</font> string&amp; recfilename, <font class="keywordtype">bool</font> recordall ) :
00071         CCallbackNetBase( rec, recfilename, recordall ),
00072         CBufServer( <a class="code" href="buf__server_8h.html#a0">DEFAULT_STRATEGY</a>, <a class="code" href="buf__server_8h.html#a1">DEFAULT_MAX_THREADS</a>, <a class="code" href="buf__server_8h.html#a2">DEFAULT_MAX_SOCKETS_PER_THREADS</a>, true, rec==Replay ),
00073         _ConnectionCallback(NULL),
00074         _ConnectionCbArg(NULL)
00075 {
00076 <font class="preprocessor">#ifndef USE_MESSAGE_RECORDER</font>
00077 <font class="preprocessor"></font>        <a class="code" href="debug_8h.html#a8">nlassertex</a>( rec==<a class="code" href="classNLNET_1_1CCallbackNetBase.html#s3s0">Off</a>, (<font class="stringliteral">"The message recorder is disabled at compilation time ; switch the recording state Off"</font>) );
00078 <font class="preprocessor">#endif</font>
00079 <font class="preprocessor"></font>        
00080         CBufServer::setDisconnectionCallback (<a class="code" href="classNLNET_1_1CCallbackNetBase.html#n2">_NewDisconnectionCallback</a>, <font class="keyword">this</font>);
00081         CBufServer::setConnectionCallback (<a class="code" href="classNLNET_1_1CCallbackServer.html#a93">cbsNewConnection</a>, <font class="keyword">this</font>);
00082 
00083         <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n7">_IsAServer</a> = <font class="keyword">true</font>;
00084         <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n6">_DefaultCallback</a> = NULL;
00085 }
00086 
00087 
00088 <font class="comment">/*</font>
00089 <font class="comment"> *</font>
00090 <font class="comment"> */</font>
<a name="l00091"></a><a class="code" href="classNLNET_1_1CCallbackServer.html#c3">00091</a> <font class="keywordtype">void</font> CCallbackServer::sendAllMyAssociations (<a class="code" href="namespaceNLNET.html#a0">TSockId</a> to)
00092 {
00093         <a class="code" href="debug_8h.html#a6">nlassert</a> (to != InvalidSockId); <font class="comment">// invalid hostid</font>
00094         <a class="code" href="classNLNET_1_1CCallbackNetBase.html#b4">checkThreadId</a> ();
00095         <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNLNET_1_1CCallbackServer.html#a6">connected</a> ());
00096 
00097         <font class="comment">// he wants all associations</font>
00098         CMessage msgout (<a class="code" href="classNLNET_1_1CCallbackNetBase.html#a13">getSIDA</a>(), <font class="stringliteral">"RAA"</font>);
00099 
00100         CStringIdArray::TStringId size;
00101         size = <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n4">_OutputSIDA</a>.<a class="code" href="classNLMISC_1_1CStringIdArray.html#a6">size</a> ();
00102 
00103         <a class="code" href="debug_8h.html#a0">nldebug</a> (<font class="stringliteral">"LNETL3S: Send all (%d) my string association to %s"</font>, size, to-&gt;asString().c_str());
00104         
00105         msgout.serial (size);
00106 
00107         <font class="keywordflow">for</font> (CStringIdArray::TStringId i = 0; i &lt; size; i++)
00108         {
00109 <font class="comment">//              nldebug ("LNETL3S:  sending association '%s' -&gt; %d", _OutputSIDA.getString(i).c_str (), i);</font>
00110                 string str(<a class="code" href="classNLNET_1_1CCallbackNetBase.html#n4">_OutputSIDA</a>.<a class="code" href="classNLMISC_1_1CStringIdArray.html#a4">getString</a>(i));
00111                 msgout.serial (str);
00112                 msgout.serial (i);
00113         }
00114 
00115         <a class="code" href="classNLNET_1_1CCallbackServer.html#a1">send</a> (msgout, to);
00116 }
00117 
00118 
00119 <font class="comment">/*</font>
00120 <font class="comment"> * Send a message to the specified host (pushing to its send queue)</font>
00121 <font class="comment"> * Recorded : YES</font>
00122 <font class="comment"> * Replayed : MAYBE</font>
00123 <font class="comment"> */</font>
<a name="l00124"></a><a class="code" href="classNLNET_1_1CCallbackServer.html#a1">00124</a> <font class="keywordtype">void</font> CCallbackServer::send (<font class="keyword">const</font> CMessage &amp;buffer, <a class="code" href="namespaceNLNET.html#a0">TSockId</a> hostid, <font class="keywordtype">bool</font> log)
00125 {
00126         <a class="code" href="classNLNET_1_1CCallbackNetBase.html#b4">checkThreadId</a> ();
00127         <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNLNET_1_1CCallbackServer.html#a6">connected</a> ());
00128         <a class="code" href="debug_8h.html#a6">nlassert</a> (buffer.length() != 0);
00129         <a class="code" href="debug_8h.html#a6">nlassert</a> (buffer.typeIsSet());
00130 
00131         <font class="keywordflow">if</font> (hostid == InvalidSockId)
00132         {
00133                 <font class="comment">// broadcast</font>
00134                 sint nb = <a class="code" href="classNLNET_1_1CBufServer.html#a19">nbConnections</a> ();
00135                 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n0">_BytesSent</a> += buffer.length () * nb;
00136         }
00137         <font class="keywordflow">else</font>
00138         {
00139                 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n0">_BytesSent</a> += buffer.length ();
00140         }
00141 
00142 <font class="comment">//      if (log)</font>
00143         {
00144 <font class="comment">//              nldebug ("LNETL3S: Server: send(%s, %s)", buffer.toString().c_str(), hostid-&gt;asString().c_str());</font>
00145         }
00146 
00147 <font class="preprocessor">#ifdef USE_MESSAGE_RECORDER</font>
00148 <font class="preprocessor"></font>        <font class="keywordflow">if</font> ( _MR_RecordingState != <a class="code" href="classNLNET_1_1CCallbackNetBase.html#s3s2">Replay</a> )
00149         {
00150 <font class="preprocessor">#endif</font>
00151 <font class="preprocessor"></font>
00152                 <font class="comment">// Send</font>
00153                 CBufServer::send (buffer, hostid);
00154 
00155 <font class="preprocessor">#ifdef USE_MESSAGE_RECORDER</font>
00156 <font class="preprocessor"></font>                <font class="keywordflow">if</font> ( _MR_RecordingState == <a class="code" href="classNLNET_1_1CCallbackNetBase.html#s3s1">Record</a> )
00157                 {
00158                         <font class="comment">// Record sent message</font>
00159                         _MR_Recorder.recordNext( _MR_UpdateCounter, <a class="code" href="namespaceNLNET.html#a156a12">Sending</a>, hostid, const_cast&lt;CMessage&amp;&gt;(buffer) );
00160                 }
00161         }
00162         <font class="keywordflow">else</font>
00163         {       
00165         }
00166 <font class="preprocessor">#endif</font>
00167 <font class="preprocessor"></font>}
00168 
00169 
00170 <font class="comment">/*</font>
00171 <font class="comment"> * Updates the network (call this method evenly)</font>
00172 <font class="comment"> * Recorded : YES (in baseUpdate())</font>
00173 <font class="comment"> * Replayed : YES (in baseUpdate())</font>
00174 <font class="comment"> */</font>
<a name="l00175"></a><a class="code" href="classNLNET_1_1CCallbackServer.html#a3">00175</a> <font class="keywordtype">void</font> CCallbackServer::update ( sint32 timeout )
00176 {
00177         <a class="code" href="classNLNET_1_1CCallbackNetBase.html#b4">checkThreadId</a> ();
00178         <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNLNET_1_1CCallbackServer.html#a6">connected</a> ());
00179 
00180         <font class="comment">//      nldebug ("LNETL3S: Client: update()");</font>
00181         <a class="code" href="classNLNET_1_1CCallbackNetBase.html#b1">baseUpdate</a> ( timeout ); <font class="comment">// first receive</font>
00182 
00183 <font class="preprocessor">#ifdef USE_MESSAGE_RECORDER</font>
00184 <font class="preprocessor"></font>        <font class="keywordflow">if</font> ( _MR_RecordingState != <a class="code" href="classNLNET_1_1CCallbackNetBase.html#s3s2">Replay</a> )
00185         {
00186 <font class="preprocessor">#endif</font>
00187 <font class="preprocessor"></font>
00188                 <font class="comment">// L1-2 Update (nothing to do in replay mode)</font>
00189                 CBufServer::update (); <font class="comment">// then send</font>
00190 
00191 <font class="preprocessor">#ifdef USE_MESSAGE_RECORDER</font>
00192 <font class="preprocessor"></font>        }
00193 <font class="preprocessor">#endif</font>
00194 <font class="preprocessor"></font>}
00195 
00196 
00197 <font class="comment">/*</font>
00198 <font class="comment"> * Read the next message in the receive queue</font>
00199 <font class="comment"> * Recorded : YES</font>
00200 <font class="comment"> * Replayed : YES</font>
00201 <font class="comment"> */</font>
<a name="l00202"></a><a class="code" href="classNLNET_1_1CCallbackServer.html#c2">00202</a> <font class="keywordtype">void</font> CCallbackServer::receive (CMessage &amp;buffer, <a class="code" href="namespaceNLNET.html#a0">TSockId</a> *hostid)
00203 {
00204         <a class="code" href="classNLNET_1_1CCallbackNetBase.html#b4">checkThreadId</a> ();
00205         <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNLNET_1_1CCallbackServer.html#a6">connected</a> ());
00206 
00207 <font class="preprocessor">#ifdef USE_MESSAGE_RECORDER</font>
00208 <font class="preprocessor"></font>        <font class="keywordflow">if</font> ( _MR_RecordingState != <a class="code" href="classNLNET_1_1CCallbackNetBase.html#s3s2">Replay</a> )
00209         {
00210 <font class="preprocessor">#endif</font>
00211 <font class="preprocessor"></font>
00212                 <font class="comment">// Receive</font>
00213                 CBufServer::receive (buffer, hostid);
00214 
00215 <font class="preprocessor">#ifdef USE_MESSAGE_RECORDER</font>
00216 <font class="preprocessor"></font>                <font class="keywordflow">if</font> ( _MR_RecordingState == <a class="code" href="classNLNET_1_1CCallbackNetBase.html#s3s1">Record</a> )
00217                 {
00218                         <font class="comment">// Record received message</font>
00219                         _MR_Recorder.recordNext( _MR_UpdateCounter, <a class="code" href="namespaceNLNET.html#a156a13">Receiving</a>, *hostid, const_cast&lt;CMessage&amp;&gt;(buffer) );
00220                 }
00221         }
00222         <font class="keywordflow">else</font>
00223         {
00224                 <font class="comment">// Retrieve received message loaded by dataAvailable()</font>
00225                 buffer = _MR_Recorder.ReceivedMessages.front().Message;
00226                 *hostid = _MR_Recorder.ReceivedMessages.front().SockId;
00227                 _MR_Recorder.ReceivedMessages.pop();
00228         }
00229 <font class="preprocessor">#endif</font>
00230 <font class="preprocessor"></font>        
00231         buffer.readType ();
00232 }
00233 
00234 
00235 <font class="comment">/*</font>
00236 <font class="comment"> * Disconnect a connection</font>
00237 <font class="comment"> * Set hostid to InvalidSockId to disconnect all connections.</font>
00238 <font class="comment"> * If hostid is not null and the socket is not connected, the method does nothing.</font>
00239 <font class="comment"> * Before disconnecting, any pending data is actually sent.</font>
00240 <font class="comment"> * Recorded : YES in noticeDisconnection called in the disconnection callback</font>
00241 <font class="comment"> * Replayed : YES in noticeDisconnection called in the disconnection callback</font>
00242 <font class="comment"> */</font>
<a name="l00243"></a><a class="code" href="classNLNET_1_1CCallbackServer.html#a7">00243</a> <font class="keywordtype">void</font> CCallbackServer::disconnect( <a class="code" href="namespaceNLNET.html#a0">TSockId</a> hostid )
00244 {
00245         <a class="code" href="classNLNET_1_1CCallbackNetBase.html#b4">checkThreadId</a> ();
00246 
00247 <font class="preprocessor">#ifdef USE_MESSAGE_RECORDER</font>
00248 <font class="preprocessor"></font>        <font class="keywordflow">if</font> ( _MR_RecordingState != <a class="code" href="classNLNET_1_1CCallbackNetBase.html#s3s2">Replay</a> )
00249         {
00250 <font class="preprocessor">#endif</font>
00251 <font class="preprocessor"></font>                <font class="comment">// Disconnect</font>
00252                 CBufServer::disconnect( hostid );
00253 
00254 <font class="preprocessor">#ifdef USE_MESSAGE_RECORDER</font>
00255 <font class="preprocessor"></font>        }
00256         <font class="comment">// else, no need to manually replay the disconnection, such as in CCallbackClient,</font>
00257         <font class="comment">// it will be replayed during the next update()</font>
00258 <font class="preprocessor">#endif</font>
00259 <font class="preprocessor"></font>}
00260 
00261 
00262 <font class="comment">/*</font>
00263 <font class="comment"> *</font>
00264 <font class="comment"> */</font>
<a name="l00265"></a><a class="code" href="classNLNET_1_1CCallbackServer.html#a9">00265</a> <a class="code" href="namespaceNLNET.html#a0">TSockId</a> CCallbackServer::getSockId (<a class="code" href="namespaceNLNET.html#a0">TSockId</a> hostid)
00266 {
00267         <a class="code" href="debug_8h.html#a6">nlassert</a> (hostid != InvalidSockId);     <font class="comment">// invalid hostid</font>
00268         <a class="code" href="classNLNET_1_1CCallbackNetBase.html#b4">checkThreadId</a> ();
00269         <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNLNET_1_1CCallbackServer.html#a6">connected</a> ());
00270         <a class="code" href="debug_8h.html#a6">nlassert</a> (hostid != NULL);
00271         <font class="keywordflow">return</font> hostid;
00272 }
00273 
00274 
00275 <font class="comment">/*</font>
00276 <font class="comment"> * Returns true if there are messages to read</font>
00277 <font class="comment"> * Recorded : NO</font>
00278 <font class="comment"> * Replayed : YES</font>
00279 <font class="comment"> */</font>
<a name="l00280"></a><a class="code" href="classNLNET_1_1CCallbackServer.html#c1">00280</a> <font class="keywordtype">bool</font> CCallbackServer::dataAvailable ()
00281 {
00282         <a class="code" href="classNLNET_1_1CCallbackNetBase.html#b4">checkThreadId</a> ();
00283 
00284 <font class="preprocessor">#ifdef USE_MESSAGE_RECORDER</font>
00285 <font class="preprocessor"></font>        <font class="keywordflow">if</font> ( _MR_RecordingState != <a class="code" href="classNLNET_1_1CCallbackNetBase.html#s3s2">Replay</a> )
00286         {
00287 <font class="preprocessor">#endif</font>
00288 <font class="preprocessor"></font>
00289                 <font class="comment">// Real dataAvailable()</font>
00290                 <font class="keywordflow">return</font> CBufServer::dataAvailable (); 
00291 
00292 <font class="preprocessor">#ifdef USE_MESSAGE_RECORDER</font>
00293 <font class="preprocessor"></font>        }
00294         <font class="keywordflow">else</font>
00295         {
00296                 <font class="comment">// Simulated dataAvailable()</font>
00297                 <font class="keywordflow">return</font> CCallbackNetBase::replayDataAvailable();
00298         }
00299 <font class="preprocessor">#endif</font>
00300 <font class="preprocessor"></font>}
00301 
00302 
00303 <font class="comment">//-------------------------</font>
00304 <font class="preprocessor">#ifdef USE_MESSAGE_RECORDER</font>
00305 <font class="preprocessor"></font>
00306   
00307 <font class="comment">/*</font>
00308 <font class="comment"> * Replay connection and disconnection callbacks, client version</font>
00309 <font class="comment"> */</font>
00310 <font class="keywordtype">bool</font> CCallbackServer::replaySystemCallbacks()
00311 {
00312         <font class="keywordflow">do</font>
00313         {
00314                 <font class="keywordflow">if</font> ( _MR_Recorder.ReceivedMessages.empty() )
00315                 {
00316                         <font class="keywordflow">return</font> <font class="keyword">false</font>;
00317                 }
00318                 <font class="keywordflow">else</font>
00319                 {
00320                         <font class="comment">// Translate the stored sockid to the replayed sockid</font>
00321                         <a class="code" href="namespaceNLNET.html#a0">TSockId</a> sockid;
00322                         std::map&lt;TSockId,TSockId&gt;::iterator isi = _MR_SockIds.find( _MR_Recorder.ReceivedMessages.front().SockId );
00323                         <font class="keywordflow">if</font> ( isi != _MR_SockIds.end() )
00324                         {
00325                                 <font class="comment">// The sockid is found in the map if the connection already exists</font>
00326                                 sockid = (*isi).second;
00327                                 _MR_Recorder.ReceivedMessages.front().SockId = sockid;
00328                         }
00329 
00330                         <font class="comment">// Test event type</font>
00331                         <font class="keywordflow">switch</font>( _MR_Recorder.ReceivedMessages.front().Event )
00332                         {
00333                         <font class="keywordflow">case</font> <a class="code" href="namespaceNLNET.html#a156a13">Receiving</a>:
00334                                 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00335 
00336                         <font class="keywordflow">case</font> <a class="code" href="namespaceNLNET.html#a156a17">Disconnecting</a>:
00337                                 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"Disconnection event for %p"</font>, sockid );
00338                                 sockid-&gt;Sock-&gt;disconnect();
00339                                 sockid-&gt;setConnectedState( <font class="keyword">false</font> );
00340         
00341                                 <font class="comment">// Call callback if needed</font>
00342                                 <font class="keywordflow">if</font> ( <a class="code" href="classNLNET_1_1CBufNetBase.html#b2">disconnectionCallback</a>() != NULL )
00343                                 {
00344                                         <a class="code" href="classNLNET_1_1CBufNetBase.html#b2">disconnectionCallback</a>()( sockid, <a class="code" href="classNLNET_1_1CBufNetBase.html#b3">argOfDisconnectionCallback</a>() );
00345                                 }
00346                                 <font class="keywordflow">break</font>;
00347 
00348                         <font class="keywordflow">case</font> <a class="code" href="namespaceNLNET.html#a156a16">Accepting</a>:
00349                                 {
00350                                 <font class="comment">// Replay connection:</font>
00351 
00352                                 <font class="comment">// Get remote address</font>
00353                                 CInetAddress <a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>;
00354                                 _MR_Recorder.ReceivedMessages.front().Message.serial( <a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a> );
00355 
00356                                 <font class="comment">// Create a new connection </font>
00357                                 sockid = <font class="keyword">new</font> CBufSock( <font class="keyword">new</font> CDummyTcpSock() );
00358                                 sockid-&gt;Sock-&gt;connect( <a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a> );
00359                                 _MR_Connections.push_back( sockid );
00360 
00361                                 <font class="comment">// Bind it to the "old" sockid</font>
00362                                 _MR_SockIds.insert( make_pair( _MR_Recorder.ReceivedMessages.front().SockId, sockid ) );
00363 
00364                                 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"LNETL1: Connection event for %p"</font>, sockid );
00365                                 sockid-&gt;setConnectedState( <font class="keyword">true</font> );
00366                                         
00367                                 <font class="comment">// Call callback if needed</font>
00368                                 <font class="keywordflow">if</font> ( <a class="code" href="classNLNET_1_1CBufServer.html#b5">connectionCallback</a>() != NULL )
00369                                 {
00370                                         <a class="code" href="classNLNET_1_1CBufServer.html#b5">connectionCallback</a>()( sockid, <a class="code" href="classNLNET_1_1CBufServer.html#b6">argOfConnectionCallback</a>() );
00371                                 }
00372                                 <font class="keywordflow">break</font>;
00373                                 }
00374                         <font class="keywordflow">default</font>:
00375                                 <a class="code" href="debug_8h.html#a3">nlerror</a>( <font class="stringliteral">"LNETL1: Invalid system event type in client receive queue"</font> );
00376                         }
00377                         <font class="comment">// Extract system event</font>
00378                         _MR_Recorder.ReceivedMessages.pop();
00379                 }
00380         }
00381         <font class="keywordflow">while</font> ( true );
00382 }
00383 
00384 
00385 <font class="comment">/*</font>
00386 <font class="comment"> * Record or replay connection</font>
00387 <font class="comment"> */</font>
00388 <font class="keywordtype">void</font> CCallbackServer::noticeConnection( <a class="code" href="namespaceNLNET.html#a0">TSockId</a> hostid )
00389 {
00390         <a class="code" href="debug_8h.html#a6">nlassert</a> (hostid != InvalidSockId);     <font class="comment">// invalid hostid</font>
00391         <font class="keywordflow">if</font> ( _MR_RecordingState != <a class="code" href="classNLNET_1_1CCallbackNetBase.html#s3s2">Replay</a> )
00392         {
00393                 <font class="keywordflow">if</font> ( _MR_RecordingState == <a class="code" href="classNLNET_1_1CCallbackNetBase.html#s3s1">Record</a> )
00394                 {
00395                         <font class="comment">// Record connection</font>
00396                         CMessage addrmsg;
00397                         addrmsg.serial( const_cast&lt;CInetAddress&amp;&gt;(<a class="code" href="classNLNET_1_1CCallbackServer.html#a8">hostAddress</a>(hostid)) );
00398                         _MR_Recorder.recordNext( _MR_UpdateCounter, <a class="code" href="namespaceNLNET.html#a156a16">Accepting</a>, hostid, addrmsg );
00399                 }
00400         }
00401         <font class="keywordflow">else</font>
00402         {
00404         }
00405 }
00406 
00407 <font class="preprocessor">#endif // USE_MESSAGE_RECORDER</font>
00408 <font class="preprocessor"></font>
00409 
00410 } <font class="comment">// NLNET</font>
</pre></div>

<!-- footer -->
<BR><FONT Size=+5>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </FONT>
</TD>
<TD WIDTH=15><IMG  SRC=/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>