Removed touch input channel thread

The touch input channel only sends small events (touch points et al)
and therefore does not require a heavy processing thread.
This commit is contained in:
Armin Novak 2019-12-18 11:31:40 +01:00
parent 2e1d719ab1
commit 947645520d
2 changed files with 23 additions and 117 deletions

View File

@ -101,11 +101,6 @@ struct _RDPEI_PLUGIN
RDPINPUT_CONTACT_DATA contacts[MAX_CONTACTS]; RDPINPUT_CONTACT_DATA contacts[MAX_CONTACTS];
RDPINPUT_CONTACT_POINT* contactPoints; RDPINPUT_CONTACT_POINT* contactPoints;
HANDLE event;
HANDLE stopEvent;
HANDLE thread;
CRITICAL_SECTION lock;
rdpContext* rdpcontext; rdpContext* rdpcontext;
}; };
typedef struct _RDPEI_PLUGIN RDPEI_PLUGIN; typedef struct _RDPEI_PLUGIN RDPEI_PLUGIN;
@ -166,76 +161,6 @@ static UINT rdpei_add_frame(RdpeiClientContext* context)
return CHANNEL_RC_OK; return CHANNEL_RC_OK;
} }
static DWORD WINAPI rdpei_schedule_thread(LPVOID arg)
{
DWORD status;
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)arg;
UINT error = CHANNEL_RC_OK;
RdpeiClientContext* context;
HANDLE hdl[2];
if (!rdpei)
{
error = ERROR_INVALID_PARAMETER;
goto out;
}
context = (RdpeiClientContext*)rdpei->iface.pInterface;
hdl[0] = rdpei->event;
hdl[1] = rdpei->stopEvent;
if (!context)
{
error = ERROR_INVALID_PARAMETER;
goto out;
}
while (1)
{
status = WaitForMultipleObjects(2, hdl, FALSE, 20);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %" PRIu32 "!", error);
break;
}
if (status == WAIT_OBJECT_0 + 1)
break;
EnterCriticalSection(&rdpei->lock);
if ((error = rdpei_add_frame(context)))
{
WLog_ERR(TAG, "rdpei_add_frame failed with error %" PRIu32 "!", error);
break;
}
if (rdpei->frame.contactCount > 0)
{
if ((error = rdpei_send_frame(context)))
{
WLog_ERR(TAG, "rdpei_send_frame failed with error %" PRIu32 "!", error);
break;
}
}
if (status == WAIT_OBJECT_0)
ResetEvent(rdpei->event);
LeaveCriticalSection(&rdpei->lock);
}
out:
if (error && rdpei && rdpei->rdpcontext)
setChannelError(rdpei->rdpcontext, error, "rdpei_schedule_thread reported an error");
ExitThread(error);
return error;
}
/** /**
* Function description * Function description
* *
@ -636,30 +561,9 @@ static UINT rdpei_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManag
} }
rdpei->listener->pInterface = rdpei->iface.pInterface; rdpei->listener->pInterface = rdpei->iface.pInterface;
InitializeCriticalSection(&rdpei->lock);
if (!(rdpei->event = CreateEvent(NULL, TRUE, FALSE, NULL)))
{
WLog_ERR(TAG, "CreateEvent failed!");
goto error_out;
}
if (!(rdpei->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
{
WLog_ERR(TAG, "CreateEvent failed!");
goto error_out;
}
if (!(rdpei->thread = CreateThread(NULL, 0, rdpei_schedule_thread, (void*)rdpei, 0, NULL)))
{
WLog_ERR(TAG, "CreateThread failed!");
goto error_out;
}
return error; return error;
error_out: error_out:
CloseHandle(rdpei->stopEvent);
CloseHandle(rdpei->event);
free(rdpei->listener_callback); free(rdpei->listener_callback);
return error; return error;
} }
@ -672,25 +576,10 @@ error_out:
static UINT rdpei_plugin_terminated(IWTSPlugin* pPlugin) static UINT rdpei_plugin_terminated(IWTSPlugin* pPlugin)
{ {
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)pPlugin; RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)pPlugin;
UINT error;
if (!pPlugin) if (!pPlugin)
return ERROR_INVALID_PARAMETER; return ERROR_INVALID_PARAMETER;
SetEvent(rdpei->stopEvent);
EnterCriticalSection(&rdpei->lock);
if (WaitForSingleObject(rdpei->thread, INFINITE) == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "!", error);
return error;
}
CloseHandle(rdpei->stopEvent);
CloseHandle(rdpei->event);
CloseHandle(rdpei->thread);
DeleteCriticalSection(&rdpei->lock);
free(rdpei->listener_callback); free(rdpei->listener_callback);
free(rdpei->context); free(rdpei->context);
free(rdpei); free(rdpei);
@ -747,16 +636,32 @@ UINT rdpei_send_frame(RdpeiClientContext* context)
* *
* @return 0 on success, otherwise a Win32 error code * @return 0 on success, otherwise a Win32 error code
*/ */
static UINT rdpei_add_contact(RdpeiClientContext* context, RDPINPUT_CONTACT_DATA* contact) static UINT rdpei_add_contact(RdpeiClientContext* context, const RDPINPUT_CONTACT_DATA* contact)
{ {
UINT error;
RDPINPUT_CONTACT_POINT* contactPoint; RDPINPUT_CONTACT_POINT* contactPoint;
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)context->handle; RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)context->handle;
EnterCriticalSection(&rdpei->lock);
contactPoint = (RDPINPUT_CONTACT_POINT*)&rdpei->contactPoints[contact->contactId]; contactPoint = (RDPINPUT_CONTACT_POINT*)&rdpei->contactPoints[contact->contactId];
CopyMemory(&(contactPoint->data), contact, sizeof(RDPINPUT_CONTACT_DATA)); CopyMemory(&(contactPoint->data), contact, sizeof(RDPINPUT_CONTACT_DATA));
contactPoint->dirty = TRUE; contactPoint->dirty = TRUE;
SetEvent(rdpei->event);
LeaveCriticalSection(&rdpei->lock); error = rdpei_add_frame(context);
if (error != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "rdpei_add_frame failed with error %" PRIu32 "!", error);
return error;
}
if (rdpei->frame.contactCount > 0)
{
error = rdpei_send_frame(context);
if (error != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "rdpei_send_frame failed with error %" PRIu32 "!", error);
return error;
}
}
return CHANNEL_RC_OK; return CHANNEL_RC_OK;
} }
@ -769,7 +674,7 @@ static UINT rdpei_touch_begin(RdpeiClientContext* context, int externalId, int x
int* contactId) int* contactId)
{ {
unsigned int i; unsigned int i;
int contactIdlocal = -1; INT64 contactIdlocal = -1;
RDPINPUT_CONTACT_DATA contact; RDPINPUT_CONTACT_DATA contact;
RDPINPUT_CONTACT_POINT* contactPoint = NULL; RDPINPUT_CONTACT_POINT* contactPoint = NULL;
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)context->handle; RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*)context->handle;

View File

@ -31,7 +31,8 @@
typedef struct _rdpei_client_context RdpeiClientContext; typedef struct _rdpei_client_context RdpeiClientContext;
typedef int (*pcRdpeiGetVersion)(RdpeiClientContext* context); typedef int (*pcRdpeiGetVersion)(RdpeiClientContext* context);
typedef UINT (*pcRdpeiAddContact)(RdpeiClientContext* context, RDPINPUT_CONTACT_DATA* contact); typedef UINT (*pcRdpeiAddContact)(RdpeiClientContext* context,
const RDPINPUT_CONTACT_DATA* contact);
typedef UINT (*pcRdpeiTouchBegin)(RdpeiClientContext* context, int externalId, int x, int y, typedef UINT (*pcRdpeiTouchBegin)(RdpeiClientContext* context, int externalId, int x, int y,
int* contactId); int* contactId);