Updated sample for new API.

This commit is contained in:
Armin Novak 2015-04-16 09:04:19 +02:00 committed by Armin Novak
parent f5cdae5586
commit efeb621721

View File

@ -21,16 +21,6 @@
#include "config.h"
#endif
#ifndef _WIN32
#include <unistd.h>
#include <pthread.h>
#include <sys/select.h>
#else
#include <winsock2.h>
#include <Windows.h>
#include <ws2tcpip.h>
#endif
#include <errno.h>
#include <stdio.h>
#include <string.h>
@ -55,24 +45,24 @@ struct tf_context
};
typedef struct tf_context tfContext;
int tf_context_new(freerdp* instance, rdpContext* context)
static int tf_context_new(freerdp* instance, rdpContext* context)
{
context->channels = freerdp_channels_new();
return 0;
}
void tf_context_free(freerdp* instance, rdpContext* context)
static void tf_context_free(freerdp* instance, rdpContext* context)
{
}
void tf_begin_paint(rdpContext* context)
static void tf_begin_paint(rdpContext* context)
{
rdpGdi* gdi = context->gdi;
gdi->primary->hdc->hwnd->invalid->null = 1;
}
void tf_end_paint(rdpContext* context)
static void tf_end_paint(rdpContext* context)
{
rdpGdi* gdi = context->gdi;
@ -80,7 +70,7 @@ void tf_end_paint(rdpContext* context)
return;
}
BOOL tf_pre_connect(freerdp* instance)
static BOOL tf_pre_connect(freerdp* instance)
{
tfContext* tfc;
rdpSettings* settings;
@ -117,7 +107,7 @@ BOOL tf_pre_connect(freerdp* instance)
return TRUE;
}
BOOL tf_post_connect(freerdp* instance)
static BOOL tf_post_connect(freerdp* instance)
{
rdpGdi* gdi;
@ -132,109 +122,12 @@ BOOL tf_post_connect(freerdp* instance)
return TRUE;
}
int tfreerdp_run(freerdp* instance)
static void* tf_client_thread_proc(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;
rdpChannels* channels;
channels = instance->context->channels;
freerdp_connect(instance);
while (1)
{
rcount = 0;
wcount = 0;
ZeroMemory(rfds, sizeof(rfds));
ZeroMemory(wfds, sizeof(wfds));
if (!freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount))
{
WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
break;
}
if (!freerdp_channels_get_fds(channels, instance, rfds, &rcount, wfds, &wcount))
{
WLog_ERR(TAG, "Failed to get channel manager file descriptor");
break;
}
max_fds = 0;
FD_ZERO(&rfds_set);
FD_ZERO(&wfds_set);
fprintf(stderr, "rcount: %d\n", rcount);
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 */
{
WLog_ERR(TAG, "tfreerdp_run: select failed");
break;
}
}
if (!freerdp_check_fds(instance))
{
WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
break;
}
if (!freerdp_channels_check_fds(channels, instance))
{
WLog_ERR(TAG, "Failed to check channel manager file descriptor");
break;
}
}
freerdp_channels_disconnect(channels, instance);
freerdp_disconnect(instance);
freerdp_channels_close(channels, instance);
freerdp_channels_free(channels);
freerdp_free(instance);
return 0;
}
void* tf_client_thread_proc(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;
DWORD nCount;
DWORD status;
HANDLE handles[64];
rdpChannels* channels;
channels = instance->context->channels;
@ -247,67 +140,24 @@ void* tf_client_thread_proc(freerdp* instance)
while (1)
{
rcount = 0;
wcount = 0;
nCount = freerdp_get_event_handles(instance->context, &handles[0]);
ZeroMemory(rfds, sizeof(rfds));
ZeroMemory(wfds, sizeof(wfds));
status = WaitForMultipleObjects(nCount, handles, FALSE, 100);
if (!freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount))
if (status == WAIT_FAILED)
{
WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
WLog_ERR(TAG, "%s: WaitForMultipleObjects failed with %lu", __FUNCTION__, status);
break;
}
if (!freerdp_channels_get_fds(channels, instance, rfds, &rcount, wfds, &wcount))
if (!freerdp_check_event_handles(instance->context))
{
WLog_ERR(TAG, "Failed to get channel manager file descriptor");
break;
}
max_fds = 0;
FD_ZERO(&rfds_set);
FD_ZERO(&wfds_set);
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 */
{
WLog_ERR(TAG, "tfreerdp_run: select failed");
break;
}
}
if (!freerdp_check_fds(instance))
{
WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
break;
}
if (!freerdp_channels_check_fds(channels, instance))
{
WLog_ERR(TAG, "Failed to check channel manager file descriptor");
WLog_ERR(TAG, "Failed to check FreeRDP event handles");
break;
}
}
freerdp_disconnect(instance);
freerdp_channels_close(channels, instance);
freerdp_channels_free(channels);
freerdp_free(instance);