[channels,printer] support printer channel in synchronous mode.

This commit is contained in:
Vic Lee 2024-03-07 17:14:18 +08:00 committed by Martin Fleisz
parent 938e1ca2f1
commit 33416fd3ac

View File

@ -62,6 +62,7 @@ typedef struct
HANDLE thread;
rdpContext* rdpcontext;
char port[64];
BOOL async;
} PRINTER_DEVICE;
typedef enum
@ -684,8 +685,21 @@ static UINT printer_irp_request(DEVICE* device, IRP* irp)
WINPR_ASSERT(printer_dev);
WINPR_ASSERT(irp);
if (printer_dev->async)
{
InterlockedPushEntrySList(printer_dev->pIrpList, &(irp->ItemEntry));
SetEvent(printer_dev->event);
}
else
{
UINT error = printer_process_irp(printer_dev, irp);
if (error)
{
WLog_ERR(TAG, "printer_process_irp failed with error %" PRIu32 "!", error);
return error;
}
}
return CHANNEL_RC_OK;
}
@ -890,6 +904,8 @@ static UINT printer_free(DEVICE* device)
WINPR_ASSERT(printer_dev);
if (printer_dev->async)
{
SetEvent(printer_dev->stopEvent);
if (WaitForSingleObject(printer_dev->thread, INFINITE) == WAIT_FAILED)
@ -915,6 +931,7 @@ static UINT printer_free(DEVICE* device)
CloseHandle(printer_dev->stopEvent);
CloseHandle(printer_dev->event);
winpr_aligned_free(printer_dev->pIrpList);
}
if (printer_dev->printer)
{
@ -961,8 +978,18 @@ static UINT printer_register(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, rdpPrint
printer_dev->device.Free = printer_free;
printer_dev->rdpcontext = pEntryPoints->rdpcontext;
printer_dev->printer = printer;
printer_dev->pIrpList = (WINPR_PSLIST_HEADER)winpr_aligned_malloc(sizeof(WINPR_SLIST_HEADER),
MEMORY_ALLOCATION_ALIGNMENT);
if (!freerdp_settings_get_bool(pEntryPoints->rdpcontext->settings,
FreeRDP_SynchronousStaticChannels))
printer_dev->async = TRUE;
if (!printer_load_from_config(pEntryPoints->rdpcontext->settings, printer, printer_dev))
goto error_out;
if (printer_dev->async)
{
printer_dev->pIrpList = (WINPR_PSLIST_HEADER)winpr_aligned_malloc(
sizeof(WINPR_SLIST_HEADER), MEMORY_ALLOCATION_ALIGNMENT);
if (!printer_dev->pIrpList)
{
@ -971,38 +998,43 @@ static UINT printer_register(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, rdpPrint
goto error_out;
}
if (!printer_load_from_config(pEntryPoints->rdpcontext->settings, printer, printer_dev))
goto error_out;
InitializeSListHead(printer_dev->pIrpList);
if (!(printer_dev->event = CreateEvent(NULL, TRUE, FALSE, NULL)))
printer_dev->event = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!printer_dev->event)
{
WLog_ERR(TAG, "CreateEvent failed!");
error = ERROR_INTERNAL_ERROR;
goto error_out;
}
if (!(printer_dev->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
printer_dev->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!printer_dev->stopEvent)
{
WLog_ERR(TAG, "CreateEvent failed!");
error = ERROR_INTERNAL_ERROR;
goto error_out;
}
}
if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman, &printer_dev->device)))
error = pEntryPoints->RegisterDevice(pEntryPoints->devman, &printer_dev->device);
if (error)
{
WLog_ERR(TAG, "RegisterDevice failed with error %" PRIu32 "!", error);
goto error_out;
}
if (!(printer_dev->thread =
CreateThread(NULL, 0, printer_thread_func, (void*)printer_dev, 0, NULL)))
if (printer_dev->async)
{
printer_dev->thread =
CreateThread(NULL, 0, printer_thread_func, (void*)printer_dev, 0, NULL);
if (!printer_dev->thread)
{
WLog_ERR(TAG, "CreateThread failed!");
error = ERROR_INTERNAL_ERROR;
goto error_out;
}
}
WINPR_ASSERT(printer->AddRef);
printer->AddRef(printer);