예제 #1
0
static void 
FramesStream_TimeSub(int time)
/* 功能:将各个动画的当前帧的等待时间与指定时间相减 */
{
	LCUI_Frame *frame;
	LCUI_Frames *frames;
	int i, total, pos;
	
	Queue_Lock(&frames_stream);
	total = Queue_GetTotal(&frames_stream);
	DEBUG_MSG("start\n");
	for(i=0; i<total; ++i) {
		frames = Queue_Get(&frames_stream, i);  
		if( !frames || frames->state == 0 ) {
			continue;
		}
		if(frames->current > 0) {
			pos = frames->current-1;
		} else {
			pos = 0;
		}
		frame = Queue_Get(&frames->pic, pos);
		if( !frame ) {
			continue; 
		}
		frame->current_time -= time; 
		DEBUG_MSG("fames: %p, current: %d, time:%ld, sub:%d\n", 
			frames, pos, frame->current_time, time);
	}
	DEBUG_MSG("end\n");
	Queue_Unlock(&frames_stream);
}
예제 #2
0
파일: timer.c 프로젝트: fshunj/LCUI
/**
 * 释放定时器
 * 当不需要定时器时,可以使用该函数释放定时器占用的资源
 * @param timer_id
 *	需要释放的定时器的标识符
 * @return
 *	正常返回0,指定ID的定时器不存在则返回-1.
 * */
LCUI_API int LCUITimer_Free( int timer_id )
{
	int i, total;
	timer_data *timer;
	
	LCUISleeper_BreakSleep( &timer_sleeper );
	Queue_Lock( &global_timer_list );
	total = Queue_GetTotal( &global_timer_list );
	for(i=0; i<total; ++i) {
		timer = (timer_data*)Queue_Get( &global_timer_list, i );
		if( !timer ) {
			continue;
		}
		if( timer->id == timer_id ) {
			DEBUG_MSG("delete timer: %d, n_ms: %d\n", timer->id, timer->total_ms);
			Queue_Delete( &global_timer_list, i );
			break;
		}
	}
	Queue_Unlock( &global_timer_list );
	if( i < total ) {
		LCUISleeper_BreakSleep( &timer_sleeper );
		return 0;
	}
	return -1;
}
예제 #3
0
static BOOL tsmf_stream_process_ack(void* arg, BOOL force)
{
	TSMF_STREAM* stream = arg;
	TSMF_SAMPLE* sample;
	UINT64 ack_time;
	BOOL rc = FALSE;

	if (!stream)
		return FALSE;

	Queue_Lock(stream->sample_ack_list);
	sample = (TSMF_SAMPLE*) Queue_Peek(stream->sample_ack_list);

	if (!sample)
		goto finally;

	if (!force)
	{
		ack_time = get_current_time();

		if (sample->ack_time > ack_time)
			goto finally;
	}

	sample = Queue_Dequeue(stream->sample_ack_list);
	tsmf_sample_ack(sample);
	tsmf_sample_free(sample);

finally:
	Queue_Unlock(stream->sample_ack_list);
	return rc;
}
예제 #4
0
파일: main.c 프로젝트: yydaor/LCUI
static int 
LCUIApp_RunTask( LCUI_App *app )
{ 
	LCUI_Task *task;

	Queue_Lock( &app->tasks );
	task = Queue_Get( &app->tasks, 0 );
	if( task == NULL ) {
		Queue_Unlock( &app->tasks );
		return -1;
	}
	Queue_DeletePointer( &app->tasks, 0 );
	if( task->func == NULL ) {
		Queue_Unlock( &app->tasks );
		return -2;
	}
	Queue_Unlock( &app->tasks );
	/* 调用函数指针指向的函数,并传递参数 */
	task->func( task->arg[0], task->arg[1] );
	/* 若需要在调用回调函数后销毁参数 */
	if( task->destroy_arg[0] ) {
		free( task->arg[0] );
	}
	if( task->destroy_arg[1] ) {
		free( task->arg[1] );
	}
	free( task );
	return 0;
}
예제 #5
0
파일: graphlayer.c 프로젝트: aem3372/LCUI
LCUI_API int GraphLayer_Sort( LCUI_GraphLayer *glayer )
{
	LCUI_GraphLayer *child_a, *child_b;
	int i, j, total;
	
	if( !glayer ) {
		return -1;
	}
	/* 排序前先锁上队列互斥锁 */
	Queue_Lock( &glayer->child );
	total = Queue_GetTotal( &glayer->child );
	/* 使用的是冒泡排序法 */
	for(j=0; j<total; ++j)
	for(i=total-1; i>=1; --i) {
		child_a = (LCUI_GraphLayer*)Queue_Get( &glayer->child, i );
		if( !child_a ) {
			continue;
		}
		child_b = (LCUI_GraphLayer*)Queue_Get( &glayer->child, i-1 );
		if( !child_b ) {
			continue;
		}
		if( child_a->z_index > child_b->z_index ) {
			Queue_Move( &glayer->child, i-1, i);
		}
	}
	/* 解开互斥锁 */
	Queue_Unlock( &glayer->child );
	return 0;
}
예제 #6
0
Frames_Play(LCUI_Frames *frames)
/* 功能:播放动画 */
{
	int i, total;
	LCUI_Frames *tmp_ptr;
	if( !frames ) {
		return -1; 
	}
	frames->state = 1;
	if(__timer_id == -1){
		Queue_Init( &frames_stream, sizeof(LCUI_Frames), NULL );
		Queue_UsingPointer( &frames_stream );
		__timer_id = set_timer( 50, Process_Frames, TRUE );
	}
	/* 检查该动画是否已存在 */
	Queue_Lock( &frames_stream );
	total = Queue_GetTotal( &frames_stream );
	for( i=0; i<total; ++i ) {
		tmp_ptr = Queue_Get( &frames_stream, i );
		if( tmp_ptr == frames ) {
			break;
		}
	}
	Queue_Unlock( &frames_stream );
	/* 添加至动画更新队列中 */ 
	if( i>=total ) {
		return Queue_AddPointer(&frames_stream, frames); 
	}
	return 1;
}
예제 #7
0
파일: device.c 프로젝트: FrankHB/LCUI
/** 处理列表中的设备的数据 */
static void proc_dev_list( void *arg )
{
	LCUI_Queue *dev_list;
	dev_func_data *data_ptr;
	int total, i, timeout_count = 0;
	
	dev_list = (LCUI_Queue *)arg;
	while( LCUI_Active() ) {
		Queue_Lock( dev_list );
		total = Queue_GetTotal( dev_list );
		for(i=0; i<total; ++i) {
			data_ptr = (dev_func_data*)Queue_Get( dev_list, i );
			if( !data_ptr || !data_ptr->proc_func ) {
				continue;
			}
			if( data_ptr->proc_func() ) {
				++timeout_count;
			}
		}
		Queue_Unlock( dev_list );
		if( timeout_count > 20 ) {
			LCUI_MSleep( 10 );
			timeout_count = 0;
		}
		LCUI_MSleep( 5 );
	}
	LCUIThread_Exit(NULL);
}
예제 #8
0
/* 向消息队列中投递消息 */
int Game_PostMsg( GameMsg *msg )
{
	Queue_Lock( &game_msg_queue );
	if( !Queue_Add( &game_msg_queue, msg ) ) {
		Queue_Unlock( &game_msg_queue );
		return -1;
	}
	Queue_Unlock( &game_msg_queue );
	return LCUISleeper_BreakSleep( &msg_sleeper );
}
예제 #9
0
파일: timer.c 프로젝트: fshunj/LCUI
/** 更新定时器在定时器列表中的位置 */
static void TimerList_UpdateTimerPos(	LCUI_Queue *timer_list,
					timer_data *p_timer )
{
	int n, src_i=-1, des_i=-1;
	int64_t time_left, tmp_time_left;
	timer_data *p_tmp_timer;
	/* 计算该定时器的剩余定时时长 */
	time_left = LCUI_GetTicks( p_timer->start_time );
	time_left -= p_timer->pause_ms;
	time_left = p_timer->total_ms - time_left;
	/* 锁上定时器列表 */
	Queue_Lock( &global_timer_list );
	n = Queue_GetTotal( &global_timer_list );
	while(n--) {
		p_tmp_timer = (timer_data*)Queue_Get( &global_timer_list, n );
		if( !p_tmp_timer ) {
			continue;
		}
		/* 若找到自己的位置,则记录 */
		if( p_tmp_timer->id == p_timer->id ) {
			src_i = n;
			/* 如果已经找到目标位置,则退出循环 */
			if( des_i != -1 ) {
				break;
			}
			continue;
		}
		tmp_time_left = LCUI_GetTicks( p_tmp_timer->start_time );
		tmp_time_left -= p_tmp_timer->pause_ms;
		tmp_time_left = p_tmp_timer->total_ms - tmp_time_left;
		/* 若该定时器的剩余定时时长不大于当前定时器,则记录 */
		if( des_i == -1 && time_left >= tmp_time_left ) {
			DEBUG_MSG("src timer: %d, pos: %d, , cur_ms: %I64dms, des timer: %d, pos: %d, cur_ms: %I64dms\n",
				p_timer->id, src_i, LCUI_GetTicks(p_timer->start_time), 
				p_tmp_timer->id, des_i, LCUI_GetTicks(p_tmp_timer->start_time) );
			des_i = n;
			/* 如果已经找到源位置,则退出循环 */
			if( src_i != -1 ) {
				break;
			}
		}
	}
	/* 若目标位置无效,则将末尾作为目标位置 */
	if( des_i == -1 ) {
		DEBUG_MSG("tip\n");
		des_i = Queue_GetTotal( &global_timer_list )-1;
	}
	/* 若源位置和目标位置有效,则开始移动 */
	if( src_i != -1 ) {
		DEBUG_MSG("src: %d, des: %d\n", src_i, des_i );
		Queue_Move( &global_timer_list, des_i, src_i );
	}
	Queue_Unlock( &global_timer_list );
}
예제 #10
0
/* Returns TRUE if no more samples are currently available
 * Returns FALSE otherwise
 */
static BOOL tsmf_stream_process_ack(void* arg, BOOL force)
{
	TSMF_STREAM* stream = arg;
	TSMF_SAMPLE* sample;
	UINT64 ack_time;
	BOOL rc = FALSE;

	if (!stream)
		return TRUE;

	Queue_Lock(stream->sample_ack_list);
	sample = (TSMF_SAMPLE*) Queue_Peek(stream->sample_ack_list);

	if (!sample)
	{
		rc = TRUE;
		goto finally;
	}

	if (!force)
	{
		/* Do some min/max ack limiting if we have access to Buffer level information */
		if (stream->decoder && stream->decoder->BufferLevel)
		{
			/* Try to keep buffer level below max by withholding acks */
			if (stream->currentBufferLevel > stream->maxBufferLevel)
				goto finally;
			/* Try to keep buffer level above min by pushing acks through quickly */
			else if (stream->currentBufferLevel < stream->minBufferLevel)
				goto dequeue;
		}

		/* Time based acks only */
		ack_time = get_current_time();

		if (sample->ack_time > ack_time)
			goto finally;
	}

dequeue:
	sample = Queue_Dequeue(stream->sample_ack_list);

	if (sample)
	{
		tsmf_sample_ack(sample);
		tsmf_sample_free(sample);
	}

finally:
	Queue_Unlock(stream->sample_ack_list);
	return rc;
}
예제 #11
0
파일: widget_event.c 프로젝트: FrankHB/LCUI
static void WidgetRecord_Reset( void )
{
	int i, n;
	WidgetRecordItem *item;

	Queue_Lock( &widget_proc_record );
	n = Queue_GetTotal( &widget_proc_record );
	for(i=0; i<n; ++i) {
		item = (WidgetRecordItem*)Queue_Get( &widget_proc_record, i );
		item->need_delete = TRUE;
	}
	Queue_Unlock( &widget_proc_record );
}
예제 #12
0
static void 
FramesStream_Sort()
/* 功能:对动画流进行排序 */
{
	int i, j, pos, total;
	LCUI_Frames *temp;
	LCUI_Frame *p, *q;
	
	Queue_Lock(&frames_stream);
	total = Queue_GetTotal(&frames_stream);
	/* 使用的是选择排序 */
	for(i=0; i<total; ++i) {
		temp = Queue_Get(&frames_stream, i);
		if( !temp ) {
			continue;
		}
		if(temp->current > 0) {
			pos = temp->current-1;
		} else {
			pos = 0;
		}
		
		p = Queue_Get(&temp->pic, pos);
		if( !p ) {
			continue; 
		}
		
		for(j=i+1; j<total; ++j) {
			temp = Queue_Get(&frames_stream, j);
			if( !temp ) {
				continue; 
			}
			if(temp->current > 0) {
				pos = temp->current-1;
			} else {
				pos = 0;
			}
			
			q = Queue_Get(&temp->pic, pos);
			if( !q ) {
				continue; 
			}
			
			if( q->current_time < p->current_time ) {
				Queue_Swap(&frames_stream, j, i);
			}
		}
	}
	Queue_Unlock(&frames_stream);
}
예제 #13
0
파일: task.c 프로젝트: fshunj/LCUI
/*
 * 功能:发送任务给程序,使这个程序进行指定任务
 * 说明:LCUI_Task结构体中的成员变量 id,保存的是目标程序的id
 */
LCUI_API int AppTasks_Add( LCUI_Task *task )
{
	LCUI_App *app;
	app = LCUIApp_Find( task->id );
	if( !app ) {
		return -1;
	}
	Queue_Lock( &app->tasks );
	if(Queue_Add( &app->tasks, task ) < 0 ) {
		Queue_Unlock( &app->tasks );
		return -2;
	}
	LCUISleeper_BreakSleep( &app->mainloop_sleeper );
	Queue_Unlock( &app->tasks );
	return 0;
}
예제 #14
0
파일: device.c 프로젝트: FrankHB/LCUI
/** 停用设备处理模块 */
LCUI_API void LCUIModule_Device_End(void)
{
	int total, i;
	dev_func_data *data_ptr;
	
	Queue_Lock( &dev_list );
	total = Queue_GetTotal( &dev_list );
	for(i=0; i<total; ++i) {
		data_ptr = (dev_func_data*)Queue_Get( &dev_list, i );
		if( !data_ptr || !data_ptr->destroy_func ) {
			continue;
		}
		data_ptr->destroy_func();
	}
	Queue_Unlock( &dev_list );
}
예제 #15
0
파일: timer.c 프로젝트: fshunj/LCUI
/**
 * 继续定时器的倒计时
 * @param timer_id
 *	目标定时器的标识符
 * @return
 *	正常返回0,指定ID的定时器不存在则返回-1.
 * */
LCUI_API int LCUITimer_Continue( int timer_id )
{
	timer_data *timer;
	
	LCUISleeper_BreakSleep( &timer_sleeper );
	Queue_Lock( &global_timer_list );
	timer = TimerList_Find( timer_id );
	if( timer ) {
		/* 计算处于暂停状态的时长 */
		timer->pause_ms += (long int)LCUI_GetTicks( timer->pause_time );
		timer->state = STATE_RUN;
		Queue_Unlock( &global_timer_list );
		return 0;
	}
	Queue_Unlock( &global_timer_list );
	return -1;
}
예제 #16
0
파일: timer.c 프로젝트: fshunj/LCUI
/**
 * 暂停定时器的倒计时
 * 一般用于往复定时的定时器
 * @param timer_id
 *	目标定时器的标识符
 * @return
 *	正常返回0,指定ID的定时器不存在则返回-1.
 * */
LCUI_API int LCUITimer_Pause( int timer_id )
{
	timer_data *timer;
	
	LCUISleeper_BreakSleep( &timer_sleeper );
	Queue_Lock( &global_timer_list );
	timer = TimerList_Find( timer_id );
	if( timer ) {
		/* 记录暂停时的时间 */
		timer->pause_time = LCUI_GetTickCount();
		timer->state = STATE_PAUSE;
		Queue_Unlock( &global_timer_list );
		return 0;
	}
	Queue_Unlock( &global_timer_list );
	return -1;
}
예제 #17
0
파일: main.c 프로젝트: yydaor/LCUI
static void LCUI_DestroyAllApps(void)
{
	LCUI_App *app; 
	int i, total;

	Queue_Lock( &LCUI_Sys.app_list );
	total = Queue_GetTotal(&LCUI_Sys.app_list);
	for (i = 0; i < total; ++i) {
		app = Queue_Get(&LCUI_Sys.app_list, 0);
		if(app == NULL) {
			continue;
		}
		Queue_Delete (&LCUI_Sys.app_list, 0); 
	}
	Queue_Unlock( &LCUI_Sys.app_list );
	Queue_Destroy( &LCUI_Sys.app_list );
}
예제 #18
0
파일: widget_event.c 프로젝트: FrankHB/LCUI
/** 移除指定部件的记录,使之不再响应状态变化 */
LCUI_API void WidgetRecord_Delete( LCUI_Widget *widget )
{
	int n;
	WidgetRecordItem *item;

	Queue_Lock( &widget_proc_record );
	n = Queue_GetTotal( &widget_proc_record );
	for(; n>=0; --n) {
		item = (WidgetRecordItem*)
		Queue_Get( &widget_proc_record, n );
		if( item && item->widget == widget ) {
			Queue_Delete( &widget_proc_record, n );
			break;
		}
	}
	Queue_Unlock( &widget_proc_record );
}
예제 #19
0
파일: timer.c 프로젝트: fshunj/LCUI
/**
 * 重设定时器的等待时间
 * @param timer_id
 *	需要释放的定时器的标识符
 * @param n_ms
 *	等待的时间,单位为毫秒
 * @return
 *	正常返回0,指定ID的定时器不存在则返回-1.
 * */
LCUI_API int LCUITimer_Reset( int timer_id, long int n_ms )
{
	timer_data *timer;
	
	LCUISleeper_BreakSleep( &timer_sleeper );
	Queue_Lock( &global_timer_list );
	timer = TimerList_Find( timer_id );
	if( timer ) {
		timer->start_time = LCUI_GetTickCount();
		timer->pause_ms = 0;
		timer->total_ms = n_ms;
		TimerList_UpdateTimerPos( &global_timer_list, timer );
		Queue_Unlock( &global_timer_list );
		return 0;
	}
	Queue_Unlock( &global_timer_list );
	return -1;
}
예제 #20
0
/* 从消息队列中取出一个消息 */
int Game_GetMsg( GameMsg *msg_buff )
{
	GameMsg *p_msg;

	Game_RecvMsg();
	while( Queue_GetTotal(&game_msg_queue)<=0 ) {
		LCUISleeper_StartSleep( &msg_sleeper, 1000 );
	}
	Queue_Lock( &game_msg_queue );
	p_msg = (GameMsg*)Queue_Get( &game_msg_queue, 0 );
	if( p_msg == NULL ) {
		Queue_Unlock( &game_msg_queue );
		return -1;
	}
	*msg_buff = *p_msg;
	Queue_Delete( &game_msg_queue, 0 );
	Queue_Unlock( &game_msg_queue );
	return 0;
}
예제 #21
0
파일: main.c 프로젝트: yydaor/LCUI
static void
LCUIApp_QuitAllMainLoops( LCUI_ID app_id )
{
	int i, total;
	LCUI_MainLoop *loop;

	Queue_Lock( &mainloop_queue );
	total = Queue_GetTotal( &mainloop_queue );
	for(i=0; i<total; ++i) {
		loop = (LCUI_MainLoop*)Queue_Get( &mainloop_queue, i );
		if( loop == NULL ) {
			continue;
		}
		if( loop->app_id == app_id ) {
			loop->quit = TRUE;
		}
	}
	Queue_Unlock( &mainloop_queue );
}
예제 #22
0
파일: timer.c 프로젝트: fshunj/LCUI
/**
 * 设置定时器
 * 定时器的作用是让一个任务在经过指定时间后才执行
 * @param n_ms
 *	等待的时间,单位为毫秒
 * @param callback_func
 *	用于响应定时器的回调函数
 * @param reuse
 *	指示该定时器是否重复使用,如果要用于循环定时处理某些
 *	任务,可将它置为 TRUE,否则置于 FALSE。
 * @return
 *	该定时器的标识符
 * */
LCUI_API int LCUITimer_Set(	long int n_ms,
				void (*callback_func)(void*),
				void *arg,
				LCUI_BOOL reuse )
{
	int n;
	int64_t time_left;
	timer_data timer, *p_timer;
	static int id = 100;

	/* 打断定时器睡眠者的睡眠 */
	LCUISleeper_BreakSleep( &timer_sleeper );
	Queue_Lock( &global_timer_list );
	n = Queue_GetTotal( &global_timer_list );
	while(n--) {
		p_timer = (timer_data*)Queue_Get( &global_timer_list, n );
		if( !p_timer ) {
			continue;
		}
		time_left = LCUI_GetTicks( p_timer->start_time );
		time_left -= p_timer->pause_ms;
		time_left = p_timer->total_ms - time_left;
		if( time_left <= n_ms ) {
			break;
		}
	}

	timer.id = ++id;
	timer.app_id = LCUIApp_GetSelfID();
	timer.state = STATE_RUN;
	timer.reuse = reuse;
	timer.total_ms = n_ms;
	timer.pause_ms = 0;
	timer.start_time = LCUI_GetTickCount();
	timer.callback_func = callback_func;
	timer.arg = arg;

	Queue_Insert( &global_timer_list, n+1, &timer );
	Queue_Unlock( &global_timer_list );
	DEBUG_MSG("set timer, id: %d, total_ms: %d,app_id: %lu\n", timer.id, timer.total_ms, timer.app_id);
	return timer.id;
}
예제 #23
0
파일: widget_event.c 프로젝트: FrankHB/LCUI
/** 清理部件列表中需要移除的部件,并将部件状态设置为NORMAL */
static void WidgetRecord_Clear( void )
{
	int i, n;
	WidgetRecordItem *item;

	Queue_Lock( &widget_proc_record );
	n = Queue_GetTotal( &widget_proc_record );
	for(i=0; i<n; ++i) {
		item = (WidgetRecordItem*)
		Queue_Get( &widget_proc_record, i );
		if( !item->need_delete ) {
			continue;
		}
		Widget_SetState( item->widget, WIDGET_STATE_NORMAL );
		Queue_Delete( &widget_proc_record, i );
		n = Queue_GetTotal( &widget_proc_record );
		--i;
	}
	Queue_Unlock( &widget_proc_record );
}
예제 #24
0
파일: device.c 프로젝트: FrankHB/LCUI
/** 
 * 功能:注册设备
 * 说明:为指定设备添加处理函数
 * */
LCUI_API int LCUIDevice_Add(	LCUI_BOOL (*init_func)(void), 
				LCUI_BOOL (*proc_func)(void), 
				LCUI_BOOL (*destroy_func)(void) )
{
	dev_func_data data;
	
	if( init_func ) {
		init_func();
	}
	data.init_func = init_func;
	data.proc_func = proc_func;
	data.destroy_func = destroy_func;
	Queue_Lock( &dev_list );
	if( Queue_Add( &dev_list, &data ) ) {
		Queue_Unlock( &dev_list );
		return 0;
	}
	Queue_Unlock( &dev_list );
	return -1;
}
예제 #25
0
파일: widget_event.c 프로젝트: FrankHB/LCUI
/** 添加部件至列表里,如果已存在,则标记该部件不需要删除 */
static int WidgetRecord_Add( LCUI_Widget *widget )
{
	int i, n;
	WidgetRecordItem new_item, *item;

	Queue_Lock( &widget_proc_record );
	n = Queue_GetTotal( &widget_proc_record );
	for(i=0; i<n; ++i) {
		item = (WidgetRecordItem*)
		Queue_Get( &widget_proc_record, i );
		if( item->widget == widget ) {
			Queue_Unlock( &widget_proc_record );
			item->need_delete = FALSE;
			return 1;
		}
	}
	new_item.need_delete = FALSE;
	new_item.widget = widget;
	Queue_Add( &widget_proc_record, &new_item );
	Queue_Unlock( &widget_proc_record );
	return 0;
}
예제 #26
0
파일: widget_msg.c 프로젝트: fshunj/LCUI
LCUI_API void WidgetMsg_Proc( LCUI_Widget *widget )
{
	int i,n;
	WidgetMsgData *data_ptr;
	LCUI_Widget *child;
	LCUI_Queue *msg_buff, *child_list;
	
	if( widget == NULL ) {
		widget = RootWidget_GetSelf();
	}
	msg_buff = Widget_GetMsgBuff( widget );
	child_list = Widget_GetChildList( widget );
	
	Queue_Lock( msg_buff );
	n = Queue_GetTotal( msg_buff );
	for(i=0; i<n; ++i) {
		DEBUG_MSG("[%d/%d]get msg\n", i, n);
		data_ptr = (WidgetMsgData*)Queue_Get( msg_buff, i );
		DEBUG_MSG("[%d/%d]dispatch msg\n", i, n);
		if( WidgetMsg_Dispatch( widget, data_ptr ) ) {
			DEBUG_MSG("[%d/%d]delete msg\n", i, n);
			Queue_Delete( msg_buff, i );
			n = Queue_GetTotal( msg_buff );
			--i;
		}
		DEBUG_MSG("[%d/%d]skip msg\n", i, n);
	}
	Queue_Unlock( msg_buff );
	n = Queue_GetTotal( child_list );
	/* 从尾到首,递归处理子部件的更新 */
	while(n--) {
		child = (LCUI_Widget*)Queue_Get( child_list, n );
		if( child ) {
			DEBUG_MSG("proc child msg\n");
			WidgetMsg_Proc( child );
		}
	}
}
예제 #27
0
파일: task.c 프로젝트: fshunj/LCUI
static int Tasks_CustomAdd( LCUI_Queue *tasks, int mode, LCUI_Task *task )
{
	int total, i;
	LCUI_Task *tmp_task;
	
	Queue_Lock( tasks );
	total = Queue_GetTotal(tasks);
	/* 如果模式是“添加新的”模式 */
	if( mode == ADD_MODE_ADD_NEW ) {
		Queue_Add(tasks, task); 
		Queue_Unlock( tasks );
		return 0;
	}
	for (i=0; i < total; ++i) { 
		tmp_task = Queue_Get(tasks, i);
		/* 如果指针无效,或者函数指针已有记录 */
		if( !tmp_task || tmp_task->func != task->func ) {
			continue;
		}
		/* 如果要求的是不重复模式 */ 
		if(Check_Option(mode, ADD_MODE_NOT_REPEAT)) {
			/* 如果要求是第1个参数不能重复 */
			if(Check_Option(mode, AND_ARG_F)) {
				/* 如果要求是第2个参数也不能重复 */
				if(Check_Option(mode, AND_ARG_S)) {
					/* 如果函数以及参数1和2都一样 */ 
					if(tmp_task->arg[0] == task->arg[0] 
					&& tmp_task->arg[1] == task->arg[1]) {
						Destroy_Task( task );
						Queue_Unlock( tasks );
						return -1; 
					}
				} else {/* 否则,只是要求函数以及第1个参数不能全部重复 */
					if(tmp_task->arg[0] == task->arg[0]) { 
						Destroy_Task( task );
						Queue_Unlock( tasks );
						return -1; 
					}
				}
			}/* 否则,如果只是要求是第2个参数不能重复 */
			else if(Check_Option(mode, AND_ARG_S)) {
				if(tmp_task->arg[1] == task->arg[1] ) {
					Destroy_Task( task );
					Queue_Unlock( tasks );
					return -1; 
				}
			} else {/* 否则,只是要求函数不同 */ 
				Destroy_Task( task );
				Queue_Unlock( tasks );
				return -1; 
			}
		}/* 如果要求的是替换模式 */
		else if(Check_Option(mode, ADD_MODE_REPLACE)) {
			/* 如果要求是第1个参数相同 */
			if( Check_Option(mode, AND_ARG_F) ) {
				/* 如果要求是第2个参数也相同 */
				if( Check_Option(mode, AND_ARG_S) ) {
					if(tmp_task->arg[0] == task->arg[0] 
					&& tmp_task->arg[1] == task->arg[1]
					) {
						break; 
					}
				} else {/* 否则,只是要求函数以及第1个参数全部相同 */
					if(tmp_task->arg[0] == task->arg[0]) {
						break; 
					}
				}
			}/* 否则,如果只是要求第2个参数不能相同 */
			else if(Check_Option(mode, AND_ARG_S)) {
				if(tmp_task->arg[1] == task->arg[1]) {
					break; 
				}
			} else { 
				break; 
			}
		}
	}
	
	if(i == total) {
		Queue_Add(tasks, task); 
	} else {
		Queue_Replace( tasks, i, task ); 
	}
	Queue_Unlock( tasks );
	return 0;
}
예제 #28
0
파일: timer.c 프로젝트: fshunj/LCUI
/** 定时器线程,用于处理列表中各个定时器 */
static void TimerThread( void *arg )
{
	int i, n;
	long int n_ms;
	LCUI_Func func_data;
	LCUI_Queue *timer_list;
	timer_data *timer = NULL;
	int64_t lost_ms;

	timer_list = (LCUI_Queue*)arg;
	func_data.arg[0] = NULL;
	func_data.arg[1] = NULL;

	while( !LCUI_Active() ) {
		LCUI_MSleep(10);
	}
	while( timer_thread_active ) {
		Queue_Lock( timer_list );
		n = Queue_GetTotal( timer_list );
		for(i=0; i<n; ++i) {
			timer = (timer_data*)Queue_Get( timer_list , i);
			if( !timer ) {
				continue;
			}
			if( timer->state == STATE_RUN ) {
				break;
			}
		}
		Queue_Unlock( timer_list );
		/* 没有要处理的定时器,停留一段时间再进行下次循环 */
		if(i >= n || !timer ) {
			LCUI_MSleep(10);
			continue;
		}
		lost_ms = LCUI_GetTicks( timer->start_time );
		/* 减去处于暂停状态的时长 */
		lost_ms -= timer->pause_ms;
		/* 若流失的时间未达到总定时时长 */
		if( lost_ms < timer->total_ms ) {
			Queue_Lock( timer_list );
			n_ms = timer->total_ms - lost_ms;
			/* 开始睡眠 */
			LCUISleeper_StartSleep( &timer_sleeper, n_ms );
			Queue_Unlock( timer_list );
			lost_ms = LCUI_GetTicks( timer->start_time );
			lost_ms -= timer->pause_ms;
			if( lost_ms < timer->total_ms ) {
				continue;
			}
		}
		DEBUG_MSG("timer: %d, start_time: %I64dms, cur_time: %I64dms, cur_ms: %I64d, total_ms: %ld\n", 
			timer->id, timer->start_time, LCUI_GetTickCount(), timer->total_ms-lost_ms, timer->total_ms);
		/* 准备任务数据 */
		func_data.id = timer->app_id;
		func_data.func = (CallBackFunc)timer->callback_func;
		func_data.arg[0] = timer->arg;
		func_data.destroy_arg[0] = FALSE;
		/* 添加该任务至指定程序的任务队列,添加模式是覆盖 */
		AppTasks_CustomAdd( ADD_MODE_REPLACE | AND_ARG_F, &func_data );
		Queue_Lock( timer_list );
		/* 若需要重复使用,则重置剩余等待时间 */
		if( timer->reuse ) {
			timer->start_time = LCUI_GetTickCount();
			timer->pause_ms = 0;
			TimerList_UpdateTimerPos( timer_list, timer );
		} else { /* 否则,释放该定时器 */
			LCUITimer_Free( timer->id );
		}
		Queue_Unlock( timer_list );
	}
	LCUIThread_Exit(NULL);
}