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;
}
}
主函数:
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;
}
}
解决方案 »
- vc++怎样打开cpl文件?求助高手!
- 请教 以包容方式重用 一个Textbox控件 应该如何做
- 问一个问题:请问如何定义自己的消息(超菜)
- 谁有ERP,CRM的程序,给我个源码,谢谢(我要一个模块就行了)
- 我调用的Navigate2()方法,我如何判断调用的URL其实没有的?
- 我在内存的一块DC中放了一张图片,然后我想将这张图片转换成DIB,放在一个DIB对象中,我该怎么办?分不够可以再加!
- 帮帮忙
- 怎样才能将ListBox中加入的字符串变色?
- 网络游戏招聘,优先刚毕业学生
- 求助 怎样让软件运行时加载软件目录下的ws2_32.dll
- 小问题,求实现
- 》》》》》》》》》》》》》》模板map编译错误》》》》》》》》》》》》》》
{
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);
}
}