fixed problem with receiving connected clients list on new connection

This commit is contained in:
Volker Fischer 2006-12-09 10:04:27 +00:00
parent 5bdf759e01
commit fc0f1d6aae
7 changed files with 174 additions and 124 deletions

View file

@ -30,6 +30,12 @@
\******************************************************************************/ \******************************************************************************/
CChannelSet::CChannelSet() CChannelSet::CChannelSet()
{ {
// enable all channels
for ( int i = 0; i < MAX_NUM_CHANNELS; i++ )
{
vecChannels[i].SetEnable ( true );
}
// make sure we have MAX_NUM_CHANNELS connections!!! // make sure we have MAX_NUM_CHANNELS connections!!!
// send message // send message
QObject::connect(&vecChannels[0],SIGNAL(MessReadyForSending(CVector<uint8_t>)),this,SLOT(OnSendProtMessCh0(CVector<uint8_t>))); QObject::connect(&vecChannels[0],SIGNAL(MessReadyForSending(CVector<uint8_t>)),this,SLOT(OnSendProtMessCh0(CVector<uint8_t>)));
@ -56,25 +62,24 @@ CChannelSet::CChannelSet()
QObject::connect(&vecChannels[9],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh9())); QObject::connect(&vecChannels[9],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh9()));
// request connected clients list // request connected clients list
QObject::connect(&vecChannels[0],SIGNAL(ReqConnClientsList()),this,SLOT(OnNewConnectionCh0())); QObject::connect(&vecChannels[0],SIGNAL(ReqConnClientsList()),this,SLOT(OnReqConnClientsListCh0()));
QObject::connect(&vecChannels[1],SIGNAL(ReqConnClientsList()),this,SLOT(OnNewConnectionCh1())); QObject::connect(&vecChannels[1],SIGNAL(ReqConnClientsList()),this,SLOT(OnReqConnClientsListCh1()));
QObject::connect(&vecChannels[2],SIGNAL(ReqConnClientsList()),this,SLOT(OnNewConnectionCh2())); QObject::connect(&vecChannels[2],SIGNAL(ReqConnClientsList()),this,SLOT(OnReqConnClientsListCh2()));
QObject::connect(&vecChannels[3],SIGNAL(ReqConnClientsList()),this,SLOT(OnNewConnectionCh3())); QObject::connect(&vecChannels[3],SIGNAL(ReqConnClientsList()),this,SLOT(OnReqConnClientsListCh3()));
QObject::connect(&vecChannels[4],SIGNAL(ReqConnClientsList()),this,SLOT(OnNewConnectionCh4())); QObject::connect(&vecChannels[4],SIGNAL(ReqConnClientsList()),this,SLOT(OnReqConnClientsListCh4()));
QObject::connect(&vecChannels[5],SIGNAL(ReqConnClientsList()),this,SLOT(OnNewConnectionCh5())); QObject::connect(&vecChannels[5],SIGNAL(ReqConnClientsList()),this,SLOT(OnReqConnClientsListCh5()));
QObject::connect(&vecChannels[6],SIGNAL(ReqConnClientsList()),this,SLOT(OnNewConnectionCh6())); QObject::connect(&vecChannels[6],SIGNAL(ReqConnClientsList()),this,SLOT(OnReqConnClientsListCh6()));
QObject::connect(&vecChannels[7],SIGNAL(ReqConnClientsList()),this,SLOT(OnNewConnectionCh7())); QObject::connect(&vecChannels[7],SIGNAL(ReqConnClientsList()),this,SLOT(OnReqConnClientsListCh7()));
QObject::connect(&vecChannels[8],SIGNAL(ReqConnClientsList()),this,SLOT(OnNewConnectionCh8())); QObject::connect(&vecChannels[8],SIGNAL(ReqConnClientsList()),this,SLOT(OnReqConnClientsListCh8()));
QObject::connect(&vecChannels[9],SIGNAL(ReqConnClientsList()),this,SLOT(OnNewConnectionCh9())); QObject::connect(&vecChannels[9],SIGNAL(ReqConnClientsList()),this,SLOT(OnReqConnClientsListCh9()));
} }
void CChannelSet::CreateAndSendChanListForAllConClients() CVector<CChannelShortInfo> CChannelSet::CreateChannelList()
{ {
int i;
CVector<CChannelShortInfo> vecChanInfo ( 0 ); CVector<CChannelShortInfo> vecChanInfo ( 0 );
// look for free channels // look for free channels
for ( i = 0; i < MAX_NUM_CHANNELS; i++ ) for ( int i = 0; i < MAX_NUM_CHANNELS; i++ )
{ {
if ( vecChannels[i].IsConnected() ) if ( vecChannels[i].IsConnected() )
{ {
@ -86,10 +91,19 @@ void CChannelSet::CreateAndSendChanListForAllConClients()
} }
} }
// now send connected channels list to all connected clients return vecChanInfo;
for ( i = 0; i < MAX_NUM_CHANNELS; i++ ) }
void CChannelSet::CreateAndSendChanListForAllExceptThisChan ( const int iCurChanID )
{
// create channel list
CVector<CChannelShortInfo> vecChanInfo ( CChannelSet::CreateChannelList() );
// now send connected channels list to all connected clients except for
// the channel with the ID "iCurChanID"
for ( int i = 0; i < MAX_NUM_CHANNELS; i++ )
{ {
if ( vecChannels[i].IsConnected() ) if ( ( vecChannels[i].IsConnected() ) && ( i != iCurChanID ) )
{ {
// send message // send message
vecChannels[i].CreateConClientListMes ( vecChanInfo ); vecChannels[i].CreateConClientListMes ( vecChanInfo );
@ -97,6 +111,15 @@ void CChannelSet::CreateAndSendChanListForAllConClients()
} }
} }
void CChannelSet::CreateAndSendChanListForThisChan ( const int iCurChanID )
{
// create channel list
CVector<CChannelShortInfo> vecChanInfo ( CChannelSet::CreateChannelList() );
// now send connected channels list to the channel with the ID "iCurChanID"
vecChannels[iCurChanID].CreateConClientListMes ( vecChanInfo );
}
int CChannelSet::GetFreeChan() int CChannelSet::GetFreeChan()
{ {
// look for a free channel // look for a free channel
@ -216,18 +239,10 @@ bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
// requested // requested
if ( bCreateChanList ) if ( bCreateChanList )
{ {
// connected clients list is only send for new connected clients after
// request, only the already connected clients get the list
// automatically, because they don't know when new clients connect
// TODO list is only send for new connected clients after request, only CreateAndSendChanListForAllExceptThisChan ( iCurChanID );
// the already connected clients get the list automatically, because they
// don't know when new clients connect!
// TODO use "void OnReqConnClientsListChx() {}" for sending list to specific client
CreateAndSendChanListForAllConClients(); // <- replace this
} }
} }
Mutex.unlock(); Mutex.unlock();
@ -384,6 +399,18 @@ CChannel::CChannel() : sName ( "" ),
this, SLOT ( OnNetwBlSiFactChange ( int ) ) ); this, SLOT ( OnNetwBlSiFactChange ( int ) ) );
} }
void CChannel::SetEnable ( const bool bNEnStat )
{
// set internal parameter
bIsEnabled = bNEnStat;
// if channel is not enabled, reset time out count
if ( !bNEnStat )
{
iConTimeOut = 0;
}
}
void CChannel::SetNetwInBlSiFact ( const int iNewBlockSizeFactor ) void CChannel::SetNetwInBlSiFact ( const int iNewBlockSizeFactor )
{ {
// store new value // store new value
@ -491,37 +518,40 @@ bool CChannel::GetAddress(CHostAddress& RetAddr)
EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData, EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
int iNumBytes ) int iNumBytes )
{ {
EPutDataStat eRet = PS_GEN_ERROR; EPutDataStat eRet = PS_GEN_ERROR;
bool bNewConnection = false;
bool bIsAudioPacket = false;
// check if this is an audio packet by checking all possible lengths if ( bIsEnabled )
for ( int i = 0; i < MAX_NET_BLOCK_SIZE_FACTOR; i++ )
{ {
if ( iNumBytes == vecNetwInBufSizes[i] ) bool bNewConnection = false;
{ bool bIsAudioPacket = false;
bIsAudioPacket = true;
// check if we are correctly initialized // check if this is an audio packet by checking all possible lengths
const int iNewNetwInBlSiFact = i + 1; for ( int i = 0; i < MAX_NET_BLOCK_SIZE_FACTOR; i++ )
if ( iNewNetwInBlSiFact != iCurNetwInBlSiFact ) {
if ( iNumBytes == vecNetwInBufSizes[i] )
{ {
// re-initialize to new value bIsAudioPacket = true;
SetNetwInBlSiFact ( iNewNetwInBlSiFact );
// check if we are correctly initialized
const int iNewNetwInBlSiFact = i + 1;
if ( iNewNetwInBlSiFact != iCurNetwInBlSiFact )
{
// re-initialize to new value
SetNetwInBlSiFact ( iNewNetwInBlSiFact );
}
} }
} }
}
// only process if packet has correct size // only process if packet has correct size
if ( bIsAudioPacket ) if ( bIsAudioPacket )
{
Mutex.lock();
{ {
// decompress audio Mutex.lock();
CVector<short> vecsDecomprAudio ( AudioCompressionIn.Decode ( vecbyData ) ); {
// decompress audio
CVector<short> vecsDecomprAudio ( AudioCompressionIn.Decode ( vecbyData ) );
// do resampling to compensate for sample rate offsets in the // do resampling to compensate for sample rate offsets in the
// different sound cards of the clients // different sound cards of the clients
/* /*
for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++) for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++)
vecdResInData[i] = (double) vecsData[i]; vecdResInData[i] = (double) vecsData[i];
@ -535,55 +565,56 @@ for ( int i = 0; i < iCurNetwInBlSiFact * MIN_BLOCK_SIZE_SAMPLES; i++ ) {
vecdResOutData[i] = (double) vecsDecomprAudio[i]; vecdResOutData[i] = (double) vecsDecomprAudio[i];
} }
if ( SockBuf.Put ( vecdResOutData ) ) if ( SockBuf.Put ( vecdResOutData ) )
{ {
eRet = PS_AUDIO_OK; eRet = PS_AUDIO_OK;
} }
else else
{ {
eRet = PS_AUDIO_ERR; eRet = PS_AUDIO_ERR;
} }
// check if channel was not connected, this is a new connection // check if channel was not connected, this is a new connection
bNewConnection = !IsConnected(); bNewConnection = !IsConnected();
// reset time-out counter // reset time-out counter
iConTimeOut = iConTimeOutStartVal; iConTimeOut = iConTimeOutStartVal;
}
Mutex.unlock();
} }
Mutex.unlock(); else
}
else
{
// only use protocol data if channel is connected
if ( IsConnected() )
{ {
// this seems not to be an audio block, parse the message // only use protocol data if channel is connected
if ( Protocol.ParseMessage ( vecbyData, iNumBytes ) ) if ( IsConnected() )
{ {
eRet = PS_PROT_OK; // this seems not to be an audio block, parse the message
if ( Protocol.ParseMessage ( vecbyData, iNumBytes ) )
{
eRet = PS_PROT_OK;
// create message for protocol status // create message for protocol status
emit ProtocolStatus ( true ); emit ProtocolStatus ( true );
} }
else else
{ {
eRet = PS_PROT_ERR; eRet = PS_PROT_ERR;
// create message for protocol status // create message for protocol status
emit ProtocolStatus ( false ); emit ProtocolStatus ( false );
}
} }
} }
}
// inform other objects that new connection was established // inform other objects that new connection was established
if ( bNewConnection ) if ( bNewConnection )
{ {
// log new connection // log new connection
CHostAddress address ( GetAddress() ); CHostAddress address ( GetAddress() );
qDebug ( CLogTimeDate::toString() + "Connected with IP %s", qDebug ( CLogTimeDate::toString() + "Connected with IP %s",
address.InetAddr.toString().latin1() ); address.InetAddr.toString().latin1() );
emit NewConnection(); emit NewConnection();
}
} }
return eRet; return eRet;

View file

@ -36,17 +36,17 @@
/* Definitions ****************************************************************/ /* Definitions ****************************************************************/
/* Set the time-out for the input buffer until the state changes from // Set the time-out for the input buffer until the state changes from
connected to not-connected (the actual time depends on the way the error // connected to not-connected (the actual time depends on the way the error
correction is implemented) */ // correction is implemented)
#define CON_TIME_OUT_SEC_MAX 5 // seconds #define CON_TIME_OUT_SEC_MAX 5 // seconds
/* maximum number of internet connections (channels) */ // maximum number of internet connections (channels)
// if you want to change this paramter, change the connections in this class, too! // if you want to change this paramter, change the connections in this class, too!
#define MAX_NUM_CHANNELS 10 /* max number channels for server */ #define MAX_NUM_CHANNELS 10 /* max number channels for server */
/* no valid channel number */ // no valid channel number
#define INVALID_CHANNEL_ID (MAX_NUM_CHANNELS + 1) #define INVALID_CHANNEL_ID (MAX_NUM_CHANNELS + 1)
enum EPutDataStat enum EPutDataStat
{ {
@ -59,7 +59,7 @@ enum EPutDataStat
/* Classes ********************************************************************/ /* Classes ********************************************************************/
/* CChannel ----------------------------------------------------------------- */ // CChannel --------------------------------------------------------------------
class CChannel : public QObject class CChannel : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -76,6 +76,9 @@ public:
bool IsConnected() const { return iConTimeOut > 0; } bool IsConnected() const { return iConTimeOut > 0; }
void SetEnable ( const bool bNEnStat );
bool IsEnabled() { return bIsEnabled; }
void SetAddress ( const CHostAddress NAddr ) { InetAddr = NAddr; } void SetAddress ( const CHostAddress NAddr ) { InetAddr = NAddr; }
bool GetAddress ( CHostAddress& RetAddr ); bool GetAddress ( CHostAddress& RetAddr );
CHostAddress GetAddress () { return InetAddr; } CHostAddress GetAddress () { return InetAddr; }
@ -102,7 +105,7 @@ public:
Protocol.CreateJitBufMes ( iJitBufSize ); Protocol.CreateJitBufMes ( iJitBufSize );
} }
} }
void CreateReqJitBufMes() { Protocol.CreateReqJitBufMes(); } void CreateReqJitBufMes() { Protocol.CreateReqJitBufMes(); }
void CreateReqConnClientsList() { Protocol.CreateReqConnClientsList(); } void CreateReqConnClientsList() { Protocol.CreateReqConnClientsList(); }
void CreateNetwBlSiFactMes ( const int iNetwBlSiFact ) void CreateNetwBlSiFactMes ( const int iNetwBlSiFact )
@ -155,6 +158,8 @@ protected:
int iConTimeOut; int iConTimeOut;
int iConTimeOutStartVal; int iConTimeOutStartVal;
bool bIsEnabled;
int vecNetwInBufSizes[MAX_NET_BLOCK_SIZE_FACTOR]; int vecNetwInBufSizes[MAX_NET_BLOCK_SIZE_FACTOR];
int iCurNetwInBlSiFact; int iCurNetwInBlSiFact;
@ -178,7 +183,7 @@ signals:
}; };
/* CChannelSet (for server) ------------------------------------------------- */ // CChannelSet (for server) ----------------------------------------------------
class CChannelSet : public QObject class CChannelSet : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -203,7 +208,7 @@ public:
CVector<int>& veciNetwOutBlSiFact, CVector<int>& veciNetwOutBlSiFact,
CVector<int>& veciNetwInBlSiFact ); CVector<int>& veciNetwInBlSiFact );
/* access functions for actual channels */ // access functions for actual channels
bool IsConnected ( const int iChanNum ) bool IsConnected ( const int iChanNum )
{ return vecChannels[iChanNum].IsConnected(); } { return vecChannels[iChanNum].IsConnected(); }
@ -215,7 +220,9 @@ public:
{ return vecChannels[iChanNum].GetAddress(); } { return vecChannels[iChanNum].GetAddress(); }
protected: protected:
void CreateAndSendChanListForAllConClients(); CVector<CChannelShortInfo> CreateChannelList();
void CreateAndSendChanListForAllExceptThisChan ( const int iCurChanID );
void CreateAndSendChanListForThisChan ( const int iCurChanID );
/* do not use the vector class since CChannel does not have appropriate /* do not use the vector class since CChannel does not have appropriate
copy constructor/operator */ copy constructor/operator */
@ -247,17 +254,16 @@ public slots:
void OnNewConnectionCh8() {vecChannels[8].CreateReqJitBufMes();} void OnNewConnectionCh8() {vecChannels[8].CreateReqJitBufMes();}
void OnNewConnectionCh9() {vecChannels[9].CreateReqJitBufMes();} void OnNewConnectionCh9() {vecChannels[9].CreateReqJitBufMes();}
// TODO void OnReqConnClientsListCh0() { CreateAndSendChanListForThisChan ( 0 ); }
void OnReqConnClientsListCh0() {} void OnReqConnClientsListCh1() { CreateAndSendChanListForThisChan ( 1 ); }
void OnReqConnClientsListCh1() {} void OnReqConnClientsListCh2() { CreateAndSendChanListForThisChan ( 2 ); }
void OnReqConnClientsListCh2() {} void OnReqConnClientsListCh3() { CreateAndSendChanListForThisChan ( 3 ); }
void OnReqConnClientsListCh3() {} void OnReqConnClientsListCh4() { CreateAndSendChanListForThisChan ( 4 ); }
void OnReqConnClientsListCh4() {} void OnReqConnClientsListCh5() { CreateAndSendChanListForThisChan ( 5 ); }
void OnReqConnClientsListCh5() {} void OnReqConnClientsListCh6() { CreateAndSendChanListForThisChan ( 6 ); }
void OnReqConnClientsListCh6() {} void OnReqConnClientsListCh7() { CreateAndSendChanListForThisChan ( 7 ); }
void OnReqConnClientsListCh7() {} void OnReqConnClientsListCh8() { CreateAndSendChanListForThisChan ( 8 ); }
void OnReqConnClientsListCh8() {} void OnReqConnClientsListCh9() { CreateAndSendChanListForThisChan ( 9 ); }
void OnReqConnClientsListCh9() {}
signals: signals:
void MessReadyForSending ( int iChID, CVector<uint8_t> vecMessage ); void MessReadyForSending ( int iChID, CVector<uint8_t> vecMessage );

View file

@ -46,6 +46,9 @@ CClient::CClient() : bRun ( false ), Socket ( &Channel ),
QObject::connect ( &Channel, QObject::connect ( &Channel,
SIGNAL ( ConClientListMesReceived ( CVector<CChannelShortInfo> ) ), SIGNAL ( ConClientListMesReceived ( CVector<CChannelShortInfo> ) ),
SIGNAL ( ConClientListMesReceived ( CVector<CChannelShortInfo> ) ) ); SIGNAL ( ConClientListMesReceived ( CVector<CChannelShortInfo> ) ) );
QObject::connect ( &Channel, SIGNAL ( NewConnection() ),
this, SLOT ( OnNewConnection() ) );
} }
void CClient::OnSendProtMessage ( CVector<uint8_t> vecMessage ) void CClient::OnSendProtMessage ( CVector<uint8_t> vecMessage )
@ -163,6 +166,9 @@ void CClient::run()
// runtime phase ------------------------------------------------------------ // runtime phase ------------------------------------------------------------
// enable channel
Channel.SetEnable ( true );
bRun = true; bRun = true;
// main loop of working thread // main loop of working thread
@ -381,6 +387,9 @@ fflush(pFileTest);
TimeLastBlock = CurTime; TimeLastBlock = CurTime;
} }
// disable channel
Channel.SetEnable ( false );
// reset current signal level and LEDs // reset current signal level and LEDs
SignalLevelMeterL.Reset(); SignalLevelMeterL.Reset();
SignalLevelMeterR.Reset(); SignalLevelMeterR.Reset();

View file

@ -11,8 +11,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>410</width> <width>404</width>
<height>249</height> <height>294</height>
</rect> </rect>
</property> </property>
<property stdset="1"> <property stdset="1">
@ -381,7 +381,7 @@
<property stdset="1"> <property stdset="1">
<name>sizePolicy</name> <name>sizePolicy</name>
<sizepolicy> <sizepolicy>
<hsizetype>1</hsizetype> <hsizetype>3</hsizetype>
<vsizetype>1</vsizetype> <vsizetype>1</vsizetype>
</sizepolicy> </sizepolicy>
</property> </property>
@ -449,7 +449,7 @@
<property stdset="1"> <property stdset="1">
<name>sizePolicy</name> <name>sizePolicy</name>
<sizepolicy> <sizepolicy>
<hsizetype>1</hsizetype> <hsizetype>3</hsizetype>
<vsizetype>1</vsizetype> <vsizetype>1</vsizetype>
</sizepolicy> </sizepolicy>
</property> </property>

View file

@ -42,7 +42,7 @@
/* version and application name (always use this version) */ /* version and application name (always use this version) */
#undef VERSION #undef VERSION
#define VERSION "0.9.8cvs" #define VERSION "0.9.9cvs"
#define APP_NAME "llcon" #define APP_NAME "llcon"

View file

@ -242,13 +242,12 @@ void CLlconClientDlg::OnConnectDisconBut ()
// TEST // TEST
/*
// make old controls invisible // make old controls invisible
for ( int i = 0; i < MAX_NUM_CHANNELS; i++ ) for ( int i = 0; i < MAX_NUM_CHANNELS; i++ )
{ {
vecpChanFader[i]->Hide(); vecpChanFader[i]->Hide();
} }
*/
} }

View file

@ -338,6 +338,11 @@ for ( int i = 0; i < iNumBytes; i++ ) {
EvaluateConClientListMes ( iPos, vecData ); EvaluateConClientListMes ( iPos, vecData );
break; break;
case PROTMESSID_REQ_CONN_CLIENTS_LIST:
EvaluateReqConnClientsList ( iPos, vecData );
break;
} }
// send acknowledge message // send acknowledge message