⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pushll.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 3 页
字号:
/*========================================================================
	PUSH_GetContentWithID
==========================================================================
Purpose: Fetch PushContent with ContentID
Params:  iContentID
Return:  pPushContentStruct
=========================================================================*/
void* PUSH_GetContentWithID( void* pContext, UINT32 iContentID,
										 UINT8 iType)
{
	BYTE* pbData=NULL;
	UINT32 iContentSize=0;

#ifdef FILE_PUSH_REPOSITORY
	INT32 iSize;
#endif

	BOOL myCheck;
	PUSHCONTENTSTRUCT* pContent=NULL;

#ifdef WAE_DEBUG
	URL_DEBUG_PRINT("End PUSH_GetContentWithID");
#endif

	if (!pushMem.isInitialized) {     
		return FALSE;
	}

	/* Get size of content */
#ifdef FILE_PUSH_REPOSITORY
	iSize = FILEa_getSize( PUSH_CATEGORY, iContentID);
	iContentSize = iSize!=-1 ? (UINT32) iSize : 0;
#else
	iContentSize=Storage_GetBlockSize (&((PUSHCONTEXT*)pContext)->Storage,iContentID);
#endif
	if (iContentSize!=0)
	{
		pbData=NEWARRAY(BYTE,iContentSize);
		if (pbData!=NULL)
		{
#ifdef FILE_PUSH_REPOSITORY
		iSize = FILEa_read( PUSH_CATEGORY, iContentID, pbData, 0, iContentSize);
		myCheck = iSize!=-1 ? TRUE : FALSE;
		iContentSize = (UINT32) iSize;
#else
		myCheck = Storage_Get (&((PUSHCONTEXT*)pContext)->Storage, iContentID,0,iContentSize,pbData);
#endif
			if(myCheck)
			{
				pContent=NEWSTRUCT(PUSHCONTENTSTRUCT);
				if (pContent!=NULL)
				{
					pContent->iType=pbData[0];
					pContent->iId=iContentID;

					if((pbData[0]==SI)&&(iType==SI))
					{
						pContent->iPortType=pbData[11];
						pContent->iNewChannelId = pbData[12];
						pContent->content.pSIContentStruct=PUSH_GetStoredSI(pbData);
					}
					else if ((pbData[0]==SL)&&(iType==SL))
					{
						pContent->iPortType=pbData[3];
						pContent->iNewChannelId = pbData[4];
						pContent->content.pSLContentStruct=PUSH_GetStoredSL(pbData);
					}
					else
					{
						/* Error */
						DEALLOC(&pContent);
					}
				}
			}
			DEALLOC(&pbData);
		}
	}
	return (void*)pContent;

} /* end of PUSH_GetContentWithID */

/*========================================================================
	PUSH_ChangePushStatus
==========================================================================
Purpose: Change status on PushContent with ContentID
Params:  iContentID
Return:  TRUE
=========================================================================*/
BOOL PUSH_ChangePushStatus (void* pContext, UINT32 iContentID, UINT8 iStatus)
{

	BYTE pbData[2];
#ifdef FILE_PUSH_REPOSITORY
	INT32 iLen;
#endif

#ifdef WAE_DEBUG
	URL_DEBUG_PRINT("End PUSH_ChangePushStatus");
#endif

	if (!pushMem.isInitialized) {     
		return FALSE;
	}

	/* Find push */
#ifdef FILE_PUSH_REPOSITORY
	iLen = FILEa_read (PUSH_CATEGORY, iContentID, (void *)pbData, 0, 2);
	if (iLen !=2)
		return FALSE;
#else
	if (!Storage_Get(&((PUSHCONTEXT*)pContext)->Storage,iContentID,0,2,pbData))
		return FALSE;
#endif
	/* Change status on push */	
	pbData[1]=iStatus;

#ifdef FILE_PUSH_REPOSITORY
	iLen = FILEa_write (PUSH_CATEGORY, iContentID, (void *)pbData, 0, 2);
	if (iLen !=2)
		return FALSE;
	FILEa_flush (PUSH_CATEGORY, iContentID);
#else
	if (!Storage_Put(&((PUSHCONTEXT*)pContext)->Storage,iContentID,0,2,pbData))
		return FALSE;
#endif

	return TRUE;

} /* end of PUSH_ChangePushStatus */

/*========================================================================
	PUSH_CompactPushBuffer
==========================================================================
	This function organizes the memory with no (minimal) fragmentation. 
	The function is called when a compactation of the push buffer is 
	needed. The function is called, for example, when content is to be 
	stored and the available memory in the push buffer is sufficient, but 
	fragmented in a way so that the largest free block is smaller than 
	the content. To allow scheduling, the compact process is not neces-
	sarily completed with one function call. As long as the function 
	returns TRUE it is possible to compact the push buffer more.

	Input: void* (MUST be pPUSHCONTEXT)
	Output: TRUE if possible to compact more, FALSE otherwise
==========================================================================*/
BOOL PUSH_CompactPushBuffer( void* pContext )
{

#ifdef WAE_DEBUG
	URL_DEBUG_PRINT("End PUSH_CompactPushBuffer");
#endif

	if (!pushMem.isInitialized) {     
		return FALSE;
	}

	if (pContext != NULL)
	{
#ifdef FILE_PUSH_REPOSITORY
		return FALSE;
#else
		return (Storage_Compact(&((PUSHCONTEXT*)pContext)->Storage));
#endif
	}
	return FALSE;

} /* end of PUSH_CompactPushBuffer */


/*========================================================================
	PUSH_InitPushMem
==========================================================================*/
void* PUSH_InitPushMem (UINT32 iPushSize)
{
	pPUSHCONTEXT pContext=NULL;

	/* Create Context struct */
	pContext=NEWSTRUCT(PUSHCONTEXT);
	if (pContext==NULL)
	{
		return NULL;
	}

	/* Init fields */
	pContext->iNumberOfElements=0;
	pContext->iCurrentElement=0;
	pContext->piElementList=NULL;
	pContext->iScanPhase=1;

#ifdef FILE_PUSH_REPOSITORY
	pushMem.isInitialized = 1;
	pushMem.storageSize=0;
	pushMem.maxStorageSize=iPushSize;
	return pContext;
#else
	/* Init Storage Object */
	if (Storage_Init (&pContext->Storage,iPushSize,(ReadFunction*)MEMa_readPushRepository,
		(WriteFunction*)MEMa_writePushRepository))
	{
		pushMem.isInitialized = 1;
		pushMem.store=&(pContext->Storage);
		return pContext;
	}
	else
	{
		/* Error -> dealloc pContext */
		DEALLOC (&pContext);
	}
#endif

	return NULL;
}

/*========================================================================
	PUSH_ResetPushMem
==========================================================================
	The function removes all content in the push memory.

	Input: void* (MUST be pPUSHCONTEXT)
	Output: -
==========================================================================*/
void PUSH_ResetPushMem (void* pContext)
{
#ifdef FILE_PUSH_REPOSITORY
	INT16 iNbr;
#endif
	UINT32* piIds=NULL;
	UINT16 iLen=0;
	UINT16 iCount=0;

	/* Get all id:s */
#ifdef FILE_PUSH_REPOSITORY
	iNbr = FILEa_getFileIds (PUSH_CATEGORY, NULL, (UINT32) cfg_wae_push_in_buffer_size);
	if (iNbr==-1)
		return;
	piIds = NEWARRAY(UINT32, iNbr);
	if (piIds==NULL)
		return;
	iNbr = FILEa_getFileIds (PUSH_CATEGORY, piIds, (UINT16) iNbr);
	if (iNbr==-1)
		return;
	iLen=iNbr;
	pushMem.storageSize=0;
#else
	Storage_GetAllBlockIds(&((PUSHCONTEXT*)pContext)->Storage,&piIds,&iLen);
#endif

	while (iCount<iLen)
	{
		/* Delete block */
#ifdef FILE_PUSH_REPOSITORY
		FILEa_delete (PUSH_CATEGORY, piIds[iCount]);
#else
		Storage_DeleteBlock(&((PUSHCONTEXT*)pContext)->Storage,piIds[iCount]);
#endif
		iCount++;
	}

	DEALLOC(&piIds);

	/* Delete in context */
	((PUSHCONTEXT*)pContext)->iCurrentElement=0;
	((PUSHCONTEXT*)pContext)->iNumberOfElements=0;
	((PUSHCONTEXT*)pContext)->iScanPhase=1;
	DEALLOC(&((PUSHCONTEXT*)pContext)->piElementList);
}

/*========================================================================
	PUSH_TerminatePushMem
==========================================================================
	The function removes the PUSHCONTEXT struct. 
	
	Input: void* (MUST be pPUSHCONTEXT)
	Output: -
==========================================================================*/
void PUSH_TerminatePushMem (void* pContext)
{
	pPUSHCONTEXT pTemp=(PUSHCONTEXT*)pContext;

	/* Delete in context */
	DEALLOC(&((PUSHCONTEXT*)pContext)->piElementList);

	/* Delete memory struct */
#ifdef FILE_PUSH_REPOSITORY
	pushMem.storageSize=0;
#else
	Storage_Finalize(&(((PUSHCONTEXT*)pContext)->Storage));
#endif

	/* To use the pushMem. The PushMem must first be initialized*/
	pushMem.isInitialized = 0;
	
	/* Delete context */
	DEALLOC(&pTemp);

}

/*========================================================================
	PUSH_ClosePushMem
==========================================================================
	The function closes the pushMem. Run PUSH_InitPushMem to be able to use the 
	memory again. If more data is stored than liNewSize specifies then data
	will be removed.
	
	Input: pContext MUST be pPUSHCONTEXT
		   pContentList must be of type ListHeader
		   liNewSize (How much can be saved)
		   iType (if content should be removed then -1=oldest SI, -2 =oldest SL)
	Output: TRUE if closed, false if more content should be removed.
==========================================================================*/
BOOL PUSH_ClosePushMem(void* pContext, void *pContentList, UINT32 liNewSize, INT8 iType)
{
	UINT32 liDate=0;
	UINT32 liStorageSize;
	pPUSHCONTEXT pTemp=(PUSHCONTEXT*)pContext;

#ifdef FILE_PUSH_REPOSITORY
	INT32  liSize;
#endif

	void *pvListElement;
	pPUSHLISTSTRUCT pPushListStruct=NULL;

	if (!pushMem.isInitialized || pContentList==NULL) {
		MEMa_pushRepositoryClosed();
		return TRUE;
	}

	/*Remove the oldest SI or SL message if iType = -1 or -2*/
	pvListElement = ME_Push_Get_First(pContentList);
	if ((iType==-1 || iType==-2) && pvListElement!=NULL)
	{
		pPushListStruct = (pPUSHLISTSTRUCT) ME_Push_Get_PushListStruct(pvListElement);
		while (pPushListStruct!=NULL) {
			if (pPushListStruct->iPushType == SI && iType == -1) 
			{
				/*Message found and shall be deleted*/
#ifdef FILE_PUSH_REPOSITORY
				liSize=FILEa_getSize(PUSH_CATEGORY, pPushListStruct->iLLPushId);
				if (liSize==-1)
					return FALSE;
				pushMem.storageSize-=liSize;
				FILEa_delete(PUSH_CATEGORY, pPushListStruct->iLLPushId);
#else
				Storage_DeleteBlock (pushMem.store, pPushListStruct->iLLPushId);
#endif
				ME_Push_List_Delete( pContentList, pPushListStruct);
				break;
			}
			else if (pPushListStruct->iPushType == SL && iType == -2) 
			{
				/*Message found and shall be deleted*/
#ifdef FILE_PUSH_REPOSITORY
				liSize=FILEa_getSize(PUSH_CATEGORY, pPushListStruct->iLLPushId);
				if (liSize==-1)
					return FALSE;
				pushMem.storageSize-=liSize;
				FILEa_delete(PUSH_CATEGORY, pPushListStruct->iLLPushId);
#else
				Storage_DeleteBlock (pushMem.store, pPushListStruct->iLLPushId);
#endif
				ME_Push_List_Delete( pContentList, pPushListStruct);
				break;
			}
			pvListElement = ME_Push_Get_Next(pContentList, pvListElement);
			if ( pvListElement != NULL )
				pPushListStruct = (pPUSHLISTSTRUCT) ME_Push_Get_PushListStruct(pvListElement);
			else
				pPushListStruct = NULL;
		}
	}

#ifdef FILE_PUSH_REPOSITORY
	liStorageSize = pushMem.storageSize;
#else
	liStorageSize = Storage_BytesUsed(pushMem.store);
	if (liStorageSize<=4)
		liStorageSize=0;
#endif

	/*Push messages must be removed if this statement is true*/
	if (liStorageSize>liNewSize)
		return FALSE;

#ifdef FILE_PUSH_REPOSITORY
	pushMem.storageSize=0;
#else
	while (Storage_Compact (pushMem.store)) {
	}

	Storage_ChangeSize (pushMem.store, liNewSize);
	Storage_Finalize (pushMem.store);
#endif
	pushMem.isInitialized = 0;
	MEMa_pushRepositoryClosed(); 

	/* Delete in context */
	DEALLOC(&((PUSHCONTEXT*)pContext)->piElementList);

	/* Delete context */
	DEALLOC(&pTemp);
	return TRUE;

}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -