ITANetAudioMessage.h 2.79 KB
Newer Older
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
/*
 * ----------------------------------------------------------------
 *
 *		ITA core libs
 *		(c) Copyright Institute of Technical Acoustics (ITA)
 *		RWTH Aachen University, Germany, 2015-2016
 *
 * ----------------------------------------------------------------
 *				    ____  __________  _______
 *				   //  / //__   ___/ //  _   |
 *				  //  /    //  /    //  /_|  |
 *				 //  /    //  /    //  ___   |
 *				//__/    //__/    //__/   |__|
 *
 * ----------------------------------------------------------------
 *
 */

#ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_MESSAGE
#define INCLUDE_WATCHER_ITA_NET_AUDIO_MESSAGE

#include <ITADataSourcesDefinitions.h>

// ITA includes
#include <ITAException.h>
#include <ITASampleBuffer.h>
#include <ITASampleFrame.h>
28
#include <ITANetAudioProtocol.h>
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

// Vista includes
#include <VistaInterProcComm/Connections/VistaByteBufferSerializer.h>
#include <VistaInterProcComm/Connections/VistaByteBufferDeSerializer.h>

// STL includes
#include <string>
#include <vector>

class VistaConnectionIP;

//! Network audio messages
/*
 * Messages consist of a message part and an answer part, each read or written
 * separately. Messages have a two-int-header (SIZE, MSGTYPE), and
 * answers have a two-int header (SIZE; ANSWERTYPE)
 */
class ITA_DATA_SOURCES_API CITANetAudioMessage
{
public:
	CITANetAudioMessage( VistaSerializingToolset::ByteOrderSwapBehavior bSwapBuffers );


	void SetConnection( VistaConnectionIP* );
	VistaConnectionIP* GetConnection() const;
	void ClearConnection();

	void WriteMessage();
	void ReadMessage();
	void WriteAnswer();
	void ReadAnswer();

	void ResetMessage();

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

	void SetMessageType( int nType );
	void SetAnswerType( int nType );
	int GetMessageType() const;
	int GetAnswerType() const;


	void WriteInt( const int );
	void WriteBool( const bool );
	void WriteDouble( const double );
	void WriteException( const ITAException& );
	void WriteFloat( const float );
	void WriteString( const std::string& );
	void WriteIntVector( const std::vector< int > );
	void WriteFloatVector( const std::vector< float > );
81
	void WriteStreamingParameters( const CITANetAudioProtocol::StreamingParameters &);
82 83 84 85 86 87 88 89 90

	std::string ReadString();
	int ReadInt();
	bool ReadBool();
	ITAException ReadException();
	float ReadFloat();
	double ReadDouble();
	std::vector< int > ReadIntVector();
	std::vector< float > ReadFloatVector();
91
	CITANetAudioProtocol::StreamingParameters ReadStreamingParameters();
92

93

94 95 96 97 98 99 100 101 102 103 104 105
private:
	int m_nMessageType;
	int m_nMessageId;
	int m_nAnswerType;
	VistaByteBufferSerializer m_oOutgoing;
	VistaByteBufferDeSerializer m_oIncoming;
	std::vector< VistaType::byte > m_vecIncomingBuffer;

	VistaConnectionIP* m_pConnection;
};

#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_MESSAGE