server sends connected client list on a new connection

This commit is contained in:
Volker Fischer 2006-11-04 13:09:42 +00:00
parent 3d4153fd75
commit efb83f15ac
5 changed files with 129 additions and 10 deletions

View File

@ -55,6 +55,38 @@ CChannelSet::CChannelSet()
// QObject::connect(&vecChannels[8],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh8()));
// QObject::connect(&vecChannels[9],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh9()));
}
void CChannelSet::CreateAndSendChanListForAllConClients()
{
int i;
CVector<uint32_t> veciIpAddrs ( 0 );
CVector<std::string> vecstrNames ( 0 );
// the channel ID is defined as the order of the channels in the channel
// set where we do not care about not-connected channels
int iCurChanID = 0;
// look for free channels
for ( i = 0; i < MAX_NUM_CHANNELS; i++ )
{
if ( vecChannels[i].IsConnected() )
{
// append IP address and channel name to storing vectors
veciIpAddrs.Add ( vecChannels[i].GetAddress().InetAddr.ip4Addr() );
vecstrNames.Add ( vecChannels[i].GetName() );
}
}
// now send connected channels list to all connected clients
for ( i = 0; i < MAX_NUM_CHANNELS; i++ )
{
if ( vecChannels[i].IsConnected() )
{
// send message
vecChannels[i].CreateConClientListMes ( veciIpAddrs, vecstrNames );
}
}
}
int CChannelSet::GetFreeChan()
{
@ -97,6 +129,7 @@ bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
const CHostAddress& HostAdr )
{
bool bRet = false;
bool bCreateChanList = false;
Mutex.lock();
{
@ -114,6 +147,12 @@ bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
if ( iCurChanID != INVALID_CHANNEL_ID )
{
vecChannels[iCurChanID].SetAddress ( HostAdr );
// a new client connected to the server, set flag to create and
// send all clients the updated channel list, we cannot create
// the message here since the received data has to be put to the
// channel first so that this channel is marked as connected
bCreateChanList = true;
}
else
{
@ -143,8 +182,16 @@ bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_YELLOW, iCurChanID );
break;
}
}
}
}
// after data is put in channel buffer, create channel list message if
// requested
if ( bCreateChanList )
{
CreateAndSendChanListForAllConClients();
}
}
Mutex.unlock();
return bRet;

View File

@ -112,6 +112,11 @@ public:
}
}
void CreateConClientListMes ( const CVector<uint32_t>& veciIpAddrs,
const CVector<std::string>& vecstrNames )
{
Protocol.CreateConClientListMes ( veciIpAddrs, vecstrNames );
}
protected:
void SetNetwInBlSiFact ( const int iNewBlockSizeFactor );
@ -134,8 +139,9 @@ protected:
// channel name
std::string sName;
// mixer and effect settings
double dGain;
// TODO we need mixer and effect settings for all the other channels, too!!!
// mixer and effect settings
double dGain;
// network jitter-buffer
CNetBuf SockBuf;
@ -205,7 +211,9 @@ public:
CHostAddress GetAddress ( const int iChanNum )
{ return vecChannels[iChanNum].GetAddress(); }
protected:
protected:
void CreateAndSendChanListForAllConClients();
/* do not use the vector class since CChannel does not have appropriate
copy constructor/operator */
CChannel vecChannels[MAX_NUM_CHANNELS];

View File

@ -229,17 +229,18 @@ bool CProtocol::ParseMessage ( const CVector<unsigned char>& vecbyData,
/*
return code: true -> ok; false -> error
*/
bool bRet;
int iRecCounter, iRecID, iData;
bool bRet, bSendNextMess;
int iRecCounter, iRecID, iData, iDataLen, iStringLen, iCurID;
unsigned int iPos;
CVector<uint8_t> vecData;
bool bSendNextMess;
std::string strCurString;
double dNewGain;
// convert unsigned char in uint8_t, TODO convert all buffers in uint8_t
CVector<uint8_t> vecbyDataConv ( iNumBytes );
for ( int i = 0; i < iNumBytes; i++ ) {
vecbyDataConv[i] = static_cast<uint8_t> ( vecbyData[i] );
vecbyDataConv[i] = static_cast<uint8_t> ( vecbyData[i] );
}
@ -332,6 +333,65 @@ vecbyDataConv[i] = static_cast<uint8_t> ( vecbyData[i] );
// send acknowledge message
CreateAndSendAcknMess ( iRecID, iRecCounter );
break;
case PROTMESSID_CHANNEL_GAIN:
// extract data from stream and emit signal for received value
iPos = 0;
// channel ID
iCurID = static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
// actual gain, we convert from integer to double with range 0..1
iData = static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
dNewGain = (double) iData / ( 1 << 16 );
// invoke message action
emit ChangeChanGain ( iCurID, dNewGain );
// send acknowledge message
CreateAndSendAcknMess ( iRecID, iRecCounter );
break;
case PROTMESSID_CONN_CLIENTS_LIST:
// extract data from stream and emit signal for received value
iPos = 0;
iDataLen = vecData.Size();
while ( iPos < iDataLen )
{
// IP address (4 bytes)
iData = static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
// TODO do something with the received IP address "iData"
// TEST
QHostAddress addrTest ( iData );
printf ( "%s ", addrTest.toString().latin1() );
// number of bytes for name string (2 bytes)
iStringLen = static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
// name string (n bytes)
strCurString = "";
for ( int j = 0; j < iStringLen; j++ )
{
// byte-by-byte copying of the string data
iData = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
strCurString += std::string ( (char*) &iData );
}
// TODO do something with the received name string "strCurString"
}
// send acknowledge message
CreateAndSendAcknMess ( iRecID, iRecCounter );
break;
}
}

View File

@ -146,6 +146,7 @@ signals:
// receiving
void ChangeJittBufSize ( int iNewJitBufSize );
void ChangeNetwBlSiFact ( int iNewNetwBlSiFact );
void ChangeChanGain ( int iChanID, double dNewGain );
void ReqJittBufSize();
};

View File

@ -96,7 +96,10 @@ void CServer::OnTimer()
/* Check if at least one client is connected. If not, stop server until
one client is connected */
if ( iNumClients != 0 )
{
{
// TODO generate a sparate mix for each channel
/* actual processing of audio data -> mix */
vecsSendData = ProcessData ( vecvecdData, vecdGains );