2011-07-18 07:16:31 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Client
|
|
|
|
* 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
|
|
|
#ifndef _WIN32
|
|
|
|
#include <unistd.h>
|
2011-08-06 00:56:40 +04:00
|
|
|
#include <pthread.h>
|
2011-08-17 04:49:46 +04:00
|
|
|
#include <sys/select.h>
|
2011-08-17 07:54:42 +04:00
|
|
|
#else
|
|
|
|
#include <winsock2.h>
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <ws2tcpip.h>
|
2011-08-17 04:49:46 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <errno.h>
|
2011-08-06 00:56:40 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2011-08-15 22:33:04 +04:00
|
|
|
#include <freerdp/gdi/gdi.h>
|
2011-08-06 00:56:40 +04:00
|
|
|
#include <freerdp/utils/args.h>
|
|
|
|
#include <freerdp/utils/event.h>
|
2012-09-19 03:40:54 +04:00
|
|
|
#include <freerdp/utils/memory.h>
|
2011-08-06 00:56:40 +04:00
|
|
|
#include <freerdp/constants.h>
|
2011-10-16 22:57:15 +04:00
|
|
|
#include <freerdp/channels/channels.h>
|
2011-08-11 07:07:03 +04:00
|
|
|
#include <freerdp/plugins/cliprdr.h>
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2012-09-19 03:40:54 +04:00
|
|
|
#include <winpr/synch.h>
|
|
|
|
|
2011-08-06 00:56:40 +04:00
|
|
|
struct tf_info
|
|
|
|
{
|
2011-08-17 07:54:42 +04:00
|
|
|
void* data;
|
2011-08-06 00:56:40 +04:00
|
|
|
};
|
|
|
|
typedef struct tf_info tfInfo;
|
|
|
|
|
2011-10-16 08:50:10 +04:00
|
|
|
struct tf_context
|
|
|
|
{
|
|
|
|
rdpContext _p;
|
|
|
|
|
|
|
|
tfInfo* tfi;
|
|
|
|
};
|
|
|
|
typedef struct tf_context tfContext;
|
|
|
|
|
2012-09-19 03:40:54 +04:00
|
|
|
HANDLE g_sem;
|
2011-08-06 00:56:40 +04:00
|
|
|
static int g_thread_count = 0;
|
|
|
|
|
|
|
|
struct thread_data
|
|
|
|
{
|
|
|
|
freerdp* instance;
|
|
|
|
};
|
2011-07-18 07:16:31 +04:00
|
|
|
|
2011-07-28 08:38:25 +04:00
|
|
|
#include <freerdp/freerdp.h>
|
2011-07-28 19:09:51 +04:00
|
|
|
#include <freerdp/utils/args.h>
|
2011-07-18 07:16:31 +04:00
|
|
|
|
2011-10-21 07:15:18 +04:00
|
|
|
void tf_context_new(freerdp* instance, rdpContext* context)
|
2011-10-16 08:50:10 +04:00
|
|
|
{
|
2011-10-17 05:39:11 +04:00
|
|
|
context->channels = freerdp_channels_new();
|
2011-10-16 08:50:10 +04:00
|
|
|
}
|
|
|
|
|
2011-10-21 07:15:18 +04:00
|
|
|
void tf_context_free(freerdp* instance, rdpContext* context)
|
2011-10-16 08:50:10 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
void 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;
|
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
void 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)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tf_receive_channel_data(freerdp* instance, int channelId, uint8* data, int size, int flags, int total_size)
|
2011-07-18 07:16:31 +04:00
|
|
|
{
|
2011-10-16 22:57:15 +04:00
|
|
|
return freerdp_channels_data(instance, channelId, data, size, flags, total_size);
|
2011-08-06 00:56:40 +04:00
|
|
|
}
|
|
|
|
|
2011-08-18 01:28:26 +04:00
|
|
|
int tf_process_plugin_args(rdpSettings* settings, const char* name, RDP_PLUGIN_DATA* plugin_data, void* user_data)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
2011-10-17 05:39:11 +04:00
|
|
|
rdpChannels* channels = (rdpChannels*) user_data;
|
2011-08-06 00:56:40 +04:00
|
|
|
|
|
|
|
printf("Load plugin %s\n", name);
|
2011-10-17 05:39:11 +04:00
|
|
|
freerdp_channels_load_plugin(channels, settings, name, plugin_data);
|
2011-08-06 00:56:40 +04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-11-01 03:15:27 +04:00
|
|
|
void tf_process_cb_monitor_ready_event(rdpChannels* channels, freerdp* instance)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
2011-08-18 01:28:26 +04:00
|
|
|
RDP_EVENT* event;
|
|
|
|
RDP_CB_FORMAT_LIST_EVENT* format_list_event;
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2011-08-18 01:28:26 +04:00
|
|
|
event = freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, RDP_EVENT_TYPE_CB_FORMAT_LIST, NULL, NULL);
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2011-11-01 03:15:27 +04:00
|
|
|
format_list_event = (RDP_CB_FORMAT_LIST_EVENT*) event;
|
2011-08-06 00:56:40 +04:00
|
|
|
format_list_event->num_formats = 0;
|
|
|
|
|
2011-10-17 05:39:11 +04:00
|
|
|
freerdp_channels_send_event(channels, event);
|
2011-08-06 00:56:40 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 05:39:11 +04:00
|
|
|
void tf_process_channel_event(rdpChannels* channels, freerdp* instance)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
2011-08-18 01:28:26 +04:00
|
|
|
RDP_EVENT* event;
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2011-10-17 05:39:11 +04:00
|
|
|
event = freerdp_channels_pop_event(channels);
|
2011-10-16 08:50:10 +04:00
|
|
|
|
2011-08-06 00:56:40 +04:00
|
|
|
if (event)
|
|
|
|
{
|
|
|
|
switch (event->event_type)
|
|
|
|
{
|
2011-11-01 03:15:27 +04:00
|
|
|
case RDP_EVENT_TYPE_CB_MONITOR_READY:
|
|
|
|
tf_process_cb_monitor_ready_event(channels, instance);
|
2011-08-06 00:56:40 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("tf_process_channel_event: unknown event type %d\n", event->event_type);
|
|
|
|
break;
|
|
|
|
}
|
2011-10-16 08:50:10 +04:00
|
|
|
|
2011-08-06 00:56:40 +04:00
|
|
|
freerdp_event_free(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean tf_pre_connect(freerdp* instance)
|
|
|
|
{
|
|
|
|
tfInfo* tfi;
|
2011-10-16 08:50:10 +04:00
|
|
|
tfContext* context;
|
2011-08-06 00:56:40 +04:00
|
|
|
rdpSettings* settings;
|
|
|
|
|
2011-10-16 08:50:10 +04:00
|
|
|
context = (tfContext*) instance->context;
|
2011-08-06 00:56:40 +04:00
|
|
|
tfi = (tfInfo*) xzalloc(sizeof(tfInfo));
|
2011-10-16 08:50:10 +04:00
|
|
|
context->tfi = tfi;
|
2011-07-28 08:38:25 +04:00
|
|
|
|
|
|
|
settings = instance->settings;
|
2011-07-18 07:16:31 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
settings->order_support[NEG_DSTBLT_INDEX] = true;
|
|
|
|
settings->order_support[NEG_PATBLT_INDEX] = true;
|
|
|
|
settings->order_support[NEG_SCRBLT_INDEX] = true;
|
|
|
|
settings->order_support[NEG_OPAQUE_RECT_INDEX] = true;
|
|
|
|
settings->order_support[NEG_DRAWNINEGRID_INDEX] = true;
|
|
|
|
settings->order_support[NEG_MULTIDSTBLT_INDEX] = true;
|
|
|
|
settings->order_support[NEG_MULTIPATBLT_INDEX] = true;
|
|
|
|
settings->order_support[NEG_MULTISCRBLT_INDEX] = true;
|
|
|
|
settings->order_support[NEG_MULTIOPAQUERECT_INDEX] = true;
|
|
|
|
settings->order_support[NEG_MULTI_DRAWNINEGRID_INDEX] = true;
|
|
|
|
settings->order_support[NEG_LINETO_INDEX] = true;
|
|
|
|
settings->order_support[NEG_POLYLINE_INDEX] = true;
|
|
|
|
settings->order_support[NEG_MEMBLT_INDEX] = true;
|
|
|
|
settings->order_support[NEG_MEM3BLT_INDEX] = true;
|
|
|
|
settings->order_support[NEG_SAVEBITMAP_INDEX] = true;
|
|
|
|
settings->order_support[NEG_GLYPH_INDEX_INDEX] = true;
|
|
|
|
settings->order_support[NEG_FAST_INDEX_INDEX] = true;
|
|
|
|
settings->order_support[NEG_FAST_GLYPH_INDEX] = true;
|
|
|
|
settings->order_support[NEG_POLYGON_SC_INDEX] = true;
|
|
|
|
settings->order_support[NEG_POLYGON_CB_INDEX] = true;
|
|
|
|
settings->order_support[NEG_ELLIPSE_SC_INDEX] = true;
|
|
|
|
settings->order_support[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
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-06 00:56:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
boolean tf_post_connect(freerdp* instance)
|
|
|
|
{
|
2011-10-16 08:50:10 +04:00
|
|
|
rdpGdi* gdi;
|
2011-07-18 07:16:31 +04:00
|
|
|
|
2011-12-13 20:36:05 +04:00
|
|
|
gdi_init(instance, CLRCONV_ALPHA | CLRCONV_INVERT | CLRBUF_16BPP | CLRBUF_32BPP, NULL);
|
2011-10-16 08:50:10 +04:00
|
|
|
gdi = instance->context->gdi;
|
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
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-06 00:56:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int tfreerdp_run(freerdp* instance)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int fds;
|
|
|
|
int max_fds;
|
|
|
|
int rcount;
|
|
|
|
int wcount;
|
|
|
|
void* rfds[32];
|
|
|
|
void* wfds[32];
|
|
|
|
fd_set rfds_set;
|
|
|
|
fd_set wfds_set;
|
2011-10-17 05:39:11 +04:00
|
|
|
rdpChannels* channels;
|
2011-08-06 00:56:40 +04:00
|
|
|
|
|
|
|
memset(rfds, 0, sizeof(rfds));
|
|
|
|
memset(wfds, 0, sizeof(wfds));
|
|
|
|
|
2011-10-21 07:15:18 +04:00
|
|
|
channels = instance->context->channels;
|
2011-07-18 07:16:31 +04:00
|
|
|
|
2011-10-17 05:02:28 +04:00
|
|
|
freerdp_connect(instance);
|
2011-07-18 07:16:31 +04:00
|
|
|
|
2011-08-06 00:56:40 +04:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
rcount = 0;
|
|
|
|
wcount = 0;
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
if (freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount) != true)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
|
|
|
printf("Failed to get FreeRDP file descriptor\n");
|
|
|
|
break;
|
|
|
|
}
|
2011-11-19 21:19:16 +04:00
|
|
|
if (freerdp_channels_get_fds(channels, instance, rfds, &rcount, wfds, &wcount) != true)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
|
|
|
printf("Failed to get channel manager file descriptor\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
max_fds = 0;
|
|
|
|
FD_ZERO(&rfds_set);
|
2012-07-06 20:19:41 +04:00
|
|
|
FD_ZERO(&wfds_set);
|
2011-08-06 00:56:40 +04:00
|
|
|
|
|
|
|
for (i = 0; i < rcount; i++)
|
|
|
|
{
|
|
|
|
fds = (int)(long)(rfds[i]);
|
|
|
|
|
|
|
|
if (fds > max_fds)
|
|
|
|
max_fds = fds;
|
|
|
|
|
|
|
|
FD_SET(fds, &rfds_set);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (max_fds == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (select(max_fds + 1, &rfds_set, &wfds_set, NULL, NULL) == -1)
|
|
|
|
{
|
|
|
|
/* these are not really errors */
|
|
|
|
if (!((errno == EAGAIN) ||
|
|
|
|
(errno == EWOULDBLOCK) ||
|
|
|
|
(errno == EINPROGRESS) ||
|
|
|
|
(errno == EINTR))) /* signal occurred */
|
|
|
|
{
|
|
|
|
printf("tfreerdp_run: select failed\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
if (freerdp_check_fds(instance) != true)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
|
|
|
printf("Failed to check FreeRDP file descriptor\n");
|
|
|
|
break;
|
|
|
|
}
|
2011-11-19 21:19:16 +04:00
|
|
|
if (freerdp_channels_check_fds(channels, instance) != true)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
|
|
|
printf("Failed to check channel manager file descriptor\n");
|
|
|
|
break;
|
|
|
|
}
|
2011-10-17 05:39:11 +04:00
|
|
|
tf_process_channel_event(channels, instance);
|
2011-08-06 00:56:40 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 05:39:11 +04:00
|
|
|
freerdp_channels_close(channels, instance);
|
|
|
|
freerdp_channels_free(channels);
|
2011-07-28 08:38:25 +04:00
|
|
|
freerdp_free(instance);
|
|
|
|
|
2011-07-18 07:16:31 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2011-08-06 00:56:40 +04:00
|
|
|
|
|
|
|
void* thread_func(void* param)
|
|
|
|
{
|
|
|
|
struct thread_data* data;
|
|
|
|
data = (struct thread_data*) param;
|
|
|
|
|
|
|
|
tfreerdp_run(data->instance);
|
|
|
|
|
|
|
|
xfree(data);
|
|
|
|
|
|
|
|
pthread_detach(pthread_self());
|
|
|
|
|
|
|
|
g_thread_count--;
|
|
|
|
|
|
|
|
if (g_thread_count < 1)
|
2012-09-19 03:40:54 +04:00
|
|
|
ReleaseSemaphore(g_sem, 1, NULL);
|
2011-08-06 00:56:40 +04:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
pthread_t thread;
|
|
|
|
freerdp* instance;
|
|
|
|
struct thread_data* data;
|
2011-10-17 05:39:11 +04:00
|
|
|
rdpChannels* channels;
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2011-10-16 22:57:15 +04:00
|
|
|
freerdp_channels_global_init();
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2012-09-19 03:40:54 +04:00
|
|
|
g_sem = CreateSemaphore(NULL, 0, 1, NULL);
|
2011-08-06 00:56:40 +04:00
|
|
|
|
|
|
|
instance = freerdp_new();
|
|
|
|
instance->PreConnect = tf_pre_connect;
|
|
|
|
instance->PostConnect = tf_post_connect;
|
|
|
|
instance->ReceiveChannelData = tf_receive_channel_data;
|
|
|
|
|
2011-10-21 07:15:18 +04:00
|
|
|
instance->context_size = sizeof(tfContext);
|
|
|
|
instance->ContextNew = tf_context_new;
|
|
|
|
instance->ContextFree = tf_context_free;
|
2011-10-16 08:50:10 +04:00
|
|
|
freerdp_context_new(instance);
|
|
|
|
|
2011-10-21 07:15:18 +04:00
|
|
|
channels = instance->context->channels;
|
2011-10-17 05:39:11 +04:00
|
|
|
freerdp_parse_args(instance->settings, argc, argv, tf_process_plugin_args, channels, NULL, NULL);
|
2011-08-06 00:56:40 +04:00
|
|
|
|
|
|
|
data = (struct thread_data*) xzalloc(sizeof(struct thread_data));
|
|
|
|
data->instance = instance;
|
|
|
|
|
|
|
|
g_thread_count++;
|
|
|
|
pthread_create(&thread, 0, thread_func, data);
|
|
|
|
|
|
|
|
while (g_thread_count > 0)
|
|
|
|
{
|
2012-09-19 03:40:54 +04:00
|
|
|
WaitForSingleObject(g_sem, INFINITE);
|
2011-08-06 00:56:40 +04:00
|
|
|
}
|
|
|
|
|
2011-10-16 22:57:15 +04:00
|
|
|
freerdp_channels_global_uninit();
|
2011-08-06 00:56:40 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|