2013-03-20 00:52:07 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Input Virtual Channel Extension
|
|
|
|
*
|
|
|
|
* Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
2013-05-09 07:18:42 +04:00
|
|
|
#include <winpr/stream.h>
|
2013-05-14 03:17:25 +04:00
|
|
|
#include <winpr/sysinfo.h>
|
2013-03-20 00:52:07 +04:00
|
|
|
#include <winpr/cmdline.h>
|
|
|
|
|
|
|
|
#include <freerdp/addin.h>
|
|
|
|
|
2013-05-09 07:18:42 +04:00
|
|
|
#include "rdpei_common.h"
|
2013-03-20 00:52:07 +04:00
|
|
|
|
|
|
|
#include "rdpei_main.h"
|
|
|
|
|
2013-05-15 01:45:52 +04:00
|
|
|
/**
|
|
|
|
* Touch Input
|
|
|
|
* http://msdn.microsoft.com/en-us/library/windows/desktop/dd562197/
|
|
|
|
*
|
|
|
|
* Windows Touch Input
|
|
|
|
* http://msdn.microsoft.com/en-us/library/windows/desktop/dd317321/
|
|
|
|
*
|
|
|
|
* Input: Touch injection sample
|
|
|
|
* http://code.msdn.microsoft.com/windowsdesktop/Touch-Injection-Sample-444d9bf7
|
|
|
|
*
|
|
|
|
* Pointer Input Message Reference
|
|
|
|
* http://msdn.microsoft.com/en-us/library/hh454916/
|
|
|
|
*
|
|
|
|
* POINTER_INFO Structure
|
|
|
|
* http://msdn.microsoft.com/en-us/library/hh454907/
|
|
|
|
*
|
|
|
|
* POINTER_TOUCH_INFO Structure
|
|
|
|
* http://msdn.microsoft.com/en-us/library/hh454910/
|
|
|
|
*/
|
|
|
|
|
2013-05-14 03:17:25 +04:00
|
|
|
#define MAX_CONTACTS 512
|
|
|
|
|
|
|
|
struct _RDPEI_CHANNEL_CALLBACK
|
2013-03-20 00:52:07 +04:00
|
|
|
{
|
2013-05-14 03:17:25 +04:00
|
|
|
IWTSVirtualChannelCallback iface;
|
2013-03-20 00:52:07 +04:00
|
|
|
|
|
|
|
IWTSPlugin* plugin;
|
|
|
|
IWTSVirtualChannelManager* channel_mgr;
|
2013-05-14 03:17:25 +04:00
|
|
|
IWTSVirtualChannel* channel;
|
2013-03-20 00:52:07 +04:00
|
|
|
};
|
2013-05-14 03:17:25 +04:00
|
|
|
typedef struct _RDPEI_CHANNEL_CALLBACK RDPEI_CHANNEL_CALLBACK;
|
2013-03-20 00:52:07 +04:00
|
|
|
|
2013-05-14 03:17:25 +04:00
|
|
|
struct _RDPEI_LISTENER_CALLBACK
|
2013-03-20 00:52:07 +04:00
|
|
|
{
|
2013-05-14 03:17:25 +04:00
|
|
|
IWTSListenerCallback iface;
|
2013-03-20 00:52:07 +04:00
|
|
|
|
|
|
|
IWTSPlugin* plugin;
|
|
|
|
IWTSVirtualChannelManager* channel_mgr;
|
2013-05-14 03:17:25 +04:00
|
|
|
RDPEI_CHANNEL_CALLBACK* channel_callback;
|
2013-03-20 00:52:07 +04:00
|
|
|
};
|
2013-05-14 03:17:25 +04:00
|
|
|
typedef struct _RDPEI_LISTENER_CALLBACK RDPEI_LISTENER_CALLBACK;
|
2013-03-20 00:52:07 +04:00
|
|
|
|
|
|
|
struct _RDPEI_PLUGIN
|
|
|
|
{
|
|
|
|
IWTSPlugin iface;
|
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
IWTSListener* listener;
|
2013-03-20 00:52:07 +04:00
|
|
|
RDPEI_LISTENER_CALLBACK* listener_callback;
|
2013-05-14 03:17:25 +04:00
|
|
|
|
|
|
|
int version;
|
2013-05-15 01:45:52 +04:00
|
|
|
UINT16 maxTouchContacts;
|
2013-05-14 03:17:25 +04:00
|
|
|
UINT64 currentFrameTime;
|
|
|
|
UINT64 previousFrameTime;
|
|
|
|
RDPINPUT_TOUCH_FRAME frame;
|
|
|
|
RDPINPUT_CONTACT_DATA contacts[MAX_CONTACTS];
|
2013-05-15 01:45:52 +04:00
|
|
|
RDPINPUT_CONTACT_POINT* contactPoints;
|
2013-03-20 00:52:07 +04:00
|
|
|
};
|
2013-05-14 00:07:42 +04:00
|
|
|
typedef struct _RDPEI_PLUGIN RDPEI_PLUGIN;
|
2013-03-20 00:52:07 +04:00
|
|
|
|
2013-05-09 07:18:42 +04:00
|
|
|
const char* RDPEI_EVENTID_STRINGS[] =
|
|
|
|
{
|
|
|
|
"",
|
|
|
|
"EVENTID_SC_READY",
|
|
|
|
"EVENTID_CS_READY",
|
|
|
|
"EVENTID_TOUCH",
|
|
|
|
"EVENTID_SUSPEND_TOUCH",
|
|
|
|
"EVENTID_RESUME_TOUCH",
|
|
|
|
"EVENTID_DISMISS_HOVERING_CONTACT"
|
|
|
|
};
|
|
|
|
|
2013-05-09 08:21:33 +04:00
|
|
|
int rdpei_send_pdu(RDPEI_CHANNEL_CALLBACK* callback, wStream* s, UINT16 eventId, UINT32 pduLength)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
Stream_SetPosition(s, 0);
|
|
|
|
Stream_Write_UINT16(s, eventId); /* eventId (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, pduLength); /* pduLength (4 bytes) */
|
|
|
|
Stream_SetPosition(s, Stream_Length(s));
|
|
|
|
|
2013-05-14 09:06:25 +04:00
|
|
|
status = callback->channel->Write(callback->channel, Stream_Length(s), Stream_Buffer(s), NULL);
|
2013-05-09 08:21:33 +04:00
|
|
|
|
2013-05-14 09:06:25 +04:00
|
|
|
printf("rdpei_send_pdu: eventId: %d (%s) length: %d status: %d\n",
|
|
|
|
eventId, RDPEI_EVENTID_STRINGS[eventId], pduLength, status);
|
2013-05-09 08:21:33 +04:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rdpei_send_cs_ready_pdu(RDPEI_CHANNEL_CALLBACK* callback)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
wStream* s;
|
|
|
|
UINT32 flags;
|
|
|
|
UINT32 pduLength;
|
2013-05-15 01:45:52 +04:00
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) callback->plugin;
|
2013-05-09 08:21:33 +04:00
|
|
|
|
|
|
|
flags = 0;
|
|
|
|
flags |= READY_FLAGS_SHOW_TOUCH_VISUALS;
|
|
|
|
//flags |= READY_FLAGS_DISABLE_TIMESTAMP_INJECTION;
|
|
|
|
|
|
|
|
pduLength = RDPINPUT_HEADER_LENGTH + 10;
|
|
|
|
s = Stream_New(NULL, pduLength);
|
|
|
|
Stream_Seek(s, RDPINPUT_HEADER_LENGTH);
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, flags); /* flags (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, RDPINPUT_PROTOCOL_V1); /* protocolVersion (4 bytes) */
|
2013-05-15 01:45:52 +04:00
|
|
|
Stream_Write_UINT16(s, rdpei->maxTouchContacts); /* maxTouchContacts (2 bytes) */
|
2013-05-09 08:21:33 +04:00
|
|
|
|
|
|
|
Stream_SealLength(s);
|
|
|
|
|
|
|
|
status = rdpei_send_pdu(callback, s, EVENTID_CS_READY, pduLength);
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2013-05-15 01:45:52 +04:00
|
|
|
void rdpei_print_contact_flags(UINT32 contactFlags)
|
|
|
|
{
|
|
|
|
if (contactFlags & CONTACT_FLAG_DOWN)
|
|
|
|
printf(" CONTACT_FLAG_DOWN");
|
|
|
|
if (contactFlags & CONTACT_FLAG_UPDATE)
|
|
|
|
printf(" CONTACT_FLAG_UPDATE");
|
|
|
|
if (contactFlags & CONTACT_FLAG_UP)
|
|
|
|
printf(" CONTACT_FLAG_UP");
|
|
|
|
if (contactFlags & CONTACT_FLAG_INRANGE)
|
|
|
|
printf(" CONTACT_FLAG_INRANGE");
|
|
|
|
if (contactFlags & CONTACT_FLAG_INCONTACT)
|
|
|
|
printf(" CONTACT_FLAG_INCONTACT");
|
|
|
|
if (contactFlags & CONTACT_FLAG_CANCELED)
|
|
|
|
printf(" CONTACT_FLAG_CANCELED");
|
|
|
|
}
|
|
|
|
|
2013-05-09 08:21:33 +04:00
|
|
|
int rdpei_write_touch_frame(wStream* s, RDPINPUT_TOUCH_FRAME* frame)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
RDPINPUT_CONTACT_DATA* contact;
|
|
|
|
|
2013-05-14 09:06:25 +04:00
|
|
|
printf("contactCount: %d\n", frame->contactCount);
|
|
|
|
printf("frameOffset: 0x%08X\n", (UINT32) frame->frameOffset);
|
|
|
|
|
|
|
|
rdpei_write_2byte_unsigned(s, frame->contactCount); /* contactCount (TWO_BYTE_UNSIGNED_INTEGER) */
|
|
|
|
rdpei_write_8byte_unsigned(s, frame->frameOffset); /* frameOffset (EIGHT_BYTE_UNSIGNED_INTEGER) */
|
2013-05-09 08:21:33 +04:00
|
|
|
|
|
|
|
Stream_EnsureRemainingCapacity(s, frame->contactCount * 32);
|
|
|
|
|
|
|
|
for (index = 0; index < frame->contactCount; index++)
|
|
|
|
{
|
|
|
|
contact = &frame->contacts[index];
|
|
|
|
|
2013-05-14 09:06:25 +04:00
|
|
|
printf("contact[%d].contactId: %d\n", index, contact->contactId);
|
|
|
|
printf("contact[%d].fieldsPresent: %d\n", index, contact->fieldsPresent);
|
|
|
|
printf("contact[%d].x: %d\n", index, contact->x);
|
|
|
|
printf("contact[%d].y: %d\n", index, contact->y);
|
2013-05-15 01:45:52 +04:00
|
|
|
printf("contact[%d].contactFlags: 0x%04X", index, contact->contactFlags);
|
|
|
|
rdpei_print_contact_flags(contact->contactFlags);
|
|
|
|
printf("\n");
|
2013-05-14 09:06:25 +04:00
|
|
|
|
|
|
|
Stream_Write_UINT8(s, contact->contactId); /* contactId (1 byte) */
|
|
|
|
|
|
|
|
/* fieldsPresent (TWO_BYTE_UNSIGNED_INTEGER) */
|
2013-05-09 08:21:33 +04:00
|
|
|
rdpei_write_2byte_unsigned(s, contact->fieldsPresent);
|
2013-05-14 09:06:25 +04:00
|
|
|
|
|
|
|
rdpei_write_4byte_signed(s, contact->x); /* x (FOUR_BYTE_SIGNED_INTEGER) */
|
|
|
|
rdpei_write_4byte_signed(s, contact->y); /* y (FOUR_BYTE_SIGNED_INTEGER) */
|
|
|
|
|
|
|
|
/* contactFlags (FOUR_BYTE_UNSIGNED_INTEGER) */
|
2013-05-09 08:21:33 +04:00
|
|
|
rdpei_write_4byte_unsigned(s, contact->contactFlags);
|
|
|
|
|
|
|
|
if (contact->fieldsPresent & CONTACT_DATA_CONTACTRECT_PRESENT)
|
|
|
|
{
|
2013-05-14 09:06:25 +04:00
|
|
|
/* contactRectLeft (TWO_BYTE_SIGNED_INTEGER) */
|
2013-05-09 08:21:33 +04:00
|
|
|
rdpei_write_2byte_signed(s, contact->contactRectLeft);
|
2013-05-14 09:06:25 +04:00
|
|
|
/* contactRectTop (TWO_BYTE_SIGNED_INTEGER) */
|
2013-05-09 08:21:33 +04:00
|
|
|
rdpei_write_2byte_signed(s, contact->contactRectTop);
|
2013-05-14 09:06:25 +04:00
|
|
|
/* contactRectRight (TWO_BYTE_SIGNED_INTEGER) */
|
2013-05-09 08:21:33 +04:00
|
|
|
rdpei_write_2byte_signed(s, contact->contactRectRight);
|
2013-05-14 09:06:25 +04:00
|
|
|
/* contactRectBottom (TWO_BYTE_SIGNED_INTEGER) */
|
2013-05-09 08:21:33 +04:00
|
|
|
rdpei_write_2byte_signed(s, contact->contactRectBottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contact->fieldsPresent & CONTACT_DATA_ORIENTATION_PRESENT)
|
|
|
|
{
|
2013-05-14 09:06:25 +04:00
|
|
|
/* orientation (FOUR_BYTE_UNSIGNED_INTEGER) */
|
2013-05-09 08:21:33 +04:00
|
|
|
rdpei_write_4byte_unsigned(s, contact->orientation);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contact->fieldsPresent & CONTACT_DATA_PRESSURE_PRESENT)
|
|
|
|
{
|
2013-05-14 09:06:25 +04:00
|
|
|
/* pressure (FOUR_BYTE_UNSIGNED_INTEGER) */
|
2013-05-09 08:21:33 +04:00
|
|
|
rdpei_write_4byte_unsigned(s, contact->pressure);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-14 03:17:25 +04:00
|
|
|
int rdpei_send_touch_event_pdu(RDPEI_CHANNEL_CALLBACK* callback, RDPINPUT_TOUCH_FRAME* frame)
|
2013-05-09 08:21:33 +04:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
wStream* s;
|
|
|
|
UINT32 pduLength;
|
|
|
|
|
2013-05-14 09:06:25 +04:00
|
|
|
pduLength = 64 + (frame->contactCount * 32);
|
2013-05-09 08:21:33 +04:00
|
|
|
|
2013-05-14 09:06:25 +04:00
|
|
|
s = Stream_New(NULL, pduLength);
|
2013-05-09 08:21:33 +04:00
|
|
|
Stream_Seek(s, RDPINPUT_HEADER_LENGTH);
|
|
|
|
|
2013-05-14 09:06:25 +04:00
|
|
|
rdpei_write_4byte_unsigned(s, frame->frameOffset); /* FOUR_BYTE_UNSIGNED_INTEGER */
|
|
|
|
rdpei_write_2byte_unsigned(s, frame->contactCount); /* TWO_BYTE_UNSIGNED_INTEGER */
|
2013-05-09 08:21:33 +04:00
|
|
|
|
2013-05-14 03:17:25 +04:00
|
|
|
rdpei_write_touch_frame(s, frame);
|
2013-05-09 08:21:33 +04:00
|
|
|
|
|
|
|
Stream_SealLength(s);
|
|
|
|
pduLength = Stream_Length(s);
|
|
|
|
|
|
|
|
status = rdpei_send_pdu(callback, s, EVENTID_TOUCH, pduLength);
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rdpei_recv_sc_ready_pdu(RDPEI_CHANNEL_CALLBACK* callback, wStream* s)
|
2013-05-09 07:18:42 +04:00
|
|
|
{
|
|
|
|
UINT32 protocolVersion;
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, protocolVersion); /* protocolVersion (4 bytes) */
|
|
|
|
|
|
|
|
if (protocolVersion != RDPINPUT_PROTOCOL_V1)
|
|
|
|
{
|
|
|
|
printf("Unknown [MS-RDPEI] protocolVersion: 0x%08X\n", protocolVersion);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-09 08:21:33 +04:00
|
|
|
int rdpei_recv_suspend_touch_pdu(RDPEI_CHANNEL_CALLBACK* callback, wStream* s)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rdpei_recv_resume_touch_pdu(RDPEI_CHANNEL_CALLBACK* callback, wStream* s)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rdpei_recv_pdu(RDPEI_CHANNEL_CALLBACK* callback, wStream* s)
|
2013-05-09 07:18:42 +04:00
|
|
|
{
|
|
|
|
UINT16 eventId;
|
|
|
|
UINT32 pduLength;
|
|
|
|
|
|
|
|
Stream_Read_UINT16(s, eventId); /* eventId (2 bytes) */
|
|
|
|
Stream_Read_UINT32(s, pduLength); /* pduLength (4 bytes) */
|
|
|
|
|
|
|
|
printf("rdpei_recv_pdu: eventId: %d (%s) length: %d\n",
|
|
|
|
eventId, RDPEI_EVENTID_STRINGS[eventId], pduLength);
|
|
|
|
|
|
|
|
switch (eventId)
|
|
|
|
{
|
|
|
|
case EVENTID_SC_READY:
|
2013-05-09 08:21:33 +04:00
|
|
|
rdpei_recv_sc_ready_pdu(callback, s);
|
|
|
|
rdpei_send_cs_ready_pdu(callback);
|
2013-05-09 07:18:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EVENTID_SUSPEND_TOUCH:
|
2013-05-09 08:21:33 +04:00
|
|
|
rdpei_recv_suspend_touch_pdu(callback, s);
|
2013-05-09 07:18:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EVENTID_RESUME_TOUCH:
|
2013-05-09 08:21:33 +04:00
|
|
|
rdpei_recv_resume_touch_pdu(callback, s);
|
2013-05-09 07:18:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-20 00:52:07 +04:00
|
|
|
static int rdpei_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, UINT32 cbSize, BYTE* pBuffer)
|
|
|
|
{
|
2013-05-09 07:18:42 +04:00
|
|
|
wStream* s;
|
2013-03-20 00:52:07 +04:00
|
|
|
int status = 0;
|
2013-05-09 08:21:33 +04:00
|
|
|
RDPEI_CHANNEL_CALLBACK* callback = (RDPEI_CHANNEL_CALLBACK*) pChannelCallback;
|
2013-03-20 00:52:07 +04:00
|
|
|
|
2013-05-09 07:18:42 +04:00
|
|
|
s = Stream_New(pBuffer, cbSize);
|
|
|
|
|
2013-05-09 08:21:33 +04:00
|
|
|
status = rdpei_recv_pdu(callback, s);
|
2013-05-09 07:18:42 +04:00
|
|
|
|
|
|
|
Stream_Free(s, FALSE);
|
|
|
|
|
2013-03-20 00:52:07 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rdpei_on_close(IWTSVirtualChannelCallback* pChannelCallback)
|
|
|
|
{
|
|
|
|
RDPEI_CHANNEL_CALLBACK* callback = (RDPEI_CHANNEL_CALLBACK*) pChannelCallback;
|
|
|
|
|
|
|
|
DEBUG_DVC("");
|
|
|
|
|
|
|
|
free(callback);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rdpei_on_new_channel_connection(IWTSListenerCallback* pListenerCallback,
|
|
|
|
IWTSVirtualChannel* pChannel, BYTE* Data, int* pbAccept,
|
|
|
|
IWTSVirtualChannelCallback** ppCallback)
|
|
|
|
{
|
|
|
|
RDPEI_CHANNEL_CALLBACK* callback;
|
|
|
|
RDPEI_LISTENER_CALLBACK* listener_callback = (RDPEI_LISTENER_CALLBACK*) pListenerCallback;
|
|
|
|
|
|
|
|
DEBUG_DVC("");
|
|
|
|
|
|
|
|
callback = (RDPEI_CHANNEL_CALLBACK*) malloc(sizeof(RDPEI_CHANNEL_CALLBACK));
|
|
|
|
ZeroMemory(callback, sizeof(RDPEI_CHANNEL_CALLBACK));
|
|
|
|
|
|
|
|
callback->iface.OnDataReceived = rdpei_on_data_received;
|
|
|
|
callback->iface.OnClose = rdpei_on_close;
|
|
|
|
callback->plugin = listener_callback->plugin;
|
|
|
|
callback->channel_mgr = listener_callback->channel_mgr;
|
|
|
|
callback->channel = pChannel;
|
2013-05-14 03:17:25 +04:00
|
|
|
listener_callback->channel_callback = callback;
|
2013-03-20 00:52:07 +04:00
|
|
|
|
|
|
|
*ppCallback = (IWTSVirtualChannelCallback*) callback;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rdpei_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr)
|
|
|
|
{
|
2013-05-14 00:07:42 +04:00
|
|
|
int status;
|
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) pPlugin;
|
2013-03-20 00:52:07 +04:00
|
|
|
|
|
|
|
DEBUG_DVC("");
|
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
rdpei->listener_callback = (RDPEI_LISTENER_CALLBACK*) malloc(sizeof(RDPEI_LISTENER_CALLBACK));
|
|
|
|
ZeroMemory(rdpei->listener_callback, sizeof(RDPEI_LISTENER_CALLBACK));
|
|
|
|
|
|
|
|
rdpei->listener_callback->iface.OnNewChannelConnection = rdpei_on_new_channel_connection;
|
|
|
|
rdpei->listener_callback->plugin = pPlugin;
|
|
|
|
rdpei->listener_callback->channel_mgr = pChannelMgr;
|
2013-03-20 00:52:07 +04:00
|
|
|
|
2013-05-14 01:39:53 +04:00
|
|
|
status = pChannelMgr->CreateListener(pChannelMgr, RDPEI_DVC_CHANNEL_NAME, 0,
|
2013-05-14 00:07:42 +04:00
|
|
|
(IWTSListenerCallback*) rdpei->listener_callback, &(rdpei->listener));
|
2013-03-20 00:52:07 +04:00
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
rdpei->listener->pInterface = rdpei->iface.pInterface;
|
|
|
|
|
|
|
|
return status;
|
2013-03-20 00:52:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int rdpei_plugin_terminated(IWTSPlugin* pPlugin)
|
|
|
|
{
|
2013-05-14 00:07:42 +04:00
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) pPlugin;
|
2013-03-20 00:52:07 +04:00
|
|
|
|
|
|
|
DEBUG_DVC("");
|
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
free(rdpei);
|
2013-03-20 00:52:07 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
/**
|
|
|
|
* Channel Client Interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
int rdpei_get_version(RdpeiClientContext* context)
|
|
|
|
{
|
2013-05-14 03:17:25 +04:00
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) context->handle;
|
|
|
|
return rdpei->version;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rdpei_begin_frame(RdpeiClientContext* context)
|
|
|
|
{
|
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) context->handle;
|
|
|
|
|
|
|
|
rdpei->frame.contactCount = 0;
|
|
|
|
rdpei->frame.frameOffset = 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rdpei_end_frame(RdpeiClientContext* context)
|
|
|
|
{
|
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) context->handle;
|
|
|
|
RDPEI_CHANNEL_CALLBACK* callback = rdpei->listener_callback->channel_callback;
|
|
|
|
|
2013-05-14 09:06:25 +04:00
|
|
|
//if (rdpei->frame.contactCount < 8)
|
|
|
|
// return 0;
|
|
|
|
|
2013-05-14 03:17:25 +04:00
|
|
|
if (!rdpei->previousFrameTime && !rdpei->currentFrameTime)
|
|
|
|
{
|
|
|
|
rdpei->currentFrameTime = (UINT64) GetTickCount64();
|
|
|
|
rdpei->frame.frameOffset = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rdpei->currentFrameTime = (UINT64) GetTickCount64();
|
|
|
|
rdpei->frame.frameOffset = rdpei->currentFrameTime - rdpei->previousFrameTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
rdpei_send_touch_event_pdu(callback, &rdpei->frame);
|
|
|
|
rdpei->previousFrameTime = rdpei->currentFrameTime;
|
|
|
|
rdpei->frame.contactCount = 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rdpei_add_contact(RdpeiClientContext* context, RDPINPUT_CONTACT_DATA* contact)
|
|
|
|
{
|
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) context->handle;
|
|
|
|
|
|
|
|
if (rdpei->frame.contactCount < MAX_CONTACTS)
|
|
|
|
{
|
2013-05-15 01:45:52 +04:00
|
|
|
CopyMemory(&(rdpei->contacts[rdpei->frame.contactCount]), contact, sizeof(RDPINPUT_CONTACT_DATA));
|
|
|
|
rdpei->frame.contactCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rdpei_contact_begin(RdpeiClientContext* context, int externalId, int x, int y)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
int contactId = -1;
|
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) context->handle;
|
|
|
|
|
|
|
|
/* Create a new contact point in an empty slot */
|
|
|
|
|
|
|
|
for (i = 0; i < rdpei->maxTouchContacts; i++)
|
|
|
|
{
|
|
|
|
if (!rdpei->contactPoints[i].flags)
|
2013-05-14 09:06:25 +04:00
|
|
|
{
|
2013-05-15 01:45:52 +04:00
|
|
|
rdpei->contactPoints[i].flags = 1;
|
|
|
|
rdpei->contactPoints[i].contactId = i;
|
|
|
|
rdpei->contactPoints[i].touchDownX = x;
|
|
|
|
rdpei->contactPoints[i].touchDownX = y;
|
2013-05-14 09:06:25 +04:00
|
|
|
|
2013-05-15 01:45:52 +04:00
|
|
|
for (j = 0; j < MAX_EXTERNAL_IDS; j++)
|
2013-05-14 09:06:25 +04:00
|
|
|
{
|
2013-05-15 01:45:52 +04:00
|
|
|
if (!rdpei->contactPoints[i].externalIds[j])
|
|
|
|
{
|
|
|
|
rdpei->contactPoints[i].externalIds[j] = externalId;
|
|
|
|
rdpei->contactPoints[i].externalIdCount++;
|
|
|
|
break;
|
|
|
|
}
|
2013-05-14 09:06:25 +04:00
|
|
|
}
|
2013-05-15 01:45:52 +04:00
|
|
|
|
|
|
|
contactId = rdpei->contactPoints[i].contactId;
|
|
|
|
break;
|
2013-05-14 09:06:25 +04:00
|
|
|
}
|
2013-05-15 01:45:52 +04:00
|
|
|
}
|
2013-05-14 09:06:25 +04:00
|
|
|
|
2013-05-15 01:45:52 +04:00
|
|
|
return contactId;
|
|
|
|
}
|
2013-05-14 09:06:25 +04:00
|
|
|
|
2013-05-15 01:45:52 +04:00
|
|
|
int rdpei_contact_update(RdpeiClientContext* context, int externalId)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
int contactId = -1;
|
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) context->handle;
|
2013-05-14 09:06:25 +04:00
|
|
|
|
2013-05-15 01:45:52 +04:00
|
|
|
for (i = 0; i < rdpei->maxTouchContacts; i++)
|
|
|
|
{
|
|
|
|
if (!rdpei->contactPoints[i].flags)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (j = 0; j < MAX_EXTERNAL_IDS; j++)
|
|
|
|
{
|
|
|
|
if (rdpei->contactPoints[i].externalIds[j] == externalId)
|
|
|
|
{
|
|
|
|
contactId = rdpei->contactPoints[i].contactId;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contactId != -1)
|
|
|
|
break;
|
2013-05-14 03:17:25 +04:00
|
|
|
}
|
|
|
|
|
2013-05-15 01:45:52 +04:00
|
|
|
return contactId;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rdpei_contact_end(RdpeiClientContext* context, int externalId)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
int contactId = -1;
|
|
|
|
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) context->handle;
|
|
|
|
|
|
|
|
for (i = 0; i < rdpei->maxTouchContacts; i++)
|
|
|
|
{
|
|
|
|
if (!rdpei->contactPoints[i].flags)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (j = 0; j < MAX_EXTERNAL_IDS; j++)
|
|
|
|
{
|
|
|
|
if (rdpei->contactPoints[i].externalIds[j] == externalId)
|
|
|
|
{
|
|
|
|
contactId = rdpei->contactPoints[i].contactId;
|
|
|
|
rdpei->contactPoints[i].externalIds[j] = 0;
|
|
|
|
rdpei->contactPoints[i].externalIdCount--;
|
|
|
|
|
|
|
|
if (rdpei->contactPoints[i].externalIdCount < 1)
|
|
|
|
{
|
|
|
|
rdpei->contactPoints[i].flags = 0;
|
|
|
|
rdpei->contactPoints[i].contactId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contactId != -1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return contactId;
|
2013-05-14 00:07:42 +04:00
|
|
|
}
|
|
|
|
|
2013-03-20 00:52:07 +04:00
|
|
|
#ifdef STATIC_CHANNELS
|
|
|
|
#define DVCPluginEntry rdpei_DVCPluginEntry
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
RDPEI_PLUGIN* rdpei;
|
2013-05-14 00:07:42 +04:00
|
|
|
RdpeiClientContext* context;
|
2013-03-20 00:52:07 +04:00
|
|
|
|
|
|
|
rdpei = (RDPEI_PLUGIN*) pEntryPoints->GetPlugin(pEntryPoints, "rdpei");
|
|
|
|
|
|
|
|
if (rdpei == NULL)
|
|
|
|
{
|
2013-05-15 01:45:52 +04:00
|
|
|
size_t size;
|
|
|
|
|
2013-03-20 00:52:07 +04:00
|
|
|
rdpei = (RDPEI_PLUGIN*) malloc(sizeof(RDPEI_PLUGIN));
|
|
|
|
ZeroMemory(rdpei, sizeof(RDPEI_PLUGIN));
|
|
|
|
|
|
|
|
rdpei->iface.Initialize = rdpei_plugin_initialize;
|
|
|
|
rdpei->iface.Connected = NULL;
|
|
|
|
rdpei->iface.Disconnected = NULL;
|
|
|
|
rdpei->iface.Terminated = rdpei_plugin_terminated;
|
|
|
|
|
2013-05-14 03:17:25 +04:00
|
|
|
rdpei->version = 1;
|
|
|
|
rdpei->currentFrameTime = 0;
|
|
|
|
rdpei->previousFrameTime = 0;
|
|
|
|
rdpei->frame.contacts = (RDPINPUT_CONTACT_DATA*) rdpei->contacts;
|
|
|
|
|
2013-05-15 01:45:52 +04:00
|
|
|
rdpei->maxTouchContacts = 10;
|
|
|
|
size = rdpei->maxTouchContacts * sizeof(RDPINPUT_CONTACT_POINT);
|
|
|
|
rdpei->contactPoints = (RDPINPUT_CONTACT_POINT*) malloc(size);
|
|
|
|
ZeroMemory(rdpei->contactPoints, size);
|
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
context = (RdpeiClientContext*) malloc(sizeof(RdpeiClientContext));
|
|
|
|
|
|
|
|
context->handle = (void*) rdpei;
|
|
|
|
context->GetVersion = rdpei_get_version;
|
2013-05-14 03:17:25 +04:00
|
|
|
context->BeginFrame = rdpei_begin_frame;
|
|
|
|
context->EndFrame = rdpei_end_frame;
|
|
|
|
context->AddContact = rdpei_add_contact;
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2013-05-15 01:45:52 +04:00
|
|
|
context->ContactBegin = rdpei_contact_begin;
|
|
|
|
context->ContactUpdate = rdpei_contact_update;
|
|
|
|
context->ContactEnd = rdpei_contact_end;
|
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
rdpei->iface.pInterface = (void*) context;
|
|
|
|
|
2013-03-20 00:52:07 +04:00
|
|
|
error = pEntryPoints->RegisterPlugin(pEntryPoints, "rdpei", (IWTSPlugin*) rdpei);
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|