📄 wae_cmmn.c
字号:
int n = (iTID & 0x3) << 1;
BYTE *tbl;
if (pWAEInObj == NULL)
return;
tbl = ((WAEMAINOBJECT*)pWAEInObj)->pTID_Table;
if (tbl == NULL)
return;
tbl[idx] &= ~(0x3 << n);
tbl[idx] |= (EMPTY << n);
}
/* ---------------------------------------------
* Deactivate ALL TIDs in the TID pool - i.e., the
* corresponding requests are no longer active.
* ----------------------------------------------*/
void SDL_DeactivateAllGlobalTIDs(void* pWAEInObj)
{
int i;
BYTE *tbl;
if (pWAEInObj == NULL)
return;
tbl = ((WAEMAINOBJECT*)pWAEInObj)->pTID_Table;
if (tbl == NULL)
return;
for (i = 1; i <= MAX_TID; i++) {
int idx = (i >> 2);
int n = (i & 0x3) << 1;
if (((tbl[idx] >> n) & 0x3) == ACTIVE) {
tbl[idx] &= ~(0x3 << n);
tbl[idx] |= (INACTIVE << n);
}
}
}
/* -----------------------------------------------------------------------------------------------
*
* LISTHANDLING
*
* -----------------------------------------------------------------------------------------------
*/
/* --------------------------------------------------
* Create a new list that will hold a maximum of
* iMax elements. If iMax = 0, no upper limit is
* enforced.
* -------------------------------------------------- */
void* SDL_NewList (int iMax)
{
LISTHEADER* pTheList;
if ((pTheList = NEWSTRUCT (LISTHEADER)) == NULL)
return NULL;
pTheList->iMax = iMax;
pTheList->iTotal = 0;
pTheList->head.pNext = pTheList->head.pPrev = &(pTheList->head);
return pTheList;
}
/* --------------------------------------------------
* Remove all elements in the list, but NOT the data
* that each element points to; it must be deallocated
* separately. Total number of elements is set to 0.
* The listheader is saved intact, and will represent
* an empty list.
* -------------------------------------------------- */
void SDL_ClearList (void* pList)
{
LISTELEMENT* pHead;
if (pList == NULL)
return;
pHead = &(((LISTHEADER *)pList)->head);
while (pHead->pNext != pHead) {
SDL_DeleteListElement (pList, pHead->pNext);
}
}
/* --------------------------------------------------
* Delete all listelements and then delete the list
* header; this does NOT delete the data that each
* element points to, it must be deallocated separately.
* To be used when a COMPLETE removal of the list is wanted.
* -------------------------------------------------- */
void SDL_DeleteList (void** ppList)
{
/* Pass through all elements and deallocate them. */
SDL_ClearList (*ppList);
/* Remove the list header. */
DEALLOC ((LISTHEADER**)ppList);
}
/* --------------------------------------------------
* Add a new element to the list.
* Puts pElement in the list and returns 1 (TRUE) if OK.
* If iPrio != 0 then the list is a priority list, where
* a iPrio controls the point of insertion; otherwise,
* the element is inserted at the end of the list.
* -------------------------------------------------- */
int
SDL_AddListElement (void* pList, int iId, int iPrio ,void* pElement)
{
LISTHEADER* pTheList = (LISTHEADER*)pList;
LISTELEMENT *pHead;
LISTELEMENT *pBefore, *pNew;
if ((pTheList == NULL) ||
(((pTheList->iMax) != 0) && (pTheList->iTotal >= pTheList->iMax)))
return 0;
pHead = &(pTheList->head);
if (iPrio != 0) {
for (pBefore = pHead->pNext; pBefore != pHead; pBefore = pBefore->pNext) {
if (pBefore->iPrio < iPrio)
break;
}
}
else
pBefore = pHead;
if ((pNew = NEWSTRUCT (LISTELEMENT)) == NULL)
return 0;
pTheList->iTotal++;
pNew->iIdentifier = iId;
pNew->pTheElement = pElement;
pNew->iPrio = iPrio;
pNew->pNext = pBefore;
pNew->pPrev = pBefore->pPrev;
pNew->pNext->pPrev = pNew;
pNew->pPrev->pNext = pNew;
return 1;
}
/* --------------------------------------------------
* Add a new element last in the list.
* Returns 1 (TRUE) if OK, 0 otherwise.
* -------------------------------------------------- */
int
SDL_AddElementLast (void* pList, int iId, void* pElement)
{
if (pList == NULL)
return 0;
return SDL_AddElementAfter (pList, iId, pElement,
((LISTHEADER *)pList)->head.pPrev);
}
/* --------------------------------------------------
* Add a new element first in the list.
* Returns 1 (TRUE) if OK, 0 otherwise.
* -------------------------------------------------- */
int
SDL_AddElementFirst (void* pList, int iId, void* pElement)
{
if (pList == NULL)
return 0;
return SDL_AddElementAfter (pList, iId, pElement,
&(((LISTHEADER *)pList)->head));
}
/*---------------------------------------------------
* Add a new element after the one specified by pAfter.
* If pAfter is NULL then add the new element first in the list.
* Returns 1 (TRUE) if OK, 0 otherwise.
* -------------------------------------------------- */
int
SDL_AddElementAfter (void* pList, int iId, void* pElement, void* pAfter)
{
LISTELEMENT* pNew = NULL;
LISTHEADER* pTheList = (LISTHEADER *)pList;
if ((pTheList == NULL) ||
(((pTheList->iMax) != 0) && (pTheList->iTotal >= pTheList->iMax)))
return 0;
if ((pNew = NEWSTRUCT (LISTELEMENT)) == NULL)
return 0;
pTheList->iTotal++;
pNew->iIdentifier = iId;
pNew->pTheElement = pElement;
pNew->iPrio = 0;
if (pAfter == NULL)
pAfter = &(pTheList->head);
pNew->pNext = ((LISTELEMENT*)pAfter)->pNext;
pNew->pPrev = (LISTELEMENT*)pAfter;
((LISTELEMENT*)pAfter)->pNext = pNew;
pNew->pNext->pPrev = pNew;
return 1;
}
/* --------------------------------------------------
* Get the element with id iID. Start searching from the
* pSearchFrom listelement; if pSearchFrom is NULL then
* the search is performed from the beginning.
* If a matching element is found this is returned,
* otherwise NULL.
* -------------------------------------------------- */
void *
SDL_SearchListElement (void* pList, int iId, void* pSearchFrom)
{
LISTELEMENT *pReturnElement = NULL;
LISTELEMENT *pHead;
if (pList == NULL)
return NULL;
pHead = &(((LISTHEADER *)pList)->head);
if (pSearchFrom == NULL)
pSearchFrom = pHead->pNext;
for (pReturnElement = (LISTELEMENT*)pSearchFrom; pReturnElement != pHead;
pReturnElement = pReturnElement->pNext) {
if (pReturnElement->iIdentifier == iId)
break;
}
return (pReturnElement == pHead) ? NULL : pReturnElement;
}
/*-------------------------------------------------
* Get the next listelement. If pTheReqElm is NULL,
* then the first element is returned.
* -------------------------------------------------- */
void *
SDL_GetNextListElement (void* pList, void* pTheReqElm)
{
LISTELEMENT *pHead;
LISTELEMENT *pElement = (LISTELEMENT *)pTheReqElm;
if (pList == NULL)
return NULL;
pHead = &(((LISTHEADER *)pList)->head);
if (pElement == NULL)
pElement = pHead;
return (pElement->pNext == pHead) ? NULL : pElement->pNext;
}
/* -------------------------------------------------
* Gets the content of a listelement, i.e., the generic
* data pointed to.
* --------------------------------------------------*/
void *
SDL_GetListElementContent (void* pTheReqElm)
{
if (pTheReqElm == NULL)
return NULL;
return ((LISTELEMENT*)pTheReqElm)->pTheElement;
}
/* --------------------------------------------------
* Change the content of a LISTElement, i.e., the generic
* data pointed to.
* -------------------------------------------------- */
void
SDL_ChangeListElementContent (void* pTheReqElm, void* pNewContentElement)
{
if (pTheReqElm != NULL)
((LISTELEMENT*)pTheReqElm)->pTheElement = pNewContentElement;
}
/* --------------------------------------------------
* Get the id of a listelement.
* -------------------------------------------------- */
int
SDL_GetListElementID (void* pTheReqElm)
{
if (pTheReqElm == NULL)
return 0;
return ((LISTELEMENT*)pTheReqElm)->iIdentifier;
}
/* --------------------------------------------------
* Change the id of a LISTElement.
* -------------------------------------------------- */
void
SDL_ChangeListElementID (void* pTheReqElm, int iId )
{
if (pTheReqElm != NULL)
((LISTELEMENT*)pTheReqElm)->iIdentifier = iId;
}
/* -------------------------------------------------
* Delete the listelement pRElement. Does NOT delete
* the generic data pointed to by the element.
* --------------------------------------------------*/
void
SDL_DeleteListElement (void* pList, void* pRElement)
{
LISTHEADER *pTheList = (LISTHEADER *)pList;
LISTELEMENT* pRemoveElement = (LISTELEMENT *)pRElement;
if ((pTheList == NULL) || (pRElement == NULL) || (pTheList->iTotal <= 0))
return;
pTheList->iTotal--;
pRemoveElement->pPrev->pNext = pRemoveElement->pNext;
pRemoveElement->pNext->pPrev = pRemoveElement->pPrev;
DEALLOC (&pRemoveElement);
}
/* --------------------------------------------------
* Get the number of elements in a list.
* -------------------------------------------------- */
int
SDL_GetCardinal (void* pList)
{
if (pList == NULL)
return 0;
return ((LISTHEADER*)pList)->iTotal;
}
/*---------------------------------------------------------------------------------------------------------
Stackfunctions
-----------------------------------------------------------------------------------------------------------*/
void* SDL_NewLIFOStack(void)
{
return SDL_NewList(0);
}
void SDL_ClearLIFOStack( void** ppStack )
{
SDL_DeleteList(ppStack);
}
void* SDL_POPLIFOStack(void* pStack)
{
void* pListElm=NULL;
void* pReturn;
/* get the first element */
pListElm = SDL_GetNextListElement(pStack, NULL);
pReturn = SDL_GetListElementContent(pListElm);
SDL_DeleteListElement(pStack, pListElm);
return pReturn;
}
int SDL_PUSHLIFOStack( void* pStack, void* pElement )
{
return SDL_AddElementFirst(pStack, 0, pElement);
}
void* SDL_CheckLIFOStack( void *pStack )
{
void* pListElm=NULL;
pListElm = SDL_GetNextListElement(pStack, NULL);
return SDL_GetListElementContent(pListElm);
}
/*------------------------------------------------------------
General
--------------------------------------------------------------*/
/*---------------------------------------------
Enables SDL to dynamically free structures in C
e.g. strings
Input: Datapointer
Output: -
----------------------------------------------*/
void SDL_Free(void** pTheData)
{
DEALLOC(pTheData);
}
/*---------------------------------------------
Enables SDL to output errormessages to the application
Input: errNo , defined in the porting guide.
Output:
----------------------------------------------*/
void SDL_OutputError(void* pUser, int iErrorcode, int iErrType)
{
if (pUser==NULL)
CLNTa_error(0, (INT16)iErrorcode, (UINT8)iErrType);
else
CLNTa_error(((UA*)pUser)->iViewID, (INT16)iErrorcode, (UINT8)iErrType);
}
void SDL_OutputStatus(void* pUser, int iStatus, void* pURL )
{
MMIa_status( ((UA*)pUser)->iViewID, (UINT8)iStatus, (CHAR*)pURL );
}
void SDL_LOG(void* pUser, int logno, void* pString)
{
/* To get rid of warnings for unused variables */
pUser = pUser;
logno = logno;
pString = pString;
#ifdef LOG_INTERNAL
if (pUser==NULL)
CLNTa_log( 0, (INT16)logno, pString );
else
CLNTa_log( ((UA*)pUser)->iViewID, (INT16)logno, pString );
#endif
}
void* GenCopyString(INT8 iSize, const void* pStr)
{
void* pRes=NULL;
if (pStr !=NULL)
{
if (iSize == 1)
{
pRes = NEWARRAY(BYTE,B_STRINGLENGTH(pStr)+1);
if (pRes)
B_COPYSTRING(pRes,pStr);
}
else
{
pRes = NEWARRAY(WCHAR,STRINGLENGTH(pStr)+1);
if (pRes)
COPYSTRING(pRes,pStr);
}
}
return pRes;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -