2
* FreeRDP: A Remote Desktop Protocol Client
5
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7
* Licensed under the Apache License, Version 2.0 (the "License");
8
* you may not use this file except in compliance with the License.
9
* You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing, software
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
* See the License for the specific language governing permissions and
17
* limitations under the License.
23
#include <sys/select.h>
33
#include <freerdp/gdi/gdi.h>
34
#include <freerdp/utils/args.h>
35
#include <freerdp/utils/memory.h>
36
#include <freerdp/utils/semaphore.h>
37
#include <freerdp/utils/event.h>
38
#include <freerdp/constants.h>
39
#include <freerdp/channels/channels.h>
40
#include <freerdp/plugins/cliprdr.h>
46
typedef struct tf_info tfInfo;
54
typedef struct tf_context tfContext;
57
static int g_thread_count = 0;
64
#include <freerdp/freerdp.h>
65
#include <freerdp/utils/args.h>
67
void tf_context_new(freerdp* instance, rdpContext* context)
69
context->channels = freerdp_channels_new();
72
void tf_context_free(freerdp* instance, rdpContext* context)
77
void tf_begin_paint(rdpContext* context)
79
rdpGdi* gdi = context->gdi;
80
gdi->primary->hdc->hwnd->invalid->null = 1;
83
void tf_end_paint(rdpContext* context)
85
rdpGdi* gdi = context->gdi;
87
if (gdi->primary->hdc->hwnd->invalid->null)
91
int tf_receive_channel_data(freerdp* instance, int channelId, uint8* data, int size, int flags, int total_size)
93
return freerdp_channels_data(instance, channelId, data, size, flags, total_size);
96
int tf_process_plugin_args(rdpSettings* settings, const char* name, RDP_PLUGIN_DATA* plugin_data, void* user_data)
98
rdpChannels* channels = (rdpChannels*) user_data;
100
printf("Load plugin %s\n", name);
101
freerdp_channels_load_plugin(channels, settings, name, plugin_data);
106
void tf_process_cb_monitor_ready_event(rdpChannels* channels, freerdp* instance)
109
RDP_CB_FORMAT_LIST_EVENT* format_list_event;
111
event = freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, RDP_EVENT_TYPE_CB_FORMAT_LIST, NULL, NULL);
113
format_list_event = (RDP_CB_FORMAT_LIST_EVENT*) event;
114
format_list_event->num_formats = 0;
116
freerdp_channels_send_event(channels, event);
119
void tf_process_channel_event(rdpChannels* channels, freerdp* instance)
123
event = freerdp_channels_pop_event(channels);
127
switch (event->event_type)
129
case RDP_EVENT_TYPE_CB_MONITOR_READY:
130
tf_process_cb_monitor_ready_event(channels, instance);
133
printf("tf_process_channel_event: unknown event type %d\n", event->event_type);
137
freerdp_event_free(event);
141
boolean tf_pre_connect(freerdp* instance)
145
rdpSettings* settings;
147
context = (tfContext*) instance->context;
148
tfi = (tfInfo*) xzalloc(sizeof(tfInfo));
151
settings = instance->settings;
153
settings->order_support[NEG_DSTBLT_INDEX] = true;
154
settings->order_support[NEG_PATBLT_INDEX] = true;
155
settings->order_support[NEG_SCRBLT_INDEX] = true;
156
settings->order_support[NEG_OPAQUE_RECT_INDEX] = true;
157
settings->order_support[NEG_DRAWNINEGRID_INDEX] = true;
158
settings->order_support[NEG_MULTIDSTBLT_INDEX] = true;
159
settings->order_support[NEG_MULTIPATBLT_INDEX] = true;
160
settings->order_support[NEG_MULTISCRBLT_INDEX] = true;
161
settings->order_support[NEG_MULTIOPAQUERECT_INDEX] = true;
162
settings->order_support[NEG_MULTI_DRAWNINEGRID_INDEX] = true;
163
settings->order_support[NEG_LINETO_INDEX] = true;
164
settings->order_support[NEG_POLYLINE_INDEX] = true;
165
settings->order_support[NEG_MEMBLT_INDEX] = true;
166
settings->order_support[NEG_MEM3BLT_INDEX] = true;
167
settings->order_support[NEG_SAVEBITMAP_INDEX] = true;
168
settings->order_support[NEG_GLYPH_INDEX_INDEX] = true;
169
settings->order_support[NEG_FAST_INDEX_INDEX] = true;
170
settings->order_support[NEG_FAST_GLYPH_INDEX] = true;
171
settings->order_support[NEG_POLYGON_SC_INDEX] = true;
172
settings->order_support[NEG_POLYGON_CB_INDEX] = true;
173
settings->order_support[NEG_ELLIPSE_SC_INDEX] = true;
174
settings->order_support[NEG_ELLIPSE_CB_INDEX] = true;
176
freerdp_channels_pre_connect(instance->context->channels, instance);
181
boolean tf_post_connect(freerdp* instance)
185
gdi_init(instance, CLRCONV_ALPHA | CLRCONV_INVERT | CLRBUF_16BPP | CLRBUF_32BPP, NULL);
186
gdi = instance->context->gdi;
188
instance->update->BeginPaint = tf_begin_paint;
189
instance->update->EndPaint = tf_end_paint;
191
freerdp_channels_post_connect(instance->context->channels, instance);
196
int tfreerdp_run(freerdp* instance)
207
rdpChannels* channels;
209
memset(rfds, 0, sizeof(rfds));
210
memset(wfds, 0, sizeof(wfds));
212
channels = instance->context->channels;
214
freerdp_connect(instance);
221
if (freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount) != true)
223
printf("Failed to get FreeRDP file descriptor\n");
226
if (freerdp_channels_get_fds(channels, instance, rfds, &rcount, wfds, &wcount) != true)
228
printf("Failed to get channel manager file descriptor\n");
235
for (i = 0; i < rcount; i++)
237
fds = (int)(long)(rfds[i]);
242
FD_SET(fds, &rfds_set);
248
if (select(max_fds + 1, &rfds_set, &wfds_set, NULL, NULL) == -1)
250
/* these are not really errors */
251
if (!((errno == EAGAIN) ||
252
(errno == EWOULDBLOCK) ||
253
(errno == EINPROGRESS) ||
254
(errno == EINTR))) /* signal occurred */
256
printf("tfreerdp_run: select failed\n");
261
if (freerdp_check_fds(instance) != true)
263
printf("Failed to check FreeRDP file descriptor\n");
266
if (freerdp_channels_check_fds(channels, instance) != true)
268
printf("Failed to check channel manager file descriptor\n");
271
tf_process_channel_event(channels, instance);
274
freerdp_channels_close(channels, instance);
275
freerdp_channels_free(channels);
276
freerdp_free(instance);
281
void* thread_func(void* param)
283
struct thread_data* data;
284
data = (struct thread_data*) param;
286
tfreerdp_run(data->instance);
290
pthread_detach(pthread_self());
294
if (g_thread_count < 1)
295
freerdp_sem_signal(&g_sem);
300
int main(int argc, char* argv[])
304
struct thread_data* data;
305
rdpChannels* channels;
307
freerdp_channels_global_init();
309
g_sem = freerdp_sem_new(1);
311
instance = freerdp_new();
312
instance->PreConnect = tf_pre_connect;
313
instance->PostConnect = tf_post_connect;
314
instance->ReceiveChannelData = tf_receive_channel_data;
316
instance->context_size = sizeof(tfContext);
317
instance->ContextNew = tf_context_new;
318
instance->ContextFree = tf_context_free;
319
freerdp_context_new(instance);
321
channels = instance->context->channels;
322
freerdp_parse_args(instance->settings, argc, argv, tf_process_plugin_args, channels, NULL, NULL);
324
data = (struct thread_data*) xzalloc(sizeof(struct thread_data));
325
data->instance = instance;
328
pthread_create(&thread, 0, thread_func, data);
330
while (g_thread_count > 0)
332
freerdp_sem_wait(g_sem);
335
freerdp_channels_global_uninit();