📄 servicedataqueue.cpp
字号:
返回: 0 找到
-1 没找到
*******************************************************/
int iReturnCode = 0;
if( m_Lock.Lock() != 0 )
{//上锁
AfxMessageBox("FindRequestInfo() can't lock");
return(-2);
}
int iCount = m_ptrListRequestInfo.GetCount();
for(int i = 0; i < iCount; i ++)
{
struct RequestInfo *prequestInfo = (struct RequestInfo *)m_ptrListRequestInfo.GetAt(m_ptrListRequestInfo.FindIndex(i));
if(prequestInfo->ParamList.iChannelNo == iChannelNo)
{
ParamList.bIsIVR = prequestInfo->ParamList.bIsIVR;
ParamList.iChannelNo = prequestInfo->ParamList.iChannelNo;
ParamList.iServiceNo = prequestInfo->ParamList.iServiceNo;
ParamList.iServiceType = prequestInfo->ParamList.iServiceType;
ParamList.ISN = prequestInfo->ParamList.ISN;
ParamList.nCount = prequestInfo->ParamList.nCount;
//删除这条记录
free(m_ptrListRequestInfo.GetAt(m_ptrListRequestInfo.FindIndex(i)));
m_ptrListRequestInfo.RemoveAt(m_ptrListRequestInfo.FindIndex(i));
break;
}
}
if(i < iCount)
iReturnCode = 0;
else
iReturnCode = -1;
if( m_Lock.Unlock() != 0 )
{//解锁
AfxMessageBox("FindRequestInfo() can't unlock");
return(-1);
}
return iReturnCode;
}
int CServiceDataQueue::SaveRequestInfo2(char *szHeader_Route, char *szSwitchID, int iSwitchIDLen)
{
/*******************************************************
功能: 保存路由消息头和请求包ID的对照表
返回: 0 成功
-1 失败
*******************************************************/
if( m_Lock.Lock() != 0 )
{//上锁
AfxMessageBox("SaveRequest2() can't lock");
return(-2);
}
char *szSaveInfo = (char *)malloc(sizeof(struct Header_Route) + iSwitchIDLen);
memcpy(szSaveInfo, szHeader_Route, sizeof(struct Header_Route));
memcpy(szSaveInfo + sizeof(struct Header_Route), szSwitchID, iSwitchIDLen);
m_ptrListRequestInfo2.AddTail(szSaveInfo);
if( m_Lock.Unlock() != 0 )
{//解锁
AfxMessageBox("SaveRequest2() can't unlock");
return(-1);
}
return 0;
}
int CServiceDataQueue::FindRequestInfo2(char *szSwitchID, int iSwithIDLen, char *szHeader_Route)
{
/*******************************************************
功能: 通过SWITCHID来查找保存的路由信息头
并删除这条记录
返回: 0 找到
-1 没找到
*******************************************************/
int iReturnCode = 0;
if( m_Lock.Lock() != 0 )
{//上锁
AfxMessageBox("FindRequestInfo2() can't lock");
return(-2);
}
int iCount = m_ptrListRequestInfo2.GetCount();
for(int i = 0; i < iCount; i ++)
{
char *szSaveInfo = (char *)m_ptrListRequestInfo2.GetAt(m_ptrListRequestInfo2.FindIndex(i));
if(memcmp(szSwitchID, szSaveInfo + sizeof(struct Header_Route), iSwithIDLen) == 0)
{
memcpy(szHeader_Route, szSaveInfo, sizeof(struct Header_Route));
//删除这条记录
free(m_ptrListRequestInfo2.GetAt(m_ptrListRequestInfo2.FindIndex(i)));
m_ptrListRequestInfo2.RemoveAt(m_ptrListRequestInfo2.FindIndex(i));
break;
}
}
if(i < iCount)
iReturnCode = 0;
else
iReturnCode = -1;
if( m_Lock.Unlock() != 0 )
{//解锁
AfxMessageBox("FindRequestInfo2() can't unlock");
return(-1);
}
return iReturnCode;
}
int CServiceDataQueue::SaveRequestInfo3(char *szHeader_Route, char *szSwitchID, int iSwitchIDLen, HANDLE hXYWSocket, void *pOtherInfo)
{
/*******************************************************
功能: 保存路由消息头和请求包ID的对照表, 顺便保存XYW的CSOCKET
返回: 0 成功
-1 失败
*******************************************************/
if( m_Lock.Lock() != 0 )
{//上锁
AfxMessageBox("SaveRequest2() can't lock");
return(-2);
}
char *szSaveInfo = (char *)malloc(sizeof(struct Header_Route) + iSwitchIDLen + sizeof(HANDLE) + sizeof(void *));
memcpy(szSaveInfo, szHeader_Route, sizeof(struct Header_Route));
memcpy(szSaveInfo + sizeof(struct Header_Route), szSwitchID, iSwitchIDLen);
memcpy(szSaveInfo + sizeof(struct Header_Route) + iSwitchIDLen, &hXYWSocket, sizeof(HANDLE));
memcpy(szSaveInfo + sizeof(struct Header_Route) + iSwitchIDLen + sizeof(HANDLE), &pOtherInfo, sizeof(void *));
m_ptrListRequestInfo2.AddTail(szSaveInfo);
if( m_Lock.Unlock() != 0 )
{//解锁
AfxMessageBox("SaveRequest2() can't unlock");
return(-1);
}
return 0;
}
int CServiceDataQueue::FindRequestInfo3(char *szSwitchID, int iSwithIDLen, char *szHeader_Route, HANDLE &hXYWSocket, void **ppOtherInfo)
{
/*******************************************************
功能: 通过SWITCHID来查找保存的路由信息头,顺便取出SAVE3中保存的XYW的SOCKET
并删除这条记录
返回: 0 找到
-1 没找到
*******************************************************/
int iReturnCode = 0;
if( m_Lock.Lock() != 0 )
{//上锁
AfxMessageBox("FindRequestInfo2() can't lock");
return(-2);
}
int iCount = m_ptrListRequestInfo2.GetCount();
for(int i = 0; i < iCount; i ++)
{
char *szSaveInfo = (char *)m_ptrListRequestInfo2.GetAt(m_ptrListRequestInfo2.FindIndex(i));
if(memcmp(szSwitchID, szSaveInfo + sizeof(struct Header_Route), iSwithIDLen) == 0)
{
memcpy(szHeader_Route, szSaveInfo, sizeof(struct Header_Route));
hXYWSocket = *(HANDLE *)(szSaveInfo + sizeof(struct Header_Route) + iSwithIDLen);
*ppOtherInfo = *(void **)(szSaveInfo + sizeof(struct Header_Route) + iSwithIDLen + sizeof(HANDLE));
//删除这条记录
free(m_ptrListRequestInfo2.GetAt(m_ptrListRequestInfo2.FindIndex(i)));
m_ptrListRequestInfo2.RemoveAt(m_ptrListRequestInfo2.FindIndex(i));
break;
}
}
if(i < iCount)
iReturnCode = 0;
else
iReturnCode = -1;
if( m_Lock.Unlock() != 0 )
{//解锁
AfxMessageBox("FindRequestInfo2() can't unlock");
return(-1);
}
return iReturnCode;
}
int CServiceDataQueue::GetCount()
{
int iReturnCode = 0;
if( m_Lock.Lock() != 0 )
{//上锁
AfxMessageBox("getcount() can't lock");
return(-2);
}
iReturnCode = m_iCount;
if( m_Lock.Unlock() != 0 )
{//解锁
return(-1);
}
return iReturnCode;
}
int CServiceDataQueue::SaveRequestInfo4(char *szPacketID, void *pfaxJob)
{
/*******************************************************
功能: 保存请求包ID和FAXJOB的对照表
返回: 0 成功
-1 失败
*******************************************************/
if( m_Lock.Lock() != 0 )
{//上锁
AfxMessageBox("SaveRequest() can't lock");
return(-2);
}
char *szSaveInfo = (char *)malloc(LEN_STRUCT_HEADER_ROUTE_PACKETID + sizeof(void *));
memcpy(szSaveInfo, szPacketID, LEN_STRUCT_HEADER_ROUTE_PACKETID);
//采用这中方法保存pfaxJob
*(void **)(szSaveInfo + LEN_STRUCT_HEADER_ROUTE_PACKETID) = pfaxJob;
m_ptrListRequestInfo4.AddTail(szSaveInfo);
if( m_Lock.Unlock() != 0 )
{//解锁
AfxMessageBox("SaveRequest() can't unlock");
return(-1);
}
return 0;
}
int CServiceDataQueue::FindRequestInfo4(char *szPacketID, void **ppfaxJob)
{
/*******************************************************
功能: 通过请求包ID来查找保存的FAXJOB
并删除这条记录
返回: 0 找到
-1 没找到
*******************************************************/
int iReturnCode = 0;
if( m_Lock.Lock() != 0 )
{//上锁
AfxMessageBox("FindRequestInfo() can't lock");
return(-2);
}
int iCount = m_ptrListRequestInfo4.GetCount();
for(int i = 0; i < iCount; i ++)
{
char *szSaveInfo = (char *)m_ptrListRequestInfo4.GetAt(m_ptrListRequestInfo4.FindIndex(i));
if(memcmp(szSaveInfo, szPacketID, LEN_STRUCT_HEADER_ROUTE_PACKETID) == 0)
{
*ppfaxJob = *(void **)(szSaveInfo + LEN_STRUCT_HEADER_ROUTE_PACKETID);
//删除这条记录
free(szSaveInfo);
m_ptrListRequestInfo4.RemoveAt(m_ptrListRequestInfo4.FindIndex(i));
break;
}
}
if(i < iCount)
iReturnCode = 0;
else
iReturnCode = -1;
if( m_Lock.Unlock() != 0 )
{//解锁
AfxMessageBox("FindRequestInfo() can't unlock");
return(-1);
}
return iReturnCode;
}
int CServiceDataQueue::CreateSaveInfo(char *szName)
{
/*******************************************************
功能: 创建一个队列来保存某些以后需要再取出来的信息(如SWITCHID等)
*******************************************************/
int iReturnCode = 0;
if( m_Lock.Lock() != 0 )
{//上锁
AfxMessageBox("FindRequestInfo() can't lock");
return(-2);
}
if(szName == NULL)
{
iReturnCode = -1;
goto HERE;
}
int i;
//查找是否已有此队列
if(m_iSaveInfoQueueCount != 0)
{
for(i = 0; i < m_iSaveInfoQueueCount; i ++)
{
if(stricmp(m_psaveInfo[i].aszQueueName, szName) == 0)
break;
}
if(i < m_iSaveInfoQueueCount)
{//已有此队列,出错
iReturnCode = -1;
goto HERE;
}
}
//创建新队列
m_iSaveInfoQueueCount ++;
m_psaveInfo = (struct SaveQueueInfo *)realloc(m_psaveInfo, m_iSaveInfoQueueCount * sizeof(struct SaveQueueInfo));
strcpy(m_psaveInfo[m_iSaveInfoQueueCount - 1].aszQueueName, szName);
m_psaveInfo[m_iSaveInfoQueueCount].pPtrlistQueue = new CPtrList;
HERE:
if( m_Lock.Unlock() != 0 )
{//解锁
AfxMessageBox("FindRequestInfo() can't unlock");
return(-1);
}
return iReturnCode;
}
int CServiceDataQueue::SaveInfo(char *szName, char *szUID, int iUIDLen, void *pInfo)
{
/*******************************************************
功能: 保存UID和指针到指定的队列中
*******************************************************/
int iReturnCode = 0;
if( m_Lock.Lock() != 0 )
{//上锁
AfxMessageBox("FindRequestInfo() can't lock");
return(-2);
}
if(szName == NULL || szUID == NULL || iUIDLen <= 0 || m_iSaveInfoQueueCount <= 0)
{
iReturnCode = -1;
goto HERE;
}
int i;
//查找此队列是否存在
for(i = 0; i < m_iSaveInfoQueueCount; i ++)
{
if(stricmp(m_psaveInfo[i].aszQueueName, szName) == 0)
break;
}
if(i >= m_iSaveInfoQueueCount)
{//没有此队列,出错
iReturnCode = -1;
goto HERE;
}
//在找到的队列中保存ELEMENTINFO
struct ElementInfo *pelementInfo;
pelementInfo = (struct ElementInfo *)malloc(sizeof(struct ElementInfo));
pelementInfo->szUID = (char *)malloc(iUIDLen);
memcpy(pelementInfo->szUID, szUID, iUIDLen);
pelementInfo->iUIDLen = iUIDLen;
pelementInfo->pInfo = pInfo;
m_psaveInfo[i].pPtrlistQueue->AddTail(pelementInfo);
HERE:
if( m_Lock.Unlock() != 0 )
{//解锁
AfxMessageBox("FindRequestInfo() can't unlock");
return(-1);
}
return iReturnCode;
}
int CServiceDataQueue::FindSaveInfo(char *szName, char *szUID, int iUIDLen, void **ppInfo)
{
/*******************************************************
功能: 在指定队列中查找UID和与它联系的指针,并释放这个找到的成员
*******************************************************/
int iReturnCode = 0;
if( m_Lock.Lock() != 0 )
{//上锁
AfxMessageBox("FindRequestInfo() can't lock");
return(-2);
}
if(szName == NULL || szUID == NULL || iUIDLen <= 0 || m_iSaveInfoQueueCount <= 0)
{
iReturnCode = -1;
goto HERE;
}
int i;
//查找此队列是否存在
for(i = 0; i < m_iSaveInfoQueueCount; i ++)
{
if(stricmp(m_psaveInfo[i].aszQueueName, szName) == 0)
break;
}
if(i >= m_iSaveInfoQueueCount)
{//没有此队列,出错
iReturnCode = -1;
goto HERE;
}
//在找到的队列中依据UID得到保存的ELEMENTINFO
struct ElementInfo *pelementInfo;
int iElementCount;
CPtrList *pPtrList;
pPtrList = m_psaveInfo[i].pPtrlistQueue;
iElementCount = pPtrList->GetCount();
if(iElementCount <= 0)
{
iReturnCode = -1;
goto HERE;
}
for(i = 0; i < iElementCount; i ++)
{
pelementInfo = (struct ElementInfo *)pPtrList->GetAt(pPtrList->FindIndex(i));
if(memicmp(pelementInfo->szUID, szUID, iUIDLen) == 0)
break;
}
if(i >= iElementCount)
{
iReturnCode = -1;
goto HERE;
}
*ppInfo = pelementInfo->pInfo;
//删除并释放这个成员(但不释放PINFO)
free(pelementInfo->szUID);
pPtrList->RemoveAt(pPtrList->FindIndex(i));
HERE:
if( m_Lock.Unlock() != 0 )
{//解锁
AfxMessageBox("FindRequestInfo() can't unlock");
return(-1);
}
return iReturnCode;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -