/*****************************************************************************
** al_event.h: AL Layer Scheduler Header File
**
** Description: Gives the functionalities for schedule different mode of events
**
** Copyright(c) 2011 Sunmedia Technologies - All Rights Reserved
**
** Author : wuliang
**
** $Id: al_scheduler.h 1910 2011-01-24 05:05:35Z anlzhao_c1 $
*****************************************************************************/

#ifndef __AL_SCHEDULER_H__
#define __AL_SCHEDULER_H__

#ifdef __cplusplus
	extern "C"{
#endif

#define AL_SCH_MAX_NO_OF_CALLBACK		(3)

#define AL_SCH_MAX_NO_OF_SCHD_EVENT	(30)

#define AL_SCH_INVALID_ID (0xffffffff)

typedef al_uint32 AL_SCH_sched_id_t;

typedef al_uint32 AL_SCH_time_t;

typedef enum _tag_AISCH_event_type_t{
	/* these are schedule types*/
	AL_SCH_TYPE_SINGLE = 0,				/* Event is single shot */
	AL_SCH_TYPE_REPEAT = (1 << 0),		/* Event to be reschedule for snooze time*/
	AL_SCH_TYPE_MULTI_EVENT = (1 << 1),	/* Event has sub event as reminder */
	AL_SCH_TYPE_MASK = (AL_SCH_TYPE_REPEAT | AL_SCH_TYPE_SINGLE | AL_SCH_TYPE_MULTI_EVENT),
	
	/*these are event types*/
	AL_SCH_TYPE_PRG_SCH = (1<<2),		/* Program for a service is scheduled */
	AL_SCH_TYPE_SRV_SCH = (2<<2),		/* Service for given time scheduled */
	AL_SCH_TYPE_PRG_EXPIRE_SCH = (3<<2),		/* General Event time FW has no action */
	AL_SCH_TYPE_SLEEP = (4<<2),			/* Sleep timer Event */
	AL_SCH_TYPE_TIME_SCH = (5<<2),		/* System Time Event */
	AL_SCH_TYPE_EVENT_EXPR = (6<<2),	/* Channel Navigation event for Event expiration*/
	AL_SCH_TYPE_LOCK_AFTER = (7<<2),	/* Lock-after schedule event*/
	AL_SCH_TYPE_MAX = (8<<2)
} AL_SCH_event_type_t;


typedef enum _tag_AL_SH_sleep_time_t{
	AL_SCH_SLEEP_OFF = 0,
	AL_SCH_SLEEP_10_MIN = 10 * 60,
	AL_SCH_SLEEP_15_MIN = 15 * 60,
	AL_SCH_SLEEP_20_MIN = 20 * 60,
	AL_SCH_SLEEP_30_MIN = 30 * 60,
	AL_SCH_SLEEP_45_MIN = 45 * 60,
	AL_SCH_SLEEP_60_MIN = 60 * 60,
	AL_SCH_SLEEP_90_MIN = 90 * 60,
	AL_SCH_SLEEP_120_MIN = 120 * 60
} AL_SCH_sleep_time_t;

typedef struct{
	AL_SCH_event_type_t sch_event;
	AL_SCH_time_t	sch_time;
	AL_SCH_time_t	sch_snooze;
	al_uint32		sch_user_para;
	AL_SCH_time_t	app_schd_time[AL_SCH_MAX_NO_OF_CALLBACK];
} AL_SCH_details_t;

typedef void (*AL_SCH_EVENT_CALLBACK)(AL_SCH_event_type_t sch_event, 
				AL_SCH_sched_id_t sch_id, AL_SCH_details_t *sch_detail);


/************************************************************************ 
 ** name		:ACSH_init()
 **
 ** description		: Scheduler COMPONENT INIT
 **
 ** input parameters	: NONE
 **
 ** output parameters	:   None
 **				  
 ** return type		: AL_Return_t SUCCESS or FAILURE
 ************************************************************************/ 
AL_Return_t AL_SCH_Init(AL_SCH_EVENT_CALLBACK sch_call_back);

/************************************************************************ 
 ** name		:AL_SCH_Terminate()
 **
 ** description		: Scheduler COMPONENT Terminate
 **
 ** input parameters	: NONE
 **
 ** output parameters	:   None
 **				  
 ** return type		: AL_Return_t SUCCESS or FAILURE
 ************************************************************************/ 
AL_Return_t AL_SCH_Terminate(void);

/************************************************************************ 
 ** name		:AL_SCH_Handle_Time_Change()
 **
 ** description		: Again check the schedule list and get the next event.
 **
 ** input parameters	: NONE
 **
 ** output parameters	:   None
 **				  
 ** return type		: AL_Return_t SUCCESS or FAILURE
 ************************************************************************/ 
AL_Return_t AL_SCH_Handle_Time_Change( al_uint32 prev_time );

/************************************************************************ 
 ** name		:AL_SCH_ScheduleEvent()
 **
 ** description		: Schedules the given event at given time
 **
 ** input parameters	: sch_detail: details structure
 **					sch_call_bck: Callback function required. If this is passed as NULL
 **								framework callback function is passed.
 **
 ** output parameters	:    sch_id: Return the scheduled event id.
 **				  
 ** return type		: AL_Return_t SUCCESS or FAILURE
 ************************************************************************/ 
AL_Return_t AL_SCH_ScheduleEvent( AL_SCH_details_t *sch_detail, AL_SCH_sched_id_t *sch_id,
	AL_SCH_EVENT_CALLBACK sch_call_bck);

/************************************************************************ 
 ** name		:AL_SCH_ReScheduleEvent()
 **
 ** description		: Reschedules the event
 **
 ** input parameters	: sch_id: Schedule ID to be reschedule
 **					sch_details: New details applicable.
 **
 ** output parameters	:   None
 ** 
 ** return type		: AL_Return_t SUCCESS or FAILURE
 ************************************************************************/ 
AL_Return_t AL_SCH_ReScheduleEvent(AL_SCH_sched_id_t *sch_id,  AL_SCH_details_t *sch_details);

/************************************************************************ 
 ** name		:AL_SCH_UnScheduleEvent()
 **
 ** description		: Unschedules the event
 **
 ** input parameters	: AL_SCH_sched_id_t *sch_id (Pointer to schedule ID);
 **
 ** output parameters	:   None
 **				  
 ** return type		: AL_Return_t SUCCESS or FAILURE
 ************************************************************************/ 
AL_Return_t AL_SCH_UnScheduleEvent(AL_SCH_sched_id_t *sch_id);

/************************************************************************ 
 ** name		:AL_SCH_GetScheduleDetails()
 **
 ** description		: Gives the details of given schedule id
 **
 ** input parameters	: AL_SCH_sched_id_t *sch_id , AL_SCH_details_t *sch_details(pointer)
 **
 ** output parameters	: AL_SCH_details_t *sch_details (details r populated)
 **				  
 ** return type		: AL_Return_t SUCCESS or FAILURE
 ************************************************************************/ 
AL_Return_t AL_SCH_GetScheduleDetails(AL_SCH_sched_id_t *sch_id, AL_SCH_details_t *sch_details);

/************************************************************************ 
 ** name		:AL_SCH_Get_ScheduleTimeRemaining
 **
 ** description		: Gives the details of given schedule id
 **
 ** input parameters	: AL_SCH_sched_id_t *sch_id , AL_SCH_details_t *sch_details(pointer)
 **
 ** output parameters	: AL_SCH_details_t *sch_details (details r populated)
 **				  
 ** return type		: AL_Return_t SUCCESS or FAILURE
 ************************************************************************/ 
AL_Return_t AL_SCH_Get_ScheduleTimeRemaining(AL_SCH_sched_id_t *sch_id, AL_SCH_time_t *sch_time);

/************************************************************************ 
 ** name				:ACSH_set_default_settings()
 **
 ** description		: this API is called during master reset;empties the sch_list;
 **
 ** input parameters	: none
 **
 ** output parameters	: none
 **				  
 ** return type		: AL_SUCCESS / AL_FAILURE
 ************************************************************************/
AL_Return_t AL_SCH_SetDefaultSettings(void);

#ifdef __cplusplus
	}
#endif /* __cplusplus */

#endif
