📄 usrapi.c
字号:
/*****************************************************************************
******************************************************************************
** **
** Copyright (c) 2002 Videon Central, Inc. **
** All rights reserved. **
** **
** The computer program contained herein contains proprietary information **
** which is the property of Videon Central, Inc. The program may be used **
** and/or copied only with the written permission of Videon Central, Inc. **
** or in accordance with the terms and conditions stipulated in the **
** agreement/contract under which the programs have been supplied. **
** **
******************************************************************************
*****************************************************************************/
/**
* @file usrapi.c
*
* API for sending unsolicited status events from the nav.
*
* $Id: usrapi.c,v 1.25 2007/01/26 20:33:24 rbehe Exp $
*/
#include "vdvd_types.h"
#include "usrapi.h"
#include "osapi.h"
#include "dbgprint.h"
/* Debug macros */
#define DBG_USR DBG_TRACE
#define DBG_ON(x) (DBG_USR >= x)
/**
* Local constants
*/
#define USR_MAX_NUMBER_OF_CALLBACKS 2
/**
* Local data handle
*/
typedef struct tagUSR_HANDLE
{
BOOLEAN fInitialized;
OS_SEM_ID critical_section;
USR_CALLBACK func[USR_MAX_NUMBER_OF_CALLBACKS];
PVOID pvContext[USR_MAX_NUMBER_OF_CALLBACKS];
} USR_HANDLE;
/**
* Local variables
*/
static USR_HANDLE m_hUsr = {FALSE, 0, {NULL}, {NULL} };
/**
* UsrInitialize -- Initialize the USRAPI.
*
* @param
* none.
*
* @retval
* USR_SUCCESS if successful
* USR_FAILURE if not successful
*/
USR_STATUS UsrInitialize(void)
{
ULONG i;
if (m_hUsr.fInitialized == TRUE)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("UsrInitialize: USRAPI already initialized!\n"));
return (USR_FAILURE);
}
/* Create critical section semaphore */
m_hUsr.critical_section = OS_SemBCreate(OS_SEM_Q_FIFO, TRUE);
if (0 == m_hUsr.critical_section)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("UsrInitialize: Failure creating sem!\n"));
goto errout;
}
/* Clear function pointers */
for (i = 0; i < USR_MAX_NUMBER_OF_CALLBACKS; i++)
{
m_hUsr.func[i] = NULL;
m_hUsr.pvContext[i] = NULL;
}
/* Set initialization flag */
m_hUsr.fInitialized = TRUE;
return (USR_SUCCESS);
errout:
if (m_hUsr.fInitialized == TRUE)
{
/* Unset initialization flag */
m_hUsr.fInitialized = FALSE;
}
if (m_hUsr.critical_section != 0)
{
/* Delete critical section sem */
OS_SemDelete(m_hUsr.critical_section);
m_hUsr.critical_section = 0;
}
return (USR_FAILURE);
}
/**
* UsrUninitialize -- Unnitialize the USRAPI.
*
* @param
* none.
*
* @retval
* USR_SUCCESS if successful
* USR_FAILURE if not successful
*/
USR_STATUS UsrUninitialize(void)
{
if (m_hUsr.fInitialized == TRUE)
{
ULONG i;
/* entering critical section */
OS_SemTake(m_hUsr.critical_section, OS_WAIT_FOREVER);
/* Clear function pointers */
for (i = 0; i < USR_MAX_NUMBER_OF_CALLBACKS; i++)
{
m_hUsr.func[i] = NULL;
m_hUsr.pvContext[i] = NULL;
}
/* leaving critical section */
OS_SemGive(m_hUsr.critical_section);
/* Delete critical section sem */
OS_SemDelete(m_hUsr.critical_section);
m_hUsr.critical_section = 0;
/* Unset initialization flag */
m_hUsr.fInitialized = FALSE;
}
return (USR_SUCCESS);
}
/**
* UsrIsInitialized -- Check if the USRAPI is initialized.
*
* @param
* none.
*
* @retval
* TRUE if USRAPI is initialized
* FALSE if USRAPI is not initialized
*/
BOOLEAN UsrIsInitialized(void)
{
return (m_hUsr.fInitialized);
}
/**
* UsrRegisterCallback -- Register to receive unsolicited status events from the nav.
*
* @param
* callback -- pointer to function to receive callback
* pvParam -- PVOID to be received with callback
*
* @retval
* USR_SUCCESS if successful
* USR_FAILURE if not successful
*/
USR_STATUS UsrRegisterCallback(USR_CALLBACK callback, PVOID pvParam)
{
ULONG i;
USR_STATUS status = USR_FAILURE;
/* Check that USRAPI is intialized */
if (m_hUsr.fInitialized == FALSE)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("UsrRegisterCallback: USRAPI not initialized!\n"));
return (USR_FAILURE);
}
/* Check that callback is a valid function pointer */
if (callback == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("UsrRegisterCallback: Bad function pointer!\n"));
return (USR_NULL_POINTER);
}
/* entering critical section */
OS_SemTake(m_hUsr.critical_section, OS_WAIT_FOREVER);
/*
* Search for a function pointer not being used and set it to
* this registered callback.
*/
for (i=0; i < USR_MAX_NUMBER_OF_CALLBACKS; i++)
{
if (m_hUsr.func[i] == NULL)
{
m_hUsr.func[i] = callback;
m_hUsr.pvContext[i] = pvParam;
status = USR_SUCCESS;
break;
}
}
/* leaving critical section */
OS_SemGive(m_hUsr.critical_section);
return (status);
}
/**
* UsrRemoveCallback -- Remove callback that was registered.
*
* @param
* callback -- pointer to function that was registered for callbacks
*
* @retval
* USR_SUCCESS if successful
* USR_FAILURE if not successful
*/
USR_STATUS UsrRemoveCallback(USR_CALLBACK callback)
{
ULONG i;
USR_STATUS status = USR_FAILURE;
/* Check that USRAPI is intialized */
if (m_hUsr.fInitialized == FALSE)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("UsrRemoveCallback: USRAPI not initialized!\n"));
return (USR_FAILURE);
}
/* Check that callback is a valid function pointer */
if (callback == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("UsrRemoveCallback: Bad function pointer!\n"));
return (USR_NULL_POINTER);
}
/* entering critical section */
OS_SemTake(m_hUsr.critical_section, OS_WAIT_FOREVER);
/*
* Search for this callback in function pointer list and remove it.
*/
for (i=0; i < USR_MAX_NUMBER_OF_CALLBACKS; i++)
{
if (m_hUsr.func[i] == callback)
{
m_hUsr.func[i] = NULL;
m_hUsr.pvContext[i] = NULL;
status = USR_SUCCESS;
break;
}
}
/* leaving critical section */
OS_SemGive(m_hUsr.critical_section);
return (status);
}
/**
* UsrEventHandler Function. Either send message to osd task, or send response.
*
* @param
* ulMessage - Message that contains response and information
*
* @retval
* PSL_SUCCESS if successful
* PSL_FAILURE if not successful
*/
USR_STATUS UsrEventHandler(ULONG *pulEvent)
{
ULONG i;
/* Check that USRAPI is intialized */
if (m_hUsr.fInitialized == FALSE)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("UsrEventHandler: USRAPI not initialized!\n"));
return (USR_FAILURE);
}
/* Check that event pointer is valid */
if (pulEvent == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("UsrEventHandler: Bad pointer!\n"));
return (USR_NULL_POINTER);
}
/* Check that status event is valid */
if (pulEvent[0] >= (ULONG)VDVD_STATUS_MAX)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("UsrEventHandler: Invalid status event type!\n"));
return (USR_FAILURE);
}
/* Send unsolicted status event to registered callbacks */
for (i=0; i < USR_MAX_NUMBER_OF_CALLBACKS; i++)
{
if (m_hUsr.func[i] != NULL)
{
/* Send event to registered callback */
m_hUsr.func[i](pulEvent, m_hUsr.pvContext[i]);
}
}
return (USR_SUCCESS);
}
/*
* Public helper function for sending prohibited messages.
*/
USR_STATUS UsrSendProhibitedEvent(ULONG info, ULONG cmd)
{
ULONG out_msg[4];
out_msg[0] = VDVD_STATUS_PROHIBITED;
out_msg[1] = info;
out_msg[2] = cmd;
return ( UsrEventHandler(out_msg) );
}
/*
* Public helper function for sending repeat mode messages.
*/
USR_STATUS UsrSendRepeatEvent(VDVD_INFO_REPEAT info)
{
ULONG out_msg[4];
out_msg[0] = VDVD_STATUS_REPEAT;
out_msg[1] = info;
return ( UsrEventHandler(out_msg) );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -