CMP EMBEDDED.COM

Login | Register     Welcome Guest  
HOME DESIGN PRODUCTS COLUMNS E-LEARNING CONFERENCES CODE FORUMS/BLOGS NEWSLETTERS CONTACT FEATURES RSS RSS

Listing 6: SendMsg() definition

// Single Entry Point for Processing all messages
//
// Note that this function does not need a switch statement and never has to 
// be changed when new messages are added.
bool CMsgSwitch::SendMsg(const CMsg& msg)
{
bool retVal = false;
// Get the message type from the message
MSG_TYPE msgType = msg.getType();
// If the map has a valid pointer for a corresponding message processing 
// function, execute it. If the msgType value is one for which the map
// has not been initialized, the returned pointer will be null. If lookup 
// succeeds, itıs safe to do the call and process the message.
PFB pProcMsgFunc = m_opMap[msgType];
if ( pProcMsgFunc != NULL )
{
// De-reference the ıthisı pointer to get to ıthis instanceı, then 
// dereference the message processing function pointer and finally do 
// the function call passing the msg.
retVal = ((*this).*pProcMsgFunc)(msg);
}
else
{
retVal = false;
}
return retVal;
}

Return to article
Embedded.com Career Center
Looking for a new job?
SEARCH JOBS

Browse all jobs

SPONSOR
RECENT JOB POSTINGS





 :