use mutexlocker in protocol class

This commit is contained in:
Volker Fischer 2008-08-17 19:50:28 +00:00
parent 6fb18b16df
commit fb363895ab
3 changed files with 38 additions and 44 deletions

View file

@ -184,7 +184,9 @@ void CChannelSet::CreateAndSendChatTextForAllConChannels ( const int iCurChanID,
ChanName = addrTest.toString();
}
// add name of the client at the beginning of the message text
// add name of the client at the beginning of the message text and use
// different colors, to get correct HTML, the "<" and ">" signs must be
// replaced by "&#60;" and "&#62;"
QString sCurColor = vstrChatColors[iCurChanID % vstrChatColors.Size()];
const QString strActualMessageText =
"<font color=""" + sCurColor + """><b>&#60;" + ChanName +
@ -213,7 +215,7 @@ int CChannelSet::GetFreeChan()
}
}
/* no free channel found, return invalid ID */
// no free channel found, return invalid ID
return INVALID_CHANNEL_ID;
}
@ -221,12 +223,12 @@ int CChannelSet::CheckAddr ( const CHostAddress& Addr )
{
CHostAddress InetAddr;
/* Check for all possible channels if IP is already in use */
// check for all possible channels if IP is already in use
for ( int i = 0; i < MAX_NUM_CHANNELS; i++ )
{
if ( vecChannels[i].GetAddress ( InetAddr ) )
{
/* IP found, return channel number */
// IP found, return channel number
if ( InetAddr == Addr )
{
return i;
@ -234,7 +236,7 @@ int CChannelSet::CheckAddr ( const CHostAddress& Addr )
}
}
/* IP not found, return invalid ID */
// IP not found, return invalid ID
return INVALID_CHANNEL_ID;
}
@ -249,7 +251,7 @@ bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
{
bool bChanOK = true;
// get channel ID ------------------------------------------------------
// Get channel ID ------------------------------------------------------
// check address
int iCurChanID = CheckAddr ( HostAdr );
@ -294,7 +296,7 @@ bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
}
// put received data in jitter buffer ----------------------------------
// Put received data in jitter buffer ----------------------------------
if ( bChanOK )
{
// put packet in socket buffer

View file

@ -273,12 +273,12 @@ public slots:
// CODE TAG: MAX_NUM_CHANNELS_TAG
// make sure we have MAX_NUM_CHANNELS connections!!!
// send message
void OnSendProtMessCh0 ( CVector<uint8_t> mess ) {emit MessReadyForSending ( 0, mess ); }
void OnSendProtMessCh1 ( CVector<uint8_t> mess ) {emit MessReadyForSending ( 1, mess ); }
void OnSendProtMessCh2 ( CVector<uint8_t> mess ) {emit MessReadyForSending ( 2, mess ); }
void OnSendProtMessCh3 ( CVector<uint8_t> mess ) {emit MessReadyForSending ( 3, mess ); }
void OnSendProtMessCh4 ( CVector<uint8_t> mess ) {emit MessReadyForSending ( 4, mess ); }
void OnSendProtMessCh5 ( CVector<uint8_t> mess ) {emit MessReadyForSending ( 5, mess ); }
void OnSendProtMessCh0 ( CVector<uint8_t> mess ) { emit MessReadyForSending ( 0, mess ); }
void OnSendProtMessCh1 ( CVector<uint8_t> mess ) { emit MessReadyForSending ( 1, mess ); }
void OnSendProtMessCh2 ( CVector<uint8_t> mess ) { emit MessReadyForSending ( 2, mess ); }
void OnSendProtMessCh3 ( CVector<uint8_t> mess ) { emit MessReadyForSending ( 3, mess ); }
void OnSendProtMessCh4 ( CVector<uint8_t> mess ) { emit MessReadyForSending ( 4, mess ); }
void OnSendProtMessCh5 ( CVector<uint8_t> mess ) { emit MessReadyForSending ( 5, mess ); }
void OnNewConnectionCh0() { vecChannels[0].CreateReqJitBufMes(); }
void OnNewConnectionCh1() { vecChannels[1].CreateReqJitBufMes(); }

View file

@ -146,14 +146,10 @@ void CProtocol::EnqueueMessage ( CVector<uint8_t>& vecMessage,
{
// check if list is empty so that we have to initiate a send process
bListWasEmpty = SendMessQueue.empty();
}
Mutex.unlock();
// create send message object for the queue
CSendMessage SendMessageObj ( vecMessage, iCnt, iID );
// create send message object for the queue
CSendMessage SendMessageObj ( vecMessage, iCnt, iID );
Mutex.lock();
{
// we want to have a FIFO: we add at the end and take from the beginning
SendMessQueue.push_back ( SendMessageObj );
}
@ -168,22 +164,20 @@ void CProtocol::EnqueueMessage ( CVector<uint8_t>& vecMessage,
void CProtocol::SendMessage()
{
CVector<uint8_t> vecMessage;
bool bSendMess = false;
QMutexLocker locker ( &Mutex );
Mutex.lock();
CVector<uint8_t> vecMessage;
bool bSendMess = false;
// we have to check that list is not empty, since in another thread the
// last element of the list might have been erased
if ( !SendMessQueue.empty() )
{
// we have to check that list is not empty, since in another thread the
// last element of the list might have been erased
if ( !SendMessQueue.empty() )
{
vecMessage.Init ( SendMessQueue.front().vecMessage.Size() );
vecMessage = SendMessQueue.front().vecMessage;
vecMessage.Init ( SendMessQueue.front().vecMessage.Size() );
vecMessage = SendMessQueue.front().vecMessage;
bSendMess = true;
}
bSendMess = true;
}
Mutex.unlock();
if ( bSendMess )
{
@ -206,8 +200,8 @@ void CProtocol::SendMessage()
void CProtocol::CreateAndSendMessage ( const int iID,
const CVector<uint8_t>& vecData )
{
CVector<uint8_t> vecNewMessage;
int iCurCounter;
CVector<uint8_t> vecNewMessage;
int iCurCounter;
Mutex.lock();
{
@ -228,9 +222,9 @@ void CProtocol::CreateAndSendMessage ( const int iID,
void CProtocol::CreateAndSendAcknMess ( const int& iID, const int& iCnt )
{
CVector<uint8_t> vecAcknMessage;
CVector<uint8_t> vecData ( 2 ); // 2 bytes of data
unsigned int iPos = 0; // init position pointer
CVector<uint8_t> vecAcknMessage;
CVector<uint8_t> vecData ( 2 ); // 2 bytes of data
unsigned int iPos = 0; // init position pointer
// build data vector
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iID ), 2 );
@ -244,12 +238,10 @@ void CProtocol::CreateAndSendAcknMess ( const int& iID, const int& iCnt )
void CProtocol::DeleteSendMessQueue()
{
Mutex.lock();
{
// delete complete "send message queue"
SendMessQueue.clear();
}
Mutex.unlock();
QMutexLocker locker ( &Mutex );
// delete complete "send message queue"
SendMessQueue.clear();
}
bool CProtocol::ParseMessage ( const CVector<unsigned char>& vecbyData,
@ -283,7 +275,7 @@ for ( int i = 0; i < iNumBytes; i++ ) {
// acknowledgments are not acknowledged
if ( iRecID != PROTMESSID_ACKN )
{
// re-send acknowledgement
// resend acknowledgement
CreateAndSendAcknMess ( iRecID, iRecCounter );
}
}
@ -382,7 +374,7 @@ for ( int i = 0; i < iNumBytes; i++ ) {
}
}
// save current message ID and counter to find out if message was re-sent
// save current message ID and counter to find out if message was resent
iOldRecID = iRecID;
iOldRecCnt = iRecCounter;
}