From bf678d5c2afa020cb379f8628f9dd882727b612f Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Wed, 8 Mar 2006 20:13:42 +0000 Subject: [PATCH] cleaning up the code a bit --- src/protocol.cpp | 62 +++++++++++++++++++++--------------------------- src/protocol.h | 4 +++- 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/src/protocol.cpp b/src/protocol.cpp index c73de8f8..2988103a 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -153,6 +153,29 @@ void CProtocol::SendMessage() } } +void CProtocol::CreateAndSendMessage ( const int iID, + const CVector& vecData ) +{ + CVector vecNewMessage; + int iCurCounter; + + Mutex.lock(); + { + // store current counter value + iCurCounter = iCounter; + + // increase counter (wraps around automatically) + iCounter++; + } + Mutex.unlock(); + + // build complete message + GenMessageFrame ( vecNewMessage, iCurCounter, iID, vecData ); + + // enqueue message + EnqueueMessage ( vecNewMessage, iCurCounter, iID ); +} + void CProtocol::CreateAndSendAcknMess ( const int& iID, const int& iCnt ) { CVector vecAcknMessage; @@ -292,53 +315,22 @@ vecbyDataConv[i] = static_cast ( vecbyData[i] ); return bRet; } + +/* Access-functions for creating messages ----------------------------------- */ void CProtocol::CreateJitBufMes ( const int iJitBufSize ) { - CVector vecNewMessage; CVector vecData ( 2 ); // 2 bytes of data - int iCurCounter; unsigned int iPos = 0; // init position pointer - Mutex.lock(); - { - // store current counter value - iCurCounter = iCounter; - - // increase counter (wraps around automatically) - iCounter++; - } - Mutex.unlock(); - // build data vector PutValOnStream ( vecData, iPos, static_cast ( iJitBufSize ), 2 ); - // build complete message - GenMessageFrame ( vecNewMessage, iCurCounter, PROTMESSID_JITT_BUF_SIZE, vecData ); - - // enqueue message - EnqueueMessage ( vecNewMessage, iCurCounter, PROTMESSID_JITT_BUF_SIZE ); + CreateAndSendMessage ( PROTMESSID_JITT_BUF_SIZE, vecData ); } void CProtocol::CreateReqJitBufMes() { - CVector vecNewMessage; - int iCurCounter; - - Mutex.lock(); - { - // store current counter value - iCurCounter = iCounter; - - // increase counter (wraps around automatically) - iCounter++; - } - Mutex.unlock(); - - // build complete message - GenMessageFrame ( vecNewMessage, iCurCounter, PROTMESSID_REQ_JITT_BUF_SIZE, CVector ( 0 ) ); - - // enqueue message - EnqueueMessage ( vecNewMessage, iCurCounter, PROTMESSID_REQ_JITT_BUF_SIZE ); + CreateAndSendMessage ( PROTMESSID_REQ_JITT_BUF_SIZE, CVector ( 0 ) ); } diff --git a/src/protocol.h b/src/protocol.h index b5cfbe61..ec0d9bf8 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -104,7 +104,7 @@ protected: void GenMessageFrame ( CVector& vecOut, const int iCnt, const int iID, - const CVector& vecData); + const CVector& vecData ); void PutValOnStream ( CVector& vecIn, unsigned int& iPos, @@ -117,6 +117,8 @@ protected: void SendMessage(); + void CreateAndSendMessage ( const int iID, const CVector& vecData ); + int iOldRecID, iOldRecCnt; // these two objects must be sequred by a mutex