QT does not use unsigned int for their "size()" functions, therefore we also do not use it for our sizes (it is actually not required here)

This commit is contained in:
Volker Fischer 2011-04-02 12:23:36 +00:00
parent 24ecf0c3f0
commit 5ca224af19
2 changed files with 53 additions and 52 deletions

View file

@ -324,7 +324,7 @@ void CProtocol::CreateAndImmSendAcknMess ( const int& iID,
{ {
CVector<uint8_t> vecAcknMessage; CVector<uint8_t> vecAcknMessage;
CVector<uint8_t> vecData ( 2 ); // 2 bytes of data CVector<uint8_t> vecData ( 2 ); // 2 bytes of data
unsigned int iPos = 0; // init position pointer int iPos = 0; // init position pointer
// build data vector // build data vector
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iID ), 2 ); PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iID ), 2 );
@ -417,7 +417,7 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false;
if ( iRecID == PROTMESSID_ACKN ) if ( iRecID == PROTMESSID_ACKN )
{ {
// extract data from stream and emit signal for received value // extract data from stream and emit signal for received value
unsigned int iPos = 0; int iPos = 0;
const int iData = const int iData =
static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) ); static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
@ -588,7 +588,7 @@ bool CProtocol::ParseConnectionLessMessage ( const CVector<uint8_t>& vecbyData,
void CProtocol::CreateJitBufMes ( const int iJitBufSize ) void CProtocol::CreateJitBufMes ( const int iJitBufSize )
{ {
CVector<uint8_t> vecData ( 2 ); // 2 bytes of data CVector<uint8_t> vecData ( 2 ); // 2 bytes of data
unsigned int iPos = 0; // init position pointer int iPos = 0; // init position pointer
// build data vector // build data vector
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iJitBufSize ), 2 ); PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iJitBufSize ), 2 );
@ -598,7 +598,7 @@ void CProtocol::CreateJitBufMes ( const int iJitBufSize )
bool CProtocol::EvaluateJitBufMes ( const CVector<uint8_t>& vecData ) bool CProtocol::EvaluateJitBufMes ( const CVector<uint8_t>& vecData )
{ {
unsigned int iPos = 0; // init position pointer int iPos = 0; // init position pointer
// check size // check size
if ( vecData.Size() != 2 ) if ( vecData.Size() != 2 )
@ -639,7 +639,7 @@ bool CProtocol::EvaluateReqJitBufMes()
void CProtocol::CreateChanGainMes ( const int iChanID, const double dGain ) void CProtocol::CreateChanGainMes ( const int iChanID, const double dGain )
{ {
CVector<uint8_t> vecData ( 3 ); // 3 bytes of data CVector<uint8_t> vecData ( 3 ); // 3 bytes of data
unsigned int iPos = 0; // init position pointer int iPos = 0; // init position pointer
// build data vector // build data vector
// channel ID // channel ID
@ -655,7 +655,7 @@ void CProtocol::CreateChanGainMes ( const int iChanID, const double dGain )
bool CProtocol::EvaluateChanGainMes ( const CVector<uint8_t>& vecData ) bool CProtocol::EvaluateChanGainMes ( const CVector<uint8_t>& vecData )
{ {
unsigned int iPos = 0; // init position pointer int iPos = 0; // init position pointer
// check size // check size
if ( vecData.Size() != 3 ) if ( vecData.Size() != 3 )
@ -686,7 +686,7 @@ void CProtocol::CreateConClientListMes ( const CVector<CChannelShortInfo>& vecCh
// build data vector // build data vector
CVector<uint8_t> vecData ( 0 ); CVector<uint8_t> vecData ( 0 );
unsigned int iPos = 0; // init position pointer int iPos = 0; // init position pointer
for ( int i = 0; i < iNumClients; i++ ) for ( int i = 0; i < iNumClients; i++ )
{ {
@ -717,8 +717,8 @@ void CProtocol::CreateConClientListMes ( const CVector<CChannelShortInfo>& vecCh
bool CProtocol::EvaluateConClientListMes ( const CVector<uint8_t>& vecData ) bool CProtocol::EvaluateConClientListMes ( const CVector<uint8_t>& vecData )
{ {
unsigned int iPos = 0; // init position pointer int iPos = 0; // init position pointer
const unsigned int iDataLen = vecData.Size(); const int iDataLen = vecData.Size();
CVector<CChannelShortInfo> vecChanInfo ( 0 ); CVector<CChannelShortInfo> vecChanInfo ( 0 );
while ( iPos < iDataLen ) while ( iPos < iDataLen )
@ -778,7 +778,7 @@ bool CProtocol::EvaluateReqConnClientsList()
void CProtocol::CreateChanNameMes ( const QString strName ) void CProtocol::CreateChanNameMes ( const QString strName )
{ {
unsigned int iPos = 0; // init position pointer int iPos = 0; // init position pointer
const int iStrLen = strName.size(); // get string size const int iStrLen = strName.size(); // get string size
// size of current list entry // size of current list entry
@ -795,7 +795,7 @@ void CProtocol::CreateChanNameMes ( const QString strName )
bool CProtocol::EvaluateChanNameMes ( const CVector<uint8_t>& vecData ) bool CProtocol::EvaluateChanNameMes ( const CVector<uint8_t>& vecData )
{ {
unsigned int iPos = 0; // init position pointer int iPos = 0; // init position pointer
// channel name // channel name
QString strName; QString strName;
@ -834,7 +834,7 @@ bool CProtocol::EvaluateReqChanNameMes()
void CProtocol::CreateChatTextMes ( const QString strChatText ) void CProtocol::CreateChatTextMes ( const QString strChatText )
{ {
unsigned int iPos = 0; // init position pointer int iPos = 0; // init position pointer
const int iStrLen = strChatText.size(); // get string size const int iStrLen = strChatText.size(); // get string size
// size of message body // size of message body
@ -851,7 +851,7 @@ void CProtocol::CreateChatTextMes ( const QString strChatText )
bool CProtocol::EvaluateChatTextMes ( const CVector<uint8_t>& vecData ) bool CProtocol::EvaluateChatTextMes ( const CVector<uint8_t>& vecData )
{ {
unsigned int iPos = 0; // init position pointer int iPos = 0; // init position pointer
// chat text // chat text
QString strChatText; QString strChatText;
@ -877,7 +877,7 @@ bool CProtocol::EvaluateChatTextMes ( const CVector<uint8_t>& vecData )
void CProtocol::CreatePingMes ( const int iMs ) void CProtocol::CreatePingMes ( const int iMs )
{ {
unsigned int iPos = 0; // init position pointer int iPos = 0; // init position pointer
// build data vector (4 bytes long) // build data vector (4 bytes long)
CVector<uint8_t> vecData ( 4 ); CVector<uint8_t> vecData ( 4 );
@ -890,7 +890,7 @@ void CProtocol::CreatePingMes ( const int iMs )
bool CProtocol::EvaluatePingMes ( const CVector<uint8_t>& vecData ) bool CProtocol::EvaluatePingMes ( const CVector<uint8_t>& vecData )
{ {
unsigned int iPos = 0; // init position pointer int iPos = 0; // init position pointer
// check size // check size
if ( vecData.Size() != 4 ) if ( vecData.Size() != 4 )
@ -905,7 +905,7 @@ bool CProtocol::EvaluatePingMes ( const CVector<uint8_t>& vecData )
void CProtocol::CreateNetwTranspPropsMes ( const CNetworkTransportProps& NetTrProps ) void CProtocol::CreateNetwTranspPropsMes ( const CNetworkTransportProps& NetTrProps )
{ {
unsigned int iPos = 0; // init position pointer int iPos = 0; // init position pointer
// size of current message body // size of current message body
const int iEntrLen = const int iEntrLen =
@ -953,7 +953,7 @@ void CProtocol::CreateNetwTranspPropsMes ( const CNetworkTransportProps& NetTrPr
bool CProtocol::EvaluateNetwTranspPropsMes ( const CVector<uint8_t>& vecData ) bool CProtocol::EvaluateNetwTranspPropsMes ( const CVector<uint8_t>& vecData )
{ {
unsigned int iPos = 0; // init position pointer int iPos = 0; // init position pointer
CNetworkTransportProps ReceivedNetwTranspProps; CNetworkTransportProps ReceivedNetwTranspProps;
// size of current message body // size of current message body
@ -1084,7 +1084,7 @@ bool CProtocol::EvaluateDisconnectionMes()
// Connection less messages ---------------------------------------------------- // Connection less messages ----------------------------------------------------
void CProtocol::CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs ) void CProtocol::CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs )
{ {
unsigned int iPos = 0; // init position pointer int iPos = 0; // init position pointer
// build data vector (4 bytes long) // build data vector (4 bytes long)
CVector<uint8_t> vecData ( 4 ); CVector<uint8_t> vecData ( 4 );
@ -1100,7 +1100,7 @@ void CProtocol::CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs )
bool CProtocol::EvaluateCLPingMes ( const CHostAddress& InetAddr, bool CProtocol::EvaluateCLPingMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData ) const CVector<uint8_t>& vecData )
{ {
unsigned int iPos = 0; // init position pointer int iPos = 0; // init position pointer
// check size // check size
if ( vecData.Size() != 4 ) if ( vecData.Size() != 4 )
@ -1132,7 +1132,7 @@ bool CProtocol::EvaluateCLServerFullMes()
void CProtocol::CreateCLRegisterServerMes ( const CHostAddress& InetAddr, void CProtocol::CreateCLRegisterServerMes ( const CHostAddress& InetAddr,
const CServerInfo& ServerInfo ) const CServerInfo& ServerInfo )
{ {
unsigned int iPos = 0; // init position pointer int iPos = 0; // init position pointer
// current string sizes // current string sizes
const int iNameLen = ServerInfo.strName.size(); const int iNameLen = ServerInfo.strName.size();
@ -1185,8 +1185,8 @@ void CProtocol::CreateCLRegisterServerMes ( const CHostAddress& InetAddr,
bool CProtocol::EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr, bool CProtocol::EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData ) const CVector<uint8_t>& vecData )
{ {
unsigned int iPos = 0; // init position pointer int iPos = 0; // init position pointer
const unsigned int iDataLen = vecData.Size(); const int iDataLen = vecData.Size();
CServerInfo RecServerInfo; CServerInfo RecServerInfo;
// check size (the first 5 bytes) // check size (the first 5 bytes)
@ -1259,8 +1259,9 @@ bool CProtocol::ParseMessageFrame ( const CVector<uint8_t>& vecIn,
int& iID, int& iID,
CVector<uint8_t>& vecData ) CVector<uint8_t>& vecData )
{ {
int iLenBy, i; int i;
unsigned int iCurPos; int iLenBy;
int iCurPos;
// vector must be at least "MESS_LEN_WITHOUT_DATA_BYTE" bytes long // vector must be at least "MESS_LEN_WITHOUT_DATA_BYTE" bytes long
if ( iNumBytesIn < MESS_LEN_WITHOUT_DATA_BYTE ) if ( iNumBytesIn < MESS_LEN_WITHOUT_DATA_BYTE )
@ -1327,18 +1328,18 @@ bool CProtocol::ParseMessageFrame ( const CVector<uint8_t>& vecIn,
} }
uint32_t CProtocol::GetValFromStream ( const CVector<uint8_t>& vecIn, uint32_t CProtocol::GetValFromStream ( const CVector<uint8_t>& vecIn,
unsigned int& iPos, int& iPos,
const unsigned int iNumOfBytes ) const int iNumOfBytes )
{ {
/* /*
note: iPos is automatically incremented in this function note: iPos is automatically incremented in this function
*/ */
// 4 bytes maximum since we return uint32 // 4 bytes maximum since we return uint32
Q_ASSERT ( ( iNumOfBytes > 0 ) && ( iNumOfBytes <= 4 ) ); Q_ASSERT ( ( iNumOfBytes > 0 ) && ( iNumOfBytes <= 4 ) );
Q_ASSERT ( static_cast<unsigned int> ( vecIn.Size() ) >= iPos + iNumOfBytes ); Q_ASSERT ( vecIn.Size() >= iPos + iNumOfBytes );
uint32_t iRet = 0; uint32_t iRet = 0;
for ( unsigned int i = 0; i < iNumOfBytes; i++ ) for ( int i = 0; i < iNumOfBytes; i++ )
{ {
iRet |= vecIn[iPos] << ( i * 8 /* size of byte */ ); iRet |= vecIn[iPos] << ( i * 8 /* size of byte */ );
iPos++; iPos++;
@ -1348,23 +1349,23 @@ uint32_t CProtocol::GetValFromStream ( const CVector<uint8_t>& vecIn,
} }
bool CProtocol::GetStringFromStream ( const CVector<uint8_t>& vecIn, bool CProtocol::GetStringFromStream ( const CVector<uint8_t>& vecIn,
unsigned int& iPos, int& iPos,
const unsigned int iMaxStringLen, const int iMaxStringLen,
QString& strOut ) QString& strOut )
{ {
/* /*
note: iPos is automatically incremented in this function note: iPos is automatically incremented in this function
*/ */
// check if at least two bytes are available // check if at least two bytes are available
const unsigned int iInLen = vecIn.Size(); const int iInLen = vecIn.Size();
if ( ( iInLen - iPos ) < 2 ) if ( ( iInLen - iPos ) < 2 )
{ {
return true; // return error code return true; // return error code
} }
// number of bytes for string (2 bytes) // number of bytes for string (2 bytes)
const unsigned int iStrLen = const int iStrLen =
static_cast<unsigned int> ( GetValFromStream ( vecIn, iPos, 2 ) ); static_cast<int> ( GetValFromStream ( vecIn, iPos, 2 ) );
if ( ( ( iInLen - iPos ) < iStrLen ) || if ( ( ( iInLen - iPos ) < iStrLen ) ||
( iStrLen > iMaxStringLen ) ) ( iStrLen > iMaxStringLen ) )
@ -1374,7 +1375,7 @@ bool CProtocol::GetStringFromStream ( const CVector<uint8_t>& vecIn,
// string (n bytes) // string (n bytes)
strOut = ""; strOut = "";
for ( unsigned int i = 0; i < iStrLen; i++ ) for ( int i = 0; i < iStrLen; i++ )
{ {
// byte-by-byte copying of the string data // byte-by-byte copying of the string data
int iData = static_cast<int> ( GetValFromStream ( vecIn, iPos, 1 ) ); int iData = static_cast<int> ( GetValFromStream ( vecIn, iPos, 1 ) );
@ -1402,7 +1403,7 @@ void CProtocol::GenMessageFrame ( CVector<uint8_t>& vecOut,
// Encode header ----------------------------------------------------------- // Encode header -----------------------------------------------------------
unsigned int iCurPos = 0; // init position pointer int iCurPos = 0; // init position pointer
// 2 bytes TAG (all zero bits) // 2 bytes TAG (all zero bits)
PutValOnStream ( vecOut, iCurPos, PutValOnStream ( vecOut, iCurPos,
@ -1444,18 +1445,18 @@ void CProtocol::GenMessageFrame ( CVector<uint8_t>& vecOut,
} }
void CProtocol::PutValOnStream ( CVector<uint8_t>& vecIn, void CProtocol::PutValOnStream ( CVector<uint8_t>& vecIn,
unsigned int& iPos, int& iPos,
const uint32_t iVal, const uint32_t iVal,
const unsigned int iNumOfBytes ) const int iNumOfBytes )
{ {
/* /*
note: iPos is automatically incremented in this function note: iPos is automatically incremented in this function
*/ */
// 4 bytes maximum since we use uint32 // 4 bytes maximum since we use uint32
Q_ASSERT ( ( iNumOfBytes > 0 ) && ( iNumOfBytes <= 4 ) ); Q_ASSERT ( ( iNumOfBytes > 0 ) && ( iNumOfBytes <= 4 ) );
Q_ASSERT ( static_cast<unsigned int> ( vecIn.Size() ) >= iPos + iNumOfBytes ); Q_ASSERT ( vecIn.Size() >= iPos + iNumOfBytes );
for ( unsigned int i = 0; i < iNumOfBytes; i++ ) for ( int i = 0; i < iNumOfBytes; i++ )
{ {
vecIn[iPos] = vecIn[iPos] =
( iVal >> ( i * 8 /* size of byte */ ) ) & 255 /* 11111111 */; ( iVal >> ( i * 8 /* size of byte */ ) ) & 255 /* 11111111 */;
@ -1465,7 +1466,7 @@ void CProtocol::PutValOnStream ( CVector<uint8_t>& vecIn,
} }
void CProtocol::PutStringOnStream ( CVector<uint8_t>& vecIn, void CProtocol::PutStringOnStream ( CVector<uint8_t>& vecIn,
unsigned int& iPos, int& iPos,
const QString& sString ) const QString& sString )
{ {
// get the string size // get the string size

View file

@ -154,21 +154,21 @@ protected:
const CVector<uint8_t>& vecData ); const CVector<uint8_t>& vecData );
void PutValOnStream ( CVector<uint8_t>& vecIn, void PutValOnStream ( CVector<uint8_t>& vecIn,
unsigned int& iPos, int& iPos,
const uint32_t iVal, const uint32_t iVal,
const unsigned int iNumOfBytes ); const int iNumOfBytes );
void PutStringOnStream ( CVector<uint8_t>& vecIn, void PutStringOnStream ( CVector<uint8_t>& vecIn,
unsigned int& iPos, int& iPos,
const QString& sString ); const QString& sString );
uint32_t GetValFromStream ( const CVector<uint8_t>& vecIn, uint32_t GetValFromStream ( const CVector<uint8_t>& vecIn,
unsigned int& iPos, int& iPos,
const unsigned int iNumOfBytes ); const int iNumOfBytes );
bool GetStringFromStream ( const CVector<uint8_t>& vecIn, bool GetStringFromStream ( const CVector<uint8_t>& vecIn,
unsigned int& iPos, int& iPos,
const unsigned int iMaxStringLen, const int iMaxStringLen,
QString& strOut ); QString& strOut );
bool IsConnectionLessMessageID ( const int iID ) const bool IsConnectionLessMessageID ( const int iID ) const