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

📄 mpqueuetask.c

📁 这是全套的PPP协议的源码
💻 C
字号:
/* mpQueueTask.c - MP receive/send Queue and Task related source file *//* Copyright 1999 Wind River Systems, Inc. */ #include "copyright_wrs.h"/*modification history--------------------01b,19feb02,ak	 input parameter validation in all the functions01a,19feb01,nts  created.*//*DESCRIPTIONThis module implements the MP receive and send Queue and the related taskswhich are useful in exchanging the packets between the MEMBER and MANAGERstacks of the MP system.INCLUDES: mpFramingLayerP.h*//* includes */#include "vxWorks.h"#include "stdio.h"#include "stdlib.h"#include "private/ppp/mpFramingLayerP.h"/* defines */#define		MAX_JOB_DATA_SIZE	64/********************************************************************************* mpSendQueueCreate - Creates the MP send Queue** This function creates the MP send Queue.* * RETURNS: OK or ERROR** SEE ALSO: mpReceiveQueueCreate*/STATUS mpSendQueueCreate    (    MP_FRAMING_LAYER	*pMpFramingLayerComponent,	unsigned int		mpSendQueueDepth    )    {	if (pMpFramingLayerComponent == NULL)		return ERROR;    if ((pMpFramingLayerComponent->mpSendRing = 			rngCreate (mpSendQueueDepth)) != NULL)		{		return OK;		}	else		{		pfwPrintError (__FILE__, "mpSendQueueCreate", __LINE__, NULL, NULL, 		       "Queue create ERROR");		return ERROR;		}	}/********************************************************************************* mpReceiveQueueCreate - Creates the MP receive Queue** This function creates the MP receive Queue.* * RETURNS: OK or ERROR** SEE ALSO: mpSendQueueCreate*/STATUS mpReceiveQueueCreate    (    MP_FRAMING_LAYER	*pMpFramingLayerComponent,	unsigned int		mpReceiveQueueDepth    )    {	if (pMpFramingLayerComponent == NULL)		return ERROR;    if ((pMpFramingLayerComponent->mpReceiveRing =			rngCreate (mpReceiveQueueDepth)) != NULL)		{		return OK;		}	else		{		pfwPrintError (__FILE__, "mpReceiveQueueCreate", __LINE__, NULL, NULL, 		       "Queue create ERROR");		return ERROR;		}	}/********************************************************************************* mpSendTask - Creates the MP send task** This function creates the MP send task* * RETURNS: N/A** SEE ALSO: mpReceiveTask*/void mpSendTask    (    MP_FRAMING_LAYER	*pMpFramingLayerComponent    )    {    MP_JOB_RING_ITEM	mpSendJobItem;	FAST BOOL			ok;	BOOL				jobQIsEmpty;	char data [MAX_JOB_DATA_SIZE];	if (pMpFramingLayerComponent == NULL)		return;	bzero (data, sizeof (data));    jobQIsEmpty = TRUE;		while (TRUE)		{		if (jobQIsEmpty)			semTake (pMpFramingLayerComponent->sendSem, WAIT_FOREVER);		/* Get a job from the job queue */		ok = rngBufGet (pMpFramingLayerComponent->mpSendRing, 						(char *) &mpSendJobItem, 						sizeof (MP_JOB_RING_ITEM)) == sizeof (MP_JOB_RING_ITEM);		if (ok)			{			ok = rngBufGet (pMpFramingLayerComponent->mpSendRing, data, 								mpSendJobItem.size) == mpSendJobItem.size;			}		jobQIsEmpty = (ok) ? FALSE : TRUE;		if (ok)			(*mpSendJobItem.jobHandlerFunc) ((void *) data); 		}	}/********************************************************************************* mpReceiveTask - Creates the MP receive task** This function creates the MP receive task* * RETURNS: N/A** SEE ALSO: mpSendTask*/void  mpReceiveTask    (    MP_FRAMING_LAYER	*pMpFramingLayerComponent    )    {    MP_JOB_RING_ITEM	mpReceiveJobItem;	FAST BOOL			ok;	BOOL				jobQIsEmpty;	char 				data [MAX_JOB_DATA_SIZE];	if (pMpFramingLayerComponent == NULL)		return;	bzero (data, sizeof (data));    jobQIsEmpty = FALSE;		while (TRUE)		{		if (jobQIsEmpty)			semTake (pMpFramingLayerComponent->receiveSem, WAIT_FOREVER);		/* Get a job from the job queue */		ok = rngBufGet (pMpFramingLayerComponent->mpReceiveRing, 						(char *) &mpReceiveJobItem, 						sizeof (MP_JOB_RING_ITEM)) == sizeof (MP_JOB_RING_ITEM);		if (ok)			ok = rngBufGet (pMpFramingLayerComponent->mpReceiveRing, data, 								mpReceiveJobItem.size) == mpReceiveJobItem.size;		jobQIsEmpty = (ok) ? FALSE : TRUE;		if (ok)			(*mpReceiveJobItem.jobHandlerFunc) ((void *) data);		}	}/********************************************************************************* mpSendQueueAdd - Adds a job to the send queue** This function adds a job to the send queue* * RETURNS: OK or ERROR** SEE ALSO: mpReceiveQueueAdd*/STATUS mpSendQueueAdd    (    PFW_OBJ		*pfwObj,		/* reference to the framework object */	FUNCPTR		jobHandlerFunc,	/* pointer to the function to be executed by									send queue task */	void		*data,			/* data buffer to be used by the function */	int			size			/* size of the data to be processed */    )    {	MP_FRAMING_LAYER	*pMpFramingLayerObj = NULL;	MP_JOB_RING_ITEM	item;	unsigned int		totalSize = 0;	if (pfwObj == NULL)		{        pfwPrintError (__FILE__, "mpSendQueueAdd", __LINE__, pfwObj, NULL, 		       "Invalid argument: Null framework object pointer");        return (ERROR);        }		pMpFramingLayerObj = (MP_FRAMING_LAYER *)pfwLayerObjGet 												(pfwObj, "MP_FRAMING_LAYER");		if (pMpFramingLayerObj == NULL)		{		pfwPrintError (__FILE__, "mpSendQueueAdd", __LINE__, pfwObj, NULL, 		       "Layer object is NULL");        return (ERROR);			}	if (pMpFramingLayerObj->mpSendRing == NULL)		{        pfwPrintError (__FILE__, "mpSendQueueAdd", __LINE__, pfwObj, NULL, 		       "Send job queue does not exist");        return (ERROR);        }	if (jobHandlerFunc == NULL)		{        pfwPrintError (__FILE__, "mpSendQueueAdd", __LINE__, pfwObj, NULL, 		       "Invalid argument: Null fuction pointer");        return (ERROR);        }		if (size < 0 || size > MAX_JOB_DATA_SIZE) 		{        pfwPrintError (__FILE__, "mpSendQueueAdd", __LINE__, pfwObj, NULL, 		       "Invalid argument: size is out of range");        return (ERROR);        }	item.jobHandlerFunc = jobHandlerFunc;	item.size = size;	totalSize = size + sizeof (MP_JOB_RING_ITEM);		if ( rngFreeBytes (pMpFramingLayerObj->mpSendRing) >= totalSize)		{		rngBufPut (pMpFramingLayerObj->mpSendRing, (char *) &item, 			                                    	sizeof (MP_JOB_RING_ITEM));        rngBufPut (pMpFramingLayerObj->mpSendRing, (char *) data, size);		semGive (pMpFramingLayerObj->sendSem);        return (OK);		}		return (ERROR);	}/********************************************************************************* mpReceiveQueueAdd - Adds a job to the receive queue** This function adds a job to the receive queue* * RETURNS: OK or ERROR** SEE ALSO: mpSendQueueAdd*/STATUS mpReceiveQueueAdd    (    PFW_OBJ		*pfwObj,		/* reference to the framework object */	FUNCPTR		jobHandlerFunc,	/* pointer to the function to be executed by									send queue task */	void		*data,			/* data buffer to be used by the function */	int			size			/* size of the data to be processed */    )    {	MP_FRAMING_LAYER	*pMpFramingLayerObj = NULL;	MP_JOB_RING_ITEM	item;	unsigned int		totalSize = 0;	if (pfwObj == NULL)		{        pfwPrintError (__FILE__, "mpReceiveQueueAdd", __LINE__, pfwObj, NULL, 		       "Invalid argument: Null framework object pointer");        return (ERROR);        }		pMpFramingLayerObj = (MP_FRAMING_LAYER *)pfwLayerObjGet 												(pfwObj, "MP_FRAMING_LAYER");	if (pMpFramingLayerObj == NULL)		{		pfwPrintError (__FILE__, "mpReceiveQueueAdd", __LINE__, pfwObj, NULL, 		       "Layer object is NULL");        return (ERROR);			}	if (pMpFramingLayerObj->mpReceiveRing == NULL)		{        pfwPrintError (__FILE__, "mpReceiveQueueAdd", __LINE__, pfwObj, NULL, 		       "Receive job queue does not exist");         return (ERROR);        }	if (jobHandlerFunc == NULL)		{        pfwPrintError (__FILE__, "mpReceiveQueueAdd", __LINE__, pfwObj, NULL, 		       "Invalid argument: Null fuction pointer");        return (ERROR);        }	if (size < 0 || size > MAX_JOB_DATA_SIZE) 		{        pfwPrintError (__FILE__, "mpReceiveQueueAdd", __LINE__, pfwObj, NULL, 		       "Invalid argument: size is out of range");        return (ERROR);        }	item.jobHandlerFunc = jobHandlerFunc;	item.size = size;	totalSize = size + sizeof (MP_JOB_RING_ITEM);	if (rngFreeBytes (pMpFramingLayerObj->mpReceiveRing) >= totalSize)		{		rngBufPut (pMpFramingLayerObj->mpReceiveRing, (char *) &item, 			                                    	sizeof (MP_JOB_RING_ITEM));        rngBufPut (pMpFramingLayerObj->mpReceiveRing, (char *) data, size);		semGive (pMpFramingLayerObj->receiveSem);        return (OK);		}		return (ERROR);	}/********************************************************************************* mpSendQueueDelete - Delete the MP send Queue** This function deletes the MP send Queue.* * RETURNS: N/A** SEE ALSO: mpReceiveQueueCreate*/void mpSendQueueDelete    (    MP_FRAMING_LAYER	*pMpFramingLayerComponent    )    {	if (pMpFramingLayerComponent == NULL)		return;	rngDelete (pMpFramingLayerComponent->mpSendRing);		}/********************************************************************************* mpReceiveQueueDelete - Delete the MP receive Queue** This function deletes the MP receive Queue.* * RETURNS: N/A** SEE ALSO: mpSendQueueDelete*/void mpReceiveQueueDelete    (    MP_FRAMING_LAYER	*pMpFramingLayerComponent    )    {	if (pMpFramingLayerComponent == NULL)		return;	rngDelete (pMpFramingLayerComponent->mpReceiveRing);	}/************************end of file mpQueueTask.c*****************************/

⌨️ 快捷键说明

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