/**
* Copyright(c) 2011 Sunmedia Technologies - All Rights Reserved.
*
* @file
*
* @brief The interface of application framework module.
*
* The file list app framework commponent related APIs.
*
*/

#ifndef AL_FW_H_INCLUDED
#define AL_FW_H_INCLUDED

#ifdef __cplusplus
extern "C" {
#endif

#include "al_basictypes.h"
#if defined(CONFIG_DTV_SUPPORT) || defined(CONFIG_ATV_SUPPORT)
#include "al_database.h"
#endif
#ifdef CONFIG_DTV_SUPPORT
#include "al_service.h"
#include "al_multiplex.h"
#include "al_network.h"
#include "al_channel_search.h"
#include "al_event.h"
#include "al_scheduler.h"
#include "al_dvb_monitor.h"
#include "al_psi_monitor.h"
#include "al_prog_reminder.h"
#endif
#include "al_setting.h"
#include "al_time.h"
#ifdef CONFIG_SUPPORT_SUBTITLE
#include "al_subtitle.h"
#endif
#ifdef CONFIG_TT_SUPPORT
#include "al_teletext.h"
#endif
#ifdef CONFIG_SUPPORT_EWS
#include "al_ews_monitor.h"
#endif

/**
* @brief frm wrk module init select.
*/
typedef enum{
	FW_MAIN_INIT = 1<<0,
	FW_DVB_T_INIT = 1<<1,
	FW_DVB_C_INIT = 1<<2,
	FW_DVB_S_INIT = 1<<3,
	FW_ATV_INIT = 1<<4,
	FW_FILEPLAYER_INIT = 1<<5,
	FW_NETWORK_INIT = 1<<6,
	#ifdef CONFIG_ISDB_SYSTEM
	FW_DVB_SBTVD_INIT = 1<<7,
	#endif
	FW_MASK_INIT = FW_MAIN_INIT|FW_ATV_INIT|FW_DVB_S_INIT|FW_DVB_C_INIT|FW_DVB_S_INIT|FW_FILEPLAYER_INIT|FW_NETWORK_INIT,
}AFW_Init_t;

/**
* @brief defines the events notify to the application through call back.
*/
typedef enum {
	/* EVENT */
	FW_EPG_NOWNEXT_UPDATE_EVENT             = 0,//00
	FW_EPG_SCHEDULE_UPDATE_EVENT,               //01
	FW_EPG_PREF_SERVICE_NAME_UPDATE_EVENT,      //02
	FW_EPG_SERIES_UPDATE_EVENT,                 //03

	/* SERVICE */
	FW_SERVICE_DELETED_EVENT,                   //04
	FW_SERVICE_UPDATE_EVENT,                    //05

	/* DATABASE */
	FW_DB_LOAD_DEFAULT,                         //06

	/* SCHEDULER */
	FW_SCHEDULER_EVENT,                         //07
	FW_SCHEDULER_MSG,                           //08
	FW_SCHEDULER_EXPIRE,                        //09

	/* DATA SAVING */
	FW_DATASAVING_ATVDB_STORE_START_EVENT,      //10
	FW_DATASAVING_ATVDB_STORE_END_EVENT,        //11
	FW_DATASAVING_DVBDB_STORE_START_EVENT,      //12
	FW_DATASAVING_DVBDB_STORE_END_EVENT,        //13
	FW_DATASAVING_USERSETING_STORE_START_EVENT, //14
	FW_DATASAVING_USERSETING_STORE_END_EVENT,   //15

	/*DVB and PSI monitor*/
	FW_MONITOR_TUNER_LOCKED,                    //16
	FW_MONITOR_TUNER_UNLOCKED,                  //17
	FW_MONITOR_STREAM_NO_DATA,                  //18
	FW_MONITOR_STREAM_HAS_DATA,                 //19
	FW_MONITOR_STREAM_INVALID_DATA,				//20
	FW_MONITOR_STREAM_UNSUPPORT_DATA,			//21
	FW_MONITOR_SERVICE_VIDEO_AUDIO_SCRAMBLE,    //22
	FW_MONITOR_SERVICE_ONLY_VIDEO_SCRAMBLE,     //23
	FW_MONITOR_SERVICE_ONLY_AUDIO_SCRAMBLE,		//24
	FW_MONITOR_SERVICE_NO_SCRAMBLE,             //25
	FW_MONITOR_PARENTAL_LOCKED,                 //26
	FW_MONITOR_PARENTAL_UNLOCKED,               //27
	FW_MONITOR_SERVICE_MOVE,                    //28
	FW_MONITOR_AUDIO_UPDATE,                    //29
	FW_MONITOR_SUBTITLE_UPDATE,                 //30
	FW_MONITOR_CLOSECAPTION_UPDATE,				//add for CC //31
	FW_MONITOR_TELETEXT_UPDATE,                 //32
	FW_MONITOR_UPDATE_SERVICE,                  //33
	FW_MONITOR_OTHERTP_SERVICE_FOUND,           //34
	FW_MONITOR_ADD_SERVICE,                     //35
	FW_MONITOR_UPDATE_SERLCN,                   //36
	FW_MONITOR_REMOVE_SERVICE,                  //37
	FW_MONITOR_FTADATA_UPDATE,                  //38
	FW_MONITOR_REMINDER_EXPIRE,                 //39
	FW_MONITOR_REMINDER_TIME_CHANGE,            //40
	FW_MONITOR_REPLACE_SERVICE,                 //41
	FW_MONITOR_REPLACE_SIMULCASE_SERVICE,       //42
	FW_MONITOR_TS_CHANGED,                      //43
	FW_MONITOR_NEW_TSID,                        //44
	FW_MONITOR_TIME_UPDATE,                     //45
	FW_MONITOR_FIND_NEW_TPLIST,                 //46
	FW_MONITOR_PMT_UPDATE,                      //47
	FW_MONITOR_SERTYPE_CHANGED,                 //48
	FW_MONITOR_UPDATE_NETWORK,					//49
	FM_DTV_AUDIO_STARTED,                       //50
	FM_DTV_AUDIO_SAMPLE_STOPPED,                //51
	FM_DTV_AUDIO_STOPPED,                       //52
	/*VCHIP module event*/
	FW_VCHIP_LOCK,                          	//53
	FW_VCHIP_UNLOCK,                         	//54
	/* ATV module event*/
	FW_NO_SIGNAL,                               //55
	FW_NOT_SUPPORT,                             //56
	FW_SIGNAL_PRESENT,                          //57
	FW_VIP_FINISH,                              //58
	FW_VIP_STATUS,								//59
	FW_SCART_INPUTSRC_CHANGE,                   //60
	FW_SCART_INPUTSTATUS_CHANGE,                //61
	FW_HDMI_HDMIDVI_CHANGE,                     //62
	FW_HDMI_ACPTYPE_CHANGE,                     //63
	FW_HDMI_PORTSTATUS,                         //64
	FW_HDMI_PROCESSING,							//65
	/* Other module event ... */
	FW_AUDIO_HEADPHONE_PLUG_IN,                 //66
	FW_AUDIO_HEADPHONE_PLUG_OUT,                //67
	FW_AUDIO_ADC_TURNOFFSOUND,					//68
	FW_AUDIO_SIF_SAS_OK,
	FW_AUDIO_SIF_SCS_OK,
	/* Internel event */
	FW_TASK_EXIT = 80,                          //80
	/*TT module event*/
	FW_TT_NO_DATA,                              //81
	/*QSD test event*/
	FW_QSD_ATV_SetCH,							//82
	FW_QSD_DTV_SetCH,							//83
	FW_QSD_Media_Play,							//84
	FW_QSD_Source_Set,							//85
	FW_QSD_DTV_SetFreq,							//86
	/* EWS */
	FW_EWS_REC_ANCM = 100,						//100
	FW_EWS_FIND_AUD,							//101
	FW_EWS_ACTIVE,								//102
	FW_EWS_INACTIVE,							//103
	FW_EWS_NON_ANCM,							//104
	FW_USB_PLUGIN,                      		//105
	FW_USB_PLUGOUT,                  			//106
	FW_USB_HUNGTASK,							//107

	/*AFT*/
	FW_AFT_PROCESS_DONE,						//108
    FW_AFT_ADEMOD_PQSET,                        //109

	/*MHL*/
	FW_HDMI_MHL_RCP_CMD,						//110
	FW_HDMI_MHL_CONNECTED,						//111
	FW_INVALID_EVENT,							//112

	FW_ASTRALCN_RECED_PMT,						//113
	FW_ASTRALCN_START_RECVPMT,					//114

	/*Nordig logo*/
	FW_MONITOR_UPDATE_NWK_STATIC,				//115
	FW_MONITOR_UPDATE_NWK_RESCAN,				//116

	/*Auto Test*/
	FW_AUTOTEST_RESET = 120,					//120
	FW_AUTOTEST_UPDATESW,						//121
	FW_FAC_TEST_SET_SOURCE,						//122
	FW_FAC_UPDATE_HDCP_KEY,						//123
	FW_CC_VCHIP_DATA,                           //124
	/*Indonesia EWS*/
	FW_INDONESIA_EWS_UPDATE,					//125
	FW_INDONESIA_EWS_STOP,						//126

	/*SPD*/
	FW_HDMI_SPD_INFOFRAME_UPDATE,				//127

#ifdef CONFIG_SUPPORT_AUDIO_CODEC_OVERLAY
	FW_AUDIO_LOADCODEC_OK,						//128
	FW_AUDIO_LOADCODEC_ERROR,					//129
	FW_AUDIO_LOADCODEC_TYPE,					//130
#endif
    FW_TVFE_TYPE_BURNNTIME,                     //131
#ifdef CONFIG_SUPPORT_DETECT_USBPLL
	FW_TYPE_USBPLLFail,
#endif
#ifdef CONFIG_CTV_UART_FAC_MODE
    FW_RS232_SET_SOURCE,
    FW_RS232_SET_VOL,
    FW_RS232_SET_BL,//backlight

#endif
	FW_ADC_AUTOCHANGE_SOURCE,
	FW_ADC_AUTOADJUST,
	FW_SIGNAL_IN_PROGRESS,
	FW_HDMI_CHANGE_SOURCE,
	
	/*MCCS*/
	FW_MCCS_IMAGE_LUMINANCE,
	FW_MCCS_IMAGE_CONTRAST,
	FW_MCCS_IMAGE_SHARPNESS,
	FW_MCCS_IMAGE_SATURATION,
	FW_MCCS_IMAGE_RGAIN,
	FW_MCCS_IMAGE_GGAIN,
	FW_MCCS_IMAGE_BGAIN,
	FW_MCCS_IMAGE_ROFFSET,
	FW_MCCS_IMAGE_GOFFSET,
	FW_MCCS_IMAGE_BOFFSET,
	FW_MCCS_IMAGE_COLORLUT_SATGAIN_R,
	FW_MCCS_IMAGE_COLORLUT_SATGAIN_Y,
	FW_MCCS_IMAGE_COLORLUT_SATGAIN_G,
	FW_MCCS_IMAGE_COLORLUT_SATGAIN_C,
	FW_MCCS_IMAGE_COLORLUT_SATGAIN_B,
	FW_MCCS_IMAGE_COLORLUT_SATGAIN_M,
	FW_MCCS_CLOSE_USERMENU,
	FW_MCCS_IMAGE_GAMMA_TABLE_INDEX,
	FW_MCCS_IMAGE_CONTRAST_AUTO,
	FW_MCCS_FLASH_EEPROM_RW,
	FW_MCCS_FLASH_CTRL,
	FW_MCCS_OSD_HPOSITION,
	FW_MCCS_OSD_VPOSITION,
	FW_MCCS_AUDIOVOLUME,
	FW_MCCS_OSD_LANGUAGE,
	FW_MCCS_FBOSD_LANGUAGE,
	FW_MCCS_SET_VGASETTING_AUTO,
	FW_MCCS_SET_VGASETTING_HPOSITION,
	FW_MCCS_SET_VGASETTING_VPOSITION,
	FW_MCCS_SET_VGASETTING_CLOCK,
	FW_MCCS_SET_VGASETTING_PHASE,
	FW_MCCS_POWER_SETMODE,
	FW_MCCS_AUDIOMUTE,
	FW_MCCS_OSDLOCK,
} AFW_event_t;

/**
* @brief defines different mode of AFW.
*
* event handling may becomes different in different mode. some event may become invalid in given mode.
*/
typedef enum
{
	FW_NORMAL_VIEW_MODE = 0,
	FW_CHAN_SRCH_MODE,
	FW_UPGRADE_MODE,
	FW_EPG_MODE,
	FW_RESET_MODE,
	FW_POWER_DOWN_MODE,
	FW_QSD_MODE,
	FW_RS232_MODE,
} FW_mode_t;
/**
* @brief al get context type define.
*/
#define	FW_CONTEXT_OP_TYPE_READ   (0x10000)
#define	FW_CONTEXT_OP_TYPE_WRITE   (0x20000)

typedef enum
{
	FW_CONTEXT_TYPE_LOCK_STATE  = 0, /**< get  lock state */
	FW_CONTEXT_TYPE_PARENTAL_LOCK_STATE, /**< get parental lock state */
	FW_CONTEXT_TYPE_COUNTRY_CODE, /**< get user setting contry code */
	FW_CONTEXT_TYPE_TIME_ZONE, /**< get user setting time zone */
	FW_CONTEXT_TYPE_TIME_OFFSET, /**< get time offset by time zone except auto */
	FW_CONTEXT_TYPE_COUNTRY_REGION, /**< get user setting country region */
	FW_CONTEXT_TYPE_COUNTRY_ID, /**< country ID defined in AL_AreaIndex_en */
	FW_CONTEXT_TYPE_ONID_MATCH, /**< whether match ONID */
	FW_CONTEXT_TYPE_PR,				/**< get/set Program Reminder of PVR*/
	FW_CONTEXT_TYPE_ISO639LANGUAGE1,	/**< get iso 639 language */
	FW_CONTEXT_TYPE_ISO639LANGUAGE2,	/**< get iso 639 language */
	FW_CONTEXT_TYPE_CHECK_OSDLANGUAGEFRENCH, /**< check osd language is french or not */
	FW_CONTEXT_TYPE_TIME_DIFFER,
	FW_CONTEXT_TYPE_CHECK_FORCE_DST,  /**< callback to decide DST on/off */
	FW_CONTEXT_TYPE_CHECK_EVENTSTATE, /**< check whether need force processing event callback*/
	FW_CONTEXT_TYPE_CHECK_AUS_AREA,    /**< check current area is australia**/
	FW_CONTEXT_TYPE_GET_IOP_TIME,       /**< get IOP sleep time count**/
	FW_CONTEXT_TYPE_GET_SAVE_TIME,      /**< get last standby saving time**/
	FW_CONTEXT_TYPE_GET_CHANNEL_LOCK,	/**< get the state of channel lock under hotel mode**/
	FW_CONTEXT_TYPE_GET_DBNVM_HANDER,  /**< get NVM Hander for DB read/write operation **/
	FW_CONTEXT_TYPE_GET_DBRESTORE_SETTER,  /**< get callback for DB restore operation **/
	FW_CONTEXT_TYPE_GET_Current_Source,  /**< get callback for qsd get current source **/
	FW_CONTEXT_TYPE_CELLID,	/**< get cell id */
	FW_CONTEXT_TYPE_GET_CURRENT_TVHDL,
#ifdef CONFIG_VCHIP_SUPPORT
	FW_CONTEXT_TYPE_VCHIP_USERSET,
#endif
#ifdef CONFIG_DVB_SYSTEM_DVBC_SUPPORT
	FW_CONTEXT_TYPE_OPERATOR, /**< operator defined in al_DVBC_Operator_en */
#endif
    FW_CONTEXT_TYPE_RRT_USERSET, /**< get rrt user setting value */
	FW_CONTEXT_TYPE_GET_LANUGAGE_NUMBER,	/**< get language number */
	FW_CONTEXT_TYPE_DB_UPDATED, /**< set database updated */
#ifdef CONFIG_EPG_LANG_DEFAULT_BY_OSDLANG
	FW_CONTEXT_TYPE_OSDISO639LANGUAGE1, /**< get OSD iso 639 language */
	FW_CONTEXT_TYPE_OSDISO639LANGUAGE2, /**< get OSD iso 639 language */
#endif
    FW_CONTEXT_TYPE_TT_LANGUAGE,
    FW_CONTEXT_TYPE_TYPE_BURNNTIME,
    
#ifdef CONFIG_SUPPORT_DETECT_USBPLL
    FW_CONTEXT_TYPE_TYPE_USBPLLFail,
#endif    
	FW_CONTEXT_TYPE_MAX,
} AL_FW_Context_Type_t;
#ifdef CONFIG_VCHIP_SUPPORT
typedef enum
{
	FW_VCHIP_TYPE_MPAA,
	FW_VCHIP_TYPE_CANE,
	FW_VCHIP_TYPE_CANF,
	FW_VCHIP_TYPE_TVPG,
	FW_VCHIP_TYPE_MAX,
}AL_FW_VCHIP_TYPE;
#endif
typedef enum {
	FW_STATUS_NOSIGNAL,
	FW_STATUS_SIGNALOK,
} AL_FW_InputStatus_t;

/* Application Callback */
/**
* @brief Application Callback
*
*/
typedef al_void (*frmwrk_app_cb_t) (AFW_event_t frmwrk_event, al_void *user_param);

/**
* @brief Callback function prototype to get context
*
*/
typedef al_uint32 (*frmwrk_pfOpConext_t)(AL_FW_Context_Type_t ContextType, al_uint32 opera, al_void * pContext, al_uint32 Param);


/**
* @brief framwork init.
*
* This application framework init function will initialize all the middleware components and framework components.
*
* @param frmwrk_init_module[input] frmwrk mudule Initialize select.
*
* @param frmwrk_app_cb[input] App framework callback.
*
* @param frmwrk_context_cb[input] App register to framwork callback for al layer get context.
*
* @return AL_SUCCESS if initialization is successful, AL_FAILURE otherwise.
*/
AL_Return_t AL_FW_Init(AFW_Init_t frmwrk_init_module,
	frmwrk_app_cb_t frmwrk_app_cb, frmwrk_pfOpConext_t frmwrk_context_cb);

/**
* @brief framwork exit.
*
* This application framework exit function will deinitialize all the middleware components and framework components.
*
* @return AL_SUCCESS if exit is successful, AL_FAILURE otherwise.
*/
#ifdef CONFIG_MOD_PACK_DTV
AL_Return_t AL_FW_DTVExit(al_void);
#endif


#ifdef CONFIG_MOD_PACK_DTV
AL_Return_t AL_FW_InitDtvModule(AFW_Init_t frmwrk_init_module);
#endif
/**
* @brief get framwork version.
*
* API gets the al layor version. version info is composed of major and minor version number.
* major and minor version number occupy the least two bytes and the highest two bytes are reserved currently.
* The follow lists the bytes order. Version can by represented with notation of XX XX MAJOR Minor, above which XX represents nothing.
*
* @param version[output] Pointer to Version Number.
*
* @return AL_SUCCESS if get version is successful, AL_FAILURE otherwise.
*/
AL_Return_t AL_FW_GetVersion(al_uint32 *version);

#if defined(CONFIG_DTV_SUPPORT) || defined(CONFIG_ATV_SUPPORT)
/**
* @brief To Terminate NVM storing task.
*
* @param IsSync[input]
*
* @return AL_SUCCESS if terminate is successful, AL_FAILURE otherwise.
*/
AL_Return_t AL_FW_TermStoreDevice(al_bool IsSync);

/**
* @brief Swtich DB module at all the DVB DB module.
*
* @param eDBType[input] the DB module will be active(other DVB DB Module will deactive).
*
* @return AL_SUCCESS if switch is successful, AL_FAILURE otherwise.
*/
AL_Return_t AL_FW_SwitchDBModule(AL_DB_EDBType_t eDBType);

/**
* @brief active DB module.
*
* @param eDBType[input] the DB module will be active.
*
* @return AL_SUCCESS if switch is successful, AL_FAILURE otherwise.
*/
AL_Return_t AL_FW_ActiveDBModule(AL_DB_EDBType_t eDBType);

/**
* @brief deactive DB module.
*
* @param eDBType[input] the DB module will be deactive.
*
* @return AL_SUCCESS if switch is successful, AL_FAILURE otherwise.
*/
AL_Return_t AL_FW_DeActiveDBModule(AL_DB_EDBType_t eDBType);

/**
* @brief Reload DB module.
*
* @param eDBType[input] the DB module will be reload.
*
* @return AL_SUCCESS if reload is successful, AL_FAILURE otherwise.
*/
AL_Return_t AL_FW_ReLoadDBModule(AL_DB_EDBType_t eDBType);

/**
* @brief Check Active Database module.
*
* @param eDBType[input] indicate which database to check
*
* @return al_true if active , al_false otherwise.
*/
al_bool AL_FW_CheckActiveDBModule(AL_DB_EDBType_t eDBType);
#endif
/**
* @brief Set FW to specific mode.
*
* @param eFWMode[input] indicated which mode to set.
*
* @return AL_SUCCESS if active is successful, AL_FAILURE otherwise.
*/
AL_Return_t AL_FW_ActiveFWModule(FW_mode_t eFWMode);

/**
* @brief Get FW to specific mode.
*
* @param peFWMode[input] indicated which mode to set.
*
* @return AL_SUCCESS if active is successful, AL_FAILURE otherwise.
*/
AL_Return_t AL_FW_GetFWModule(FW_mode_t *peFWMode);

/**
* @brief get context callback funcion.
*
* @param ppfGetContext[output] callback function.
*
* @return AL_SUCCESS get callback funcion is successful, AL_FAILURE otherwise.
*/
AL_Return_t AL_FW_GetContextCb(frmwrk_pfOpConext_t *ppfOpContext);
/**
* @brief clear fw queue funcion.
*
* @param None.
*
* @return AL_SUCCESS clear queue funcion is successful, AL_FAILURE otherwise.
*/
AL_Return_t AL_FW_ReleaseQueue(void);

AL_Return_t AL_FW_ShowQueue(void);

/**
* @brief check dtv demux has data funcion.
*
* @param None.
*
* @return AL_SUCCESS check dtv demux has data function is successful, AL_FAILURE otherwise.
*/
AL_Return_t AL_FW_Check_DTVDemux_HasData(al_bool *flag);

#ifdef CONFIG_SUPPORT_NOSIGNAL_AUTO_CHANGE_SOURCE
al_uint32 AL_FW_Check_HDMI_PortStatus(void);
#endif

al_uint32 AL_FW_RW_PseudoEEPROM(unsigned char *extraData);

#ifdef __cplusplus
}
#endif

#endif /* AL_FW_H_INCLUDED */

