pcsyn_task.c

来自「是一个手机功能的模拟程序」· C语言 代码 · 共 75 行

C
75
字号
#include <windows.h>

#include "pcsyn_task.h"
#include "pcsyn_protocol.h"


static PCSyn_TaskInfo pcsyn_taskinfo;


VOID pcsyn_task_core(void* argc)
{
	pcsyn_taskinfo.bIsRunning = TRUE;
 while( 1)
  {	
    switch(WaitForMultipleObjects(PCTASK_EVENT,pcsyn_taskinfo.hEvent,FALSE, INFINITE) - WAIT_OBJECT_0 )
	{
	case 0:
		pc_writebystatus(handle_inbuffer());
		break;
	case 1:
		pc_resend();
		break;
	case 2:
		return;
	}
  }
 
}




void send_pcsyn_event(int index)
{
	SetEvent(pcsyn_taskinfo.hEvent[index]);
}

void pcsyn_start_task()
{
	int i = 0;
	if(pcsyn_taskinfo.hPCTask)
		return;
	/*create task*/
	
	for(i = 0; i< PCTASK_EVENT; i++)
		pcsyn_taskinfo.hEvent[i] = CreateEvent(NULL, FALSE, FALSE, NULL);

	
	pcsyn_taskinfo.hPCTask= CreateThread( (LPSECURITY_ATTRIBUTES) NULL, //安全属性
		0,
		(LPTHREAD_START_ROUTINE)pcsyn_task_core, //线程的全局函数
		NULL,
		0,
		NULL);
}

void pcsyn_stop_task()
{
	int i;
	pcsyn_taskinfo.bIsRunning = FALSE;
	
	send_pcsyn_event(2);
	WaitForSingleObject(pcsyn_taskinfo.hPCTask,INFINITE);

	for(i = 0; i< PCTASK_EVENT; i++)
	{	
		CloseHandle(pcsyn_taskinfo.hEvent[i]);
		pcsyn_taskinfo.hEvent[i] = NULL;
	}

	CloseHandle(pcsyn_taskinfo.hPCTask);
	pcsyn_taskinfo.hPCTask = NULL;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?