/**
* Copyright(c) 2011 Sunmedia Technologies - All Rights Reserved.
*
* @file al_parent_control.h
*
* @brief this file defines atsc parent control api for up layer.
*
* 
* 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 __AL_PARENT_CONTROL_H__
#define __AL_PARENT_CONTROL_H__

#include "al_basictypes.h"
#ifdef CONFIG_ATSC_SYSTEM
#include "psip.h"
#include "psip_dr.h"
#endif

#define MAX_DIMENNAME_LEN   (20*2+1)
#define MAX_RATINGNAME_LEN  (8*2+1)
#define MAX_RATING_DIM      (20)
#define MAX_NUM_OF_RATINGS  (15)


typedef enum
{
	AL_PC_REG_NONE = 0,
	AL_PC_REG_USA,
	AL_PC_REG_CANADA,
	AL_PC_REG_TAIWAN,
	AL_PC_REG_KOREA,
	AL_PC_REG_DRRT
} AL_PC_region_list_t;

typedef enum
{
	AL_PC_PRESET_OFF,
	AL_PC_PRESET_CHILD,
	AL_PC_PRESET_YOUTH,
	AL_PC_PRESET_ADULT,
	AL_PC_PRESET_CUSTOM
} AL_PC_preset_mode_t;

typedef enum
{
	AL_PC_TV_Y_NULL,
	AL_PC_TV_Y,
	AL_PC_TV_Y7,
	AL_PC_TV_Y7_FV
} AL_PC_us_child_t;

typedef enum 
{	
	AL_PC_TV_NULL,
	AL_PC_TV_G,
	AL_PC_TV_PG,
	AL_PC_TV_14,
	AL_PC_TV_MA,
} AL_PC_us_tv_t;

typedef enum 
{
	AL_PC_VIO_NULL,
	AL_PC_VIO_PG,
	AL_PC_VIO_14,
	AL_PC_VIO_MA,
} AL_PC_us_vio_t;

typedef enum 
{
	AL_PC_SEX_NULL,
	AL_PC_SEX_PG,
	AL_PC_SEX_14,
	AL_PC_SEX_MA,
} AL_PC_us_sex_t;

typedef enum 
{
	AL_PC_LAN_NULL,
	AL_PC_LAN_PG,
	AL_PC_LAN_14,
	AL_PC_LAN_MA,
} AL_PC_us_lan_t;

typedef enum 
{
	AL_PC_DIA_NULL,
	AL_PC_DIA_PG,
	AL_PC_DIA_14,
	AL_PC_DIA_NA,
} AL_PC_us_dia_t;

typedef enum 
{
	AL_PC_MPAA_NULL,
	AL_PC_MPAA_NA,
	AL_PC_MPAA_G,
	AL_PC_MPAA_PG,
	AL_PC_MPAA_PG_13,
	AL_PC_MPAA_R,
	AL_PC_MPAA_NC_17,
	AL_PC_MPAA_X,
	AL_PC_MPAA_NR,
} AL_PC_us_mpaa_t;

typedef enum 
{
	/* ADD FOR NULL */
	AL_PC_ENG_NULL = 0,
	AL_PC_ENG_EXEMPT = 0x8,
	AL_PC_ENG_CHILD = 0x1,
	AL_PC_ENG_8_P = 0x2,
	AL_PC_ENG_GENERAL = 0x3,
	AL_PC_ENG_PG = 0x4,
	AL_PC_ENG_14 = 0x5,
	AL_PC_ENG_18 = 0x6,
} AL_PC_can_eng_t;

typedef enum 
{
	/* ADD FOR NULL */
	AL_PC_FRA_NULL = 0,
	AL_PC_FRA_EXEMPT = 0x8,
	AL_PC_FRA_ALL = 0x1,
	AL_PC_FRA_8_P = 0x2,
	AL_PC_FRA_13 = 0x3,
	AL_PC_FRA_16 = 0x4,
	AL_PC_FRA_18 = 0x5,
} AL_PC_can_fra_t;

typedef struct
{
	AL_PC_us_tv_t	us_tv;
	AL_PC_us_dia_t	us_dia;
	AL_PC_us_lan_t	us_lan;
	AL_PC_us_sex_t	us_sex;
	AL_PC_us_vio_t	us_vio;
	AL_PC_us_child_t	us_child;
	AL_PC_us_mpaa_t	us_mpaa;
} AL_PC_us_rat_t;
#if 0
typedef enum
{
	AL_PC_US_TV = 0x10,
	AL_PC_US_DIA = 0x20,
	AL_PC_US_LAN = 0x30,
	AL_PC_US_SEX = 0x40,
	AL_PC_US_VIO = 0x50,
	AL_PC_US_CHILD = 0x60,
	AL_PC_US_MPAA = 0x70,
	AL_PC_CAN_ENG = 0x80,
	AL_PC_CAN_FRA = 0x90,
} AL_PC_dimen_all_t;
#else
typedef enum
{
	AL_PC_US_TV = 1<<4,
	AL_PC_US_DIA = 1<<5,
	AL_PC_US_LAN = 1<<6,
	AL_PC_US_SEX = 1<<7,
	AL_PC_US_VIO = 1<<8,
	AL_PC_US_CHILD = 1<<9,
	AL_PC_US_MPAA = 1<<10,
	AL_PC_CAN_ENG = 1<<11,
	AL_PC_CAN_FRA = 1<<12,
} AL_PC_dimen_all_t;
#endif

typedef	struct
{
	AL_PC_can_eng_t	can_eng;
	AL_PC_can_fra_t	can_fra;
} AL_PC_can_rat_t;	

typedef 	struct
{
	AL_PC_region_list_t region;
	struct
	{
		AL_PC_us_rat_t	us_mem;
		AL_PC_can_rat_t	can_mem;
	};
} AL_PC_dime_t;


/**
* @brief It defines the maximum dimension, it depends on settings in middleware.
*/
#define AL_PARENTCONTROL_MAX_DIM	(MAX_RATING_DIM)

/**
* @brief It defines the maximum rating, it depends on settings in middleware.
*/
#define AL_PARENTCONTROL_MAX_RATING	(MAX_NUM_OF_RATINGS)

/**
* @brief It keeps the UI status from UI.
*/
typedef struct
{
	/**< store all dimension's all rating value setting, one bit store one rating value setting, al_true: set/al_false: not set */
	al_uint8 u8aDrrtUserPerference[AL_PARENTCONTROL_MAX_DIM][(AL_PARENTCONTROL_MAX_RATING+7)/8]; 
} AL_PC_DimenUserSet_t;

/**
* @brief get dimension details
*
* @param pstDime[output] pointer to the demension data.
*
* @return AL_SUCCESS if get demension success, AL_FAILURE otherwise.
*/
AL_Return_t AL_PC_GetRating(AL_PC_dime_t *pstDime);

/**
* @brief API to Encode User Set Rating level
*
* @param pc_app[output] the demension data.
*
* @param RatingDime[input] specify which dimension
*
* @param DimeValue[input]demension value
*
* @Lock[input] al_true if locked, al_false if unlocked.
* 
* @return AL_SUCCESS if encode success, AL_FAILURE otherwise.
*/
AL_Return_t AL_PC_SetRating(AL_PC_dime_t *pc_app, AL_PC_dimen_all_t RatingDime, 
	al_uint8 DimeValue, al_bool Lock);

/**
* @brief API to  store User Set Rating level to flash
*
* @param pststDime[iutput] the demension data.
* 
* @return AL_SUCCESS if encode success, AL_FAILURE otherwise.
*/
AL_Return_t AL_PC_StoreRating(AL_PC_dime_t *pststDime);

al_uint32 AL_PC_GetCurrRatingDimen(void);

al_uint32 AL_PC_GetOriginalRatingDimen(void);
#ifdef CONFIG_ATSC_SYSTEM
/**
* @brief get dimension number from DRRT information.
*
* @param pDimenNum[output] dimension total number.
*
* @return AL_SUCCESS if get dimension number success, AL_FAILURE otherwise.
*/
AL_Return_t AL_PC_GetDRRTDimenNum(al_uint8 *pDimenNum);

/**
* @brief get one dimension information of Dimenindex.
*
* @param DimenIndex[input] dimension index.
*
* @param pGradScale[output] the garduated scale of the dimension of dimension index.
*
* @param pDimenName[output] the dimension name of the dimension of dimension index.
*
* @param pDimenNameLen[output] the dimension name length of the dimension of dimension index.
*
* @param pRatingNum[output] the rating value total number of the dimension of dimension index.
*
* @return AL_SUCCESS if get dimension information success, AL_FAILURE otherwise.
*/
AL_Return_t AL_PC_GetDRRTDimenInfo(al_uint8 DimenIndex, 
	al_bool *pGradScale, al_uint8 *pDimenName, al_uint8 *pDimenNameLen, al_uint8 *pRatingNum);

/**
* @brief get one rating value information of Dimenindex and rating index.
*
* @param DimenIndex[input] dimension index.
*
* @param RatingIndex[input] the rating index of the dimension of dimension index.
*
* @param pRatingName[output] the rating name of the rating of dimension index and rating index.
*
* @param pRatingNamLen[output] the rating name length of the rating  of dimension index and rating index.
*
* @return AL_SUCCESS if get rating information success, AL_FAILURE otherwise.
*/
AL_Return_t AL_PC_GetDRRTRatingInfo(al_uint8 DimenIndex, 
	al_uint8 RatingIndex, al_uint8 *pRatingName, al_uint8 *pRatingNamLen);

/**
* @brief Set the lock flag for dimension index and rating index form user setting valuses.
*
* @param DrrtUserSeting[output] user setting valuses.
*
* @param DimenIndex[input] the dimension index
*
* @param RatingIndex[input] the rating index of the dimension of dimension index.
*
* @param bLock[input] the lock flag of the rating of dimension index and rating index.
*
* @return AL_SUCCESS if get demension success, AL_FAILURE otherwise.
*/
AL_Return_t AL_PC_SetDRRTRatingLock(AL_PC_DimenUserSet_t *pDimenUserSeting, 
	al_uint8 DimenIndex, al_uint8 RatingIndex, al_bool bLock);

/**
* @brief Get the lock flag for dimension index and rating index form user setting valuses.
*
* @param DrrtUserSeting[input] user setting valuses.
*
* @param DimenIndex[input] the dimension index
*
* @param RatingIndex[input] the rating index of the dimension of dimension index.
*
* @param bLock[output] the lock flag of the rating of dimension index and rating index.
*
* @return AL_SUCCESS if get demension success, AL_FAILURE otherwise.
*/
AL_Return_t AL_PC_GetDRRTRatingLock(AL_PC_DimenUserSet_t DrrtUserSeting, 
	al_uint8 DimenIndex, al_uint8 RatingIndex, al_bool *bLock);
#endif
AL_Return_t AL_PC_Reset(al_void);
#ifdef CONFIG_ATSC_SYSTEM
/**
* @brief check rating value according to current program's content advisory descriptor.
*
* @param pstContentAdvDesc[input] the content advisory descriptor of current program.
*
* @param bLocked[output] geted lock state.
*
* @return AL_SUCCESS check rating successed, other value check rating failed.
*/
AL_Return_t AL_PC_CheckRating(ContentAdvDesc_t *pstContentAdvDesc, al_bool *bLocked);
#endif
#endif
