static int run_dfbfreerdp(rdpSet * settings, rdpChanMan * chan_man) { rdpInst * inst; void * dfb_info; void * read_fds[32]; void * write_fds[32]; int read_count; int write_count; int index; int sck; int max_sck; fd_set rfds; fd_set wfds; memset(read_fds, 0, sizeof(read_fds)); memset(write_fds, 0, sizeof(write_fds)); printf("run_dfbfreerdp:\n"); /* create an instance of the library */ inst = freerdp_new(settings); if (inst == NULL) { printf("run_dfbfreerdp: freerdp_new failed\n"); return 1; } if ((inst->version != FREERDP_INTERFACE_VERSION) || (inst->size != sizeof(rdpInst))) { printf("run_dfbfreerdp: freerdp_new size, version / size do not " "match expecting v %d s %d got v %d s %d\n", FREERDP_INTERFACE_VERSION, (int)sizeof(rdpInst), inst->version, inst->size); return 1; } if (dfb_pre_connect(inst) != 0) { printf("run_dfbfreerdp: dfb_pre_connect failed\n"); return 1; } if (freerdp_chanman_pre_connect(chan_man, inst) != 0) { printf("run_dfbfreerdp: freerdp_chanman_pre_connect failed\n"); return 1; } /* call connect */ printf("keyboard_layout: %X\n", inst->settings->keyboard_layout); if (inst->rdp_connect(inst) != 0) { printf("run_dfbfreerdp: inst->rdp_connect failed\n"); return 1; } if (freerdp_chanman_post_connect(chan_man, inst) != 0) { printf("run_dfbfreerdp: freerdp_chanman_post_connect failed\n"); return 1; } if (dfb_post_connect(inst) != 0) { printf("run_dfbfreerdp: dfb_post_connect failed\n"); return 1; } /* program main loop */ while (1) { read_count = 0; write_count = 0; /* get libfreerdp fds */ if (inst->rdp_get_fds(inst, read_fds, &read_count, write_fds, &write_count) != 0) { printf("run_dfbfreerdp: inst->rdp_get_fds failed\n"); break; } /* get DirectFB fds */ if (dfb_get_fds(inst, read_fds, &read_count, write_fds, &write_count) != 0) { printf("run_dfbfreerdp: dfb_get_fds failed\n"); break; } /* get channel fds */ if (freerdp_chanman_get_fds(chan_man, inst, read_fds, &read_count, write_fds, &write_count) != 0) { printf("run_dfbfreerdp: freerdp_chanman_get_fds failed\n"); break; } max_sck = 0; /* setup read fds */ FD_ZERO(&rfds); for (index = 0; index < read_count; index++) { sck = (int)(long) (read_fds[index]); if (sck > max_sck) max_sck = sck; FD_SET(sck, &rfds); } /* setup write fds */ FD_ZERO(&wfds); for (index = 0; index < write_count; index++) { sck = (int)(long) (write_fds[index]); if (sck > max_sck) max_sck = sck; FD_SET(sck, &wfds); } /* exit if nothing to do */ if (max_sck == 0) { printf("run_dfbfreerdp: max_sck is zero\n"); break; } /* do the wait */ if (select(max_sck + 1, &rfds, &wfds, NULL, NULL) == -1) { /* these are not really errors */ if (!((errno == EAGAIN) || (errno == EWOULDBLOCK) || (errno == EINPROGRESS) || (errno == EINTR))) /* signal occurred */ { printf("run_dfbfreerdp: select failed\n"); break; } } /* check the libfreerdp fds */ if (inst->rdp_check_fds(inst) != 0) { printf("run_dfbfreerdp: inst->rdp_check_fds failed\n"); break; } /* check DirectFB fds */ if (dfb_check_fds(inst, &rfds) != 0) { printf("run_dfbfreerdp: dfb_check_fds failed\n"); break; } /* check channel fds */ if (freerdp_chanman_check_fds(chan_man, inst) != 0) { printf("run_dfbfreerdp: freerdp_chanman_check_fds failed\n"); break; } } /* cleanup */ dfb_info = inst->param1; inst->rdp_disconnect(inst); freerdp_free(inst); dfb_uninit(dfb_info); return 0; }
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; rdpChanMan* chanman; memset(rfds, 0, sizeof(rfds)); memset(wfds, 0, sizeof(wfds)); chanman = GET_CHANMAN(instance); instance->Connect(instance); while (1) { rcount = 0; wcount = 0; if (instance->GetFileDescriptor(instance, rfds, &rcount, wfds, &wcount) != True) { printf("Failed to get FreeRDP file descriptor\n"); break; } if (freerdp_chanman_get_fds(chanman, instance, rfds, &rcount, wfds, &wcount) != True) { printf("Failed to get channel manager file descriptor\n"); break; } max_fds = 0; FD_ZERO(&rfds_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 */ { printf("tfreerdp_run: select failed\n"); break; } } if (instance->CheckFileDescriptor(instance) != True) { printf("Failed to check FreeRDP file descriptor\n"); break; } if (freerdp_chanman_check_fds(chanman, instance) != True) { printf("Failed to check channel manager file descriptor\n"); break; } tf_process_channel_event(chanman, instance); } freerdp_chanman_close(chanman, instance); freerdp_chanman_free(chanman); freerdp_free(instance); return 0; }
static int run_wfreerdp(wfInfo * wfi) { rdpInst * inst; void * read_fds[32]; void * write_fds[32]; int read_count; int write_count; int index; HANDLE fds[64]; int fds_count; int gmcode; int alldone; MSG msg; DEBUG("run_wfreerdp:\n"); /* create an instance of the library */ wfi->inst = inst = freerdp_new(wfi->settings); if (inst == NULL) { printf("run_wfreerdp: freerdp_new failed\n"); return 1; } SET_WFI(inst, wfi); if ((inst->version != FREERDP_INTERFACE_VERSION) || (inst->size != sizeof(rdpInst))) { printf("run_wfreerdp: freerdp_new size, version / size do not " "match expecting v %d s %d got v %d s %d\n", FREERDP_INTERFACE_VERSION, sizeof(rdpInst), inst->version, inst->size); return 1; } inst->settings->keyboard_layout = (int)GetKeyboardLayout(0) & 0x0000FFFF; printf("keyboard_layout: 0x%X\n", inst->settings->keyboard_layout); if (wf_pre_connect(wfi) != 0) { printf("run_wfreerdp: wf_pre_connect failed\n"); return 1; } if (freerdp_chanman_pre_connect(wfi->chan_man, inst) != 0) { printf("run_wfreerdp: freerdp_chanman_pre_connect failed\n"); return 1; } /* call connect */ if (inst->rdp_connect(inst) != 0) { printf("run_wfreerdp: inst->rdp_connect failed\n"); return 1; } if (freerdp_chanman_post_connect(wfi->chan_man, inst) != 0) { printf("run_wfreerdp: freerdp_chanman_post_connect failed\n"); return 1; } if (wf_post_connect(wfi) != 0) { printf("run_wfreerdp: wf_post_connect failed\n"); return 1; } /* program main loop */ while (1) { read_count = 0; write_count = 0; /* get libfreerdp fds */ if (inst->rdp_get_fds(inst, read_fds, &read_count, write_fds, &write_count) != 0) { printf("run_wfreerdp: inst->rdp_get_fds failed\n"); break; } /* get channel fds */ if (freerdp_chanman_get_fds(wfi->chan_man, inst, read_fds, &read_count, write_fds, &write_count) != 0) { printf("run_wfreerdp: freerdp_chanman_get_fds failed\n"); break; } fds_count = 0; /* setup read fds */ for (index = 0; index < read_count; index++) { fds[fds_count++] = read_fds[index]; } /* setup write fds */ for (index = 0; index < write_count; index++) { fds[fds_count++] = write_fds[index]; } /* exit if nothing to do */ if (fds_count == 0) { printf("run_wfreerdp: fds_count is zero\n"); break; } /* do the wait */ if (MsgWaitForMultipleObjects(fds_count, fds, FALSE, INFINITE, QS_ALLINPUT) == WAIT_FAILED) { printf("run_wfreerdp: WaitForMultipleObjects failed\n"); break; } /* check the libfreerdp fds */ if (inst->rdp_check_fds(inst) != 0) { printf("run_wfreerdp: inst->rdp_check_fds failed\n"); break; } /* check channel fds */ if (freerdp_chanman_check_fds(wfi->chan_man, inst) != 0) { printf("run_wfreerdp: freerdp_chanman_check_fds failed\n"); break; } alldone = FALSE; while (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE)) { gmcode = GetMessage(&msg, 0, 0, 0); if (gmcode == 0 || gmcode == -1) { alldone = TRUE; break; } TranslateMessage(&msg); DispatchMessage(&msg); } if (alldone) { break; } } /* cleanup */ wf_uninit(wfi); freerdp_chanman_free(wfi->chan_man); freerdp_free(inst); free(wfi->settings); free(wfi); return 0; }
static int run_xfreerdp(xfInfo * xfi) { rdpInst * inst; void * read_fds[32]; void * write_fds[32]; int read_count; int write_count; int index; int sck; int max_sck; fd_set rfds; fd_set wfds; RD_EVENT * event; /* create an instance of the library */ inst = freerdp_new(xfi->settings); if (inst == NULL) { printf("run_xfreerdp: freerdp_new failed\n"); return XF_EXIT_MEMORY; } if ((inst->version != FREERDP_INTERFACE_VERSION) || (inst->size != sizeof(rdpInst))) { printf("run_xfreerdp: freerdp_new size, version / size do not " "match expecting v %d s %d got v %d s %d\n", FREERDP_INTERFACE_VERSION, (int)sizeof(rdpInst), inst->version, inst->size); return XF_EXIT_PROTOCOL; } xfi->inst = inst; SET_XFI(inst, xfi); if (xf_pre_connect(xfi) != 0) { printf("run_xfreerdp: xf_pre_connect failed\n"); return XF_EXIT_CONN_FAILED; } if (freerdp_chanman_pre_connect(xfi->chan_man, inst) != 0) { printf("run_xfreerdp: freerdp_chanman_pre_connect failed\n"); return XF_EXIT_CONN_FAILED; } xf_kb_init(xfi->display, xfi->keyboard_layout_id); xf_kb_inst_init(xfi); printf("keyboard_layout: 0x%X\n", inst->settings->keyboard_layout); /* call connect */ if (inst->rdp_connect(inst) != 0) { printf("run_xfreerdp: inst->rdp_connect failed\n"); return XF_EXIT_CONN_FAILED; } if (freerdp_chanman_post_connect(xfi->chan_man, inst) != 0) { printf("run_xfreerdp: freerdp_chanman_post_connect failed\n"); return XF_EXIT_CONN_FAILED; } if (xf_post_connect(xfi) != 0) { printf("run_xfreerdp: xf_post_connect failed\n"); return XF_EXIT_CONN_FAILED; } xf_video_init(xfi); xf_decode_init(xfi); /* program main loop */ while (1) { read_count = 0; write_count = 0; /* get libfreerdp fds */ if (inst->rdp_get_fds(inst, read_fds, &read_count, write_fds, &write_count) != 0) { printf("run_xfreerdp: inst->rdp_get_fds failed\n"); break; } /* get x fds */ if (xf_get_fds(xfi, read_fds, &read_count, write_fds, &write_count) != 0) { printf("run_xfreerdp: xf_get_fds failed\n"); break; } /* get channel fds */ if (freerdp_chanman_get_fds(xfi->chan_man, inst, read_fds, &read_count, write_fds, &write_count) != 0) { printf("run_xfreerdp: freerdp_chanman_get_fds failed\n"); break; } max_sck = 0; /* setup read fds */ FD_ZERO(&rfds); for (index = 0; index < read_count; index++) { sck = (int)(long) (read_fds[index]); if (sck > max_sck) max_sck = sck; FD_SET(sck, &rfds); } /* setup write fds */ FD_ZERO(&wfds); for (index = 0; index < write_count; index++) { sck = (int)(long) (write_fds[index]); if (sck > max_sck) max_sck = sck; FD_SET(sck, &wfds); } /* exit if nothing to do */ if (max_sck == 0) { printf("run_xfreerdp: max_sck is zero\n"); break; } /* do the wait */ if (select(max_sck + 1, &rfds, &wfds, NULL, NULL) == -1) { /* these are not really errors */ if (!((errno == EAGAIN) || (errno == EWOULDBLOCK) || (errno == EINPROGRESS) || (errno == EINTR))) /* signal occurred */ { printf("run_xfreerdp: select failed\n"); break; } } /* check the libfreerdp fds */ if (inst->rdp_check_fds(inst) != 0) { printf("run_xfreerdp: inst->rdp_check_fds failed\n"); break; } /* check x fds */ if (xf_check_fds(xfi) != 0) { /* xfreerdp is usually terminated by this failing because the X windows has been closed */ DEBUG_X11("xf_check_fds failed"); break; } /* check channel fds */ if (freerdp_chanman_check_fds(xfi->chan_man, inst) != 0) { printf("run_xfreerdp: freerdp_chanman_check_fds failed\n"); break; } /* check channel event */ event = freerdp_chanman_pop_event(xfi->chan_man); if (event) { switch (event->event_type) { case RD_EVENT_TYPE_VIDEO_FRAME: xf_video_process_frame(xfi, (RD_VIDEO_FRAME_EVENT *) event); break; case RD_EVENT_TYPE_REDRAW: xf_handle_redraw_event(xfi, (RD_REDRAW_EVENT *) event); break; default: printf("run_xfreerdp: unknown event type %d\n", event->event_type); break; } freerdp_chanman_free_event(xfi->chan_man, event); } } g_disconnect_reason = inst->disc_reason; /* cleanup */ xf_decode_uninit(xfi); xf_video_uninit(xfi); freerdp_chanman_close(xfi->chan_man, inst); inst->rdp_disconnect(inst); freerdp_free(inst); xf_uninit(xfi); return 0; }