2011-07-18 07:16:31 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-18 07:16:31 +04:00
|
|
|
* FreeRDP Test UI
|
|
|
|
*
|
2011-08-06 00:56:40 +04:00
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2011-07-18 07:16:31 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:20:53 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-08-17 04:49:46 +04:00
|
|
|
#include <errno.h>
|
2011-08-06 00:56:40 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2012-10-09 04:33:58 +04:00
|
|
|
|
2012-11-26 21:49:21 +04:00
|
|
|
#include <freerdp/freerdp.h>
|
2012-10-09 04:33:58 +04:00
|
|
|
#include <freerdp/constants.h>
|
2011-08-15 22:33:04 +04:00
|
|
|
#include <freerdp/gdi/gdi.h>
|
2012-11-26 21:49:21 +04:00
|
|
|
#include <freerdp/client/file.h>
|
|
|
|
#include <freerdp/client/cmdline.h>
|
2012-10-09 04:33:58 +04:00
|
|
|
#include <freerdp/client/cliprdr.h>
|
2011-10-16 22:57:15 +04:00
|
|
|
#include <freerdp/channels/channels.h>
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
#include <winpr/crt.h>
|
2012-09-19 03:40:54 +04:00
|
|
|
#include <winpr/synch.h>
|
2014-09-12 19:13:01 +04:00
|
|
|
#include <freerdp/log.h>
|
|
|
|
|
|
|
|
#define TAG CLIENT_TAG("sample")
|
2012-09-19 03:40:54 +04:00
|
|
|
|
2011-10-16 08:50:10 +04:00
|
|
|
struct tf_context
|
|
|
|
{
|
|
|
|
rdpContext _p;
|
|
|
|
};
|
|
|
|
typedef struct tf_context tfContext;
|
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
static BOOL tf_context_new(freerdp* instance, rdpContext* context)
|
2011-10-16 08:50:10 +04:00
|
|
|
{
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!(context->channels = freerdp_channels_new()))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
2011-10-16 08:50:10 +04:00
|
|
|
}
|
|
|
|
|
2015-04-16 10:04:19 +03:00
|
|
|
static void tf_context_free(freerdp* instance, rdpContext* context)
|
2011-10-16 08:50:10 +04:00
|
|
|
{
|
2015-04-19 11:20:48 +03:00
|
|
|
if (context && context->channels)
|
|
|
|
{
|
|
|
|
freerdp_channels_close(context->channels, instance);
|
|
|
|
freerdp_channels_free(context->channels);
|
2015-04-28 18:00:41 +03:00
|
|
|
context->channels = NULL;
|
2015-04-19 11:20:48 +03:00
|
|
|
}
|
2011-10-16 08:50:10 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
static BOOL tf_begin_paint(rdpContext* context)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
2011-11-22 04:41:49 +04:00
|
|
|
rdpGdi* gdi = context->gdi;
|
2011-08-06 00:56:40 +04:00
|
|
|
gdi->primary->hdc->hwnd->invalid->null = 1;
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-08-06 00:56:40 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
static BOOL tf_end_paint(rdpContext* context)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
2011-11-22 04:41:49 +04:00
|
|
|
rdpGdi* gdi = context->gdi;
|
2011-08-06 00:56:40 +04:00
|
|
|
|
|
|
|
if (gdi->primary->hdc->hwnd->invalid->null)
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2015-04-21 15:15:53 +03:00
|
|
|
return TRUE;
|
2011-08-06 00:56:40 +04:00
|
|
|
}
|
|
|
|
|
2015-04-16 10:04:19 +03:00
|
|
|
static BOOL tf_pre_connect(freerdp* instance)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
|
|
|
rdpSettings* settings;
|
|
|
|
|
2011-07-28 08:38:25 +04:00
|
|
|
|
|
|
|
settings = instance->settings;
|
2011-07-18 07:16:31 +04:00
|
|
|
|
2012-11-08 00:13:14 +04:00
|
|
|
settings->OrderSupport[NEG_DSTBLT_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_PATBLT_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_SCRBLT_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_OPAQUE_RECT_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_DRAWNINEGRID_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_MULTIDSTBLT_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_MULTIPATBLT_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_MULTISCRBLT_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_MULTIOPAQUERECT_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_MULTI_DRAWNINEGRID_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_LINETO_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_POLYLINE_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_MEMBLT_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_MEM3BLT_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_SAVEBITMAP_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_GLYPH_INDEX_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_FAST_INDEX_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_FAST_GLYPH_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_POLYGON_SC_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_POLYGON_CB_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_ELLIPSE_SC_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_ELLIPSE_CB_INDEX] = TRUE;
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2011-10-21 07:15:18 +04:00
|
|
|
freerdp_channels_pre_connect(instance->context->channels, instance);
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-06 00:56:40 +04:00
|
|
|
}
|
|
|
|
|
2015-04-16 10:04:19 +03:00
|
|
|
static BOOL tf_post_connect(freerdp* instance)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
2011-12-13 20:36:05 +04:00
|
|
|
gdi_init(instance, CLRCONV_ALPHA | CLRCONV_INVERT | CLRBUF_16BPP | CLRBUF_32BPP, NULL);
|
2011-08-06 00:56:40 +04:00
|
|
|
|
|
|
|
instance->update->BeginPaint = tf_begin_paint;
|
|
|
|
instance->update->EndPaint = tf_end_paint;
|
|
|
|
|
2011-10-21 07:15:18 +04:00
|
|
|
freerdp_channels_post_connect(instance->context->channels, instance);
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-06 00:56:40 +04:00
|
|
|
}
|
|
|
|
|
2015-04-16 10:04:19 +03:00
|
|
|
static void* tf_client_thread_proc(freerdp* instance)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
2015-04-16 10:04:19 +03:00
|
|
|
DWORD nCount;
|
|
|
|
DWORD status;
|
|
|
|
HANDLE handles[64];
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2015-02-15 18:06:17 +03:00
|
|
|
if (!freerdp_connect(instance))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "connection failure");
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2015-04-19 11:20:48 +03:00
|
|
|
while (!freerdp_shall_disconnect(instance))
|
2014-11-07 23:25:37 +03:00
|
|
|
{
|
2015-04-21 13:24:50 +03:00
|
|
|
nCount = freerdp_get_event_handles(instance->context, &handles[0], 64);
|
|
|
|
|
|
|
|
if (nCount == 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "%s: freerdp_get_event_handles failed", __FUNCTION__);
|
|
|
|
break;
|
|
|
|
}
|
2014-11-07 23:25:37 +03:00
|
|
|
|
2015-04-16 10:04:19 +03:00
|
|
|
status = WaitForMultipleObjects(nCount, handles, FALSE, 100);
|
2014-11-07 23:25:37 +03:00
|
|
|
|
2015-04-16 10:04:19 +03:00
|
|
|
if (status == WAIT_FAILED)
|
2014-11-07 23:25:37 +03:00
|
|
|
{
|
2015-04-16 10:04:19 +03:00
|
|
|
WLog_ERR(TAG, "%s: WaitForMultipleObjects failed with %lu", __FUNCTION__, status);
|
2014-11-07 23:25:37 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-04-16 10:04:19 +03:00
|
|
|
if (!freerdp_check_event_handles(instance->context))
|
2014-11-07 23:25:37 +03:00
|
|
|
{
|
2015-04-16 10:04:19 +03:00
|
|
|
WLog_ERR(TAG, "Failed to check FreeRDP event handles");
|
2014-11-07 23:25:37 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-16 10:04:19 +03:00
|
|
|
freerdp_disconnect(instance);
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2014-07-14 21:27:50 +04:00
|
|
|
ExitThread(0);
|
2011-08-06 00:56:40 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2012-11-26 21:49:21 +04:00
|
|
|
int status;
|
2014-11-07 23:25:37 +03:00
|
|
|
HANDLE thread;
|
2011-08-06 00:56:40 +04:00
|
|
|
freerdp* instance;
|
|
|
|
|
|
|
|
instance = freerdp_new();
|
2015-03-23 19:25:23 +03:00
|
|
|
if (!instance)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Couldn't create instance");
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-08-06 00:56:40 +04:00
|
|
|
instance->PreConnect = tf_pre_connect;
|
|
|
|
instance->PostConnect = tf_post_connect;
|
|
|
|
|
2013-06-14 05:34:46 +04:00
|
|
|
instance->ContextSize = sizeof(tfContext);
|
2011-10-21 07:15:18 +04:00
|
|
|
instance->ContextNew = tf_context_new;
|
|
|
|
instance->ContextFree = tf_context_free;
|
2015-04-28 18:00:41 +03:00
|
|
|
|
|
|
|
if (!freerdp_context_new(instance))
|
2015-03-23 19:25:23 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Couldn't create context");
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-10-16 08:50:10 +04:00
|
|
|
|
2015-03-16 12:15:37 +03:00
|
|
|
status = freerdp_client_settings_parse_command_line(instance->settings, argc, argv, FALSE);
|
2012-11-26 21:49:21 +04:00
|
|
|
|
|
|
|
if (status < 0)
|
2014-11-07 23:25:37 +03:00
|
|
|
{
|
2012-11-26 21:49:21 +04:00
|
|
|
exit(0);
|
2014-11-07 23:25:37 +03:00
|
|
|
}
|
2012-11-26 21:49:21 +04:00
|
|
|
|
|
|
|
freerdp_client_load_addins(instance->context->channels, instance->settings);
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2014-11-07 23:25:37 +03:00
|
|
|
thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)
|
|
|
|
tf_client_thread_proc, instance, 0, NULL);
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2014-11-07 23:25:37 +03:00
|
|
|
WaitForSingleObject(thread, INFINITE);
|
2015-04-19 11:20:48 +03:00
|
|
|
freerdp_context_free(instance);
|
|
|
|
freerdp_free(instance);
|
2011-08-06 00:56:40 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|