1 | /*! |
---|
2 | * @file network_stream.h |
---|
3 | * implementation of a network pipe |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _HANDSHAKE |
---|
7 | #define _HANDSHAKE |
---|
8 | |
---|
9 | #include "base_object.h" |
---|
10 | #include "synchronizeable.h" |
---|
11 | |
---|
12 | #define _INITIAL_DATA "orxonox" |
---|
13 | #define _INITIAL_DATA_LENGTH 7 |
---|
14 | |
---|
15 | #define _ORXONOX_VERSION "\x00\x00\x00\x01" |
---|
16 | #define _ORXONOX_VERSION_LENGTH 4 |
---|
17 | |
---|
18 | typedef enum HandshakeState { |
---|
19 | HS_SENT_INIT = 0x00000001, |
---|
20 | HS_RECVD_INIT = 0x00000002, |
---|
21 | HS_SENT_VER = 0x00000004, |
---|
22 | HS_RECVD_VER = 0x00000008, |
---|
23 | HS_SENT_HID = 0x00000010, |
---|
24 | HS_RECVD_HID = 0x00000020, |
---|
25 | HS_COMPLETED = 0X00000040, |
---|
26 | |
---|
27 | NUM_STATES |
---|
28 | }; |
---|
29 | |
---|
30 | class Handshake : public Synchronizeable |
---|
31 | { |
---|
32 | public: |
---|
33 | Handshake(bool server, int clientId = 0); |
---|
34 | inline bool completed(){ return hasState( HS_COMPLETED ); } |
---|
35 | inline bool ok(){ return isOk; } |
---|
36 | inline int getHostId(){ return newHostId; } |
---|
37 | |
---|
38 | virtual void writeBytes(const byte* data, int length); |
---|
39 | virtual int readBytes(byte* data, int maxLength, int * reciever); |
---|
40 | virtual void writeDebug() const; |
---|
41 | virtual void readDebug() const; |
---|
42 | |
---|
43 | private: |
---|
44 | int state; |
---|
45 | int clientId; |
---|
46 | int newHostId; |
---|
47 | bool isOk; |
---|
48 | |
---|
49 | inline bool hasState( int a ){ return (state & a) == a; } |
---|
50 | inline void setState( int a ){ state = state | a; } |
---|
51 | inline void unsetState( int a ){ state = state & (~a); } |
---|
52 | |
---|
53 | }; |
---|
54 | |
---|
55 | |
---|
56 | #endif |
---|