VANetMessage.h 3.84 KB
Newer Older
1
2
3
/*
 *  --------------------------------------------------------------------------------------------
 *
4
5
6
7
8
9
 *    VVV        VVV A           Virtual Acoustics (VA) | http://www.virtualacoustics.org
 *     VVV      VVV AAA          Licensed under the Apache License, Version 2.0
 *      VVV    VVV   AAA
 *       VVV  VVV     AAA        Copyright 2015-2017
 *        VVVVVV       AAA       Institute of Technical Acoustics (ITA)
 *         VVVV         AAA      RWTH Aachen University
10
11
12
13
14
15
 *
 *  --------------------------------------------------------------------------------------------
 */

#ifndef IW_VANET_MESSAGE
#define IW_VANET_MESSAGE
Jonas Stienen's avatar
Jonas Stienen committed
16

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
17
#include <VA.h>
Jonas Stienen's avatar
Jonas Stienen committed
18
19
20
21
22
23
24
25
26
27
28
29

#include "VANetVistaCompatibility.h"

#include <VistaBase/VistaBaseTypes.h>
#include <VistaBase/VistaSerializingToolset.h>
#include <VistaInterProcComm/Connections/VistaByteBufferSerializer.h>
#include <VistaInterProcComm/Connections/VistaByteBufferDeSerializer.h>

#include <string>

class VistaConnectionIP;

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
30
class CVAEvent;
Jonas Stienen's avatar
Jonas Stienen committed
31
class CVAException;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
32
class CVAVersionInfo;
Jonas Stienen's avatar
Jonas Stienen committed
33
34
35
36
class CVADirectivityInfo;
class CVASignalSourceInfo;
class CVASceneInfo;

37
38
39
40
41
//! Network message helper
/** Messages consist of a message part and an answer part, each read or written
  * separately. Messages have a three-int-header (SIZE, MSGTYPE; EXCEPTIONMODE), while
  * answers have a two-int header (SIZE; ANSWERTYPE)
  */
Jonas Stienen's avatar
Jonas Stienen committed
42
43
44
class CVANetMessage
{
public:
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
45
	explicit CVANetMessage( const VistaSerializingToolset::ByteOrderSwapBehavior bSwapBuffers );
Jonas Stienen's avatar
Jonas Stienen committed
46
47
48
49
50
51
52

	void ResetMessage();

	void SetConnection( VistaConnectionIP* pConn );

	void WriteMessage();
	void ReadMessage();
53
	void WriteAnswer();
Jonas Stienen's avatar
Jonas Stienen committed
54
	void ReadAnswer();
55

Jonas Stienen's avatar
Jonas Stienen committed
56
57
58
59
	int GetExceptionMode() const;
	int GetMessageType() const;
	int GetAnswerType() const;

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
60
61
62
	void SetExceptionMode( const int nMode );
	void SetMessageType( const int nType );
	void SetAnswerType( const int nType );
Jonas Stienen's avatar
Jonas Stienen committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

	int GetIncomingMessageSize() const;
	int  GetOutgoingMessageSize() const;
	bool GetOutgoingMessageHasData() const;


	// serializing functions

	void WriteString( const std::string& sValue );
	void WriteInt( const int iValue );
	void WriteUInt64( const uint64_t iValue );
	void WriteBool( const bool bValue );
	void WriteFloat( const float fValue );
	void WriteDouble( const double fValue );
	void WriteVec3( const VAVec3& oVec );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
78
	void WriteQuat( const VAQuat& qOrient );
Jonas Stienen's avatar
Jonas Stienen committed
79
	void WriteException( const CVAException& oException );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
80
81
	void WriteEvent( const CVAEvent& oEvent );
	void WriteVersionInfo( const CVAVersionInfo& oInfo );
Jonas Stienen's avatar
Jonas Stienen committed
82
83
84
85
86
87
	void WriteDirectivityInfo( const CVADirectivityInfo& oInfo );
	void WriteSignalSourceInfo( const CVASignalSourceInfo& oInfo );
	void WriteSceneInfo( const CVASceneInfo& oInfo );
	void WriteModuleInfo( const CVAModuleInfo& oInfo );
	void WriteBlob( const void* pBuf, int nBytes );
	void WriteVAStruct( const CVAStruct& oStruct );
88
89
	void WriteAudioRenderingModuleInfo( const CVAAudioRendererInfo& );
	void WriteAudioReproductionModuleInfo( const CVAAudioReproductionInfo& );
Jonas Stienen's avatar
Jonas Stienen committed
90
91
92
93
94
95
96
97

	std::string ReadString();
	int ReadInt();
	uint64_t ReadUInt64();
	bool ReadBool();
	float ReadFloat();
	double ReadDouble();
	VAVec3 ReadVec3();
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
98
	VAQuat ReadQuat();
Jonas Stienen's avatar
Jonas Stienen committed
99
	CVAException ReadException();
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
100
101
	CVAEvent ReadEvent();
	CVAVersionInfo ReadVersionInfo();
Jonas Stienen's avatar
Jonas Stienen committed
102
103
104
105
106
107
	CVADirectivityInfo ReadDirectivityInfo();
	CVASignalSourceInfo ReadSignalSourceInfo();
	CVASceneInfo ReadSceneInfo();
	void ReadModuleInfo( CVAModuleInfo& oInfo );
	void ReadBlob( void* pBuf, int nBytes );
	void ReadVAStruct( CVAStruct& oStruct );
108
109
	CVAAudioRendererInfo ReadAudioRenderingModuleInfo();
	CVAAudioReproductionInfo ReadAudioReproductionModuleInfo();
Jonas Stienen's avatar
Jonas Stienen committed
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

	VistaConnectionIP* GetConnection() const;
	void ClearConnection();
private:
	int m_nMessageType;
	int m_nMessageId;
	int m_nAnswerType;
	int m_nExceptionMode;
	VistaByteBufferSerializer	m_oOutgoing;
	VistaByteBufferDeSerializer	m_oIncoming;
	std::vector<VANetCompat::byte>			m_vecIncomingBuffer;

	VistaConnectionIP* m_pConnection;
};

125
#endif// IW_VANET_MESSAGE