20个通宵没明白的爱立信的面试题(几十行代码):下面函数OnQueryUeData中的pucResult 的值的来龙去脉SetRspMsgInfo函数 是怎么样影响到nQueryUeData中的pucResult 的值?求解释APP_MM_INQ_IMSI_CNF_STRU *pMmCnf =   (APP_MM_INQ_IMSI_CNF_STRU *)cnfinfo;之类的强制转化合理吗另外,下面的流程很复杂,能简化吗
主函数:
UINT32 CUECtrlV20::OnQueryUeData(UINT8* pucPara,UINT32 ulParaLen,UINT8* pucResult,UINT32& ulResultLen)
{
 .....
if(!SearchIMSI(pRes))
{
sprintf_s((char*)pRes->IMSI,sizeof(pRes->IMSI),"%s","error");
}
PRINT_LOG("CUECtrlV20","OnQueryUeData Sussessful",......
class CRespMsgInfo
{
public:
//constructor
CRespMsgInfo();
//destructor
~CRespMsgInfo(); BOOL SetRspMsgInfo4Wait(UINT32 ulMsgId);
BOOL GetRspMsgInfo2Wait(UINT8 * pucInfo,UINT32 & ulInfoLen);
VOID SetRspMsgInfo(OM_MSG_STRU_V2* pucInfo );
private: //临界区
CRITICAL_SECTION m_csLock;
UINT32 m_ulIsUpdated;
UINT32 m_ulResponseMsgId;
UINT32 m_ulInfoLen;
UINT8  m_aucInfo[10000];};
BOOL CUECtrlV20::SearchIMSI(STRU_QUERYUEDATA_OUT *pRes)
{
ResetEvent(g_hEventimsi);
m_respMsgInfo.SetRspMsgInfo4Wait(ID_APP_MM_INQ_IMSI_CNF_V2);
for(int i=0;i<1;i++)
{
if(!m_OmtSocket.Send((UINT8*)pMsg, ulMsgLen))
{
......
}
}
free(pMsg); UINT32 ulResultLen;
UINT8 cnfinfo[sizeof(APP_MM_INQ_IMSI_CNF_STRU) + 1000] ={0};

DWORD dws = 0;
dws = WaitForSingleObject(g_hEventimsi,30000);

if(m_respMsgInfo.GetRspMsgInfo2Wait(cnfinfo,ulResultLen))
{
APP_MM_INQ_IMSI_CNF_STRU *pMmCnf =   (APP_MM_INQ_IMSI_CNF_STRU *)cnfinfo; UINT32 ulRet = OMT_NTOHL(pMmCnf->ulRslt);
if(enError_SUCCESS == ulRet)
{
memset(pRes->IMSI,0,sizeof(pRes->IMSI));
memcpy(pRes->IMSI,pMmCnf->aucImsi,APP_MAX_IMSI_BUF_SIZE);
PRINT_LOG("CUECtrlV20","SearchIMSI","SearchIMSI = %s: command success",pRes->IMSI);
return TRUE;
}
}
PRINT_LOG("CUECtrlV20","SearchIMSI","SearchIMSI: command failed"); return FALSE;
}BOOL CRespMsgInfo::SetRspMsgInfo4Wait(UINT32 ulMsgId )
{
CMYCriticalSection lock(&m_csLock, TRUE); //m_ulIsUpdated = FALSE;  modify by chenlin //by dkf40287
//ResetEvent(g_hEvent);
//SetEvent(g_hEvent);//modified by xianglei,这里无需激活,注释掉
m_ulResponseMsgId = ulMsgId;
m_ulInfoLen = 0;
memset(m_aucInfo,0,10000);
PRINT_LOG("CRespMsgInfo","SetRspMsgInfo4Wait","set expected msg 0x%x",m_ulResponseMsgId); return TRUE;
}BOOL CRespMsgInfo::GetRspMsgInfo2Wait(UINT8 *  pucInfo,UINT32 & ulInfoLen)
{ //DWORD dw = 0;

//dw = WaitForSingleObject(g_hEvent,30000);
CMYCriticalSection lock(&m_csLock, TRUE);
//if(dw != WAIT_TIMEOUT)
{
ulInfoLen = m_ulInfoLen;
memcpy(pucInfo,m_aucInfo,m_ulInfoLen);
return TRUE;
}
}

解决方案 »

  1.   

    另外个线程写数据void CUECtrlV20::PostMsgToUE(UINT8 *data)
    {
    OM_MSG_STRU_V2 * pOMTMsg = (OM_MSG_STRU_V2*)data;
       UINT32 ulMsgId=OMT_NTOHL(pOMTMsg->ulMsgId);
       
    switch(ulMsgId)
    {
    case APP_OM_SHAKEHAND_CNF_MSG_ID:
    {
    ProcessResponseMsgs(pOMTMsg);  
    break;
    }
    BOOL CUECtrlV20::ProcessResponseMsgs(OM_MSG_STRU_V2* pOmMsg)
    {

    ......
       
    m_respMsgInfo.SetRspMsgInfo(pOmMsg);
    }下面函数是数据的源头
    VOID CRespMsgInfo::SetRspMsgInfo(OM_MSG_STRU_V2* pucInfo )
    { if(OMT_HTONL(pucInfo->ulMsgId) == m_ulResponseMsgId)
    {
    m_ulInfoLen = OMT_HTONL(pucInfo->ulLength) - 20;
    memcpy(m_aucInfo,pucInfo->aucPara,m_ulInfoLen);

    }

    }