Skip to content

Instantly share code, notes, and snippets.

@eventhelix
Created March 10, 2015 01:53
Show Gist options
  • Save eventhelix/470a9c3cc7e31f1adfea to your computer and use it in GitHub Desktop.
Save eventhelix/470a9c3cc7e31f1adfea to your computer and use it in GitHub Desktop.
Overworked Message Handler class and a simple Get-Set DSP class http://www.eventhelix.com/realtimemantra/object_oriented/object_design_tips_2.htm
class DSP
{
public:
Queue *GetWriteBufferQueue();
Queue *GetReadBufferQueue();
void SetStatusRegister(int mask);
void SetCongestionLevel();
void SetWriteBufferQueue(Buffer *pQueue);
void SetReadBufferQueue(Buffer *pQueue);
};
Status MessageHandler::SendMessage(Buffer *pBuffer)
{
int dspId = pBuffer->GetDSP();
DSP* pDSP = m_dsp[dspId];
Queue *pQueue = pDSP->GetWriteBufferQueue();
int status = pQueue->Add(pBuffer);
pDSP->SetStatusRegister(WRITTEN_MESSAGE);
if (pQueue->GetLength() > CONGESTION_THRESHOLD)
{
pDSP->SetCongestionLevel();
}
return status;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment