aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/message__recorder_8cpp-source.html
blob: af8ee5bc38eeae4a57fa94fd0edf163ed9c42a04 (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
478
<!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='/'><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>message_recorder.cpp</h1><a href="message__recorder_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="message__recorder_8h.html">nel/net/message_recorder.h</a>"</font>
00029 <font class="preprocessor">#include "<a class="code" href="inet__address_8h.html">nel/net/inet_address.h</a>"</font>
00030 
00031 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
00032 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00033 
00034 
00035 <font class="keyword">namespace </font>NLNET {
00036 
00037 
00039 string <a class="code" href="namespaceNLNET.html#a86">EventToString</a>( <a class="code" href="namespaceNLNET.html#a162">TNetworkEvent</a> e )
00040 {
00041         <font class="keywordflow">switch</font> ( e )
00042         {
00043         <font class="keywordflow">case</font> <a class="code" href="namespaceNLNET.html#a162a12">Sending</a>: <font class="keywordflow">return</font> <font class="stringliteral">"SEND"</font>;
00044         <font class="keywordflow">case</font> <a class="code" href="namespaceNLNET.html#a162a13">Receiving</a>: <font class="keywordflow">return</font> <font class="stringliteral">"RECV"</font>;
00045         <font class="keywordflow">case</font> <a class="code" href="namespaceNLNET.html#a162a14">Connecting</a>: <font class="keywordflow">return</font> <font class="stringliteral">"CONN"</font>;
00046         <font class="keywordflow">case</font> <a class="code" href="namespaceNLNET.html#a162a15">ConnFailing</a>: <font class="keywordflow">return</font> <font class="stringliteral">"CNFL"</font>;
00047         <font class="keywordflow">case</font> <a class="code" href="namespaceNLNET.html#a162a16">Accepting</a>: <font class="keywordflow">return</font> <font class="stringliteral">"ACCP"</font>;
00048         <font class="keywordflow">case</font> <a class="code" href="namespaceNLNET.html#a162a17">Disconnecting</a>: <font class="keywordflow">return</font> <font class="stringliteral">"DISC"</font>;
00049         <font class="keywordflow">default</font>: <a class="code" href="debug_8h.html#a12">nlstop</a>; <font class="keywordflow">return</font> <font class="stringliteral">"-ERR-"</font>;
00050         }
00051 }
00052 
00054 <a class="code" href="namespaceNLNET.html#a162">TNetworkEvent</a> <a class="code" href="namespaceNLNET.html#a87">StringToEvent</a>( string&amp; <a class="code" href="driver__opengl__extension__def_8h.html#a260">s</a> )
00055 {
00056         <font class="keywordflow">if</font> ( <a class="code" href="driver__opengl__extension__def_8h.html#a260">s</a> == <font class="stringliteral">"RECV"</font> )
00057                 <font class="keywordflow">return</font> <a class="code" href="namespaceNLNET.html#a162a13">Receiving</a>;
00058         <font class="keywordflow">else</font> <font class="keywordflow">if</font> ( <a class="code" href="driver__opengl__extension__def_8h.html#a260">s</a> == <font class="stringliteral">"SEND"</font> )
00059                 <font class="keywordflow">return</font> <a class="code" href="namespaceNLNET.html#a162a12">Sending</a>;
00060         <font class="keywordflow">else</font> <font class="keywordflow">if</font> ( <a class="code" href="driver__opengl__extension__def_8h.html#a260">s</a> == <font class="stringliteral">"DISC"</font> )
00061                 <font class="keywordflow">return</font> <a class="code" href="namespaceNLNET.html#a162a17">Disconnecting</a>;
00062         <font class="keywordflow">else</font> <font class="keywordflow">if</font> ( <a class="code" href="driver__opengl__extension__def_8h.html#a260">s</a> == <font class="stringliteral">"ACCP"</font> )
00063                 <font class="keywordflow">return</font> <a class="code" href="namespaceNLNET.html#a162a16">Accepting</a>;
00064         <font class="keywordflow">else</font> <font class="keywordflow">if</font> ( <a class="code" href="driver__opengl__extension__def_8h.html#a260">s</a> == <font class="stringliteral">"CONN"</font> )
00065                 <font class="keywordflow">return</font> <a class="code" href="namespaceNLNET.html#a162a14">Connecting</a>;
00066         <font class="keywordflow">else</font> <font class="keywordflow">if</font> ( <a class="code" href="driver__opengl__extension__def_8h.html#a260">s</a> == <font class="stringliteral">"CNFL"</font> )
00067                 <font class="keywordflow">return</font> <a class="code" href="namespaceNLNET.html#a162a15">ConnFailing</a>;
00068         <font class="keywordflow">else</font> 
00069         {
00070                 <a class="code" href="debug_8h.html#a12">nlstop</a>;
00071                 <font class="keywordflow">return</font> <a class="code" href="namespaceNLNET.html#a162a18">Error</a>;
00072         }
00073 }
00074 
00075 
00076 <font class="comment">/*</font>
00077 <font class="comment"> * Constructor</font>
00078 <font class="comment"> */</font>
<a name="l00079"></a><a class="code" href="classNLNET_1_1CMessageRecorder.html#a0">00079</a> CMessageRecorder::CMessageRecorder() : _RecordAll(true)
00080 {
00081 <font class="preprocessor">#ifndef MESSAGES_PLAIN_TEXT</font>
00082 <font class="preprocessor"></font>        <a class="code" href="debug_8h.html#a3">nlerror</a>( <font class="stringliteral">"The message recorder works only with plain text messages. Please #define MESSAGES_PLAIN_TEXT"</font> );
00083 <font class="preprocessor">#endif</font>
00084 <font class="preprocessor"></font>}
00085 
00086 
00087 <font class="comment">/*</font>
00088 <font class="comment"> * Destructor</font>
00089 <font class="comment"> */</font>
<a name="l00090"></a><a class="code" href="classNLNET_1_1CMessageRecorder.html#a1">00090</a> CMessageRecorder::~CMessageRecorder()
00091 {
00092         <font class="keywordflow">if</font> ( <a class="code" href="classNLNET_1_1CMessageRecorder.html#o1">_Filename</a> != <font class="stringliteral">""</font> )
00093         {
00094                 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"MR:%s: End of recording"</font>, <a class="code" href="classNLNET_1_1CMessageRecorder.html#o1">_Filename</a>.c_str() );
00095         }
00096         <a class="code" href="classNLNET_1_1CMessageRecorder.html#a4">stopRecord</a>();
00097         <a class="code" href="classNLNET_1_1CMessageRecorder.html#a9">stopReplay</a>();
00098 }
00099 
00100 
00101 <font class="comment">/*</font>
00102 <font class="comment"> * Start recording</font>
00103 <font class="comment"> */</font>
<a name="l00104"></a><a class="code" href="classNLNET_1_1CMessageRecorder.html#a2">00104</a> <font class="keywordtype">bool</font> CMessageRecorder::startRecord( <font class="keyword">const</font> std::string&amp; filename, <font class="keywordtype">bool</font> recordall )
00105 {
00106         <a class="code" href="classNLNET_1_1CMessageRecorder.html#o1">_Filename</a> = filename;
00107         <a class="code" href="classNLNET_1_1CMessageRecorder.html#o0">_File</a>.open( <a class="code" href="classNLNET_1_1CMessageRecorder.html#o1">_Filename</a>.c_str(), ios_base::out );
00108         <a class="code" href="classNLNET_1_1CMessageRecorder.html#o0">_File</a> &lt;&lt; endl;
00109         <a class="code" href="classNLNET_1_1CMessageRecorder.html#o4">_RecordAll</a> = recordall;
00110         <font class="keywordflow">if</font> ( <a class="code" href="classNLNET_1_1CMessageRecorder.html#o0">_File</a>.fail() )
00111         {
00112                 <a class="code" href="debug_8h.html#a2">nlwarning</a>( <font class="stringliteral">"MR: Record: Cannot open file %s"</font>, <a class="code" href="classNLNET_1_1CMessageRecorder.html#o1">_Filename</a>.c_str() );
00113                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00114         }
00115         <font class="keywordflow">else</font>
00116         {
00117                 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"MR: Start recording into %s"</font>, <a class="code" href="classNLNET_1_1CMessageRecorder.html#o1">_Filename</a>.c_str() );
00118                 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00119         }
00120 }
00121 
00122 
00123 <font class="comment">/*</font>
00124 <font class="comment"> * Same as stringFromVector() but assumes the vector contains only printable characters</font>
00125 <font class="comment"> */</font>
00126 <font class="comment">/*string stringFromTextVector( const vector&lt;uint8&gt;&amp; v )</font>
00127 <font class="comment">{</font>
00128 <font class="comment">        string s;</font>
00129 <font class="comment"></font>
00130 <font class="comment">        // Copy contents</font>
00131 <font class="comment">        s.resize( v.size() );</font>
00132 <font class="comment">        memcpy( &amp;*s.begin(), &amp;*v.begin(), v.size() );</font>
00133 <font class="comment"></font>
00134 <font class="comment">        return s;</font>
00135 <font class="comment">}*/</font>
00136 
00137 
00138 <font class="comment">/*</font>
00139 <font class="comment"> * Add a record</font>
00140 <font class="comment"> */</font>
<a name="l00141"></a><a class="code" href="classNLNET_1_1CMessageRecorder.html#a3">00141</a> <font class="keywordtype">void</font> CMessageRecorder::recordNext( <a class="code" href="types__nl_8h.html#a11">sint64</a> updatecounter, <a class="code" href="namespaceNLNET.html#a162">TNetworkEvent</a> event, <a class="code" href="namespaceNLNET.html#a0">TSockId</a> sockid, CMessage&amp; message )
00142 {
00143         <a class="code" href="debug_8h.html#a6">nlassert</a>( <a class="code" href="classNLNET_1_1CMessageRecorder.html#o0">_File</a>.is_open() );
00144 
00145         <font class="keywordflow">if</font> ( (_RecordAll) || (event != <a class="code" href="namespaceNLNET.html#a162a12">Sending</a>) )
00146         {
00147                 <font class="comment">// Serial to stream</font>
00148                 TMessageRecord rec ( event, sockid, message, updatecounter <font class="comment">/*CTime::getLocalTime()*/</font> );
00149                 CMemStream stream ( <font class="keyword">false</font>, <font class="keyword">true</font> );
00150                 rec.serial( stream );
00151                 <font class="keywordtype">char</font> c = <font class="charliteral">'\0'</font>;      <font class="comment">// end of cstring</font>
00152                 stream.serial( c ); <font class="comment">// added to the stream for _File &lt;&lt; (char*)stream.buffer()</font>
00153 
00154                 <font class="comment">// Dump to file</font>
00155                 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"MR:%s: Recording [%s]"</font>, <a class="code" href="classNLNET_1_1CMessageRecorder.html#o1">_Filename</a>.c_str(), stream.buffer() );
00156                 <font class="keywordtype">int</font> len = (int)(stream.length()-2); <font class="comment">// not the null character (and its separator) at the end of the buffer</font>
00157                 <a class="code" href="classNLNET_1_1CMessageRecorder.html#o0">_File</a> &lt;&lt; <font class="stringliteral">"* "</font>;
00158                 <a class="code" href="classNLNET_1_1CMessageRecorder.html#o0">_File</a> &lt;&lt;  len; <font class="comment">// if we put the expression directly, it makes an access violation ! Weird.</font>
00159                 <a class="code" href="classNLNET_1_1CMessageRecorder.html#o0">_File</a> &lt;&lt; <font class="stringliteral">" "</font>;
00160                 <a class="code" href="classNLNET_1_1CMessageRecorder.html#o0">_File</a> &lt;&lt; (<font class="keywordtype">char</font>*)stream.buffer() &lt;&lt; endl; 
00161         }
00162 }
00163 
00164 
00165 <font class="comment">/*</font>
00166 <font class="comment"> * Stop recording</font>
00167 <font class="comment"> */</font>
<a name="l00168"></a><a class="code" href="classNLNET_1_1CMessageRecorder.html#a4">00168</a> <font class="keywordtype">void</font> CMessageRecorder::stopRecord()
00169 {
00170         <a class="code" href="classNLNET_1_1CMessageRecorder.html#o0">_File</a>.close();
00171         <a class="code" href="classNLNET_1_1CMessageRecorder.html#o1">_Filename</a> = <font class="stringliteral">""</font>;
00172 }
00173 
00174 
00175 <font class="comment">/*</font>
00176 <font class="comment"> * Start playback</font>
00177 <font class="comment"> */</font>
<a name="l00178"></a><a class="code" href="classNLNET_1_1CMessageRecorder.html#a5">00178</a> <font class="keywordtype">bool</font> CMessageRecorder::startReplay( <font class="keyword">const</font> std::string&amp; filename )
00179 {
00180         <a class="code" href="classNLNET_1_1CMessageRecorder.html#o1">_Filename</a> = filename;
00181         <a class="code" href="classNLNET_1_1CMessageRecorder.html#o0">_File</a>.open( <a class="code" href="classNLNET_1_1CMessageRecorder.html#o1">_Filename</a>.c_str(), ios_base::in );
00182         <font class="keywordflow">if</font> ( <a class="code" href="classNLNET_1_1CMessageRecorder.html#o0">_File</a>.fail() )
00183         {
00184                 <a class="code" href="debug_8h.html#a3">nlerror</a>( <font class="stringliteral">"MR: Replay: Cannot open file %s"</font>, <a class="code" href="classNLNET_1_1CMessageRecorder.html#o1">_Filename</a>.c_str() );
00185                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00186         }
00187         <font class="keywordflow">else</font>
00188         {
00189                 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"MR: Start replaying from %s"</font>, <a class="code" href="classNLNET_1_1CMessageRecorder.html#o1">_Filename</a>.c_str() );
00190                 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00191         }
00192 }
00193 
00194 
00195 <font class="comment">/*</font>
00196 <font class="comment"> * Get next record (throw EStreamOverflow)</font>
00197 <font class="comment"> */</font>
<a name="l00198"></a><a class="code" href="classNLNET_1_1CMessageRecorder.html#b0">00198</a> <font class="keywordtype">bool</font> CMessageRecorder::loadNext( TMessageRecord&amp; record )
00199 {
00200         <font class="comment">// WARNING!!! This features doesn't work anymore becaues bufferAsVector() is not available with new CMemStream</font>
00201         <a class="code" href="debug_8h.html#a12">nlstop</a>;
00202         <font class="keywordflow">return</font> <font class="keyword">false</font>;
00203 
00204         <a class="code" href="debug_8h.html#a6">nlassert</a>( <a class="code" href="classNLNET_1_1CMessageRecorder.html#o0">_File</a>.is_open() );
00205 
00206         <font class="comment">// Dump from file</font>
00207         CMemStream stream ( <font class="keyword">true</font>, <font class="keyword">true</font> );
00208         <a class="code" href="types__nl_8h.html#a10">uint32</a> len;
00209         <font class="keywordtype">char</font> c;
00210         <a class="code" href="classNLNET_1_1CMessageRecorder.html#o0">_File</a> &gt;&gt; c; <font class="comment">// skip "* ";</font>
00211         <a class="code" href="classNLNET_1_1CMessageRecorder.html#o0">_File</a> &gt;&gt; (<font class="keywordtype">int</font>&amp;)len;
00212         <a class="code" href="classNLNET_1_1CMessageRecorder.html#o0">_File</a>.ignore(); <font class="comment">// skip delimiter</font>
00213         <font class="keywordflow">if</font> ( ! <a class="code" href="classNLNET_1_1CMessageRecorder.html#o0">_File</a>.fail() )
00214         {
00215                 <a class="code" href="classNLNET_1_1CMessageRecorder.html#o0">_File</a>.get( (<font class="keywordtype">char</font>*)stream.bufferToFill( len+1 ), len+1, <font class="charliteral">'\0'</font> );
00216                 <font class="comment">//stream.bufferAsVector().resize( len ); // cut end of cstring</font>
00217                 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"MR:%s: Reading [%s]"</font>, <a class="code" href="classNLNET_1_1CMessageRecorder.html#o1">_Filename</a>.c_str(), stream.buffer() );
00218 
00219                 <font class="comment">// Serial from stream</font>
00220                 record.serial( stream ); <font class="comment">// may throw EStreamOverflow if _File.fail()</font>
00221         }
00222 
00223         <font class="keywordflow">return</font> ! <a class="code" href="classNLNET_1_1CMessageRecorder.html#o0">_File</a>.fail(); <font class="comment">// retest</font>
00224 }
00225 
00226 
00227 <font class="comment">/*</font>
00228 <font class="comment"> * Get the next record (from the preloaded records, or from the file)</font>
00229 <font class="comment"> */</font>
<a name="l00230"></a><a class="code" href="classNLNET_1_1CMessageRecorder.html#b1">00230</a> <font class="keywordtype">bool</font> CMessageRecorder::getNext( TMessageRecord&amp; record, <a class="code" href="types__nl_8h.html#a11">sint64</a> updatecounter )
00231 {
00232         <font class="keywordflow">if</font> ( ! <a class="code" href="classNLNET_1_1CMessageRecorder.html#o2">_PreloadedRecords</a>.empty() )
00233         {
00234                 <font class="keywordflow">if</font> ( <a class="code" href="classNLNET_1_1CMessageRecorder.html#o2">_PreloadedRecords</a>.front().UpdateCounter == updatecounter )
00235                 {
00236                         <font class="comment">// The requested record is in the preload</font>
00237                         record = <a class="code" href="classNLNET_1_1CMessageRecorder.html#o2">_PreloadedRecords</a>.front();
00238                         <a class="code" href="classNLNET_1_1CMessageRecorder.html#o2">_PreloadedRecords</a>.pop_front();
00239                         <font class="keywordflow">return</font> <font class="keyword">true</font>;
00240                 }
00241                 <font class="keywordflow">else</font>
00242                 {
00243                         <font class="comment">// The requested record is not in the file</font>
00244                         <a class="code" href="debug_8h.html#a6">nlassert</a>( updatecounter &lt; _PreloadedRecords.front().UpdateCounter ); // not &gt;
00245                         <font class="keywordflow">return</font> <font class="keyword">false</font>;
00246                 }
00247         }
00248         <font class="keywordflow">else</font>
00249         {
00250                 <font class="keywordflow">if</font> ( <a class="code" href="classNLNET_1_1CMessageRecorder.html#b0">loadNext</a>( record ) )
00251                 {
00252                         <font class="keywordflow">if</font> ( record.UpdateCounter == updatecounter )
00253                         {
00254                                 <font class="comment">// The requested record has been loaded</font>
00255                                 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00256                         }
00257                         <font class="keywordflow">else</font>
00258                         {
00259                                 <font class="comment">// The next loaded record is a new one</font>
00260                                 <a class="code" href="debug_8h.html#a6">nlassert</a>( updatecounter &lt; record.UpdateCounter ); // not &gt;
00261                                 <a class="code" href="classNLNET_1_1CMessageRecorder.html#o2">_PreloadedRecords</a>.push_back( record ); <font class="comment">// when we read one too far</font>
00262                                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00263                         }
00264                 }
00265                 <font class="keywordflow">else</font>
00266                 {
00267                         <font class="keywordflow">return</font> <font class="keyword">false</font>;
00268                 }
00269         }
00270 }
00271 
00272 
00273 <font class="comment">/*</font>
00274 <font class="comment"> * Push the received blocks for this counter into the receive queue</font>
00275 <font class="comment"> */</font>
<a name="l00276"></a><a class="code" href="classNLNET_1_1CMessageRecorder.html#a6">00276</a> <font class="keywordtype">void</font> CMessageRecorder::replayNextDataAvailable( <a class="code" href="types__nl_8h.html#a11">sint64</a> updatecounter )
00277 {
00278         TMessageRecord rec( <font class="keyword">true</font> ); <font class="comment">// input message</font>
00279 
00280         <font class="keywordflow">while</font> ( <a class="code" href="classNLNET_1_1CMessageRecorder.html#b1">getNext</a>( rec, updatecounter ) )
00281         {
00282                 <font class="keywordflow">switch</font> ( rec.Event )
00283                 {
00284                 <font class="keywordflow">case</font> <a class="code" href="namespaceNLNET.html#a162a13">Receiving</a> :
00285                 <font class="keywordflow">case</font> <a class="code" href="namespaceNLNET.html#a162a16">Accepting</a> :
00286                 <font class="keywordflow">case</font> <a class="code" href="namespaceNLNET.html#a162a17">Disconnecting</a> :
00287                         <a class="code" href="classNLNET_1_1CMessageRecorder.html#m0">ReceivedMessages</a>.push( rec );
00288                         <font class="keywordflow">break</font>;
00289 
00290                 <font class="keywordflow">case</font> <a class="code" href="namespaceNLNET.html#a162a12">Sending</a> :
00291                         <font class="keywordflow">break</font>;
00292 
00293                 <font class="keywordflow">case</font> <a class="code" href="namespaceNLNET.html#a162a14">Connecting</a> :
00294                 <font class="keywordflow">case</font> <a class="code" href="namespaceNLNET.html#a162a15">ConnFailing</a> :
00295                         <a class="code" href="classNLNET_1_1CMessageRecorder.html#o3">_ConnectionAttempts</a>.push_back( rec );
00296                         <font class="keywordflow">break</font>;
00297                         
00298                 <font class="keywordflow">default</font> :
00299                         <a class="code" href="debug_8h.html#a12">nlstop</a>;
00300                 }
00301         }
00302 }
00303 
00304 
00305 <font class="comment">/*</font>
00306 <font class="comment"> * Returns true and the event type if the counter of the next data is updatecounter</font>
00307 <font class="comment"> */</font>
<a name="l00308"></a><a class="code" href="classNLNET_1_1CMessageRecorder.html#a7">00308</a> <a class="code" href="namespaceNLNET.html#a162">TNetworkEvent</a> CMessageRecorder::checkNextOne( <a class="code" href="types__nl_8h.html#a11">sint64</a> updatecounter )
00309 {
00310         TMessageRecord record;
00311         <font class="keywordflow">if</font> ( <a class="code" href="classNLNET_1_1CMessageRecorder.html#b1">getNext</a>( record, updatecounter ) )
00312         {
00313                 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"MR: Check next one: %s at update %"</font><a class="code" href="types__nl_8h.html#a3">NL_I64</a><font class="stringliteral">"u"</font>, <a class="code" href="namespaceNLNET.html#a86">EventToString</a>(record.Event).c_str(), updatecounter );
00314                 <font class="keywordflow">return</font> record.Event;
00315         }
00316         <font class="keywordflow">else</font>
00317         {
00318                 <font class="keywordflow">return</font> <a class="code" href="namespaceNLNET.html#a162a18">Error</a>;
00319         }
00320 }
00321 
00322 
00323 <font class="comment">/*</font>
00324 <font class="comment"> * Get the first stored connection attempt corresponding to addr</font>
00325 <font class="comment"> */</font>
<a name="l00326"></a><a class="code" href="classNLNET_1_1CMessageRecorder.html#a8">00326</a> <a class="code" href="namespaceNLNET.html#a162">TNetworkEvent</a> CMessageRecorder::replayConnectionAttempt( <font class="keyword">const</font> CInetAddress&amp; addr )
00327 {
00328         <a class="code" href="namespaceNLNET.html#a162">TNetworkEvent</a> event;
00329         deque&lt;TMessageRecord&gt;::iterator ipr;
00330         
00331         <font class="keywordflow">if</font> ( ! <a class="code" href="classNLNET_1_1CMessageRecorder.html#o3">_ConnectionAttempts</a>.empty() )
00332         {
00333                 <font class="comment">// Search in the already processed connection attempts</font>
00334                 <font class="keywordflow">for</font> ( ipr=<a class="code" href="classNLNET_1_1CMessageRecorder.html#o3">_ConnectionAttempts</a>.begin(); ipr!=<a class="code" href="classNLNET_1_1CMessageRecorder.html#o3">_ConnectionAttempts</a>.end(); ++ipr )
00335                 {
00336                         CInetAddress stored_addr;
00337                         (*ipr).Message.serial( stored_addr );
00338                         <font class="keywordflow">if</font> ( stored_addr == addr )
00339                         {
00340                                 <font class="comment">// Found</font>
00341                                 event = (*ipr).Event;
00342                                 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"MR: Connection attempt found at update %"</font><a class="code" href="types__nl_8h.html#a3">NL_I64</a><font class="stringliteral">"u"</font>, (*ipr).UpdateCounter );
00343                                 <a class="code" href="classNLNET_1_1CMessageRecorder.html#o3">_ConnectionAttempts</a>.erase( ipr );
00344                                 <font class="keywordflow">return</font> event;
00345                         }
00346                 }
00347         }
00348         
00349         <font class="comment">// Seek in the preloaded records</font>
00350         <font class="keywordflow">for</font> ( ipr=<a class="code" href="classNLNET_1_1CMessageRecorder.html#o2">_PreloadedRecords</a>.begin(); ipr!=<a class="code" href="classNLNET_1_1CMessageRecorder.html#o2">_PreloadedRecords</a>.end(); ++ipr )
00351         {
00352                 event = (*ipr).Event;
00353                 <font class="keywordflow">if</font> ( (event == <a class="code" href="namespaceNLNET.html#a162a14">Connecting</a>) || (event == <a class="code" href="namespaceNLNET.html#a162a15">ConnFailing</a>) )
00354                 {
00355                         CInetAddress stored_addr;
00356                         (*ipr).Message.serial( stored_addr );
00357                         <font class="keywordflow">if</font> ( stored_addr == addr )
00358                         {
00359                                 <font class="comment">// Found</font>
00360                                 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"MR: Connection attempt found at update %"</font><a class="code" href="types__nl_8h.html#a3">NL_I64</a><font class="stringliteral">"u"</font>, (*ipr).UpdateCounter );
00361                                 <a class="code" href="classNLNET_1_1CMessageRecorder.html#o2">_PreloadedRecords</a>.erase( ipr );
00362                                 <font class="keywordflow">return</font> event;
00363                         }
00364                 }
00365         }
00366         <font class="keywordflow">if</font> ( ipr==<a class="code" href="classNLNET_1_1CMessageRecorder.html#o2">_PreloadedRecords</a>.end() )
00367         {
00368                 <font class="comment">// If not found, load next records until found !</font>
00369                 TMessageRecord rec( <font class="keyword">true</font> );
00370                 <font class="keywordflow">while</font> ( <a class="code" href="classNLNET_1_1CMessageRecorder.html#b0">loadNext</a>( rec ) )
00371                 {
00372                         <font class="keywordflow">if</font> ( ( rec.Event == <a class="code" href="namespaceNLNET.html#a162a14">Connecting</a> ) || ( rec.Event == <a class="code" href="namespaceNLNET.html#a162a15">ConnFailing</a> ) )
00373                         {
00374                                 CInetAddress stored_addr;
00375                                 rec.Message.serial( stored_addr );
00376                                 <font class="keywordflow">if</font> ( stored_addr == addr )
00377                                 {
00378                                         <font class="comment">// Found</font>
00379                                         <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"MR: Connection attempt found at update %"</font><a class="code" href="types__nl_8h.html#a3">NL_I64</a><font class="stringliteral">"u"</font>, rec.UpdateCounter );
00380                                         <font class="keywordflow">return</font> rec.Event;
00381                                 }
00382                                 <font class="keywordflow">else</font>
00383                                 {
00384                                         <a class="code" href="classNLNET_1_1CMessageRecorder.html#o2">_PreloadedRecords</a>.push_back( rec );
00385                                 }
00386                         }
00387                         <font class="keywordflow">else</font>
00388                         {
00389                                 <a class="code" href="classNLNET_1_1CMessageRecorder.html#o2">_PreloadedRecords</a>.push_back( rec );
00390                         }
00391                 }
00392                 <font class="comment">// Not found</font>
00393                 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"MR: Connection attempt not found"</font> );          
00394                 <font class="keywordflow">return</font> <a class="code" href="namespaceNLNET.html#a162a18">Error</a>;
00395         }
00396         <a class="code" href="debug_8h.html#a12">nlstop</a>;
00397         <font class="keywordflow">return</font> <a class="code" href="namespaceNLNET.html#a162a18">Error</a>;
00398 }
00399 
00400 
00401 <font class="comment">/*</font>
00402 <font class="comment"> * Stop playback</font>
00403 <font class="comment"> */</font>
<a name="l00404"></a><a class="code" href="classNLNET_1_1CMessageRecorder.html#a9">00404</a> <font class="keywordtype">void</font> CMessageRecorder::stopReplay()
00405 {
00406         <a class="code" href="classNLNET_1_1CMessageRecorder.html#o0">_File</a>.close();
00407         <a class="code" href="classNLNET_1_1CMessageRecorder.html#o1">_Filename</a> = <font class="stringliteral">""</font>;
00408 }
00409 
00410 
00411 } <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>