From f3ce0f8ea24338cd7df4733d2e6a0496ca8819be Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sat, 9 Dec 2006 10:40:18 +0000 Subject: [PATCH] connected client list is now updated for all other clients if one channel is disconnected --- src/channel.cpp | 68 +++++++++++++++++++++++++++++++++++++++++-------- src/channel.h | 11 +++++++- src/client.cpp | 4 +-- 3 files changed, 69 insertions(+), 14 deletions(-) diff --git a/src/channel.cpp b/src/channel.cpp index fc439dfb..d8aa8d50 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -94,6 +94,22 @@ CVector CChannelSet::CreateChannelList() return vecChanInfo; } +void CChannelSet::CreateAndSendChanListForAllConChannels() +{ + // create channel list + CVector vecChanInfo ( CChannelSet::CreateChannelList() ); + + // now send connected channels list to all connected clients + for ( int i = 0; i < MAX_NUM_CHANNELS; i++ ) + { + if ( vecChannels[i].IsConnected() ) + { + // send message + vecChannels[i].CreateConClientListMes ( vecChanInfo ); + } + } +} + void CChannelSet::CreateAndSendChanListForAllExceptThisChan ( const int iCurChanID ) { // create channel list @@ -254,7 +270,8 @@ void CChannelSet::GetBlockAllConC ( CVector& vecChanID, CVector >& vecvecdData, CVector >& vecvecdGains ) { - int i, j; + int i, j; + bool bCreateChanList = false; // init temporal data vector and clear input buffers CVector vecdData ( MIN_BLOCK_SIZE_SAMPLES ); @@ -272,7 +289,14 @@ void CChannelSet::GetBlockAllConC ( CVector& vecChanID, { // read out all input buffers to decrease timeout counter on // disconnected channels - const bool bGetOK = vecChannels[i].GetData ( vecdData ); + const EGetDataStat eGetStat = vecChannels[i].GetData ( vecdData ); + + // if channel was just disconnected, set flag that connected + // client list is sent to all other clients + if ( eGetStat == GS_CHAN_NOW_DISCONNECTED ) + { + bCreateChanList = true; + } if ( vecChannels[i].IsConnected() ) { @@ -285,7 +309,7 @@ void CChannelSet::GetBlockAllConC ( CVector& vecChanID, vecvecdData[iOldSize] = vecdData; // send message for get status (for GUI) - if ( bGetOK ) + if ( eGetStat == GS_BUFFER_OK ) { PostWinMessage ( MS_JIT_BUF_GET, MUL_COL_LED_GREEN, i ); } @@ -311,7 +335,14 @@ void CChannelSet::GetBlockAllConC ( CVector& vecChanID, // query the IDs of the currently connected channels vecvecdGains[i][j] = vecChannels[i].GetGain( vecChanID[j] ); } - } + } + + // create channel list message if requested + if ( bCreateChanList ) + { + // update channel list for all currently connected clients + CreateAndSendChanListForAllConChannels(); + } } Mutex.unlock(); // release mutex } @@ -620,26 +651,41 @@ for ( int i = 0; i < iCurNetwInBlSiFact * MIN_BLOCK_SIZE_SAMPLES; i++ ) { return eRet; } -bool CChannel::GetData ( CVector& vecdData ) +EGetDataStat CChannel::GetData ( CVector& vecdData ) { - bool bGetOK = false; + // init with ok flag + EGetDataStat eGetStatus = GS_BUFFER_OK; Mutex.lock(); // get mutex lock { - bGetOK = SockBuf.Get ( vecdData ); - - if ( !bGetOK ) + if ( !SockBuf.Get ( vecdData ) ) { // decrease time-out counter if ( iConTimeOut > 0 ) { iConTimeOut--; + + if ( iConTimeOut == 0 ) + { + // channel is just disconnected + eGetStatus = GS_CHAN_NOW_DISCONNECTED; + } + else + { + // channel is not yet disconnected but no data in buffer + eGetStatus = GS_BUFFER_UNDERRUN; + } + } + else + { + // channel is disconnected + eGetStatus = GS_CHAN_NOT_CONNECTED; } - } + } } Mutex.unlock(); // get mutex unlock - return bGetOK; + return eGetStatus; } CVector CChannel::PrepSendPacket ( const CVector& vecsNPacket ) diff --git a/src/channel.h b/src/channel.h index 908f481c..8b30a671 100755 --- a/src/channel.h +++ b/src/channel.h @@ -55,6 +55,14 @@ enum EPutDataStat PS_AUDIO_ERR, PS_PROT_OK, PS_PROT_ERR +}; + +enum EGetDataStat +{ + GS_BUFFER_OK, + GS_BUFFER_UNDERRUN, + GS_CHAN_NOW_DISCONNECTED, + GS_CHAN_NOT_CONNECTED }; @@ -70,7 +78,7 @@ public: EPutDataStat PutData ( const CVector& vecbyData, int iNumBytes ); - bool GetData ( CVector& vecdData ); + EGetDataStat GetData ( CVector& vecdData ); CVector PrepSendPacket ( const CVector& vecsNPacket ); @@ -221,6 +229,7 @@ public: protected: CVector CreateChannelList(); + void CreateAndSendChanListForAllConChannels(); void CreateAndSendChanListForAllExceptThisChan ( const int iCurChanID ); void CreateAndSendChanListForThisChan ( const int iCurChanID ); diff --git a/src/client.cpp b/src/client.cpp index 6d12e638..2063d014 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -252,8 +252,8 @@ void CClient::run() Socket.SendPacket ( Channel.PrepSendPacket ( vecsNetwork ), Channel.GetAddress () ); - // receive a new block - if ( Channel.GetData ( vecdNetwData ) ) + // receive a new block + if ( Channel.GetData ( vecdNetwData ) == GS_BUFFER_OK ) { PostWinMessage ( MS_JIT_BUF_GET, MUL_COL_LED_GREEN ); }