#include <stdio.h>
#include "types.h"
#include <types.h>
#include "gl_task.h"
#include "umf_autodvd.h"

#define AUTODVD_DAEMON_DELAY         	60

static Autodvd_ModCbk_pf g_pfAutoDvdCallback = NULL;

static UINT8 g_u8AutodvdFlag = TRUE;

GL_Task_t g_pAutodvdProgramId = NULL;

static GL_Task_t AUTODVD_DAEMON = NULL;


void autodvd_program(void *data)
{

	while(1)
	{
		if(g_u8AutodvdFlag == TRUE)
		{
		    if (g_pfAutoDvdCallback != NULL)
			{
				g_pfAutoDvdCallback();
			}
        }
		GL_TaskSleep(AUTODVD_DAEMON_DELAY);
	}
	GL_TaskSelfDelete();
	return;
}

/********************************************************************
Prototype: autodvd_Initialize()
Parameters: None
Returns: None
Description: Create autodvd daemon program
Restrictions:
********************************************************************/
void Autodvd_Initialize(Autodvd_ModualCfg_t *pAutodvdCfg)
{
	
	if ((pAutodvdCfg != NULL) && (pAutodvdCfg->pfCallBack != NULL))
	{
		g_pfAutoDvdCallback = pAutodvdCfg->pfCallBack;
	}

    if (GL_SUCCESS != GL_TaskCreate("AUTO DVD Daemon",autodvd_program, NULL,
    									5,
    									4096,					// thread stack size
    									TRUE,					// resume after created
    									&(AUTODVD_DAEMON)))
    {
		printf("[%s:%d] create task fail!!\n",__FUNCTION__,__LINE__);
	}
}

