⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 workerthread.cpp

📁 Dialogic VFX传真卡编程,程序实现了在Windows Fax服务中注册Dialogic VFX传真的功能
💻 CPP
字号:
#include "stdafx.h"
#include "sivfax.h"
#include "exports.h"
#include "global.h"

int ProcessDialogicEvent();
int ProcessSystemEvent();

DWORD WINAPI WorkerThread(LPVOID lpParam)
{
	BOOL bRet;
	DWORD dwNumberOfBytes;
	DWORD dwCompletionKey;
	LPOVERLAPPED lpov;
	while ( TRUE )
	{
		bRet = GetQueuedCompletionStatus(g_hCallbackIocp,
			&dwNumberOfBytes,&dwCompletionKey,&lpov,INFINITE);
		if ( bRet == TRUE )
		{
			switch(dwCompletionKey)
			{
			case DIALOGIC_EVENT:
				ProcessDialogicEvent();
				break;
			default:
				break;
			
			}
		}
		else
			return -1;
	}
	return 0;
}

int ProcessDialogicEvent()
{
	sr_waitevt(0);
	int chdev = sr_getevtdev(0);
	int eventType = sr_getevttype(0);
	DX_CST *cstp = ( DX_CST * )sr_getevtdatap(0);
	switch(eventType)
	{
	case TDX_CST:
		WriteDebugString(L"%s",L"CST Event");
		//振零事件
		if (cstp->cst_event == DE_RINGS)
		{
			WriteDebugString(L"%s",L"Ring Event");
			PDEVICE_INFO pd;
			int nRet = sr_getparm(chdev,SR_USERCONTEXT,(void *)&pd);
			if (nRet == -1)
			{
				WriteDebugString(L"%s",L"ProcessDialogicEvent: Errorsr_getparm error");
				return -1;
			}
			WriteDebugString(L"Begin Post Ring Event");
			EnterCriticalSection(&pd->cs);
			LINEMESSAGE* LineMsg;
			LineMsg = (LINEMESSAGE *)LocalAlloc(LPTR,sizeof(LINEMESSAGE));//(LocalAlloc(LPTR,sizeof(LINEMESSAGE)));
			WriteDebugString(L"DeviceId: %d",pd->DeviceId);
			LineMsg->hDevice = pd->DeviceId + DEVICE_ID_PREFIX;
			LineMsg->dwMessageID = 0;
			LineMsg->dwCallbackInstance = 0;
			LineMsg->dwParam1 = LINEDEVSTATE_RINGING;
			LineMsg->dwParam2 = 0;
			LineMsg->dwParam3 = 0;
			PostQueuedCompletionStatus(g_hIocpRing,sizeof(LINEMESSAGE),(ULONG_PTR)g_dwComKeyRing,(LPOVERLAPPED)LineMsg);
			LeaveCriticalSection(&pd->cs);
			WriteDebugString(L"End Post Ring Event");
		}
		break;
	case TFX_PHASEB:
		{
			char remoteid[21] = {"SIVFax"};
			PDEVICE_INFO pd;
//			WriteDebugString(L"%s",L"ProcessDialogicEvent: Information PhaseB Event");
		
			int nRet = sr_getparm(chdev,SR_USERCONTEXT,(void *)&pd);
			if (nRet == -1)
			{
				WriteDebugString(L"%s",L"ProcessDialogicEvent: Errorsr_getparm error");
				return -1;
			}

			PJOB_INFO pJobInfo;
			pJobInfo = pd->pJobInfo;
			if(pJobInfo)
			{
				EnterCriticalSection(&pd->cs);
				if (pJobInfo->CSI == NULL)
				{
					if(ATFX_BSTAT(chdev) & DFS_REMOTEID)
					{
						if(fx_getparm(chdev, FC_REMOTEID, (void*)remoteid) == -1)
							WriteDebugString(L"%s","ProcessDialogicEvent: GetRemoteID Error");
						pJobInfo->CSI = StringToWString(remoteid);
					}
				}
				if (pJobInfo->JobType == JOB_SEND)
				{
					WriteDebugString(L"%s:%d",L"ProcessDialogicEvent: Information PhaseB Job Send",ATFX_PGXFER(chdev));
					pJobInfo->PageCount  = ATFX_PGXFER(chdev) + 1;
					pJobInfo->Status = FS_TRANSMITTING;
					PostJobStatus2(pd,ERROR_SUCCESS);
				}
				else if (pJobInfo->JobType == JOB_RECEIVE)
				{
					WriteDebugString(L"%s",L"ProcessDialogicEvent: Information PhaseB Job Receive");
					pJobInfo->PageCount  = ATFX_PGXFER(chdev) + 1;
					pJobInfo->Status = FS_RECEIVING;
					PostJobStatus2(pd,ERROR_SUCCESS);
				}
				LeaveCriticalSection(&pd->cs);
			}
		}
		break;
	case TFX_PHASED:
		{
			PDEVICE_INFO pd;
			char remoteid[21] = {"SIVFax"};

			int nRet = sr_getparm(chdev,SR_USERCONTEXT,(void *)&pd);
			if (nRet == -1)
			{
				WriteDebugString(L"%s",L"ProcessDialogicEvent: Error sr_getparm error");
				return -1;
			}

			PJOB_INFO pJobInfo;
			pJobInfo = pd->pJobInfo;
			if(pJobInfo)
			{
				EnterCriticalSection(&pd->cs);
				if (pJobInfo->CSI == NULL)
				{
					if(ATFX_BSTAT(chdev) & DFS_REMOTEID)
					{
						if(fx_getparm(chdev, FC_REMOTEID, (void*)remoteid) == -1)
							WriteDebugString(L"%s","ProcessDialogicEvent: GetRemoteID Error");
						
						pJobInfo->CSI = StringToWString(remoteid);
					}
				}
				if (pJobInfo->JobType == JOB_SEND)
				{
					WriteDebugString(L"%s:%d",L"ProcessDialogicEvent: Information PhaseD Job Send",ATFX_PGXFER(chdev));
					if (ATFX_PGXFER(chdev) < pJobInfo->TotoalPages)
					{
						pJobInfo->PageCount  = ATFX_PGXFER(chdev) + 1;
						pJobInfo->Status = FS_TRANSMITTING;
						PostJobStatus2(pd,ERROR_SUCCESS);
					}
					else
					{
						pJobInfo->Status = FS_COMPLETED;
						PostJobStatus2(pd,ERROR_SUCCESS);
						WriteDebugString(L"%s",L"Last Pages");
					}

				}

				else if (pJobInfo->JobType == JOB_RECEIVE)
				{
					WriteDebugString(L"%s",L"ProcessDialogicEvent: Information PhaseD Job Receive");

					pJobInfo->PageCount  = ATFX_PGXFER(chdev) + 1;
					pJobInfo->Status = FS_RECEIVING;
					PostJobStatus2(pd,ERROR_SUCCESS);
				}
				LeaveCriticalSection(&pd->cs);
			}

		}
		break;
	}
	return 0;
}	

int ProcessSystemEvent()
{



	return 0;
}

⌨️ 快捷键说明

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