/*****************************************************************************
** ai_datasaving.h: AL Layer Storage Internal Interface
**
** Description: This file is only used by AL modules and the application
** can't access it directly
**
** Copyright(c) 2011 Sunmedia Technologies - All Rights Reserved
**
** Author : anlzhao
**
** $Id: ai_datasaving.h 1901 2011-01-22 05:47:03Z liang.wu_c1 $
*****************************************************************************/

#ifndef AI_DATASAVING_H_INCLUDED
#define AI_DATASAVING_H_INCLUDED

#include "al_basictypes.h"

/* NVM Message Queue Size , NVMSTORE_URGENT_Q_SIZE should be set 0 coz this Data saving task
* is not supposed to deal with urgent msg by the current timing-oriented mechanism.
*/
#define NVMSTORE_NORMAL_Q_SIZE			(8)
#define NVMSTORE_URGENT_Q_SIZE			(0)
#define SLEEP_FOR_PE_FINISH_TIME			200

#ifdef __cplusplus
extern "C" {
#endif

/* Storage command type */
typedef enum NvmStore_Msg_e
{
#ifdef CONFIG_DTV_SUPPORT
	AI_NVMSTORE_CMD_DTV_STORE_ALL = 1,	/* Store DTV Database */
	AI_NVMSTORE_CMD_DTV_RST_ALL,		/* Reset DTV Database */
	AI_NVMSTORE_CMD_DTV_EMPTY_ALL,		/* Empty DTV Database */
	
	AI_NVMSTORE_CMD_DTV_STORE_SINGLE,	/* Store DTV -T/C/S Database */
	AI_NVMSTORE_CMD_DTV_RST_SINGLE,		/* Reset DTV -T/C/S Database */
	AI_NVMSTORE_CMD_DTV_EMPTY_SINGLE,	/* Empty DTV -T/C/S Database */
#endif
#ifdef CONFIG_ATV_SUPPORT
	AI_NVMSTORE_CMD_ATV_STORE,			/* Store ATV Database */
	AI_NVMSTORE_CMD_ATV_RST,			/* Reset ATV Database */
	AI_NVMSTORE_CMD_ATV_EMPTY,			/* Empty ATV Database */
#endif
#if defined(CONFIG_DTV_SUPPORT) || defined(CONFIG_ATV_SUPPORT)
	AI_NVMSTORE_CMD_ATV_DTV_RST, 		/* Reset DTV & ATV */
#endif
	AI_NVMSTORE_CMD_TERM,
	AI_NVMSTORE_BUSY_WAIT = 0x4000,
} AI_NvmStore_CMD_e;

/*Data saving message type*/
typedef enum
{
#if defined(CONFIG_DTV_SUPPORT) || defined(CONFIG_ATV_SUPPORT)
	AI_DATASAVING_MSG_ATVDB_STORE_START,
	AI_DATASAVING_MSG_ATVDB_STORE_END,
	AI_DATASAVING_MSG_DVBDB_STORE_START,
	AI_DATASAVING_MSG_DVBDB_STORE_END,
#endif
	AI_DATASAVING_MSG_USERSETING_STORE_START,
	AI_DATASAVING_MSG_USERSETING_STORE_END,
} AI_DataSaving_Msg_Type_t;

/* message structure and command sending to nvm storing thread */
typedef struct _APP_NvmStoreCMD_t
{
	al_uint32 dEventType; /* AI_NvmStore_CMD_e */
	al_uint32 eventData; /* For system setting, it is refer to ID */
	al_uint32 req_tick;	/* ticks when requiring */
} AI_NvmStore_CMD_t;

typedef al_int32 (*ALDataSavingCallback)(AI_DataSaving_Msg_Type_t MessageType, al_void* pParam);

/*****************************************************************************
** FUNCTION : AI_SETTING_Request
**
** DESCRIPTION :
**				This method sends a request for storage.
**
** PARAMETERS :
**				storetype	- Storage type
**				data		- message data
**				req_id 	- the id of request
**
** RETURN VALUES:
**				AL_SUCCESS
*****************************************************************************/
AL_Return_t AI_DataSaving_Request(al_uint32 storetype, al_uint32 data, al_uint32 *req_id);

/***************************************************************************
** FUNCTION :      AI_SETTING_Init
**
** DESCRIPTION :
**                 initialize the data saving thread.
** PARAMETERS :
**                 func
** RETURN VALUES :
**				AL_SUCCESS
**				AL_FAILURE
***************************************************************************/
AL_Return_t AI_DataSaving_Init(ALDataSavingCallback fpFunc);

/*****************************************************************************
** FUNCTION : AI_DataSaving_AnyStoreInProgress
**
** DESCRIPTION :
**				This function is used to check if any nvm store request
**				or process in progress.
**				Notice: This function is not thread safe and it may be
**				modified later.
**
** PARAMETERS :
**				None
**
** RETURN VALUES:
**				al_true is storing is in process
**				al_false if storing is not in process
*****************************************************************************/
al_bool AI_DataSaving_AnyStoreInProgress(al_void);

/*****************************************************************************
** FUNCTION : AI_DataSaving_IsFinished
**
** DESCRIPTION :
**				This function is to check whether saving request is handled by Datasaving 
**				module.
**
** PARAMETERS :
**				req_id - the id of the request
**
** RETURN VALUES:
**				al_true is storing is in process
**				al_false if storing is not in process
*****************************************************************************/
al_bool AI_DataSaving_IsFinished(al_uint32 req_id);

/*****************************************************************************
** FUNCTION : AI_DataSaving_Term
**
** DESCRIPTION :
**				This function is used to terminate datasaving task.
**				Notice: This function will not return until task is terminated.
**
** PARAMETERS :
**				None
**
** RETURN VALUES:
**				al_true is storing is in process
**				al_false if storing is not in process
*****************************************************************************/
AL_Return_t AI_DataSaving_Term(al_bool IsSync);

#ifdef __cplusplus
}
#endif

#endif /* AI_DATASAVING_H_INCLUDED */

/*****************************************************************************
** $Rev: 1901 $
**
*****************************************************************************/
