/**
* Copyright(c) 2011 Sunmedia Technologies - All Rights Reserved.
*
* @file al_service.h
*
* The interface to init, uninit and manipulate service.
*
* @brief Gives the functionalities for quering as well as manipulating
* 		the database on service related data.
*
* @note .
*/

#ifndef __AL_SERVICE_DBMERGE_H__
#define __AL_SERVICE_DBMERGE_H__

#include "al_basictypes.h"
#include "al_database.h"

#ifdef __cplusplus
	extern "C"{
#endif

/****************************************************
 * Enumeration definition
 ****************************************************//**
 * @addtogroup EnumDef Enumeration definition
 * @{
 ********************************************************/
/**
* @brief Enumeration of DVB service attribute.
*/
typedef enum
{
	AL_SRV_DATTRIB_FAV1 = 1 << 1,				/**<  fave 1 bit*/
	AL_SRV_DATTRIB_FAV2 = 1 << 2,				/**<  fave 2 bit*/
	AL_SRV_DATTRIB_FAV3 = 1 << 3,				/**<  fave 3 bit*/
	AL_SRV_DATTRIB_FAV4 = 1 << 4,				/**<  fave 4 bit*/
	AL_SRV_DATTRIB_FAV5 = 1 << 5,				/**<  fave 5 bit */
	AL_SRV_DATTRIB_FAV6 = 1 << 6,				/**<  fave 6 bit*/
	AL_SRV_DATTRIB_FAV7 = 1 << 7,				/**<  fave 7 bit*/
	AL_SRV_DATTRIB_FAV8 = 1 << 8,				/**<  fave 8 bit*/
	AL_SRV_DATTRIB_MOVE = 1 << 9,				/**<  move bit*/
	AL_SRV_DATTRIB_SKIP = 1 << 10,				/**<  skip bit*/
	AL_SRV_DATTRIB_DEL = 1 << 11,    			/**<  delete bit*/
	AL_SRV_DATTRIB_UNSTABLE = 1 << 12,    		/**<  unstable bit*/
	AL_SRV_DATTRIB_LOCK = 1 << 13,				/**<  parental lock bit*/
	AL_SRV_DATTRIB_SCAMBLE = 1 << 14,			/**<  scramble bit*/
	AL_SRV_DATTRIB_NOTRUN = 1 << 15,			/**<  */
	AL_SRV_DATTRIB_TMPSRV = 1 << 16,			/**< temp service type */
	AL_SRV_DATTRIB_MPEG4TYPE = 1 << 17,  		/**< mpeg4 type  */
	AL_SRV_DATTRIB_VIDEOAVC = 1 << 18,  		/**< avc type  */
	AL_SRV_DATTRIB_NOTVISIBLE = 1 << 19,  		/**< not visible */
	AL_SRV_DATTRIB_NOTSELETECTABLE = 1 << 20, 	/**< not selectable type  */
	AL_SRV_DATTRIB_FREECA = 1 << 21,  			/**< free CA type  */
	AL_SRV_DATTRIB_NAMEMODIFIED = 1 << 22,		/**< program name modified by user */
	AL_SRV_DATTRIB_NITMATCH = 1 <<23,			/**< network id matched */
	AL_SRV_DATTRIB_ONIDMATCH = 1 << 24,		/**< origine network matched */
    AL_SRV_DATTRIB_PROGNAMEMATCH = 1 << 25,       /**<  program name matched */
	AL_SRV_DATTRIB_CIPLUSUSED = 1 << 26,   /**<  only ci plus direct tune and play used */

	AL_SRV_DATTRIB_MAX = 1 << 31,
} AL_Serv_EDigitalAttrib_t;

/**
* @brief Enumeration of Analog service attribute.
*/
typedef enum
{
	AL_SRV_AATTRIB_FAV1 = 1 << 1,			/**<  fave 1 bit*/
	AL_SRV_AATTRIB_FAV2 = 1 << 2,			/**<  fave 2 bit*/
	AL_SRV_AATTRIB_FAV3 = 1 << 3,			/**<  fave 3 bit*/
	AL_SRV_AATTRIB_FAV4 = 1 << 4,			/**<  fave 4 bit*/
	AL_SRV_AATTRIB_FAV5 = 1 << 5,			/**<  fave 5 bit */
	AL_SRV_AATTRIB_FAV6 = 1 << 6,			/**<  fave 6 bit*/
	AL_SRV_AATTRIB_FAV7 = 1 << 7,			/**<  fave 7 bit*/
	AL_SRV_AATTRIB_FAV8 = 1 << 8,			/**<  fave 8 bit*/
	AL_SRV_AATTRIB_INUSE = 1 << 9,			/**<  inuse bit*/
	AL_SRV_AATTRIB_SKIP = 1 << 10,			/**<  skip bit*/
	AL_SRV_AATTRIB_DEL = 1 << 11,    		/**<  delete bit*/
	AL_SRV_AATTRIB_LOCK = 1 << 12,			/**<  parental lock bit*/
	AL_SRV_AATTRIB_AFC = 1 << 13,			/**<  AFC bit*/

    AL_SRV_AATTRIB_TVTYPE = 1 << 14,
    AL_SRV_AVATTRIB_VALID = 1 << 15,

	AL_SRV_AATTRIB_MAX = 1 << 31,
} AL_Serv_EAnalogAttrib_t;

/**
* @brief Enumeration of search field.
*/
typedef enum
{
    AL_SRV_SEARCHFIELD_TSID = 1 << 1,
    AL_SRV_SEARCHFIELD_SRVID = 1 << 2,
    AL_SRV_SEARCHFIELD_ORIGNETID = 1 << 3,
    AL_SRV_SEARCHFIELD_PROGNO = 1 << 4,
    AL_SRV_SEARCHFIELD_FREQ = 1 << 5,
    AL_SRV_SEARCHFIELD_SYMRATE = 1 << 6,
    AL_SRV_SEARCHFIELD_NETID = 1 << 7,
} AL_Serv_ESearchField_t;

/****************************************************
 * Structure definition
 ****************************************************//**
 * @}
 * @defgroup StructDef Structure definition
 * @{
 ********************************************************/
/**
* @brief Structure of service attribute filter.
*/
 typedef struct
{
	AL_DB_EDBType_t eDBType;
	AL_DB_ERecordType_t eRecType;
	AL_Serv_EAnalogAttrib_t eAPositive;
	AL_Serv_EAnalogAttrib_t eANegative;
	AL_Serv_EDigitalAttrib_t eDPositive;
	AL_Serv_EDigitalAttrib_t eDNegative;
	al_uint8 szProgName[DB_DVB_MAX_CHNAME_LEN]; /**< program name*/
} AL_Serv_AttribFilter_t;

/**
* @brief Structure for searching services.
*/
typedef struct
{
	AL_DB_EDBType_t eDBType;
	AL_DB_ERecordType_t eRecType;
	AL_Serv_ESearchField_t eSearchField;
	al_uint16 u16ServId;
	al_uint16 u16TsId;
	al_uint16 u16OrigNetId;
	al_uint32 u32ProgNo;
	al_uint32 u32Frequency;
    al_uint32 u32SymbolRate;
    al_uint16 u16NetId;
    /**
    * zhongbaoxing added this element to consider the attrib
    * in AL_Serv_MatchRecBySearchKey @20120204
    */
    AL_Serv_EDigitalAttrib_t eIncludeAttrib;
} AL_Serv_SearchKey_t;

#ifdef CONFIG_ISDB_SYSTEM
typedef enum
{
    ATVDB_AIR = 0,
    ATVDB_CABLE,
}APP_AtvDb_Type;

void APP_Database_SwitchATVDB(APP_AtvDb_Type type);
void APP_Database_SetCareIsValid(al_bool care);
#endif

#ifdef CONFIG_SUPPORT_ATV_SCAN_NTSCM_PALM_N
typedef enum
{
    ATVDB_AIR = 0,
    ATVDB_CABLE,
}APP_AtvDb_Type;

void APP_Database_SwitchATVDB(APP_AtvDb_Type type);
void APP_Database_SetCareIsValid(al_bool care);
#endif

/****************************************************
 * API definition - Internal Operation
 ****************************************************//**
 * @}
 * @addtogroup InterAPI  Internal Interface
 * @{
 ********************************************************/
/**
* @brief Initialize service component.
*
* The implementation may perform appropriate service initialisation when this
* call is made, if required.
*
* @note
*		1.This API must be called before any service-related function is called; <br>
* 		2.Must be called once successfully, and still return success when called again.
*
* @param eDBType [in]select one or more database to initialize service component.
*
* @return
* 	#AL_SUCCESS indicates success,
* 	On failure, #AL_FAILURE is returned.
*/
AL_Return_t AI_Service_Init(
	AL_DB_EDBType_t eDBType);

/**
* @brief Terminate service commponent.
*
* The implementation may perform appropriate service termination when this
* call is made, if required.
*
* @note
* 		1.This API must be called after any service-related function is called, <br>
* 		2.Must be called once successfully, and still return success when called again.
*
* @param eDBType [in]Select one or more database to terminate service component.
*
* @return
* 	#AL_SUCCESS indicates success,
* 	On failure, #AL_FAILURE is returned.
*
*/
AL_Return_t AI_Service_Term(
	AL_DB_EDBType_t eDBType);

/****************************************************
 * API definition - Service Operation
 ****************************************************//**
 * @}
 * @addtogroup COMAPI  Component APIs
 * @{
 ********************************************************/
/**
* @brief Match service by specified attribute flag.
*
* @note Refers to the prototype #AL_DB_RecordMatchFunc.
*
* @param param		[in]Service attributes filter, type: #AL_Serv_AttribFilter_t.
* @param pRec		[in]Servie Info.
*
* @return
* 	#AL_SUCCESS indicates success,
* 	On failure, #AL_FAILURE is returned.
*/
al_bool AL_Serv_MatchRecByAttribute(al_void *param, al_void const*pRec);

/**
* @brief Match service by specified search field.
*
* @note Refers to the prototype #AL_DB_RecordMatchFunc.
*
* @param param		[in]Search key, type: #AL_Serv_SearchKey_t.
* @param pRec		[in]Service detail.
*
* @return
* 	#AL_SUCCESS indicates success,
* 	On failure, #AL_FAILURE is returned.
*/
al_bool AL_Serv_MatchRecBySearchKey(al_void *param, al_void const*pRec);

#ifdef SUPPORT_GHANA_LCN
AL_Return_t AL_Serv_BackupUserServsLCN( al_uint8 country );
#endif

AL_Return_t AL_Serv_StoreUserServs(AL_DB_EDBType_t eDBType);

AL_Return_t AL_Serv_RetrieveUserServs(AL_DB_EDBType_t eDBType);


/****************************************************//**
 * @}
 ********************************************************/
#ifdef __cplusplus
	}
#endif /* __cplusplus */

#endif /* __AL_SERVICE_H__ */
