chore: structure basic
[KDIS.git] / Examples / Logging / DIS_Logger_Playback / KDIS.cpp
blob6cf6513a7b1cc8efca0811219390688adb066eae
1 /**********************************************************************
2 The following UNLICENSE statement applies to this example.
4 This is free and unencumbered software released into the public domain.
6 Anyone is free to copy, modify, publish, use, compile, sell, or
7 distribute this software, either in source code form or as a compiled
8 binary, for any purpose, commercial or non-commercial, and by any
9 means.
11 In jurisdictions that recognize copyright laws, the author or authors
12 of this software dedicate any and all copyright interest in the
13 software to the public domain. We make this dedication for the benefit
14 of the public at large and to the detriment of our heirs and
15 successors. We intend this dedication to be an overt act of
16 relinquishment in perpetuity of all present and future rights to this
17 software under copyright law.
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 OTHER DEALINGS IN THE SOFTWARE.
27 For more information, please refer to <http://unlicense.org/>
28 *********************************************************************/
30 /*********************************************************************
31 For Further Information on KDIS:
32 http://p.sf.net/kdis/UserGuide
33 *********************************************************************/
35 #include <iostream>
36 #include <time.h>
37 #include "KDIS/Extras/DIS_Logger_Playback.h"
38 #include "KDIS/Network/Connection.h" // A cross platform connection class.
40 #define LOG_FILE "Log.txt"
42 using namespace std;
43 using namespace KDIS;
44 using namespace DATA_TYPE;
45 using namespace PDU;
46 using namespace ENUMS;
47 using namespace UTILS;
48 using namespace NETWORK;
50 int main()
52 try
54 // Note this address will probably be different for your network.
55 Connection conn( "192.168.3.255" );
57 KOCTET cBuffer[MAX_PDU_SIZE]; // Somewhere to store the data we receive.
59 // Load all data into memory from the log.
60 DIS_Logger_Playback Log( LOG_FILE, 0 );
62 KUINT32 uiStartTime = time( NULL );
63 KUINT32 ui32Timepassed;
64 KBOOL bWaiting;
66 while( Log.EndOfLogReached() == false )
68 ui32Timepassed = time( NULL ) - uiStartTime;
70 // Get the next entry in the log
71 KUINT32 ui32Stamp;
72 KDataStream stream;
73 Log.GetNext( ui32Stamp, stream );
75 bWaiting = true;
77 // Wait untill it is time to send the PDU
78 while( bWaiting )
80 if( ui32Stamp <= ui32Timepassed )
82 bWaiting = false;
83 stream.CopyIntoBuffer( cBuffer, MAX_PDU_SIZE );
85 conn.Send( cBuffer, stream.GetBufferSize() );
87 stream.Clear();
89 else
91 ui32Timepassed = time( NULL ) - uiStartTime;
96 catch( exception & e )
98 cout << e.what() << endl;
99 return -1;
102 return 0;