Commit 0d9073a6 authored by Jonas Stienen's avatar Jonas Stienen

Fixing disconnect problems with client

parent d4d3a8b2
...@@ -78,6 +78,8 @@ public: ...@@ -78,6 +78,8 @@ public:
*/ */
bool Connect( const std::string& sAddress, int iPort = 12480 ); bool Connect( const std::string& sAddress, int iPort = 12480 );
void Disconnect();
//! Returns the connection status //! Returns the connection status
/** /**
* @return True, if connected * @return True, if connected
......
...@@ -69,13 +69,16 @@ private: ...@@ -69,13 +69,16 @@ private:
CITANetAudioMessage* m_pMessage; CITANetAudioMessage* m_pMessage;
VistaConnectionIP* m_pConnection; VistaConnectionIP* m_pConnection;
VistaThreadEvent m_oBlockIncrementEvent; //VistaThreadEvent m_oBlockIncrementEvent;
ITASampleFrame m_sfReceivingBuffer; //!< Buffer incoming data ITASampleFrame m_sfReceivingBuffer; //!< Buffer incoming data
CITANetAudioProtocol::StreamingParameters m_oParams; CITANetAudioProtocol::StreamingParameters m_oParams;
bool m_bStopIndicated; bool m_bStopIndicated;
bool m_bStopped;
int iStreamingBlockId;
ITABufferedDataLoggerImplClient* m_pClientLogger;
friend class CITANetAudioStream; friend class CITANetAudioStream;
}; };
......
...@@ -46,5 +46,5 @@ void CITANetAudioClient::Disconnect() ...@@ -46,5 +46,5 @@ void CITANetAudioClient::Disconnect()
bool CITANetAudioClient::GetIsConnected() const bool CITANetAudioClient::GetIsConnected() const
{ {
return m_pConnection ? true : false; return ( m_pConnection != NULL ) ? true : false;
} }
...@@ -126,6 +126,11 @@ bool CITANetAudioStream::Connect( const std::string& sAddress, int iPort ) ...@@ -126,6 +126,11 @@ bool CITANetAudioStream::Connect( const std::string& sAddress, int iPort )
return m_pNetAudioStreamingClient->Connect( sAddress, iPort ); return m_pNetAudioStreamingClient->Connect( sAddress, iPort );
} }
void CITANetAudioStream::Disconnect()
{
m_pNetAudioStreamingClient->Disconnect();
}
bool CITANetAudioStream::GetIsConnected() const bool CITANetAudioStream::GetIsConnected() const
{ {
return m_pNetAudioStreamingClient->GetIsConnected(); return m_pNetAudioStreamingClient->GetIsConnected();
......
...@@ -6,12 +6,13 @@ ...@@ -6,12 +6,13 @@
#include <VistaInterProcComm/Connections/VistaConnectionIP.h> #include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaBase/VistaStreamUtils.h> #include <VistaBase/VistaStreamUtils.h>
#include <VistaBase/VistaTimeUtils.h>
CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pParent ) CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pParent )
: m_oBlockIncrementEvent( VistaThreadEvent::WAITABLE_EVENT ) : m_pStream( pParent )
, m_pStream( pParent )
, m_pConnection( NULL ) , m_pConnection( NULL )
, m_bStopIndicated( false ) , m_bStopIndicated( false )
, m_bStopped( false )
{ {
m_pClient = new CITANetAudioClient(); m_pClient = new CITANetAudioClient();
...@@ -24,14 +25,14 @@ CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pP ...@@ -24,14 +25,14 @@ CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pP
CITANetAudioStreamingClient::~CITANetAudioStreamingClient() CITANetAudioStreamingClient::~CITANetAudioStreamingClient()
{ {
if( m_pConnection ) if( GetIsConnected() )
{ Disconnect();
m_pMessage->ResetMessage();
m_pMessage->SetConnection( m_pConnection ); StopGently( true );
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_CLOSE );
m_pMessage->WriteMessage(); delete m_pClientLogger;
m_pClient->Disconnect(); delete m_pClient;
} delete m_pMessage;
} }
bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPort ) bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPort )
...@@ -66,10 +67,27 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor ...@@ -66,10 +67,27 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor
bool CITANetAudioStreamingClient::LoopBody() bool CITANetAudioStreamingClient::LoopBody()
{ {
if( m_bStopIndicated ) if( !GetIsConnected() )
return true; return true;
// Send message to server that samples can be received ITAClientLog oLog;
oLog.uiBlockId = ++iStreamingBlockId;
if( m_bStopIndicated && !m_bStopped )
{
m_pMessage->ResetMessage();
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_CLOSE );
m_pMessage->WriteMessage();
m_bStopped = true;
m_pMessage->SetConnection( NULL );
while( GetIsConnected() )
VistaTimeUtils::Sleep( 100 );
return true;
}
m_pMessage->ResetMessage(); m_pMessage->ResetMessage();
m_pMessage->SetConnection( m_pConnection ); m_pMessage->SetConnection( m_pConnection );
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_WAITING_FOR_SAMPLES ); m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_WAITING_FOR_SAMPLES );
...@@ -79,11 +97,11 @@ bool CITANetAudioStreamingClient::LoopBody() ...@@ -79,11 +97,11 @@ bool CITANetAudioStreamingClient::LoopBody()
m_pMessage->WriteInt( iFreeSamplesUntilAllowedReached ); m_pMessage->WriteInt( iFreeSamplesUntilAllowedReached );
m_pMessage->WriteMessage(); m_pMessage->WriteMessage();
// Wait for answer of server // Read answer (blocking)
m_pMessage->ReadAnswer(); m_pMessage->ResetMessage( );
int iAnswerType = m_pMessage->GetAnswerType(); if ( m_pMessage->ReadMessage( 0 ) )
switch( iAnswerType )
{ {
int iMsgType = m_pMessage->GetMessageType( );
case CITANetAudioProtocol::NP_INVALID: case CITANetAudioProtocol::NP_INVALID:
// Something went wrong // Something went wrong
...@@ -112,11 +130,6 @@ bool CITANetAudioStreamingClient::LoopBody() ...@@ -112,11 +130,6 @@ bool CITANetAudioStreamingClient::LoopBody()
return true; return true;
} }
void CITANetAudioStreamingClient::TriggerBlockIncrement()
{
m_oBlockIncrementEvent.SignalEvent();
}
bool CITANetAudioStreamingClient::GetIsConnected() const bool CITANetAudioStreamingClient::GetIsConnected() const
{ {
return m_pClient->GetIsConnected(); return m_pClient->GetIsConnected();
...@@ -125,10 +138,12 @@ bool CITANetAudioStreamingClient::GetIsConnected() const ...@@ -125,10 +138,12 @@ bool CITANetAudioStreamingClient::GetIsConnected() const
void CITANetAudioStreamingClient::Disconnect() void CITANetAudioStreamingClient::Disconnect()
{ {
m_bStopIndicated = true; m_bStopIndicated = true;
StopGently( true );
delete m_pConnection; while( !m_bStopped )
VistaTimeUtils::Sleep( 100 );
m_pConnection = NULL; m_pConnection = NULL;
m_pClient->Disconnect();
m_bStopIndicated = false; m_bStopIndicated = false;
m_bStopped = false;
} }
...@@ -61,7 +61,7 @@ private: ...@@ -61,7 +61,7 @@ private:
int main( int, char** ) int main( int, char** )
{ {
// Sample server (forked away into a thread) // Sample server (forked away into a thread)
CServer oServer( g_sInputFilePath ); CServer* pServer = new CServer( g_sInputFilePath );
// Client dumping received stream and mixing down to two channels // Client dumping received stream and mixing down to two channels
CITANetAudioStream oNetAudioStream( g_iChannels, g_dSampleRate, g_iBlockLength, 100 * g_iBlockLength ); CITANetAudioStream oNetAudioStream( g_iChannels, g_dSampleRate, g_iBlockLength, 100 * g_iBlockLength );
...@@ -105,6 +105,8 @@ int main( int, char** ) ...@@ -105,6 +105,8 @@ int main( int, char** )
ITAPA.Sleep( fSeconds ); // blocking ITAPA.Sleep( fSeconds ); // blocking
vstr::out() << "[ NetAudioTestClient ] Done." << endl; vstr::out() << "[ NetAudioTestClient ] Done." << endl;
oNetAudioStream.Disconnect();
vstr::out() << "[ NetAudioTestClient ] Will now disconnect from net audio server '" << g_sServerName << "' and port " << g_iServerPort << endl; vstr::out() << "[ NetAudioTestClient ] Will now disconnect from net audio server '" << g_sServerName << "' and port " << g_iServerPort << endl;
vstr::out() << "[ NetAudioTestClient ] Closing in 1 second (net audio stream not connected and playing back zeros)" << endl; vstr::out() << "[ NetAudioTestClient ] Closing in 1 second (net audio stream not connected and playing back zeros)" << endl;
ITAPA.Sleep( 1.0f ); ITAPA.Sleep( 1.0f );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment