ITANetAudioMessage.h 3.67 KB
Newer Older
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
1 2 3 4 5
/*
 * ----------------------------------------------------------------
 *
 *		ITA core libs
 *		(c) Copyright Institute of Technical Acoustics (ITA)
6
 *		RWTH Aachen University, Germany, 2015-2018
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * ----------------------------------------------------------------
 *				    ____  __________  _______
 *				   //  / //__   ___/ //  _   |
 *				  //  /    //  /    //  /_|  |
 *				 //  /    //  /    //  ___   |
 *				//__/    //__/    //__/   |__|
 *
 * ----------------------------------------------------------------
 *
 */

#ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_MESSAGE
#define INCLUDE_WATCHER_ITA_NET_AUDIO_MESSAGE

#include <ITADataSourcesDefinitions.h>

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
24 25
#include "ITANetAudioProtocol.h"

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39
// ITA includes
#include <ITAException.h>
#include <ITASampleBuffer.h>
#include <ITASampleFrame.h>

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

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

class VistaConnectionIP;
Anne Heimes's avatar
Anne Heimes committed
40
class ITABufferedDataLoggerImplProtocol;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
41 42

//! Network audio messages
43 44 45 46 47 48 49
/**
  * Messages consist of a message part and an answer part, each read or written
  * separately. Messages have a three-int-header (SIZE, MSGTYPE, ID), and
  * answers have a three-int header (SIZE, ANSWERTYPE, ID)
  *
  * @todo move to src folder
  */
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
50 51 52 53 54 55 56 57 58
class ITA_DATA_SOURCES_API CITANetAudioMessage
{
public:
	CITANetAudioMessage( VistaSerializingToolset::ByteOrderSwapBehavior bSwapBuffers );

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

59
	//! Will always block processing until data is completely send
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
60
	void WriteMessage();
61 62 63

	//! Returns false if no incomming data during timeout
	bool ReadMessage( const int iTimeoutMilliseconds );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

	void ResetMessage();

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

	void SetMessageType( int nType );
	int GetMessageType() 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 > );
Anne's avatar
Anne committed
83 84 85
	void WriteStreamingParameters(const CITANetAudioProtocol::StreamingParameters &); 
	void WriteRingBufferSize(const int);
	void WriteRingBufferFree(const int);
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
86 87 88 89 90 91 92 93 94 95
	void WriteSampleFrame(ITASampleFrame*);

	std::string ReadString();
	int ReadInt();
	bool ReadBool();
	ITAException ReadException();
	float ReadFloat();
	double ReadDouble();
	std::vector< int > ReadIntVector();
	std::vector< float > ReadFloatVector();
Anne's avatar
Anne committed
96 97 98
	CITANetAudioProtocol::StreamingParameters ReadStreamingParameters();
	int ReadRingBufferSize();
	int ReadRingBufferFree();
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
99 100
	void ReadSampleFrame(ITASampleFrame* pSampleFrame);

Jonas Stienen's avatar
Jonas Stienen committed
101 102
	void SetMessageLoggerBaseName( const std::string& );
	std::string GetMessageLoggerBaseName() const;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
103 104
	void SetDebuggingEnabled( bool bEnabled );
	bool GetIsDebuggingEnabled() const;
Jonas Stienen's avatar
Jonas Stienen committed
105

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
106 107 108
private:
	int m_nMessageType;
	int m_nMessageId;
Anne Heimes's avatar
Anne Heimes committed
109 110
	unsigned long m_iBytesReceivedTotal;

111 112 113
	VistaByteBufferSerializer m_oOutgoing; //!< Serialization buffer for messages
	VistaByteBufferDeSerializer m_oIncoming; //!< Deserialization buffer for messages
	std::vector< VistaType::byte > m_vecIncomingBuffer; // Net IO buffer
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
114 115

	VistaConnectionIP* m_pConnection;
Anne Heimes's avatar
Anne Heimes committed
116

Jonas Stienen's avatar
Jonas Stienen committed
117 118
	ITABufferedDataLoggerImplProtocol* m_pMessageLogger;
	std::string m_sMessageLoggerBaseName;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
119
	bool m_bDebuggingEnabled;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
120 121 122
};

#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_MESSAGE