📄 au_dlg.cpp
字号:
#ifdef _MULTI_THREAD
pthread_mutex_lock(&Lock);
#endif
auBitMap.size = (maxDlgId - minDlgId) /8 + 1;
#if 0
if (SGetSBuf(AU_REG, AU_POOL, (Data **) &auBitMap.map,
auBitMap.size) != ROK)
#else
if ((auBitMap.map = (Data *)malloc(auBitMap.size)) == NULLP)
#endif
{
/* initialize the bit map variables */
auBitMap.map = NULLP;
#ifdef _MULTI_THREAD
pthread_mutex_unlock(&Lock);
#endif
RETVALUE(RFAILED);
}
#if 0
cmZero((Data *)auBitMap.map,auBitMap.size);
#else
memset(auBitMap.map, 0, auBitMap.size);
#endif
#ifdef _MULTI_THREAD
pthread_mutex_unlock(&Lock);
#endif
RETVALUE(ROK);
}
/*
* Function name: bitMapFree
* Des: Free all the bit Map
* Return Value : ROK or RFAILED
*/
S16 Dialog_Queue::bitMapFree()
{
#ifdef _MULTI_THREAD
pthread_mutex_lock(&Lock);
#endif
free(auBitMap.map);
#ifdef _MULTI_THREAD
pthread_mutex_unlock(&Lock);
#endif
RETVALUE(ROK);
}
/*
* Function name: dlgIdGen
* Des: Generate the AU dialog ID with bitMap method
* Return Value : MaDlgId or AU_ID_NULL
*/
MaDlgId Dialog_Queue::dlgIdGen()
{
MaDlgId dlgId;
U32 bitMapPos;
U32 octIdx;
U8 bitIdx;
U8 bitMask;
U32 idx;
auDlgIdPool++;
if (auDlgIdPool >= maxDlgId)
{
auDlgIdPool = minDlgId;
}
if (auDlgIdPool == AU_ID_NULL)
{
auDlgIdPool++;
}
dlgId = auDlgIdPool;
bitMapPos = auDlgIdPool - minDlgId;
octIdx = bitMapPos / 8;
bitIdx = bitMapPos % 8;
bitMask = 0x01 << bitIdx;
if (!(auBitMap.map[octIdx] & bitMask))
{
auBitMap.map[octIdx] |= bitMask;
#if 1
dlgIdGenSuc();
#endif
/* Arthur Yin added for MAP Load sharing, 16/10/2003
* To get the local active noCritical map resource sets and append it in the
* first byte of the dlgId, which is used as the route identification in LDF,
* this mens that the digId allocated before shall not >= 0x00ffffff;
*/
#if(!defined(LOCRSET_NO_ROUND) && defined(ZAU))
dlgId = dlgId | (dmGetLocalNonCritRset() << 24);
#endif
RETVALUE(dlgId);
}
idx = octIdx;
while (1)
{
if (auBitMap.map[idx] != 0xff)
{
for (bitIdx = 0, bitMask = 0x01; bitIdx < 8; bitIdx++, bitMask <<= 1)
{
if (!(auBitMap.map[idx] & bitMask))
{
auBitMap.map[idx] |= bitMask;
dlgId = idx * 8 + bitIdx + minDlgId;
if (dlgId > maxDlgId)
{
break;
}
#if 1
dlgIdGenSuc();
#endif
auDlgIdPool = dlgId;
/* Arthur Yin added for MAP Load sharing, 16/10/2003
* To get the local active noCritical map resource sets and append it in the
* first byte of the dlgId, which is used as the route identification in LDF,
* this mens that the digId allocated before shall not >= 0x00ffffff;
*/
#if(!defined(LOCRSET_NO_ROUND) && defined(ZAU))
dlgId = dlgId | (dmGetLocalNonCritRset() << 24);
#endif
RETVALUE(dlgId);
}
}
}
idx++;
if (idx == auBitMap.size)
{
idx = 0;
}
if (idx == octIdx)
{
#if 1
dlgIdGenFal();
#endif
RETVALUE(AU_ID_NULL);
}
bitIdx = 0;
}
}
/*
* Function name: dlgIdFree
* Des: Free the Dialogure corresponding bitMap
* Return Value : ROK or RFAILED
*/
S16 Dialog_Queue::dlgIdFree(MaDlgId auDlgId)
{
MaDlgId bitMapPos;
U32 octIdx;
U8 bit;
/* Arthur Yin added for MAP Load sharing, 16/10/2003
* To get the local active noCritical map resource sets and append it in the
* first byte of the dlgId, which is used as the route identification in LDF,
* this mens that the digId allocated before shall not >= 0x00ffffff;
*/
#ifdef ZAU
auDlgId = auDlgId & 0x00ffffff;
#endif /* ZAU */
if (auDlgId == AU_ID_NULL)
{
RETVALUE(RFAILED);
}
bitMapPos = auDlgId - minDlgId;
octIdx = bitMapPos / 8;
bit = bitMapPos % 8;
auBitMap.map[octIdx] &= (~(0x01 << bit));
RETVALUE(ROK);
}
/*
* Function name: dlgInsert
* Des: Insert the newDlg to Dialogure
* Return Value : ROK or RFAILED
*/
Dialog *Dialog_Queue::dlgInsert(MaDlgId suDlgId, MaDlgId spDlgId)
{
Dialog *curDlg;
Dialog *newDlg=NULLP;
S16 idx;
#ifdef _MULTI_THREAD
if (pthread_mutex_trylock(&Lock) != 0)
{
AUACC_PRINT("DLG INSERT LOCK FAILED**************\n");
RETVALUE(NULLP);
}
#endif
if (actDlgNum == maxDlgNum)
{
#ifdef _MULTI_THREAD
pthread_mutex_unlock(&Lock);
#endif
AUACC_PRINT("dlgInsert failure_______actDlgNum == maxDlgNum\n");
RETVALUE(NULLP);
}
curDlg = dlgFind(suDlgId, spDlgId);
try
{
if (curDlg == NULLP)
{
if ((suDlgId = dlgIdGen()) == AU_ID_NULL)
{
#ifdef _MULTI_THREAD
pthread_mutex_unlock(&Lock);
#endif
AUACC_PRINT("dlgInsert failure_______DlgIdGen Failure dlgId %ld\n",auDlgIdPool);
RETVALUE(NULLP);
}
idx = suDlgId % AU_HASH_SIZE;
curDlg = auDlgQueue[idx];
if (curDlg == NULLP)
{
newDlg = new Dialog(suDlgId, spDlgId);
auDlgQueue[idx] = newDlg;
newDlg->prev = NULLP;
newDlg->next = NULLP;
}
else
{
while (curDlg->next != NULLP)
{
curDlg = curDlg->next;
}
newDlg = new Dialog(suDlgId, spDlgId);
curDlg->next = newDlg;
newDlg->prev = curDlg;
newDlg->next = NULLP;
}
}
else
{
#ifdef _MULTI_THREAD
pthread_mutex_unlock(&Lock);
#endif
AUACC_PRINT("dlgInsert failure_______DlgID =%ld find\n",suDlgId);
RETVALUE(NULLP);
}
}
catch ( ... )
{
#ifdef _MULTI_THREAD
pthread_mutex_unlock(&Lock);
#endif
RETVALUE(NULLP);
}
actDlgNum++;
#ifdef _MULTI_THREAD
pthread_mutex_unlock(&Lock);
#endif
RETVALUE(newDlg);
}
/*
* Function name: dlgDelete
* Des: Delete Dialogue from Queue
* Return Value : ROK or RFAILED
*/
S16 Dialog_Queue::dlgDelete(MaDlgId suDlgId)
{
Dialog *curDlg;
S16 idx;
#ifdef _MULTI_THREAD
pthread_mutex_lock(&Lock);
#endif
if (suDlgId == AU_ID_NULL)
{
#ifdef _MULTI_THREAD
pthread_mutex_unlock(&Lock);
#endif
RETVALUE(RFAILED);
}
idx = suDlgId % AU_HASH_SIZE;
curDlg = auDlgQueue[idx];
while ( curDlg != NULLP)
{
if (curDlg->auDlgId == suDlgId)
{
if (curDlg->prev)
curDlg->prev->next = curDlg->next;
if (curDlg->next)
curDlg->next->prev = curDlg->prev;
if (curDlg == auDlgQueue[idx])
{
if (curDlg->next == NULLP)
auDlgQueue[idx] = NULLP;
else
auDlgQueue[idx] = curDlg->next;
}
dlgIdFree(curDlg->auDlgId);
//AUACC_PRINT("delete dialog %d\r\n", curDlg->auDlgId);
delete curDlg;
actDlgNum--;
#ifdef _MULTI_THREAD
pthread_mutex_unlock(&Lock);
#endif
RETVALUE(ROK);
}
curDlg = curDlg->next;
}
#ifdef _MULTI_THREAD
pthread_mutex_unlock(&Lock);
#endif
RETVALUE(RFAILED);
}
/*
* Function name: dlgFind
* Des: Find the Dialogue from Queue
* Return Value : ROK or RFAILED
*/
Dialog *Dialog_Queue::dlgFind(MaDlgId suDlgId, MaDlgId spDlgId)
{
S16 idx;
Dialog *curDlg;
#ifdef LOCRSET_NO_ROUND
MaDlgId suDlgId_loc;
suDlgId_loc = suDlgId&0x00ffffff;
#endif /* LOCRSET_NO_ROUND */
if (suDlgId == AU_ID_NULL)
{
if (spDlgId == AU_ID_NULL)
{
RETVALUE(NULLP);
}
for (idx = 0; idx < AU_HASH_SIZE; idx++)
{
curDlg = auDlgQueue[idx];
while (curDlg != NULLP)
{
if (curDlg->maDlgId == spDlgId)
{
RETVALUE(curDlg);
}
curDlg = curDlg->next;
}
}
RETVALUE(NULLP);
}
else
{
#ifdef LOCRSET_NO_ROUND
idx = suDlgId_loc % AU_HASH_SIZE;
#else
idx = suDlgId % AU_HASH_SIZE;
#endif /* LOCRSET_NO_ROUND */
curDlg = auDlgQueue[idx];
#ifdef LOCRSET_NO_ROUND
while (curDlg != NULLP)
{
if ((curDlg->auDlgId == suDlgId_loc)||(curDlg->auDlgId == suDlgId))
{
if (suDlgId != curDlg->auDlgId)
{
curDlg->auDlgId = suDlgId;
}
RETVALUE(curDlg);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -