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

📄 psl_interface.cpp

📁 这是DVD中伺服部分的核心代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        if (m_hPsl->pPsl != NULL)
        {
            /* Delete the PSL handle */
            OS_MemFree(m_hPsl->pPsl);
            m_hPsl->pPsl = NULL;
        }

        /* Delete the local handle */
        OS_MemFree(m_hPsl);
        m_hPsl = NULL;
    }

    return (PSL_FAILURE);
}

/**
 * PslDelete -- Delete the PSL.
 *
 * @param
 *    none.
 *
 * @retval
 *    PSL_SUCCESS if successful
 *    PSL_FAILURE if not successful
 */
PSL_STATUS  PslDelete(void)
{
    if (m_hPsl != NULL)
    {
        PSL_MESSAGE msg;

        /* Send an abort message to the PSL task */
        msg.tMsgType        = PSL_MSG_ABORT;
        msg.pvBuffer        = NULL;
        msg.ulBufferLength  = 0;
        msg.ulData0         = 0;
        msg.ulData1         = 0;
        msg.ulData2         = 0;
        msg.ulSemID         = 0;
        OS_MsgQSend(m_hPsl->msg_queue, (char *)&msg, sizeof(PSL_MESSAGE), OS_NO_WAIT, OS_MSG_PRI_NORMAL);

        /* Wait for PSL task to exit then delete the task */
        OS_TaskJoin(m_hPsl->ulTaskId);
        OS_TaskDelete(m_hPsl->ulTaskId);
        m_hPsl->ulTaskId = 0;

        /* Delete the PSL msg queue */
        OS_MsgQDelete(m_hPsl->msg_queue);
        m_hPsl->msg_queue = 0;

        /* Delete the command processing semaphore */
        if (0 != m_hPsl->cmd_processing_sem)
        {
            OS_SemDelete(m_hPsl->cmd_processing_sem);
            m_hPsl->cmd_processing_sem = 0;
        }

        /* Delete the PSL handle */
        OS_MemFree(m_hPsl->pPsl);
        m_hPsl->pPsl = NULL;

        /* Delete the local handle */
        OS_MemFree(m_hPsl);
        m_hPsl = NULL;
    }

    DBGPRINT(DBG_ON(DBG_TRACE), ("PslDelete: PSL deleted\n"));

    return (PSL_SUCCESS);
}

/**
 * PslSendInitialize -- Send an initialization message to the PSL thread.
 *
 * @param
 *      ulSemID     - Id of semaphore used to block application from exiting
 *
 * @retval
 *    PSL_SUCCESS if successful
 *    PSL_FAILURE if not successful
 */
PSL_STATUS PslSendInitialize(ULONG ulSemID)
{
    PSL_MESSAGE msg;

    /* Check that message queue is created */
    if (m_hPsl->msg_queue == 0)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslSendInitialize: Msg queue not created!\n"));
        return (PSL_FAILURE);
    }

    /* Send initialization message to the PSL task */
    msg.tMsgType        = PSL_MSG_INITIALIZE;
    msg.pvBuffer        = NULL;
    msg.ulBufferLength  = 0;
    msg.ulData0         = ulSemID;
    msg.ulData1         = 0;
    msg.ulData2         = 0;
    msg.ulSemID         = 0;
    if (OS_MsgQSend(m_hPsl->msg_queue, (char *)&msg, sizeof(PSL_MESSAGE), OS_NO_WAIT, OS_MSG_PRI_NORMAL) != OS_OK)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslSendInitialize: Failure sending message!\n"));
        return (PSL_FAILURE);
    }

    return (PSL_SUCCESS);
}

/**
 * PslSendProcessUserInput -- Send user input command to the PSL task
 *
 * @param
 *      tUserInput  -- User command to process
 *      ulInfo      -- Information with the command
 *      ulSemID     -- Id of synchronization semaphore
 *
 * @retval
 *    PSL_SUCCESS if successful
 *    PSL_FAILURE if not successful
 */
PSL_STATUS  PslSendProcessUserInput(PSL_USER_INPUT_TYPE tUserInput, ULONG ulInfo, ULONG ulSemID)
{
    PSL_MESSAGE msg;

    /* Check if the psl is initialized */
    if (m_hPsl->fInit == FALSE)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslSendProcessUserInput: PSL not initialized!\n"));
        return (PSL_FAILURE);
    }

    /* Check that message queue is created */
    if (m_hPsl->msg_queue == 0)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslSendProcessUserInput: Msg queue not created!\n"));
        return (PSL_FAILURE);
    }

    /*
     * Do not let user input commands queue up.  If a command is currently
     * processing, then drop this command.
     */
    if (OS_SemTake(m_hPsl->cmd_processing_sem, OS_NO_WAIT) == OS_OK)
    {
        /* Send message to the PSL task */
        msg.tMsgType        = PSL_MSG_PROCESS_USER_INPUT;
        msg.pvBuffer        = NULL;
        msg.ulBufferLength  = 0;
        msg.ulData0         = (ULONG)tUserInput;
        msg.ulData1         = ulInfo;
        msg.ulData2         = 0;
        msg.ulSemID         = ulSemID;
        if (OS_MsgQSend(m_hPsl->msg_queue, (char *)&msg, sizeof(PSL_MESSAGE), OS_NO_WAIT, OS_MSG_PRI_NORMAL) != OS_OK)
        {
            DBGPRINT(DBG_ON(DBG_ERROR), ("PslSendProcessUserInput: Failure sending message!\n"));
            return (PSL_FAILURE);
        }

        /* If sem was specified, wait for user input to process */
        if (ulSemID != 0)
        {
            OS_SemTake(ulSemID, OS_WAIT_FOREVER);
        }
    }

    return (PSL_SUCCESS);
}

/**
 * PslSendProcessStatus -- Send status event to the PSL task
 *
 * @param
 *      tStatusEvent    -- User command to process
 *      ulDataParam1    -- data parameter 
 *      ulDataParam2    -- data parameter
 *      pvBuffer        -- Buffer with additional information about status event
 *      ulBufferSize    -- Size of pvBuffer
 *      ulSemID         -- Id of synchronization semaphore
 *
 * @retval
 *    PSL_SUCCESS if successful
 *    PSL_FAILURE if not successful
 *
 * @remark
 *      Data associated with the status event can be passed in
 *      the two data params.  If more data needs to be passed, a pointer
 *      to a buffer can be passed in pvBuffer.  The size of the buffer
 *      must be passed in ulBufferSize.  If a pointer to a buffer is passed,
 *      and a synchronization semaphore is not specified, then the buffer
 *      will be copied to a buffer that is allocated by the PSL and the
 *      message will be processed asyncronously.  Otherwise,
 *      the message will be processed synchronously.
 */
PSL_STATUS  PslSendProcessStatus(
                                 PSL_STATUS_TYPE tStatusEvent, 
                                 ULONG ulDataParam1,
                                 ULONG ulDataParam2,
                                 PVOID pvBuffer, 
                                 ULONG ulBufferSize, 
                                 ULONG ulSemID
                                )
{
    PSL_MESSAGE msg;
    PVOID       pvBuf   = NULL;

    /* Check if the psl is initialized */
    if (m_hPsl->fInit == FALSE)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslSendProcessStatus: PSL not initialized!\n"));
        return (PSL_FAILURE);
    }

    /* Check that message queue is created */
    if (m_hPsl->msg_queue == 0)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslSendProcessStatus: Msg queue not created!\n"));
        return (PSL_FAILURE);
    }

    /* 
     * If buffer is specified, but no synchronization semaphore is specified, then
     * allocate a buffer and copy the specified buffer data into it.
     */
    if (ulBufferSize > 0)
    {
        if (pvBuffer == NULL)
        {
            DBGPRINT(DBG_ON(DBG_ERROR), ("PslSendProcessStatus: Pointer to buffer is NULL!\n"));
            return (PSL_FAILURE);
        }
        else
        {
            /* Create buffer */
            pvBuf = OS_MemAlloc(ulBufferSize);
            if (pvBuf == NULL)
            {
                DBGPRINT(DBG_ON(DBG_ERROR), ("PslSendProcessStatus: Failure allocating buffer!\n"));
                return (PSL_FAILURE);
            }

            /* Copy contents of specified buffer into newly allocated buffer */
            memcpy(pvBuf, pvBuffer, ulBufferSize);
        }
    }
    else
    {
        pvBuf = pvBuffer;
    }

    /* Send message to the PSL task */
    msg.tMsgType        = PSL_MSG_PROCESS_STATUS;
    msg.ulData0         = (ULONG)tStatusEvent;
    msg.ulData1         = ulDataParam1;
    msg.ulData2         = ulDataParam2;
    msg.pvBuffer        = pvBuf;
    msg.ulBufferLength  = ulBufferSize;
    msg.ulSemID         = ulSemID;
    if (OS_MsgQSend(m_hPsl->msg_queue, (char *)&msg, sizeof(PSL_MESSAGE), OS_NO_WAIT, OS_MSG_PRI_NORMAL) != OS_OK)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("PslSendProcessStatus: Failure sending message!\n"));
        return (PSL_FAILURE);
    }

    /* If sem was specified, wait for status event to process */
    if (ulSemID != 0)
    {
        OS_SemTake(ulSemID, OS_WAIT_FOREVER);
    }

    return (PSL_SUCCESS);
}

/**
 * InitUserInputCommands -- Map user input commands to user input functions
 *
 * @param
 *      none
 *
 * @retval
 *    none
 */
static void InitUserInputCommands(void)
{
    m_hPsl->ProcessUserInput[PSL_USER_INPUT_POWER]          = PslProcessUserInputPower;

⌨️ 快捷键说明

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