/**
* Copyright(c) 2011 Sunmedia Technologies - All Rights Reserved.
*
* @file ai_parent_control.h
*
* @brief this file defines atsc parent control api for afw layer inner.
*
* 
* 1.This file not dispose RRT, because for RRT rating only support TV-Rating/MPAA static rating information.
* 2.This file store DRRT information to cash for application get and set.
* 3.This file provide check content advisory descriptor for current program and user setting rating value.
*/

#ifndef __AI_PARENT_CONTROL_H__
#define __AI_PARENT_CONTROL_H__

#include "al_basictypes.h"
#ifdef CONFIG_ATSC_SYSTEM
#include "psip_dr.h"
#endif
#include "mid_common.h"
#include "al_parent_control.h"

#define AL_ZERO_MALLOC_FUNC(func_malloc, x) \
({ \
	UINT32 x_align = (x + (HAL_DCACHE_LINE_SIZE-1)) & (~(HAL_DCACHE_LINE_SIZE-1));	\
	UINT8 *ret = (UINT8 *)func_malloc(x_align);	\
	if(ret) memset(ret, 0, x_align); \
	else printf("alloc memery failed\n"); \
	ret; \
})

#define AL_SAFR_FREE_FUNC(func_free, p)		{if(p){ func_free(p); p = al_null;}}

/**< malloc cached DRAM-A or DRAM-B when A not enough */
#define al_zero_malloc(x) 			AL_ZERO_MALLOC_FUNC(GL_MemAlloc, x)
/**< free */
#define AL_SAFE_FREE(p)				AL_SAFR_FREE_FUNC(GL_MemFree, p)

/**
* @brief Define message type of parent control component, usted to notify framwork.
*/
typedef enum
{
	AI_PC_DRRT_UPDATE, /**< Received new drrt table, need notify uplayer update */
	
	AI_PC_MAX,
} AI_PC_Message_Type_t;

/**
* @brief call back function prototype for framwork to register.
*/
typedef	al_int32 (* AI_pfPCCallback)(AI_PC_Message_Type_t EventType, al_uint32 u32Param);

/**
* @brief This structure is store/access a rating value.
*/
typedef struct 
{
	al_uint8 StrLen; /**< length of aucString */
	al_uint8 *String; /**< a rating value's abbreviation defined in DRRT table */
} AI_PC_RatingValue_t;

/**
* @brief This structure is store/access a rating dimension and its rating value.
*/
typedef struct
{
	struct 
	{
		al_uint8 StrLen; /**< length of aucString */
		al_uint8 *String; /**< a rating dimension defined in DRRT table */
	} stDimensionName; /**< Struct represents a rating dimension information defined in RRT */
	
	al_uint8 GraduatedScale:1; /**< Graduate scale for a rating dimension defined in RRT */
	al_uint8 NumOfValues:4; /**< Number of rating value contained in this dimension defined in RRT */
	al_uint8 Reserved:3;
	AI_PC_RatingValue_t *RatingValue; /**< rating value information in this dimension */
} AI_PC_RatingDimension_t;

/**
* @brief This structure is store/access a rating dimension and its rating value.
*/
typedef struct
{
	al_uint8 NumOfDimensions; /**< Number of dimensions defined in RRT */
	AI_PC_RatingDimension_t *RatingDimensions; /**< all dimensions infromation defined in RRT */
} AI_PC_RRT_t;

/**
* @brief check rating value according to content advisory XDS data, refer to CEA608C 9.5.1.5.
*
* @param pu8Data[input] the content advisory XDS data which has 2-byte data.
*
* @param bLocked[output] geted lock state.
*
* @return AL_SUCCESS check rating successed, other value check rating failed.
*/
AL_Return_t AI_PC_CheckXDSRating(al_uint8 *pu8Data, al_bool *bLocked);
#ifdef CONFIG_ATSC_SYSTEM
/**
* @brief regist to mid psi monitor callback function for get and parse RRT information.
*
* @param pData[output] RRT information.
*
* @return none.
*/
al_void AI_PC_RrtCallback(al_void *pData);
#endif
/**
* @brief parent control init function.
*
* @param pfPCCallbks[input] parent control notify framwork callback function.
*
* @return AL_SUCCESS if initialization is successful, AL_FAILURE otherwise.
*/
AL_Return_t AI_PC_Init(AI_pfPCCallback pfPCCallbks);

/**
* @brief parent control uninit function.
*
* @param none.
*
* @return AL_SUCCESS if initialization is successful, AL_FAILURE otherwise.
*/
AL_Return_t AI_PC_Uninit(al_void);
#ifdef CONFIG_ATSC_SYSTEM
/**
* @brief get current region set by user
*
* @param region_id[input] specify the region.
*
* @return AL_SUCCESS if set region success, AL_FAILURE otherwise.
*/
AL_Return_t AI_PC_GetCurrentRegion(AL_PC_region_list_t *region_id);
#endif
#endif	/* __AI_PARENT_CONTROL_H__ */

