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

📄 sysdep.c

📁 基于h323协议的软phone
💻 C
字号:
/***************************************************************************
*
*  Module:         SysDep.c
*
*  Description:    Phone-On-A-Chip system dependent routines.
*
*  Author:         Doug Oucharek
*
*  Copyright 2000, Trillium Digital Systems, Inc., All rights reserved
*
*
*  Change Log:
*
*  Date        By      Description
*  ========    ===     ====================================================
*  01/31/00    DSO     Created
*
***************************************************************************/

/*
 * Includes
 */

#include "SysDep.h"

/*
 * Typedefs
 */

/*
 * Global variables
 */

static MSG_Q_ID theMsgQId = NULL;
static BufDef   theBuffers[MAX_BUFFERS];

static SEM_ID bufferSem;

/******************************************************************************
 *                                                                            *
 * Message Queue Handling Routines.  These include buffer handling routines.
 *                                                                            *
 *****************************************************************************/

/***************************************************************************
 *
 *  MQInit()
 *
 *  Arguments
 *      Input: None
 *
 *  Returns:   int - return code of queue creation.
 *
 *  Description:
 *  1. Create the message queue.
 *  2. Create a buffer pool for sending and receiving messages.
 *
 **************************************************************************/

int MQInit( void )
{
    int  i;

    if (theMsgQId != NULL)
        /*  We have been initialized already.  */
        return (OK);

    if ((theMsgQId = msgQCreate( MAX_BUFFERS, MAX_BUF_LEN, MSG_Q_FIFO ))
           == NULL)
        return (ERROR);

    for (i = 0; i < MAX_BUFFERS; i++)
        theBuffers[i].InUse = FALSE;

    if ((bufferSem = semBCreate( SEM_Q_PRIORITY, SEM_EMPTY )) == NULL)
    {
        return (ERROR);
    }
    semGive(bufferSem);

    return (OK);
}

/***************************************************************************
 *
 *  MQSend()
 *
 *  Arguments
 *      Input: char* - pointer to buffer to send.
 *
 *  Returns:   int - return code of send.
 *
 *  Description:
 *  1. Send the given message to the owner of the message queue.
 *
 **************************************************************************/

int MQSend( char *givenMsg, int WaitTime )
{
    return (msgQSend( theMsgQId, (char*)&givenMsg, sizeof(givenMsg), WAIT_FOREVER,
        MSG_PRI_NORMAL ));
}

/***************************************************************************
 *
 *  MQReceive()
 *
 *  Arguments
 *      Input: int - time to wait for.
 *
 *  Returns:   Pointer to returned buffer.
 *             Event which was received (pointer parameter)
 *
 *  Description:
 *  1. Get a message off of my message queue.
 *
 **************************************************************************/

char *MQReceive( int *theEvent, int WaitTime )
{
    char *thePointer;
    int  *intPtr;

    if (msgQReceive( theMsgQId, (char*)&thePointer, sizeof(thePointer), WaitTime )
            == ERROR)
    {
    	if (errno == S_objLib_OBJ_TIMEOUT)
    	{
    		*theEvent = timeout_event;
    	}
	else
	{
		*theEvent = null_event;
	}
	
        return (NULL);
    }

    /*
     * We can derive the event type from the first int of the message.
     */
    intPtr = (int *) thePointer;
    *theEvent = intPtr[0];
    return (thePointer);
}

/***************************************************************************
 *
 *  MQBufFree()
 *
 *  Arguments
 *      Input: Pointer to buffer being returned.
 *
 *  Returns:   Nothing
 *
 *  Description:
 *  1. Put the given message buffer back into the buffer pool.
 *
 **************************************************************************/

void MQBufFree( char *retBuf )
{
    int  i;
	
    semTake(bufferSem, WAIT_FOREVER);
    for (i = 0; i < MAX_BUFFERS; i++)
    {
        if ((theBuffers[i].InUse) && (retBuf == theBuffers[i].Buf))
        {
            theBuffers[i].InUse = FALSE;
            semGive(bufferSem);
            return;
        }
    }
    semGive(bufferSem);
}

/***************************************************************************
 *
 *  MQBufGet()
 *
 *  Arguments
 *      Input: None
 *
 *  Returns:   Pointer to buffer (char *) or NULL if no buffers.
 *
 *  Description:
 *  1. Get a message buffer from the buffer pool.
 *
 **************************************************************************/

char *MQBufGet( void )
{
    int  i;
	
    semTake(bufferSem, WAIT_FOREVER);
    for (i = 0; i < MAX_BUFFERS; i++)
    {
        if (!theBuffers[i].InUse)
        {
            theBuffers[i].InUse = TRUE;
            semGive(bufferSem);
            return (theBuffers[i].Buf);
        }
    }
    semGive(bufferSem);
    return (NULL);
}


/******************************************************************************
 *                                                                            *
 * Task Spawn Handling Routines.
 *                                                                            *
 *****************************************************************************/

/***************************************************************************
 *
 *  SpawnTask()
 *
 *  Arguments
 *      Input: char* - String with name for task.
 *             FUNCPTR - Pointer to function which is main for task.
 *             char - boolean indicating if the taskProc should be passed the
 *                    message queue ID.
 *
 *  Returns:   int - return code for task spawn.
 *
 *  Description:
 *  1. Spawn off a listening task and get it running the indicated routine.
 *
 **************************************************************************/

int SpawnTask( char *taskId, FUNCPTR taskProc, char giveMsgQueue,
                int priority, int stackSize )
{
    if (!giveMsgQueue)
        return (taskSpawn( taskId, priority, (int)NULL, stackSize, taskProc,
                   (int)NULL, (int)NULL, (int)NULL, (int)NULL, (int)NULL,
                   (int)NULL, (int)NULL, (int)NULL, (int)NULL, (int)NULL ));
    else
        return (taskSpawn( taskId, priority, (int)NULL, stackSize, taskProc,
                    (int)theMsgQId, (int)NULL, (int)NULL, (int)NULL, (int)NULL,
                    (int)NULL, (int)NULL, (int)NULL, (int)NULL, (int)NULL ));

}

⌨️ 快捷键说明

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