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
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
|
<!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="http://www.nevrax.org/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="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.org><b>Home</B></FONT></A> </TD>
<TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.com><b>nevrax.com</B></FONT></A> </TD>
</TR>
</TABLE>
<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=100%>
<TR><TD BGCOLOR="#000000" BACKGROUND="http://www.nevrax.org/inc/img/black_banner.jpg"><A HREF="http://www.nevrax.org"><IMG SRC="http://www.nevrax.org/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="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG SRC="http://www.nevrax.org/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="http://www.nevrax.org/news/" TITLE="Rubrique news"><img width=13 height=15 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-news.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="News">News</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Rubrique mail"><img width=15 height=11 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-mail.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Rubrique docs"><img width=14 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-docs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Documentation">Documentation</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="Rubrique cvs"><img width=13 height=17 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-cvs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="CVS Web">CVS</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Rubrique bugs"><img width=20 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-bugs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="Rubrique license"><img width=18 height=12 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-gpl.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="License">License</a></td></tr>
</TABLE>
</TD></TR></TABLE></TD></TR></TABLE>
<!------ End Box ------>
</TD>
<TD WIDTH=15><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD ALIGN=left valign=top><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
<!-- title -->
<TABLE background="http://www.nevrax.org/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td>
<A HREF="http://www.nevrax.org/docs/"><img src="http://www.nevrax.org/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT="">
</td></tr></table>
<!-- 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="http://www.nevrax.org/inc/img/reddots.gif"></TD>
<TD><B>Documentation</B></TD>
<TD ALIGN=RIGHT> </td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindexRef" doxygen="_cgi:http://www.nevrax.org/cgi-bin/nel-search.cgi" href="http://www.nevrax.org/cgi-bin/nel-search.cgi">Search</a> </center>
<hr><h1>callback_net_base.cpp</h1><a href="callback__net__base_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 <font class="preprocessor">#include "<a class="code" href="hierarchical__timer_8h.html">nel/misc/hierarchical_timer.h</a>"</font>
00030
00031 <font class="preprocessor">#include "<a class="code" href="buf__sock_8h.html">nel/net/buf_sock.h</a>"</font>
00032 <font class="preprocessor">#include "<a class="code" href="callback__net__base_8h.html">nel/net/callback_net_base.h</a>"</font>
00033
00034 <font class="preprocessor">#ifdef USE_MESSAGE_RECORDER</font>
00035 <font class="preprocessor"></font><font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00036 <font class="preprocessor"></font><font class="preprocessor">#pragma message ( "NeL Net layer 3: message recorder enabled" )</font>
00037 <font class="preprocessor"></font><font class="preprocessor">#endif // NL_OS_WINDOWS</font>
00038 <font class="preprocessor"></font><font class="preprocessor">#include "<a class="code" href="message__recorder_8h.html">nel/net/message_recorder.h</a>"</font>
00039 <font class="preprocessor">#else</font>
00040 <font class="preprocessor"></font><font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00041 <font class="preprocessor"></font><font class="preprocessor">#pragma message ( "NeL Net layer 3: message recorder disabled" )</font>
00042 <font class="preprocessor"></font><font class="preprocessor">#endif // NL_OS_WINDOWS</font>
00043 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
00044 <font class="preprocessor"></font>
00045
00046 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00047 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
00048
00049 <font class="keyword">namespace </font>NLNET {
00050
00051
00052 <font class="comment">/*</font>
00053 <font class="comment"> *</font>
00054 <font class="comment"> */</font>
<a name="l00055"></a><a class="code" href="classNLNET_1_1CCallbackNetBase.html#a90">00055</a> <font class="keywordtype">void</font> <a class="code" href="namespaceNLNET.html#a90">cbnbMessageRecvAssociations</a> (CMessage &msgin, <a class="code" href="namespaceNLNET.html#a0">TSockId</a> from, CCallbackNetBase &netbase)
00056 {
00057 <font class="comment">// receive a new message association</font>
00058
00059 CStringIdArray::TStringId size;
00060 msgin.serial (size);
00061
00062 <a class="code" href="debug_8h.html#a0">nldebug</a> (<font class="stringliteral">"LNETL3NB_ASSOC: The other side gave me %d association strings"</font>, size);
00063
00064 <font class="keywordflow">for</font> (CStringIdArray::TStringId i = 0; i < size; i++)
00065 {
00066 std::string name;
00067 CStringIdArray::TStringId <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>;
00068
00069 msgin.serial (name);
00070 msgin.serial (<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>);
00071
00072 <font class="comment">// if id == -1, it means that there are no callback associated to this message</font>
00073 <font class="comment">// it should not happen, it mean that one side send a message that the other side</font>
00074 <font class="comment">// can't manage in his callbackarray.</font>
00075 <font class="comment">// to resolve the problem, add the callback in the callbackarray in the other side</font>
00076 <font class="comment">// and put NULL if you don't want to manage this message</font>
00077 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a> != -1);
00078
00079 <a class="code" href="debug_8h.html#a0">nldebug</a> (<font class="stringliteral">"LNETL3NB_ASSOC: association '%s' -> %d"</font>, name.c_str (), <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>);
00080 netbase.getSIDA().addString (name, <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>);
00081 }
00082 }
00083
00084
00085 <font class="comment">/*</font>
00086 <font class="comment"> * the other side want to know some of my association, send them!</font>
00087 <font class="comment"> */</font>
<a name="l00088"></a><a class="code" href="classNLNET_1_1CCallbackNetBase.html#a91">00088</a> <font class="keywordtype">void</font> <a class="code" href="namespaceNLNET.html#a91">cbnbMessageAskAssociations</a> (CMessage &msgin, <a class="code" href="namespaceNLNET.html#a0">TSockId</a> from, CCallbackNetBase &netbase)
00089 {
00090 CMessage msgout (netbase.getSIDA(), <font class="stringliteral">"RA"</font>);
00091 CStringIdArray::TStringId size;
00092 msgin.serial (size);
00093
00094 <a class="code" href="debug_8h.html#a0">nldebug</a> (<font class="stringliteral">"LNETL3NB_ASSOC: The other side want %d string associations"</font>, size);
00095
00096 msgout.serial (size);
00097
00098 <font class="keywordflow">for</font> (sint i = 0; i < size; i++)
00099 {
00100 string name;
00101 msgin.serial (name);
00102 <a class="code" href="debug_8h.html#a0">nldebug</a> (<font class="stringliteral">"LNETL3NB_ASSOC: sending association '%s' -> %d"</font>, name.c_str (), netbase._OutputSIDA.getId(name));
00103
00104 <font class="comment">// if this assert occurs, it means that the other side ask an unknown message</font>
00105 <font class="comment">// or that there are different types of client (with differents callbackarray) and one of the client doesn't have this callback</font>
00106 <a class="code" href="debug_8h.html#a6">nlassert</a>(netbase._OutputSIDA.getId(name) != -1);
00107
00108 msgout.serial (name);
00109
00110 CStringIdArray::TStringId <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a> = netbase._OutputSIDA.getId (name);
00111 msgout.serial (<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>);
00112 }
00113 <font class="comment">// send the message to the other side</font>
00114 netbase.send (msgout, from);
00115 }
00116
00117 <font class="keyword">static</font> TCallbackItem <a class="code" href="namespaceNLNET.html#a28">cbnbMessageAssociationArray</a>[] =
00118 {
00119 { <font class="stringliteral">"AA"</font>, <a class="code" href="namespaceNLNET.html#a91">cbnbMessageAskAssociations</a> },
00120 { <font class="stringliteral">"RA"</font>, <a class="code" href="namespaceNLNET.html#a90">cbnbMessageRecvAssociations</a> },
00121 };
00122
00123
00124 <font class="comment">/*</font>
00125 <font class="comment"> * Disconnection callback</font>
00126 <font class="comment"> */</font>
<a name="l00127"></a><a class="code" href="classNLNET_1_1CCallbackNetBase.html#a92">00127</a> <font class="keywordtype">void</font> <a class="code" href="namespaceNLNET.html#a92">cbnbNewDisconnection</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>)
00128 {
00129 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a> != NULL);
00130 CCallbackNetBase *base = (CCallbackNetBase *)<a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a>;
00131
00132 <a class="code" href="debug_8h.html#a0">nldebug</a>(<font class="stringliteral">"LNETL3NB: cbnbNewDisconnection()"</font>);
00133
00134 <font class="preprocessor">#ifdef USE_MESSAGE_RECORDER</font>
00135 <font class="preprocessor"></font> <font class="comment">// Record or replay disconnection</font>
00136 base->noticeDisconnection( from );
00137 <font class="preprocessor">#endif</font>
00138 <font class="preprocessor"></font>
00139 <font class="comment">// Call the client callback if necessary</font>
00140 <font class="keywordflow">if</font> (base->_DisconnectionCallback != NULL)
00141 base->_DisconnectionCallback (from, base->_DisconnectionCbArg);
00142 }
00143
00144
00145 <font class="comment">/*</font>
00146 <font class="comment"> * Constructor</font>
00147 <font class="comment"> */</font>
00148 CCallbackNetBase::CCallbackNetBase( TRecordingState rec, <font class="keyword">const</font> string& recfilename, <font class="keywordtype">bool</font> recordall ) :
00149 _FirstUpdate (true), _DisconnectionCallback(NULL), _DisconnectionCbArg(NULL)
00150 #ifdef USE_MESSAGE_RECORDER
00151 , _MR_RecordingState(rec), _MR_UpdateCounter(0)
00152 #endif
00153 {
00154 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n9">_ThreadId</a> = <a class="code" href="namespaceNLMISC.html#a237">getThreadId</a> ();
00155 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n2">_NewDisconnectionCallback</a> = <a class="code" href="classNLNET_1_1CCallbackNetBase.html#a92">cbnbNewDisconnection</a>;
00156
00157 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n0">_BytesSent</a> = 0;
00158 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n1">_BytesReceived</a> = 0;
00159
00160 <a class="code" href="namespaceNLMISC.html#a247">createDebug</a>(); <font class="comment">// for addNegativeFilter to work even in release and releasedebug modes</font>
00161
00162 <font class="comment">// add the callback needed to associate messages with id</font>
00163 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#a7">addCallbackArray</a> (<a class="code" href="namespaceNLNET.html#a28">cbnbMessageAssociationArray</a>, <font class="keyword">sizeof</font> (<a class="code" href="namespaceNLNET.html#a28">cbnbMessageAssociationArray</a>) / <font class="keyword">sizeof</font> (<a class="code" href="namespaceNLNET.html#a28">cbnbMessageAssociationArray</a>[0]));
00164
00165 <font class="preprocessor">#ifdef USE_MESSAGE_RECORDER</font>
00166 <font class="preprocessor"></font> <font class="keywordflow">switch</font> ( _MR_RecordingState )
00167 {
00168 <font class="keywordflow">case</font> <a class="code" href="classNLNET_1_1CCallbackNetBase.html#s3s1">Record</a> :
00169 _MR_Recorder.startRecord( recfilename, recordall );
00170 <font class="keywordflow">break</font>;
00171 <font class="keywordflow">case</font> <a class="code" href="classNLNET_1_1CCallbackNetBase.html#s3s2">Replay</a> :
00172 _MR_Recorder.startReplay( recfilename );
00173 <font class="keywordflow">break</font>;
00174 <font class="keywordflow">default</font>:;
00175 <font class="comment">// No recording</font>
00176 }
00177 <font class="preprocessor">#endif</font>
00178 <font class="preprocessor"></font>}
00179
00180
00181 <font class="comment">/*</font>
00182 <font class="comment"> * Append callback array with the specified array</font>
00183 <font class="comment"> */</font>
<a name="l00184"></a><a class="code" href="classNLNET_1_1CCallbackNetBase.html#a7">00184</a> <font class="keywordtype">void</font> CCallbackNetBase::addCallbackArray (<font class="keyword">const</font> TCallbackItem *callbackarray, CStringIdArray::TStringId arraysize)
00185 {
00186 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#b4">checkThreadId</a> ();
00187
00188 <font class="comment">// be sure that the 2 array have the same size</font>
00189 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNLNET_1_1CCallbackNetBase.html#n5">_CallbackArray</a>.size () == (uint)<a class="code" href="classNLNET_1_1CCallbackNetBase.html#n4">_OutputSIDA</a>.<a class="code" href="classNLMISC_1_1CStringIdArray.html#a6">size</a> ());
00190
00191 <font class="keywordflow">if</font> (arraysize == 1 && callbackarray[0].Callback == NULL && string(<font class="stringliteral">""</font>) == callbackarray[0].Key)
00192 {
00193 <font class="comment">// it's an empty array, ignore it</font>
00194 <font class="keywordflow">return</font>;
00195 }
00196
00197 <font class="comment">// resize the array</font>
00198 sint oldsize = <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n5">_CallbackArray</a>.size();
00199
00200 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n5">_CallbackArray</a>.resize (oldsize + arraysize);
00201 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n4">_OutputSIDA</a>.<a class="code" href="classNLMISC_1_1CStringIdArray.html#a5">resize</a> (oldsize + arraysize);
00202
00203 <font class="comment">//TOO MUCH MESSAGE nldebug ("L3NB_CB: Adding %d callback to the array", arraysize);</font>
00204
00205 <font class="keywordflow">for</font> (sint i = 0; i < arraysize; i++)
00206 {
00207 CStringIdArray::TStringId ni = oldsize + i;
00208 <font class="comment">//TOO MUCH MESSAGE nldebug ("L3NB_CB: Adding callback to message '%s', id '%d'", callbackarray[i].Key, ni);</font>
00209 <font class="comment">// copy callback value</font>
00210
00211 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n5">_CallbackArray</a>[ni] = callbackarray[i];
00212 <font class="comment">// add the string to the string id array</font>
00213 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n4">_OutputSIDA</a>.<a class="code" href="classNLMISC_1_1CStringIdArray.html#a1">addString</a> (callbackarray[i].Key, ni);
00214
00215 }
00216 <font class="comment">// nldebug ("LNETL3NB_CB: Added %d callback Now, there's %d callback associated with message type", arraysize, _CallbackArray.size ());</font>
00217 }
00218
00219
00220 <font class="comment">/*</font>
00221 <font class="comment"> * processOneMessage()</font>
00222 <font class="comment"> */</font>
<a name="l00223"></a><a class="code" href="classNLNET_1_1CCallbackNetBase.html#b2">00223</a> <font class="keywordtype">void</font> CCallbackNetBase::processOneMessage ()
00224 {
00225 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#b4">checkThreadId</a> ();
00226
00227 <font class="comment">// slow down the layer H_AUTO (CCallbackNetBase_processOneMessage);</font>
00228
00229 CMessage msgin (<a class="code" href="classNLNET_1_1CCallbackNetBase.html#n4">_OutputSIDA</a>, <font class="stringliteral">""</font>, <font class="keyword">true</font>);
00230 <a class="code" href="namespaceNLNET.html#a0">TSockId</a> tsid;
00231 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#b3">receive</a> (msgin, &tsid);
00232
00233 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n1">_BytesReceived</a> += msgin.length ();
00234
00235 <font class="comment">// now, we have to call the good callback</font>
00236 <a class="code" href="classNLMISC_1_1CStringIdArray.html#s0">NLMISC::CStringIdArray::TStringId</a> pos = -1;
00237 <font class="keywordflow">if</font> (msgin.TypeHasAnId)
00238 {
00239 pos = msgin.getId ();
00240 }
00241 <font class="keywordflow">else</font>
00242 {
00243 std::string name = msgin.getName ();
00244 sint16 i;
00245 <font class="keywordflow">for</font> (i = 0; i < (sint16) <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n5">_CallbackArray</a>.size (); i++)
00246 {
00247 <font class="keywordflow">if</font> (name == <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n5">_CallbackArray</a>[i].Key)
00248 {
00249 pos = i;
00250 <font class="keywordflow">break</font>;
00251 }
00252 }
00253 }
00254
00255 <a class="code" href="namespaceNLNET.html#a9">TMsgCallback</a> cb = NULL;
00256 <font class="keywordflow">if</font> (pos < 0 || pos >= (sint16) <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n5">_CallbackArray</a>.size ())
00257 {
00258 <font class="keywordflow">if</font> (<a class="code" href="classNLNET_1_1CCallbackNetBase.html#n6">_DefaultCallback</a> == NULL)
00259 {
00260 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"LNETL3NB_CB: Callback %s not found in _CallbackArray"</font>, msgin.toString().c_str());
00261 }
00262 <font class="keywordflow">else</font>
00263 {
00264 cb = <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n6">_DefaultCallback</a>;
00265 }
00266 }
00267 <font class="keywordflow">else</font>
00268 {
00269 cb = <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n5">_CallbackArray</a>[pos].Callback;
00270 }
00271
00272 <a class="code" href="namespaceNLNET.html#a0">TSockId</a> realid = <a class="code" href="classNLNET_1_1CCallbackNetBase.html#a10">getSockId</a> (tsid);
00273
00274 <font class="keywordflow">if</font> (!realid->AuthorizedCallback.empty() && msgin.getName() != realid->AuthorizedCallback)
00275 {
00276 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"LNETL3NB_CB: %s try to call the callback %s but only %s is authorized. Disconnect him!"</font>, tsid->asString().c_str(), msgin.toString().c_str(), tsid->AuthorizedCallback.c_str());
00277 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#a17">disconnect</a> (tsid);
00278 }
00279 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (cb == NULL)
00280 {
00281 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"LNETL3NB_CB: Callback %s is NULL, can't call it"</font>, msgin.toString().c_str());
00282 }
00283 <font class="keywordflow">else</font>
00284 {
00285 <a class="code" href="debug_8h.html#a0">nldebug</a> (<font class="stringliteral">"LNETL3NB_CB: Calling callback (%s)%s"</font>, msgin.getName().c_str(), (cb==<a class="code" href="classNLNET_1_1CCallbackNetBase.html#n6">_DefaultCallback</a>)?<font class="stringliteral">" DEFAULT_CB"</font>:<font class="stringliteral">""</font>);
00286 cb(msgin, realid, *<font class="keyword">this</font>);
00287 }
00288
00289 <font class="comment">/*</font>
00290 <font class="comment"> if (pos < 0 || pos >= (sint16) _CallbackArray.size ())</font>
00291 <font class="comment"> {</font>
00292 <font class="comment"> if (_DefaultCallback == NULL)</font>
00293 <font class="comment"> nlwarning ("LNETL3NB_CB: Callback %s not found in _CallbackArray", msgin.toString().c_str());</font>
00294 <font class="comment"> else</font>
00295 <font class="comment"> {</font>
00296 <font class="comment"> // ...</font>
00297 <font class="comment"> }</font>
00298 <font class="comment"> }</font>
00299 <font class="comment"> else</font>
00300 <font class="comment"> {</font>
00301 <font class="comment"> TSockId realid = getSockId (tsid);</font>
00302 <font class="comment"></font>
00303 <font class="comment"> if (!realid->AuthorizedCallback.empty() && msgin.getName() != realid->AuthorizedCallback)</font>
00304 <font class="comment"> {</font>
00305 <font class="comment"> nlwarning ("LNETL3NB_CB: %s try to call the callback %s but only %s is authorized. Disconnect him!", tsid->asString().c_str(), msgin.toString().c_str(), tsid->AuthorizedCallback.c_str());</font>
00306 <font class="comment"> disconnect (tsid);</font>
00307 <font class="comment"> }</font>
00308 <font class="comment"> else if (_CallbackArray[pos].Callback == NULL)</font>
00309 <font class="comment"> {</font>
00310 <font class="comment"> nlwarning ("LNETL3NB_CB: Callback %s is NULL, can't call it", msgin.toString().c_str());</font>
00311 <font class="comment"> }</font>
00312 <font class="comment"> else</font>
00313 <font class="comment"> {</font>
00314 <font class="comment"> nldebug ("LNETL3NB_CB: Calling callback (%s)", _CallbackArray[pos].Key);</font>
00315 <font class="comment"> _CallbackArray[pos].Callback (msgin, realid, *this);</font>
00316 <font class="comment"> }</font>
00317 <font class="comment"> }</font>
00318 <font class="comment">*/</font>
00319 }
00320
00321
00322
00323 <font class="comment">/*</font>
00324 <font class="comment"> * baseUpdate</font>
00325 <font class="comment"> * Recorded : YES</font>
00326 <font class="comment"> * Replayed : YES</font>
00327 <font class="comment"> */</font>
<a name="l00328"></a><a class="code" href="classNLNET_1_1CCallbackNetBase.html#b1">00328</a> <font class="keywordtype">void</font> CCallbackNetBase::baseUpdate (sint32 timeout)
00329 {
00330 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#b4">checkThreadId</a> ();
00331
00332 <font class="comment">// slow down the layer H_AUTO (CCallbackNetBase_baseUpdate);</font>
00333
00334 <a class="code" href="debug_8h.html#a6">nlassert</a>( timeout >= -1 );
00335 <a class="code" href="namespaceNLMISC.html#a183">TTime</a> t0 = CTime::getLocalTime();
00336
00337 <font class="comment">//</font>
00338 <font class="comment">// The first time, we init time counters</font>
00339 <font class="comment">//</font>
00340 <font class="keywordflow">if</font> (_FirstUpdate)
00341 {
00342 <font class="comment">// nldebug("LNETL3NB: First update()");</font>
00343 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n8">_FirstUpdate</a> = <font class="keyword">false</font>;
00344 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#o0">_LastUpdateTime</a> = t0;
00345 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#o1">_LastMovedStringArray</a> = t0;
00346 }
00347
00348 <font class="comment">//</font>
00349 <font class="comment">// Every 1 seconds if we have new unknown association, we ask them to the other side</font>
00350 <font class="comment">//</font>
00351 <font class="keywordflow">if</font> (t0 - <a class="code" href="classNLNET_1_1CCallbackNetBase.html#o0">_LastUpdateTime</a> > 1000)
00352 {
00353 <font class="comment">// nldebug("LNETL3NB: baseUpdate()");</font>
00354 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#o0">_LastUpdateTime</a> = t0;
00355
00356 <font class="keyword">const</font> set<string> &sa = <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n3">_InputSIDA</a>.<a class="code" href="classNLMISC_1_1CStringIdArray.html#a7">getNeedToAskedStringArray</a> ();
00357 <font class="keywordflow">if</font> (!sa.empty ())
00358 {
00359 CMessage msgout (<a class="code" href="classNLNET_1_1CCallbackNetBase.html#n3">_InputSIDA</a>, <font class="stringliteral">"AA"</font>);
00360 <font class="comment">//nlassert (sa.size () < 65536); // no size limit anymore</font>
00361 CStringIdArray::TStringId size = sa.size ();
00362 <a class="code" href="debug_8h.html#a0">nldebug</a> (<font class="stringliteral">"LNETL3NB_ASSOC: I need %d string association, ask them to the other side"</font>, size);
00363 msgout.serial (size);
00364 <font class="keywordflow">for</font> (set<string>::iterator it = sa.begin(); it != sa.end(); it++)
00365 {
00366 <a class="code" href="debug_8h.html#a0">nldebug</a> (<font class="stringliteral">"LNETL3NB_ASSOC: what is the id of '%s'?"</font>, (*it).c_str ());
00367 string str(*it);
00368 msgout.serial (str);
00369 }
00370 <font class="comment">// send the message to the other side</font>
00371 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#a1">send</a> (msgout, 0);
00372 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n3">_InputSIDA</a>.<a class="code" href="classNLMISC_1_1CStringIdArray.html#a9">moveNeedToAskToAskedStringArray</a>();
00373 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#o1">_LastMovedStringArray</a> = t0;
00374 }
00375 }
00376
00377 <font class="comment">//</font>
00378 <font class="comment">// Every 60 seconds if we have not answered association, we ask again to get them!</font>
00379 <font class="comment">//</font>
00380 <font class="keywordflow">if</font> (!<a class="code" href="classNLNET_1_1CCallbackNetBase.html#n3">_InputSIDA</a>.<a class="code" href="classNLMISC_1_1CStringIdArray.html#a8">getAskedStringArray</a>().empty() && t0 - <a class="code" href="classNLNET_1_1CCallbackNetBase.html#o1">_LastMovedStringArray</a> > 60000)
00381 {
00382 <font class="comment">// we didn't have an answer for the association, resend them</font>
00383 <font class="keyword">const</font> set<string> sa = <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n3">_InputSIDA</a>.<a class="code" href="classNLMISC_1_1CStringIdArray.html#a8">getAskedStringArray</a> ();
00384 CMessage msgout (<a class="code" href="classNLNET_1_1CCallbackNetBase.html#n3">_InputSIDA</a>, <font class="stringliteral">"AA"</font>);
00385 <font class="comment">//nlassert (sa.size () < 65536); // no size limit anymore</font>
00386 CStringIdArray::TStringId size = sa.size ();
00387 <a class="code" href="debug_8h.html#a0">nldebug</a> (<font class="stringliteral">"LNETL3NB_ASSOC: client didn't answer my asked association, retry! I need %d string association, ask them to the other side"</font>, size);
00388 msgout.serial (size);
00389 <font class="keywordflow">for</font> (set<string>::iterator it = sa.begin(); it != sa.end(); it++)
00390 {
00391 <a class="code" href="debug_8h.html#a0">nldebug</a> (<font class="stringliteral">"LNETL3NB_ASSOC: what is the id of '%s'?"</font>, (*it).c_str ());
00392 string str(*it);
00393 msgout.serial (str);
00394 }
00395 <font class="comment">// sends the message to the other side</font>
00396 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#a1">send</a> (msgout, 0);
00397 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#o1">_LastMovedStringArray</a> = t0;
00398 }
00399
00400 <font class="comment">/*</font>
00401 <font class="comment"> * timeout -1 => read one message in the queue or nothing if no message in queue</font>
00402 <font class="comment"> * timeout 0 => read all messages in the queue</font>
00403 <font class="comment"> * timeout other => read all messages in the queue until timeout expired (at least all one time)</font>
00404 <font class="comment"> */</font>
00405
00406 <font class="keywordtype">bool</font> exit = <font class="keyword">false</font>;
00407
00408 <font class="keywordflow">while</font> (!exit)
00409 {
00410 <font class="comment">// process all messages in the queue</font>
00411 <font class="keywordflow">while</font> (<a class="code" href="classNLNET_1_1CCallbackNetBase.html#a14">dataAvailable</a> ())
00412 {
00413 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#b2">processOneMessage</a> ();
00414 <font class="keywordflow">if</font> (timeout == -1)
00415 {
00416 exit = <font class="keyword">true</font>;
00417 <font class="keywordflow">break</font>;
00418 }
00419 }
00420
00421 <font class="comment">// need to exit?</font>
00422 <font class="keywordflow">if</font> (timeout == 0 || (sint32)(CTime::getLocalTime() - t0) > timeout)
00423 {
00424 exit = <font class="keyword">true</font>;
00425 }
00426 <font class="keywordflow">else</font>
00427 {
00428 <font class="comment">// enable multithreading on windows :-/</font>
00429 <font class="comment">// slow down the layer H_AUTO (CCallbackNetBase_baseUpdate_nlSleep);</font>
00430 <a class="code" href="namespaceNLMISC.html#a236">nlSleep</a> (10);
00431 }
00432 }
00433
00434 <font class="preprocessor">#ifdef USE_MESSAGE_RECORDER</font>
00435 <font class="preprocessor"></font> _MR_UpdateCounter++;
00436 <font class="preprocessor">#endif</font>
00437 <font class="preprocessor"></font>
00438 }
00439
00440
<a name="l00441"></a><a class="code" href="classNLNET_1_1CCallbackNetBase.html#a18">00441</a> <font class="keyword">const</font> CInetAddress& CCallbackNetBase::hostAddress (<a class="code" href="namespaceNLNET.html#a0">TSockId</a> hostid)
00442 {
00443 <font class="comment">// should never be called</font>
00444 <a class="code" href="debug_8h.html#a12">nlstop</a>;
00445 <font class="keyword">static</font> CInetAddress tmp;
00446 <font class="keywordflow">return</font> tmp;
00447 }
00448
<a name="l00449"></a><a class="code" href="classNLNET_1_1CCallbackNetBase.html#a20">00449</a> <font class="keywordtype">void</font> CCallbackNetBase::setOtherSideAssociations (<font class="keyword">const</font> <font class="keywordtype">char</font> **associationarray, <a class="code" href="classNLMISC_1_1CStringIdArray.html#s0">NLMISC::CStringIdArray::TStringId</a> arraysize)
00450 {
00451 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#b4">checkThreadId</a> ();
00452
00453 <a class="code" href="debug_8h.html#a0">nldebug</a> (<font class="stringliteral">"LNETL3NB_ASSOC: setOtherSideAssociations() sets %d association strings"</font>, arraysize);
00454
00455 <font class="keywordflow">for</font> (sint i = 0; i < arraysize; i++)
00456 {
00457 <a class="code" href="debug_8h.html#a0">nldebug</a> (<font class="stringliteral">"LNETL3NB_ASSOC: association '%s' -> %d"</font>, associationarray[i], i);
00458 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#a13">getSIDA</a>().<a class="code" href="classNLMISC_1_1CStringIdArray.html#a1">addString</a> (associationarray[i], i);
00459 }
00460 }
00461
<a name="l00462"></a><a class="code" href="classNLNET_1_1CCallbackNetBase.html#a21">00462</a> <font class="keywordtype">void</font> CCallbackNetBase::displayAllMyAssociations ()
00463 {
00464 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#b4">checkThreadId</a> ();
00465
00466 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#n4">_OutputSIDA</a>.<a class="code" href="classNLMISC_1_1CStringIdArray.html#a12">display</a> ();
00467 }
00468
<a name="l00469"></a><a class="code" href="classNLNET_1_1CCallbackNetBase.html#a11">00469</a> <font class="keywordtype">void</font> CCallbackNetBase::authorizeOnly (<font class="keyword">const</font> <font class="keywordtype">char</font> *callbackName, <a class="code" href="namespaceNLNET.html#a0">TSockId</a> hostid)
00470 {
00471 <a class="code" href="classNLNET_1_1CCallbackNetBase.html#b4">checkThreadId</a> ();
00472
00473 <a class="code" href="debug_8h.html#a0">nldebug</a> (<font class="stringliteral">"LNETL3NB: authorizeOnly (%s, %s)"</font>, callbackName, hostid->asString().c_str());
00474
00475 hostid = <a class="code" href="classNLNET_1_1CCallbackNetBase.html#a10">getSockId</a> (hostid);
00476
00477 <a class="code" href="debug_8h.html#a6">nlassert</a> (hostid != InvalidSockId);
00478
00479 hostid->AuthorizedCallback = (callbackName == NULL)?<font class="stringliteral">""</font>:callbackName;
00480 }
00481
00482
00483 <font class="preprocessor">#ifdef USE_MESSAGE_RECORDER</font>
00484 <font class="preprocessor"></font>
00485 <font class="comment">/*</font>
00486 <font class="comment"> * Replay dataAvailable() in replay mode</font>
00487 <font class="comment"> */</font>
00488 <font class="keywordtype">bool</font> CCallbackNetBase::replayDataAvailable()
00489 {
00490 <a class="code" href="debug_8h.html#a6">nlassert</a>( _MR_RecordingState == <a class="code" href="classNLNET_1_1CCallbackNetBase.html#s3s2">Replay</a> );
00491
00492 <font class="keywordflow">if</font> ( _MR_Recorder.ReceivedMessages.empty() )
00493 {
00494 <font class="comment">// Fill the queue of received messages related to the present update</font>
00495 _MR_Recorder.replayNextDataAvailable( _MR_UpdateCounter );
00496 }
00497
00498 <font class="keywordflow">return</font> replaySystemCallbacks();
00499 }
00500
00501
00502 <font class="comment">/*</font>
00503 <font class="comment"> * Record or replay disconnection</font>
00504 <font class="comment"> */</font>
00505 <font class="keywordtype">void</font> CCallbackNetBase::noticeDisconnection( <a class="code" href="namespaceNLNET.html#a0">TSockId</a> hostid )
00506 {
00507 <a class="code" href="debug_8h.html#a6">nlassert</a> (hostid != InvalidSockId); <font class="comment">// invalid hostid</font>
00508 <font class="keywordflow">if</font> ( _MR_RecordingState != <a class="code" href="classNLNET_1_1CCallbackNetBase.html#s3s2">Replay</a> )
00509 {
00510 <font class="keywordflow">if</font> ( _MR_RecordingState == <a class="code" href="classNLNET_1_1CCallbackNetBase.html#s3s1">Record</a> )
00511 {
00512 <font class="comment">// Record disconnection</font>
00513 CMessage emptymsg;
00514 _MR_Recorder.recordNext( _MR_UpdateCounter, <a class="code" href="namespaceNLNET.html#a156a17">Disconnecting</a>, hostid, emptymsg );
00515 }
00516 }
00517 <font class="keywordflow">else</font>
00518 {
00519 <font class="comment">// Replay disconnection</font>
00520 hostid->disconnect( <font class="keyword">false</font> );
00521 }
00522 }
00523
00524 <font class="preprocessor">#endif // USE_MESSAGE_RECORDER</font>
00525 <font class="preprocessor"></font>
00526
00527
00528 <font class="comment">/*</font>
00529 <font class="comment"> * checkThreadId</font>
00530 <font class="comment"> */</font>
<a name="l00531"></a><a class="code" href="classNLNET_1_1CCallbackNetBase.html#b4">00531</a> <font class="keywordtype">void</font> CCallbackNetBase::checkThreadId ()<font class="keyword"> const</font>
00532 <font class="keyword"></font>{
00533 <font class="comment">/* some people use this class in different thread but with a mutex to be sure to have</font>
00534 <font class="comment"> no concurent access</font>
00535 <font class="comment"> if (getThreadId () != _ThreadId)</font>
00536 <font class="comment"> {</font>
00537 <font class="comment"> nlerror ("You try to access to the same CCallbackClient or CCallbackServer with 2 differents thread (%d and %d)", _ThreadId, getThreadId());</font>
00538 <font class="comment"> }</font>
00539 <font class="comment">*/</font>
00540 }
00541
00542
00543 } <font class="comment">// NLNET</font>
00544
</pre></div>
<!-- footer -->
<BR><FONT Size=+5> </FONT>
</TD>
<TD WIDTH=15><IMG SRC=http://www.nevrax.org/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>
|