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
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>NeL: NLNET::_CUniTime class Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.6 -->
<div class="qindex"> <form class="search" action="search.php" method="get">
<a class="qindex" href="main.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">Data Structures</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">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a> | <span class="search"><u>S</u>earch for <input class="search" type="text" name="query" value="" size="20" accesskey="s"/></span></form></div>
<h1>NLNET::_CUniTime Class Reference</h1><code>#include <<a class="el" href="a06651.html">unitime.h</a>></code>
<p>
<p>Inheritance diagram for NLNET::_CUniTime:
<p><center><img src="a02141.png" usemap="#NLNET::_CUniTime_map" border="0" alt=""></center>
<map name="NLNET::_CUniTime_map">
<area href="a02142.html" alt="NLMISC::CTime" shape="rect" coords="0,0,118,24">
</map>
<hr><a name="_details"></a><h2>Detailed Description</h2>
This class provide a independant universal time system. <dl compact><dt><b>Author:</b></dt><dd>Vianney Lecroart <p>
Nevrax France </dd></dl>
<dl compact><dt><b>Date:</b></dt><dd>2000</dd></dl>
THIS CLASS IS DEPRECATED, DON'T USE IT
<p>
<p>
Definition at line <a class="el" href="a06651.html#l00051">51</a> of file <a class="el" href="a06651.html">unitime.h</a>.<table border=0 cellpadding=0 cellspacing=0>
<tr><td></td></tr>
<tr><td colspan=2><br><h2>Static Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>TTime </td><td class="memItemRight" valign=bottom><a class="el" href="a02142.html#NLMISC_1_1CTimee0">getLocalTime</a> ()</td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>TTicks </td><td class="memItemRight" valign=bottom><a class="el" href="a02142.html#NLMISC_1_1CTimee1">getPerformanceTime</a> ()</td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top><a class="el" href="a04558.html#a11">uint32</a> </td><td class="memItemRight" valign=bottom><a class="el" href="a02142.html#NLMISC_1_1CTimee2">getSecondsSince1970</a> ()</td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>const char * </td><td class="memItemRight" valign=bottom><a class="el" href="a02141.html#NLNET_1_1__CUniTimee3">getStringUniTime</a> (<a class="el" href="a05378.html#a242">NLMISC::TTime</a> ut)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Return the time in a string format to be display. <a href="#NLNET_1_1__CUniTimee3"></a><br><br></td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>const char * </td><td class="memItemRight" valign=bottom><a class="el" href="a02141.html#NLNET_1_1__CUniTimee4">getStringUniTime</a> ()</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Return the time in a string format to be display. <a href="#NLNET_1_1__CUniTimee4"></a><br><br></td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top><a class="el" href="a05378.html#a242">NLMISC::TTime</a> </td><td class="memItemRight" valign=bottom><a class="el" href="a02141.html#NLNET_1_1__CUniTimee5">getUniTime</a> ()</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Return the time in millisecond. This time is the same on all computers at the <b>same</b> moment. <a href="#NLNET_1_1__CUniTimee5"></a><br><br></td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>void </td><td class="memItemRight" valign=bottom><a class="el" href="a02141.html#NLNET_1_1__CUniTimee6">installServer</a> (<a class="el" href="a02307.html">CCallbackServer</a> *server)</td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>void </td><td class="memItemRight" valign=bottom><a class="el" href="a02141.html#NLNET_1_1__CUniTimee7">setUniTime</a> (<a class="el" href="a05378.html#a242">NLMISC::TTime</a> uTime)</td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>void </td><td class="memItemRight" valign=bottom><a class="el" href="a02141.html#NLNET_1_1__CUniTimee8">setUniTime</a> (<a class="el" href="a05378.html#a242">NLMISC::TTime</a> uTime, <a class="el" href="a05378.html#a242">NLMISC::TTime</a> lTime)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">used by the time service to set the universal time the first time <a href="#NLNET_1_1__CUniTimee8"></a><br><br></td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>void </td><td class="memItemRight" valign=bottom><a class="el" href="a02141.html#NLNET_1_1__CUniTimee9">simulate</a> ()</td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>void </td><td class="memItemRight" valign=bottom><a class="el" href="a02141.html#NLNET_1_1__CUniTimee10">syncUniTimeFromServer</a> (<a class="el" href="a02305.html">CCallbackClient</a> *client)</td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>void </td><td class="memItemRight" valign=bottom><a class="el" href="a02141.html#NLNET_1_1__CUniTimee11">syncUniTimeFromService</a> (<a class="el" href="a02306.html#NLNET_1_1CCallbackServerw8">CCallbackNetBase::TRecordingState</a> rec=CCallbackNetBase::Off, const <a class="el" href="a02665.html">CInetAddress</a> *<a class="el" href="a04223.html#a657">addr</a>=NULL)</td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>double </td><td class="memItemRight" valign=bottom><a class="el" href="a02142.html#NLMISC_1_1CTimee3">ticksToSecond</a> (TTicks ticks)</td></tr>
<tr><td colspan=2><br><h2>Static Public Attributes</h2></td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>bool </td><td class="memItemRight" valign=bottom><a class="el" href="a02141.html#NLNET_1_1__CUniTimes0">Sync</a> = false</td></tr>
<tr><td colspan=2><br><h2>Static Private Attributes</h2></td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>bool </td><td class="memItemRight" valign=bottom><a class="el" href="a02141.html#NLNET_1_1__CUniTimev0">_Simulate</a> = false</td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top><a class="el" href="a05378.html#a242">NLMISC::TTime</a> </td><td class="memItemRight" valign=bottom><a class="el" href="a02141.html#NLNET_1_1__CUniTimev1">_SyncLocalTime</a> = 0</td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top><a class="el" href="a05378.html#a242">NLMISC::TTime</a> </td><td class="memItemRight" valign=bottom><a class="el" href="a02141.html#NLNET_1_1__CUniTimev2">_SyncUniTime</a> = 0</td></tr>
</table>
<hr><h2>Member Function Documentation</h2>
<a class="anchor" name="NLMISC_1_1CTimee0" doxytag="NLNET::_CUniTime::getLocalTime" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> TTime NLMISC::CTime::getLocalTime </td>
<td class="md" valign="top">( </td>
<td class="mdname1" valign="top" nowrap> </td>
<td class="md" valign="top"> ) </td>
<td class="md" nowrap><code> [static, inherited]</code></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
get the time in millisecond. It's a <b>local</b> time, it means that the value is <b>different</b> on 2 differents computers. Use the CUniTime to get a universal time that is the same on all computers. <dl compact><dt><b>Warning:</b></dt><dd>On Windows, the value is on 32 bits only.</dd></dl>
<p>
Definition at line <a class="el" href="a06552.html#l00055">55</a> of file <a class="el" href="a06552.html">time_nl.cpp</a>.
<p>
References <a class="el" href="a06552.html#l00105">NLMISC::CTime::getPerformanceTime()</a>, <a class="el" href="a05622.html#l00154">nlerror</a>, and <a class="el" href="a06553.html#l00047">NLMISC::TTime</a>.
<p>
Referenced by <a class="el" href="a05416.html#l00396">NLAIAGENT::CAgentWatchTimer::attach()</a>, <a class="el" href="a05466.html#l00565">NLSOUND::CAudioMixerUser::curTime()</a>, <a class="el" href="a06737.html#l01170">NL3D::CWaterModel::doSimpleRender()</a>, <a class="el" href="a05593.html#l00441">NLSOUND::CComplexSource::getTime()</a>, <a class="el" href="a05926.html#l00145">loadForm()</a>, <a class="el" href="a05593.html#l00577">NLSOUND::CComplexSource::onEvent()</a>, <a class="el" href="a05593.html#l00456">NLSOUND::CComplexSource::onUpdate()</a>, <a class="el" href="a05593.html#l00105">NLSOUND::CComplexSource::playStuf()</a>, <a class="el" href="a05416.html#l00140">NLAIAGENT::CAgentManagerTimer::CRunTimer::run()</a>, <a class="el" href="a05416.html#l00631">NLAIAGENT::CAgentClockTimer::runActivity()</a>, <a class="el" href="a05416.html#l00280">NLAIAGENT::CAgentWatchTimer::runActivity()</a>, <a class="el" href="a06737.html#l00831">NL3D::CWaterModel::setupMaterialNVertexShader()</a>, <a class="el" href="a06552.html#l00143">NLMISC::CTime::ticksToSecond()</a>, <a class="el" href="a06420.html#l00679">NLSOUND::CSoundDriverDSound::TimerCallback()</a>, <a class="el" href="a06420.html#l00703">NLSOUND::CSoundDriverDSound::update()</a>, <a class="el" href="a05465.html#l01268">NLSOUND::CAudioMixerUser::update()</a>, and <a class="el" href="a05471.html#l00861">NLSOUND::CBackgroundSoundManager::updateBackgroundStatus()</a>.
<p>
<div class="fragment"><pre>00056 {
00057 <span class="preprocessor">#ifdef NL_OS_WINDOWS</span>
00058 <span class="preprocessor"></span>
00059 <span class="keyword">static</span> <span class="keywordtype">bool</span> byperfcounter;
00060 <span class="keyword">static</span> <span class="keywordtype">bool</span> initdone = <span class="keyword">false</span>;
00061
00062 <span class="comment">// Initialization</span>
00063 <span class="keywordflow">if</span> ( ! initdone )
00064 {
00065 byperfcounter = (<a class="code" href="a02142.html#NLMISC_1_1CTimee1">getPerformanceTime</a>() != 0);
00066 initdone = <span class="keyword">true</span>;
00067 }
00068
00069 <span class="comment">/* Retrieve time is ms</span>
00070 <span class="comment"> * Why do we prefer getPerformanceTime() to timeGetTime() ? Because on one dual-processor Win2k</span>
00071 <span class="comment"> * PC, we have noticed that timeGetTime() slows down when the client is running !!!</span>
00072 <span class="comment"> */</span>
00073
00074
00075 <span class="comment">/* Now we have noticed that on all WinNT4 PC the getPerformanceTime can give us value that</span>
00076 <span class="comment"> * are less than previous</span>
00077 <span class="comment"> */</span>
00078
00079 <span class="comment">//if ( byperfcounter )</span>
00080 <span class="comment">//{</span>
00081 <span class="comment">// return (TTime)(ticksToSecond(getPerformanceTime()) * 1000.0f);</span>
00082 <span class="comment">//}</span>
00083 <span class="comment">//else</span>
00084 <span class="comment">//{</span>
00085 <span class="keywordflow">return</span> timeGetTime();
00086 <span class="comment">//}</span>
00087
00088 <span class="preprocessor">#elif defined (NL_OS_UNIX)</span>
00089 <span class="preprocessor"></span>
00090 <span class="keyword">struct </span>timeval tv;
00091
00092 <span class="keywordflow">if</span> ( gettimeofday( &tv, NULL) == -1 )
00093 {
00094 <a class="code" href="a04199.html#a3">nlerror</a> (<span class="stringliteral">"Cannot get time of day."</span>);
00095 }
00096 <span class="keywordflow">return</span> (<a class="code" href="a05378.html#a242">TTime</a>)tv.tv_sec * (<a class="code" href="a05378.html#a242">TTime</a>)1000 + (<a class="code" href="a05378.html#a242">TTime</a>)tv.tv_usec / (<a class="code" href="a05378.html#a242">TTime</a>)1000;
00097
00098 <span class="preprocessor">#endif</span>
00099 <span class="preprocessor"></span>}
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="NLMISC_1_1CTimee1" doxytag="NLNET::_CUniTime::getPerformanceTime" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> TTicks NLMISC::CTime::getPerformanceTime </td>
<td class="md" valign="top">( </td>
<td class="mdname1" valign="top" nowrap> </td>
<td class="md" valign="top"> ) </td>
<td class="md" nowrap><code> [static, inherited]</code></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
get the time in processor ticks. Use it for profile purpose. Only implemented under windows for the time. If the performance time is not supported on this hardware, it returns 0.
<p>
Definition at line <a class="el" href="a06552.html#l00105">105</a> of file <a class="el" href="a06552.html">time_nl.cpp</a>.
<p>
References <a class="el" href="a05622.html#l00135">nlwarning</a>, <a class="el" href="a06553.html#l00048">NLMISC::TTicks</a>, and <a class="el" href="a05646.html#l00236">x</a>.
<p>
Referenced by <a class="el" href="a06552.html#l00055">NLMISC::CTime::getLocalTime()</a>, <a class="el" href="a06479.html#l00441">NLMISC::CSystemInfo::getProcessorFrequency()</a>, <a class="el" href="a05412.html#l01628">NLAIAGENT::CAgentScript::run()</a>, <a class="el" href="a05412.html#l01284">NLAIAGENT::CAgentScript::sendMessage()</a>, and <a class="el" href="a06552.html#l00143">NLMISC::CTime::ticksToSecond()</a>.
<p>
<div class="fragment"><pre>00106 {
00107 <span class="preprocessor">#ifdef NL_OS_WINDOWS</span>
00108 <span class="preprocessor"></span> LARGE_INTEGER ret;
00109 <span class="keywordflow">if</span> (QueryPerformanceCounter (&ret))
00110 <span class="keywordflow">return</span> ret.QuadPart;
00111 <span class="keywordflow">else</span>
00112 <span class="keywordflow">return</span> 0;
00113 <span class="preprocessor">#else // NL_OS_WINDOWS</span>
00114 <span class="preprocessor"></span>
00115 <span class="preprocessor">#ifdef HAVE_X86</span>
00116 <span class="preprocessor"></span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <span class="keywordtype">long</span> <span class="keywordtype">int</span> <a class="code" href="a04223.html#a572">x</a>;
00117 __asm__ <span class="keyword">volatile</span> (<span class="stringliteral">".byte 0x0f, 0x31"</span> : <span class="stringliteral">"=A"</span> (<a class="code" href="a04223.html#a572">x</a>));
00118 <span class="keywordflow">return</span> <a class="code" href="a04223.html#a572">x</a>;
00119 <span class="preprocessor">#else // HAVE_X86</span>
00120 <span class="preprocessor"></span> <span class="keyword">static</span> <span class="keywordtype">bool</span> firstWarn = <span class="keyword">true</span>;
00121 <span class="keywordflow">if</span> (firstWarn)
00122 {
00123 <a class="code" href="a04199.html#a2">nlwarning</a> (<span class="stringliteral">"TTicks CTime::getPerformanceTime () is not implemented for your processor, returning 0"</span>);
00124 firstWarn = <span class="keyword">false</span>;
00125 }
00126 <span class="keywordflow">return</span> 0;
00127 <span class="preprocessor">#endif // HAVE_X86</span>
00128 <span class="preprocessor"></span>
00129 <span class="preprocessor">#endif // NL_OS_WINDOWS</span>
00130 <span class="preprocessor"></span>}
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="NLMISC_1_1CTimee2" doxytag="NLNET::_CUniTime::getSecondsSince1970" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> <a class="el" href="a04558.html#a11">uint32</a> NLMISC::CTime::getSecondsSince1970 </td>
<td class="md" valign="top">( </td>
<td class="mdname1" valign="top" nowrap> </td>
<td class="md" valign="top"> ) </td>
<td class="md" nowrap><code> [static, inherited]</code></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
returns the number of second since midnight (00:00:00), January 1, 1970, coordinated universal time, according to the system clock. This values is the same on all computer if computers are synchronized (with NTP for example).
<p>
Definition at line <a class="el" href="a06552.html#l00045">45</a> of file <a class="el" href="a06552.html">time_nl.cpp</a>.
<p>
References <a class="el" href="a05981.html#l00100">uint32</a>.
<p>
Referenced by <a class="el" href="a06033.html#l00258">NLAINIMAT::CMHiCSagent::CTemporaryPriority::CTemporaryPriority()</a>, and <a class="el" href="a06032.html#l01219">NLAINIMAT::CMHiCSagent::learningComputation()</a>.
<p>
<div class="fragment"><pre>00046 {
00047 <span class="keywordflow">return</span> (<a class="code" href="a04558.html#a11">uint32</a>) time (NULL);
00048 }
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="NLNET_1_1__CUniTimee3" doxytag="NLNET::_CUniTime::getStringUniTime" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> const char * NLNET::_CUniTime::getStringUniTime </td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top"><a class="el" href="a05378.html#a242">NLMISC::TTime</a> </td>
<td class="mdname1" valign="top" nowrap> <em>ut</em> </td>
<td class="md" valign="top"> ) </td>
<td class="md" nowrap><code> [static]</code></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
Return the time in a string format to be display.
<p>
<p>
Definition at line <a class="el" href="a06650.html#l00096">96</a> of file <a class="el" href="a06650.html">unitime.cpp</a>.
<p>
References <a class="el" href="a05622.html#l00416">nlstop</a>, <a class="el" href="a05646.html#l00977">s</a>, <a class="el" href="a05586.html#l00161">NLMISC::smprintf()</a>, <a class="el" href="a06553.html#l00047">NLMISC::TTime</a>, <a class="el" href="a05981.html#l00105">uint</a>, and <a class="el" href="a05981.html#l00100">uint32</a>.
<p>
<div class="fragment"><pre>00097 {
00098 <a class="code" href="a04199.html#a12">nlstop</a>;
00099 <span class="keyword">static</span> <span class="keywordtype">char</span> str[512];
00100
00101 <a class="code" href="a04558.html#a11">uint32</a> ms = (<a class="code" href="a04558.html#a11">uint32</a>) (ut % 1000); <span class="comment">// time in ms 1000ms dans 1s</span>
00102 ut /= 1000;
00103
00104 <a class="code" href="a04558.html#a11">uint32</a> <a class="code" href="a04223.html#a626">s</a> = (<a class="code" href="a04558.html#a11">uint32</a>) (ut % 60); <span class="comment">// time in seconds 60s dans 1mn</span>
00105 ut /= 60;
00106
00107 <a class="code" href="a04558.html#a11">uint32</a> m = (<a class="code" href="a04558.html#a11">uint32</a>) (ut % 60); <span class="comment">// time in minutes 60m dans 1h</span>
00108 ut /= 60;
00109
00110 <a class="code" href="a04558.html#a11">uint32</a> h = (<a class="code" href="a04558.html#a11">uint32</a>) (ut % 9); <span class="comment">// time in hours 9h dans 1j</span>
00111 ut /= 9;
00112
00113 <a class="code" href="a04558.html#a11">uint32</a> day = (<a class="code" href="a04558.html#a11">uint32</a>) (ut % (8*4)); <span class="comment">// time in days 8day dans 1month</span>
00114 ut /= 8;
00115
00116 <a class="code" href="a04558.html#a11">uint32</a> week = (<a class="code" href="a04558.html#a11">uint32</a>) (ut % 4); <span class="comment">// time in weeks 4week dans 1month</span>
00117 ut /= 4;
00118
00119 <a class="code" href="a04558.html#a11">uint32</a> month = (<a class="code" href="a04558.html#a11">uint32</a>) (ut % 12); <span class="comment">// time in months 12month dans 1year</span>
00120 ut /= 12;
00121
00122 <a class="code" href="a04558.html#a15">uint</a> year = (<a class="code" href="a04558.html#a11">uint32</a>) ut; <span class="comment">// time in years</span>
00123
00124 <a class="code" href="a05378.html#a259">smprintf</a> (str, 512, <span class="stringliteral">"%02d/%02d/%04d (week %d) %02d:%02d:%02d.%03d"</span>, day+1, month+1, year+1, week+1, h, m, s, ms);
00125 <span class="keywordflow">return</span> str;
00126 }
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="NLNET_1_1__CUniTimee4" doxytag="NLNET::_CUniTime::getStringUniTime" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> const char * NLNET::_CUniTime::getStringUniTime </td>
<td class="md" valign="top">( </td>
<td class="mdname1" valign="top" nowrap> </td>
<td class="md" valign="top"> ) </td>
<td class="md" nowrap><code> [static]</code></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
Return the time in a string format to be display.
<p>
<p>
Definition at line <a class="el" href="a06650.html#l00089">89</a> of file <a class="el" href="a06650.html">unitime.cpp</a>.
<p>
References <a class="el" href="a05622.html#l00416">nlstop</a>.
<p>
<div class="fragment"><pre>00090 {
00091 <a class="code" href="a04199.html#a12">nlstop</a>;
00092 <span class="keywordflow">return</span> <a class="code" href="a02141.html#NLNET_1_1__CUniTimee4">getStringUniTime</a>(_CUniTime::getUniTime());
00093 }
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="NLNET_1_1__CUniTimee5" doxytag="NLNET::_CUniTime::getUniTime" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> TTime NLNET::_CUniTime::getUniTime </td>
<td class="md" valign="top">( </td>
<td class="mdname1" valign="top" nowrap> </td>
<td class="md" valign="top"> ) </td>
<td class="md" nowrap><code> [static]</code></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
Return the time in millisecond. This time is the same on all computers at the <b>same</b> moment.
<p>
<p>
Definition at line <a class="el" href="a06650.html#l00076">76</a> of file <a class="el" href="a06650.html">unitime.cpp</a>.
<p>
References <a class="el" href="a05622.html#l00416">nlstop</a>, and <a class="el" href="a06553.html#l00047">NLMISC::TTime</a>.
<p>
<div class="fragment"><pre>00077 {
00078 <a class="code" href="a04199.html#a12">nlstop</a>;
00079 <span class="keywordflow">return</span> 0;
00080 <span class="comment">/* if (!Sync)</span>
00081 <span class="comment"> {</span>
00082 <span class="comment"> nlerror ("called getUniTime before calling syncUniTimeFromServer");</span>
00083 <span class="comment"> }</span>
00084 <span class="comment"> return getLocalTime () - (_SyncLocalTime - _SyncUniTime);</span>
00085 <span class="comment">*/</span>
00086 }
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="NLNET_1_1__CUniTimee6" doxytag="NLNET::_CUniTime::installServer" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> void NLNET::_CUniTime::installServer </td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top"><a class="el" href="a02307.html">CCallbackServer</a> * </td>
<td class="mdname1" valign="top" nowrap> <em>server</em> </td>
<td class="md" valign="top"> ) </td>
<td class="md" nowrap><code> [static]</code></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
Call this function in the init part of the front end service to enable time syncro between shard and clients.
<p>
Definition at line <a class="el" href="a06650.html#l00280">280</a> of file <a class="el" href="a06650.html">unitime.cpp</a>.
<p>
References <a class="el" href="a05526.html#l00184">NLNET::CCallbackNetBase::addCallbackArray()</a>, <a class="el" href="a05622.html#l00290">nlassert</a>, <a class="el" href="a05622.html#l00416">nlstop</a>, and <a class="el" href="a06650.html#l00275">NLNET::ServerTimeServiceCallbackArray</a>.
<p>
<div class="fragment"><pre>00281 {
00282 <a class="code" href="a04199.html#a12">nlstop</a>;
00283 <span class="keyword">static</span> <span class="keywordtype">bool</span> alreadyAddedCallback = <span class="keyword">false</span>;
00284 <a class="code" href="a04199.html#a6">nlassert</a> (server != NULL);
00285 <a class="code" href="a04199.html#a6">nlassert</a> (!alreadyAddedCallback);
00286
00287 server->addCallbackArray (ServerTimeServiceCallbackArray, <span class="keyword">sizeof</span> (ServerTimeServiceCallbackArray) / <span class="keyword">sizeof</span> (ServerTimeServiceCallbackArray[0]));
00288 alreadyAddedCallback = <span class="keyword">true</span>;
00289 }
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="NLNET_1_1__CUniTimee7" doxytag="NLNET::_CUniTime::setUniTime" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> void NLNET::_CUniTime::setUniTime </td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top"><a class="el" href="a05378.html#a242">NLMISC::TTime</a> </td>
<td class="mdname1" valign="top" nowrap> <em>uTime</em> </td>
<td class="md" valign="top"> ) </td>
<td class="md" nowrap><code> [static]</code></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="a06650.html#l00068">68</a> of file <a class="el" href="a06650.html">unitime.cpp</a>.
<p>
References <a class="el" href="a05622.html#l00416">nlstop</a>, and <a class="el" href="a06553.html#l00047">NLMISC::TTime</a>.
<p>
<div class="fragment"><pre>00069 {
00070 <a class="code" href="a04199.html#a12">nlstop</a>;
00071 <span class="comment">// setUniTime (uTime, getLocalTime ());</span>
00072 }
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="NLNET_1_1__CUniTimee8" doxytag="NLNET::_CUniTime::setUniTime" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> void NLNET::_CUniTime::setUniTime </td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top"><a class="el" href="a05378.html#a242">NLMISC::TTime</a> </td>
<td class="mdname" nowrap> <em>uTime</em>, </td>
</tr>
<tr>
<td class="md" nowrap align="right"></td>
<td></td>
<td class="md" nowrap><a class="el" href="a05378.html#a242">NLMISC::TTime</a> </td>
<td class="mdname" nowrap> <em>lTime</em></td>
</tr>
<tr>
<td></td>
<td class="md">) </td>
<td class="md" colspan="2"><code> [static]</code></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
used by the time service to set the universal time the first time
<p>
<p>
Definition at line <a class="el" href="a06650.html#l00049">49</a> of file <a class="el" href="a06650.html">unitime.cpp</a>.
<p>
References <a class="el" href="a05622.html#l00416">nlstop</a>, and <a class="el" href="a06553.html#l00047">NLMISC::TTime</a>.
<p>
<div class="fragment"><pre>00050 {
00051 <a class="code" href="a04199.html#a12">nlstop</a>;
00052 <span class="comment">/* if (Sync)</span>
00053 <span class="comment"> {</span>
00054 <span class="comment"> TTime lt = getLocalTime ();</span>
00055 <span class="comment"> TTime delta = uTime - lTime + _SyncLocalTime - _SyncUniTime;</span>
00056 <span class="comment"></span>
00057 <span class="comment"> nlinfo ("_CUniTime::setUniTime(%"NL_I64"d, %"NL_I64"d): Resyncing delta %"NL_I64"dms",uTime,lTime,delta);</span>
00058 <span class="comment"> }</span>
00059 <span class="comment"> else</span>
00060 <span class="comment"> {</span>
00061 <span class="comment"> nlinfo ("_CUniTime::setUniTime(%"NL_I64"d, %"NL_I64"d)",uTime,lTime);</span>
00062 <span class="comment"> Sync = true;</span>
00063 <span class="comment"> }</span>
00064 <span class="comment"> _SyncUniTime = uTime;</span>
00065 <span class="comment"> _SyncLocalTime = lTime;</span>
00066 <span class="comment">*/</span>}
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="NLNET_1_1__CUniTimee9" doxytag="NLNET::_CUniTime::simulate" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> void NLNET::_CUniTime::simulate </td>
<td class="md" valign="top">( </td>
<td class="mdname1" valign="top" nowrap> </td>
<td class="md" valign="top"> ) </td>
<td class="md" nowrap><code> [inline, static]</code></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
Call this method before to prevent <a class="el" href="a02141.html#NLNET_1_1__CUniTimee11">syncUniTimeFromService()</a> from real synchronization: <a class="el" href="a02141.html#NLNET_1_1__CUniTimee11">syncUniTimeFromService()</a> will still communicate with the time service, as usual, but the local time will not be synchronized.
<p>
Definition at line <a class="el" href="a06651.html#l00096">96</a> of file <a class="el" href="a06651.html">unitime.h</a>.
<p>
References <a class="el" href="a06650.html#l00044">_Simulate</a>, and <a class="el" href="a05622.html#l00416">nlstop</a>.
<p>
<div class="fragment"><pre>00096 { <a class="code" href="a04199.html#a12">nlstop</a>; <a class="code" href="a02141.html#NLNET_1_1__CUniTimev0">_Simulate</a> = <span class="keyword">true</span>; }
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="NLNET_1_1__CUniTimee10" doxytag="NLNET::_CUniTime::syncUniTimeFromServer" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> void NLNET::_CUniTime::syncUniTimeFromServer </td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top"><a class="el" href="a02305.html">CCallbackClient</a> * </td>
<td class="mdname1" valign="top" nowrap> <em>client</em> </td>
<td class="md" valign="top"> ) </td>
<td class="md" nowrap><code> [static]</code></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
Call this functions in the init part of the client side to synchronize between client and shard. client is the connection between the client and the front end. The connection must be established before calling this function.
<p>
Definition at line <a class="el" href="a06650.html#l00314">314</a> of file <a class="el" href="a06650.html">unitime.cpp</a>.
<p>
References <a class="el" href="a05622.html#l00416">nlstop</a>.
<p>
<div class="fragment"><pre>00315 {
00316 <a class="code" href="a04199.html#a12">nlstop</a>;
00317 <span class="comment">/***************************************************************/</span>
00318 <span class="comment">/******************* THE FOLLOWING CODE IS COMMENTED OUT *******/</span>
00319 <span class="comment">/***************************************************************</span>
00320 <span class="comment"></span>
00321 <span class="comment"> static bool alreadyAddedCallback = false;</span>
00322 <span class="comment"> nlassert (client != NULL);</span>
00323 <span class="comment"></span>
00324 <span class="comment"> if (!alreadyAddedCallback)</span>
00325 <span class="comment"> {</span>
00326 <span class="comment"> client->addCallbackArray (ClientUniTimeCallbackArray, sizeof (ClientUniTimeCallbackArray) / sizeof (ClientUniTimeCallbackArray[0]));</span>
00327 <span class="comment"> alreadyAddedCallback = true;</span>
00328 <span class="comment"> }</span>
00329 <span class="comment"></span>
00330 <span class="comment"> sint attempt = 0;</span>
00331 <span class="comment"> TTime bestdelta = 60000; // 1 minute</span>
00332 <span class="comment"></span>
00333 <span class="comment"> if (!client->connected ()) goto error;</span>
00334 <span class="comment"></span>
00335 <span class="comment"> while (attempt < 10)</span>
00336 <span class="comment"> {</span>
00337 <span class="comment"> CMessage msgout (client->getSIDA(), "AUT");</span>
00338 <span class="comment"></span>
00339 <span class="comment"> if (!client->connected()) goto error;</span>
00340 <span class="comment"></span>
00341 <span class="comment"> // send the message</span>
00342 <span class="comment"> client->send (msgout);</span>
00343 <span class="comment"></span>
00344 <span class="comment"> // before time</span>
00345 <span class="comment"> TTime before = CTime::getLocalTime ();</span>
00346 <span class="comment"></span>
00347 <span class="comment"> // receive the answer</span>
00348 <span class="comment"> GetClientUniversalTime = false;</span>
00349 <span class="comment"> while (!GetClientUniversalTime)</span>
00350 <span class="comment"> {</span>
00351 <span class="comment"> if (!client->connected()) goto error;</span>
00352 <span class="comment"> </span>
00353 <span class="comment"> client->update ();</span>
00354 <span class="comment"> }</span>
00355 <span class="comment"></span>
00356 <span class="comment"> TTime after = CTime::getLocalTime (), delta = after - before;</span>
00357 <span class="comment"></span>
00358 <span class="comment"> if (delta < 10 || delta < bestdelta)</span>
00359 <span class="comment"> {</span>
00360 <span class="comment"> bestdelta = delta;</span>
00361 <span class="comment"></span>
00362 <span class="comment"> _CUniTime::setUniTime (GetClientUniversalTimeUniTime, (before+after)/2);</span>
00363 <span class="comment"></span>
00364 <span class="comment"> if (delta < 10) break;</span>
00365 <span class="comment"> }</span>
00366 <span class="comment"> attempt++;</span>
00367 <span class="comment"> }</span>
00368 <span class="comment"> client->disconnect ();</span>
00369 <span class="comment"> nlinfo ("Universal time is %"NL_I64"dms with a mean error of %"NL_I64"dms", _CUniTime::getUniTime(), bestdelta/2);</span>
00370 <span class="comment"> return;</span>
00371 <span class="comment">error:</span>
00372 <span class="comment"> nlwarning ("there's no connection or lost or can't synchronize universal time");</span>
00373 <span class="comment">***************************************************************/</span>
00374 }
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="NLNET_1_1__CUniTimee11" doxytag="NLNET::_CUniTime::syncUniTimeFromService" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> void NLNET::_CUniTime::syncUniTimeFromService </td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top"><a class="el" href="a02306.html#NLNET_1_1CCallbackServerw8">CCallbackNetBase::TRecordingState</a> </td>
<td class="mdname" nowrap> <em>rec</em> = CCallbackNetBase::Off, </td>
</tr>
<tr>
<td class="md" nowrap align="right"></td>
<td></td>
<td class="md" nowrap>const <a class="el" href="a02665.html">CInetAddress</a> * </td>
<td class="mdname" nowrap> <em>addr</em> = NULL</td>
</tr>
<tr>
<td></td>
<td class="md">) </td>
<td class="md" colspan="2"><code> [static]</code></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
You need to call this function before calling getUniTime or an assert will occured. This function will connect to the time service and synchronize your computer. This function assumes that all services run on server that are time synchronized with NTP for example. If addr is NULL, the function will connect to the Time Service via the Naming Service. In this case, the <a class="el" href="a02980.html">CNamingClient</a> must be connected to a Naming Service. This function can be called *ONLY* by services that are inside of the shard. Don't use it for a client or a service outside of the shard.
<p>
Definition at line <a class="el" href="a06650.html#l00157">157</a> of file <a class="el" href="a06650.html">unitime.cpp</a>.
<p>
References <a class="el" href="a05646.html#l01127">addr</a>, and <a class="el" href="a05622.html#l00416">nlstop</a>.
<p>
<div class="fragment"><pre>00158 {
00159 <a class="code" href="a04199.html#a12">nlstop</a>;
00160 <span class="comment">/***************************************************************/</span>
00161 <span class="comment">/******************* THE FOLLOWING CODE IS COMMENTED OUT *******/</span>
00162 <span class="comment">/***************************************************************</span>
00163 <span class="comment"> TTime deltaAdjust, lt;</span>
00164 <span class="comment"> uint32 firstsecond, nextsecond;</span>
00165 <span class="comment"> TTime before, after, delta;</span>
00166 <span class="comment"></span>
00167 <span class="comment"> // create a message with type in the full text format</span>
00168 <span class="comment"> CMessage msgout ("AUT");</span>
00169 <span class="comment"> CCallbackClient server( rec, "TS.nmr" );</span>
00170 <span class="comment"> server.addCallbackArray (UniTimeCallbackArray, sizeof (UniTimeCallbackArray) / sizeof (UniTimeCallbackArray[0]));</span>
00171 <span class="comment"></span>
00172 <span class="comment"> if (addr == NULL)</span>
00173 <span class="comment"> {</span>
00174 <span class="comment"> CNamingClient::lookupAndConnect ("TS", server);</span>
00175 <span class="comment"> }</span>
00176 <span class="comment"> else</span>
00177 <span class="comment"> {</span>
00178 <span class="comment"> server.connect (*addr);</span>
00179 <span class="comment"> }</span>
00180 <span class="comment"></span>
00181 <span class="comment"> if (!server.connected()) goto error;</span>
00182 <span class="comment"></span>
00183 <span class="comment"> server.send (msgout);</span>
00184 <span class="comment"></span>
00185 <span class="comment"> // before time</span>
00186 <span class="comment"> before = CTime::getLocalTime ();</span>
00187 <span class="comment"></span>
00188 <span class="comment"> // receive the answer</span>
00189 <span class="comment"> GetUniversalTime = false;</span>
00190 <span class="comment"> while (!GetUniversalTime)</span>
00191 <span class="comment"> {</span>
00192 <span class="comment"> if (!server.connected()) goto error;</span>
00193 <span class="comment"> </span>
00194 <span class="comment"> server.update ();</span>
00195 <span class="comment"></span>
00196 <span class="comment"> nlSleep( 0 );</span>
00197 <span class="comment"> }</span>
00198 <span class="comment"></span>
00199 <span class="comment"> // after, before and delta is not used. It's only for information purpose.</span>
00200 <span class="comment"> after = CTime::getLocalTime ();</span>
00201 <span class="comment"> delta = after - before;</span>
00202 <span class="comment"></span>
00203 <span class="comment"> nlinfo ("_CUniTime::syncUniTimeFromService(): ping:%"NL_I64"dms, time:%ds, unitime:%"NL_I64"dms", delta, GetUniversalTimeSecondsSince1970, GetUniversalTimeUniTime);</span>
00204 <span class="comment"></span>
00205 <span class="comment">// <-- from here to the "-->" comment, the block must be executed in less than one second or an infinite loop occurs</span>
00206 <span class="comment"></span>
00207 <span class="comment"> // get the second</span>
00208 <span class="comment"> firstsecond = CTime::getSecondsSince1970 ();</span>
00209 <span class="comment"> nextsecond = firstsecond+1;</span>
00210 <span class="comment"> </span>
00211 <span class="comment"> // wait the next start of the second (take 100% of CPU to be more accurate)</span>
00212 <span class="comment"> while (nextsecond != CTime::getSecondsSince1970 ())</span>
00213 <span class="comment"> nlassert (CTime::getSecondsSince1970 () <= nextsecond);</span>
00214 <span class="comment"></span>
00215 <span class="comment">// --></span>
00216 <span class="comment"></span>
00217 <span class="comment"> // get the local time of the beginning of the next second</span>
00218 <span class="comment"> lt = CTime::getLocalTime ();</span>
00219 <span class="comment"></span>
00220 <span class="comment"> if ( ! _Simulate )</span>
00221 <span class="comment"> {</span>
00222 <span class="comment"> if (abs((sint32)((TTime)nextsecond - (TTime)GetUniversalTimeSecondsSince1970)) > 10)</span>
00223 <span class="comment"> {</span>
00224 <span class="comment"> nlerror ("the time delta (between me and the Time Service) is too big (more than 10s), servers aren't NTP synchronized");</span>
00225 <span class="comment"> goto error;</span>
00226 <span class="comment"> }</span>
00227 <span class="comment"> </span>
00228 <span class="comment"> // compute the delta between the other side and our side number of second since 1970</span>
00229 <span class="comment"> deltaAdjust = ((TTime) nextsecond - (TTime) GetUniversalTimeSecondsSince1970) * 1000;</span>
00230 <span class="comment"></span>
00231 <span class="comment"> // adjust the unitime to the current localtime</span>
00232 <span class="comment"> GetUniversalTimeUniTime += deltaAdjust;</span>
00233 <span class="comment"></span>
00234 <span class="comment"> nlinfo ("_CUniTime::syncUniTimeFromService(): rtime:%ds, runitime:%"NL_I64"ds, rlocaltime:%"NL_I64"d, deltaAjust:%"NL_I64"dms", nextsecond, GetUniversalTimeUniTime, lt, deltaAdjust);</span>
00235 <span class="comment"> }</span>
00236 <span class="comment"> else</span>
00237 <span class="comment"> {</span>
00238 <span class="comment"> nlinfo ("_CUniTime::syncUniTimeFromService(): runitime:%"NL_I64"ds, rlocaltime:%"NL_I64"d", GetUniversalTimeUniTime, lt);</span>
00239 <span class="comment"> }</span>
00240 <span class="comment"></span>
00241 <span class="comment"> _CUniTime::setUniTime (GetUniversalTimeUniTime, lt);</span>
00242 <span class="comment"></span>
00243 <span class="comment"> server.disconnect ();</span>
00244 <span class="comment"> return;</span>
00245 <span class="comment"></span>
00246 <span class="comment">error:</span>
00247 <span class="comment"> nlerror ("Time Service is not found, lost or can't synchronize universal time");</span>
00248 <span class="comment">***************************************************************/</span>
00249
00250 }
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="NLMISC_1_1CTimee3" doxytag="NLNET::_CUniTime::ticksToSecond" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> double NLMISC::CTime::ticksToSecond </td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top"><a class="el" href="a05378.html#a243">TTicks</a> </td>
<td class="mdname1" valign="top" nowrap> <em>ticks</em> </td>
<td class="md" valign="top"> ) </td>
<td class="md" nowrap><code> [static, inherited]</code></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
convert a ticks count into second. If the performance time is not supported on this hardware, it returns 0.0.
<p>
Definition at line <a class="el" href="a06552.html#l00143">143</a> of file <a class="el" href="a06552.html">time_nl.cpp</a>.
<p>
References <a class="el" href="a06552.html#l00055">NLMISC::CTime::getLocalTime()</a>, <a class="el" href="a06552.html#l00105">NLMISC::CTime::getPerformanceTime()</a>, <a class="el" href="a05981.html#l00101">sint64</a>, <a class="el" href="a06553.html#l00048">NLMISC::TTicks</a>, and <a class="el" href="a06553.html#l00047">NLMISC::TTime</a>.
<p>
Referenced by <a class="el" href="a06348.html#l00300">NL3D::CScene::render()</a>.
<p>
<div class="fragment"><pre>00144 {
00145 <span class="preprocessor">#ifdef NL_OS_WINDOWS</span>
00146 <span class="preprocessor"></span> LARGE_INTEGER ret;
00147 <span class="keywordflow">if</span> (QueryPerformanceFrequency(&ret))
00148 {
00149 <span class="keywordflow">return</span> (<span class="keywordtype">double</span>)(<a class="code" href="a04558.html#a12">sint64</a>)ticks/(<span class="keywordtype">double</span>)ret.QuadPart;
00150 }
00151 <span class="keywordflow">else</span>
00152 <span class="preprocessor">#endif // NL_OS_WINDOWS</span>
00153 <span class="preprocessor"></span> {
00154 <span class="keyword">static</span> <span class="keywordtype">bool</span> benchFrequency = <span class="keyword">true</span>;
00155 <span class="keyword">static</span> <a class="code" href="a04558.html#a12">sint64</a> freq = 0;
00156 <span class="keywordflow">if</span> (benchFrequency)
00157 {
00158 <span class="comment">// try to have an estimation of the cpu frequency</span>
00159
00160 <a class="code" href="a05378.html#a243">TTicks</a> tickBefore = <a class="code" href="a02142.html#NLMISC_1_1CTimee1">getPerformanceTime</a> ();
00161 <a class="code" href="a05378.html#a243">TTicks</a> tickAfter = tickBefore;
00162 <a class="code" href="a05378.html#a242">TTime</a> timeBefore = <a class="code" href="a02142.html#NLMISC_1_1CTimee0">getLocalTime</a> ();
00163 <a class="code" href="a05378.html#a242">TTime</a> timeAfter = timeBefore;
00164 <span class="keywordflow">while</span> (<span class="keyword">true</span>)
00165 {
00166 <span class="keywordflow">if</span> (timeAfter - timeBefore > 1000)
00167 <span class="keywordflow">break</span>;
00168 timeAfter = <a class="code" href="a02142.html#NLMISC_1_1CTimee0">getLocalTime</a> ();
00169 tickAfter = <a class="code" href="a02142.html#NLMISC_1_1CTimee1">getPerformanceTime</a> ();
00170 }
00171
00172 <a class="code" href="a05378.html#a242">TTime</a> timeDelta = timeAfter - timeBefore;
00173 <a class="code" href="a05378.html#a243">TTicks</a> tickDelta = tickAfter - tickBefore;
00174
00175 freq = 1000 * tickDelta / timeDelta;
00176 benchFrequency = <span class="keyword">false</span>;
00177 }
00178
00179 <span class="keywordflow">return</span> (<span class="keywordtype">double</span>)(<a class="code" href="a04558.html#a12">sint64</a>)ticks/(<span class="keywordtype">double</span>)freq;
00180 }
00181 }
</pre></div> </td>
</tr>
</table>
<hr><h2>Field Documentation</h2>
<a class="anchor" name="NLNET_1_1__CUniTimev0" doxytag="NLNET::_CUniTime::_Simulate" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> bool <a class="el" href="a02141.html#NLNET_1_1__CUniTimev0">NLNET::_CUniTime::_Simulate</a> = false<code> [static, private]</code>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="a06650.html#l00044">44</a> of file <a class="el" href="a06650.html">unitime.cpp</a>.
<p>
Referenced by <a class="el" href="a06651.html#l00096">simulate()</a>. </td>
</tr>
</table>
<a class="anchor" name="NLNET_1_1__CUniTimev1" doxytag="NLNET::_CUniTime::_SyncLocalTime" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> TTime <a class="el" href="a02141.html#NLNET_1_1__CUniTimev1">NLNET::_CUniTime::_SyncLocalTime</a> = 0<code> [static, private]</code>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="a06650.html#l00043">43</a> of file <a class="el" href="a06650.html">unitime.cpp</a>. </td>
</tr>
</table>
<a class="anchor" name="NLNET_1_1__CUniTimev2" doxytag="NLNET::_CUniTime::_SyncUniTime" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> TTime <a class="el" href="a02141.html#NLNET_1_1__CUniTimev2">NLNET::_CUniTime::_SyncUniTime</a> = 0<code> [static, private]</code>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="a06650.html#l00042">42</a> of file <a class="el" href="a06650.html">unitime.cpp</a>. </td>
</tr>
</table>
<a class="anchor" name="NLNET_1_1__CUniTimes0" doxytag="NLNET::_CUniTime::Sync" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> bool <a class="el" href="a02141.html#NLNET_1_1__CUniTimes0">NLNET::_CUniTime::Sync</a> = false<code> [static]</code>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="a06650.html#l00046">46</a> of file <a class="el" href="a06650.html">unitime.cpp</a>. </td>
</tr>
</table>
<hr>The documentation for this class was generated from the following files:<ul>
<li><a class="el" href="a06651.html">unitime.h</a><li><a class="el" href="a06650.html">unitime.cpp</a></ul>
<hr size="1"><address style="align: right;"><small>Generated on Tue Mar 16 13:51:20 2004 for NeL by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 >
</a>1.3.6 </small></address>
</body>
</html>
|