static void* svc_plugin_thread_func(void* arg) { rdpSvcPlugin* plugin = (rdpSvcPlugin*)arg; DEBUG_SVC("in"); IFCALL(plugin->connect_callback, plugin); while (1) { if (plugin->interval_ms > 0) freerdp_thread_wait_timeout(plugin->priv->thread, plugin->interval_ms); else freerdp_thread_wait(plugin->priv->thread); if (freerdp_thread_is_stopped(plugin->priv->thread)) break; freerdp_thread_reset(plugin->priv->thread); svc_plugin_process_data_in(plugin); if (plugin->interval_ms > 0) IFCALL(plugin->interval_callback, plugin); } freerdp_thread_quit(plugin->priv->thread); DEBUG_SVC("out"); return 0; }
static void* serial_thread_func(void* arg) { SERIAL_DEVICE* serial = (SERIAL_DEVICE*)arg; while (1) { freerdp_thread_wait(serial->thread); serial->nfds = 1; FD_ZERO(&serial->read_fds); FD_ZERO(&serial->write_fds); serial->tv.tv_sec = 20; serial->tv.tv_usec = 0; serial->select_timeout = 0; if (freerdp_thread_is_stopped(serial->thread)) break; freerdp_thread_reset(serial->thread); serial_process_irp_list(serial); if (wait_obj_is_set(serial->in_event)) { if (serial_check_fds(serial)) wait_obj_clear(serial->in_event); } } freerdp_thread_quit(serial->thread); return NULL; }
static void* audin_alsa_thread_func(void* arg) { int error; uint8* buffer; int rbytes_per_frame; int tbytes_per_frame; snd_pcm_t* capture_handle = NULL; AudinALSADevice* alsa = (AudinALSADevice*) arg; DEBUG_DVC("in"); rbytes_per_frame = alsa->actual_channels * alsa->bytes_per_channel; tbytes_per_frame = alsa->target_channels * alsa->bytes_per_channel; alsa->buffer = (uint8*) xzalloc(tbytes_per_frame * alsa->frames_per_packet); alsa->buffer_frames = 0; buffer = (uint8*) xzalloc(rbytes_per_frame * alsa->frames_per_packet); memset(&alsa->adpcm, 0, sizeof(ADPCM)); do { if ((error = snd_pcm_open(&capture_handle, alsa->device_name, SND_PCM_STREAM_CAPTURE, 0)) < 0) { DEBUG_WARN("snd_pcm_open (%s)", snd_strerror(error)); break; } if (!audin_alsa_set_params(alsa, capture_handle)) { break; } while (!freerdp_thread_is_stopped(alsa->thread)) { error = snd_pcm_readi(capture_handle, buffer, alsa->frames_per_packet); if (error == -EPIPE) { snd_pcm_recover(capture_handle, error, 0); continue; } else if (error < 0) { DEBUG_WARN("snd_pcm_readi (%s)", snd_strerror(error)); break; } if (!audin_alsa_thread_receive(alsa, buffer, error * rbytes_per_frame)) break; } } while (0); xfree(buffer); xfree(alsa->buffer); alsa->buffer = NULL; if (capture_handle) snd_pcm_close(capture_handle); freerdp_thread_quit(alsa->thread); DEBUG_DVC("out"); return NULL; }
static void* tf_debug_channel_thread_func(void* arg) { void* fd; STREAM* s; void* buffer; UINT32 bytes_returned = 0; testPeerContext* context = (testPeerContext*) arg; freerdp_thread* thread = context->debug_channel_thread; if (WTSVirtualChannelQuery(context->debug_channel, WTSVirtualFileHandle, &buffer, &bytes_returned) == TRUE) { fd = *((void**) buffer); WTSFreeMemory(buffer); thread->signals[thread->num_signals++] = CreateFileDescriptorEvent(NULL, TRUE, FALSE, ((int) (long) fd)); } s = stream_new(4096); WTSVirtualChannelWrite(context->debug_channel, (BYTE*) "test1", 5, NULL); while (1) { freerdp_thread_wait(thread); if (freerdp_thread_is_stopped(thread)) break; stream_set_pos(s, 0); if (WTSVirtualChannelRead(context->debug_channel, 0, stream_get_head(s), stream_get_size(s), &bytes_returned) == FALSE) { if (bytes_returned == 0) break; stream_check_size(s, bytes_returned); if (WTSVirtualChannelRead(context->debug_channel, 0, stream_get_head(s), stream_get_size(s), &bytes_returned) == FALSE) { /* should not happen */ break; } } stream_set_pos(s, bytes_returned); printf("got %d bytes\n", bytes_returned); } stream_free(s); freerdp_thread_quit(thread); return 0; }
static void* tf_debug_channel_thread_func(void* arg) { void* fd; STREAM* s; void* buffer; uint32 bytes_returned = 0; testPeerContext* context = (testPeerContext*) arg; freerdp_thread* thread = context->debug_channel_thread; if (WTSVirtualChannelQuery(context->debug_channel, WTSVirtualFileHandle, &buffer, &bytes_returned) == true) { fd = *((void**)buffer); WTSFreeMemory(buffer); thread->signals[thread->num_signals++] = wait_obj_new_with_fd(fd); } s = stream_new(4096); WTSVirtualChannelWrite(context->debug_channel, (uint8*) "test1", 5, NULL); while (1) { freerdp_thread_wait(thread); if (freerdp_thread_is_stopped(thread)) break; stream_set_pos(s, 0); if (WTSVirtualChannelRead(context->debug_channel, 0, stream_get_head(s), stream_get_size(s), &bytes_returned) == false) { if (bytes_returned == 0) break; stream_check_size(s, bytes_returned); if (WTSVirtualChannelRead(context->debug_channel, 0, stream_get_head(s), stream_get_size(s), &bytes_returned) == false) { /* should not happen */ break; } } stream_set_pos(s, bytes_returned); printf("got %d bytes\n", bytes_returned); } stream_free(s); freerdp_thread_quit(thread); return 0; }
static void* printer_thread_func(void* arg) { PRINTER_DEVICE* printer_dev = (PRINTER_DEVICE*) arg; while (1) { freerdp_thread_wait(printer_dev->thread); if (freerdp_thread_is_stopped(printer_dev->thread)) break; freerdp_thread_reset(printer_dev->thread); printer_process_irp_list(printer_dev); } freerdp_thread_quit(printer_dev->thread); return NULL; }
static void* parallel_thread_func(void* arg) { PARALLEL_DEVICE* parallel = (PARALLEL_DEVICE*) arg; while (1) { freerdp_thread_wait(parallel->thread); if (freerdp_thread_is_stopped(parallel->thread)) break; freerdp_thread_reset(parallel->thread); parallel_process_irp_list(parallel); } freerdp_thread_quit(parallel->thread); return NULL; }
static void * scard_thread_func(void* arg) { SCARD_DEVICE* scard = (SCARD_DEVICE*) arg; while (1) { freerdp_thread_wait(scard->thread); if (freerdp_thread_is_stopped(scard->thread)) break; freerdp_thread_reset(scard->thread); scard_process_irp_list(scard); } freerdp_thread_quit(scard->thread); return NULL; }
static void* audin_server_thread_func(void* arg) { void* fd; STREAM* s; void* buffer; BYTE MessageId; BOOL ready = FALSE; UINT32 bytes_returned = 0; audin_server* audin = (audin_server*) arg; freerdp_thread* thread = audin->audin_channel_thread; if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualFileHandle, &buffer, &bytes_returned) == TRUE) { fd = *((void**)buffer); WTSFreeMemory(buffer); thread->signals[thread->num_signals++] = wait_obj_new_with_fd(fd); } /* Wait for the client to confirm that the Audio Input dynamic channel is ready */ while (1) { freerdp_thread_wait(thread); if (freerdp_thread_is_stopped(thread)) break; if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualChannelReady, &buffer, &bytes_returned) == FALSE) break; ready = *((BOOL*)buffer); WTSFreeMemory(buffer); if (ready) break; } s = stream_new(4096); if (ready) { audin_server_send_version(audin, s); } while (ready) { freerdp_thread_wait(thread); if (freerdp_thread_is_stopped(thread)) break; stream_set_pos(s, 0); if (WTSVirtualChannelRead(audin->audin_channel, 0, stream_get_head(s), stream_get_size(s), &bytes_returned) == FALSE) { if (bytes_returned == 0) break; stream_check_size(s, (int) bytes_returned); if (WTSVirtualChannelRead(audin->audin_channel, 0, stream_get_head(s), stream_get_size(s), &bytes_returned) == FALSE) break; } if (bytes_returned < 1) continue; stream_read_BYTE(s, MessageId); bytes_returned--; switch (MessageId) { case MSG_SNDIN_VERSION: if (audin_server_recv_version(audin, s, bytes_returned)) audin_server_send_formats(audin, s); break; case MSG_SNDIN_FORMATS: if (audin_server_recv_formats(audin, s, bytes_returned)) audin_server_send_open(audin, s); break; case MSG_SNDIN_OPEN_REPLY: audin_server_recv_open_reply(audin, s, bytes_returned); break; case MSG_SNDIN_DATA_INCOMING: break; case MSG_SNDIN_DATA: audin_server_recv_data(audin, s, bytes_returned); break; case MSG_SNDIN_FORMATCHANGE: break; default: printf("audin_server_thread_func: unknown MessageId %d\n", MessageId); break; } } stream_free(s); WTSVirtualChannelClose(audin->audin_channel); audin->audin_channel = NULL; freerdp_thread_quit(thread); return NULL; }
static void* rdpsnd_server_thread_func(void* arg) { void* fd; STREAM* s; void* buffer; BYTE msgType; UINT16 BodySize; UINT32 bytes_returned = 0; rdpsnd_server* rdpsnd = (rdpsnd_server*) arg; freerdp_thread* thread = rdpsnd->rdpsnd_channel_thread; if (WTSVirtualChannelQuery(rdpsnd->rdpsnd_channel, WTSVirtualFileHandle, &buffer, &bytes_returned) == TRUE) { fd = *((void**)buffer); WTSFreeMemory(buffer); thread->signals[thread->num_signals++] = wait_obj_new_with_fd(fd); } s = stream_new(4096); rdpsnd_server_send_formats(rdpsnd, s); while (1) { freerdp_thread_wait(thread); if (freerdp_thread_is_stopped(thread)) break; stream_set_pos(s, 0); if (WTSVirtualChannelRead(rdpsnd->rdpsnd_channel, 0, stream_get_head(s), stream_get_size(s), &bytes_returned) == FALSE) { if (bytes_returned == 0) break; stream_check_size(s, (int) bytes_returned); if (WTSVirtualChannelRead(rdpsnd->rdpsnd_channel, 0, stream_get_head(s), stream_get_size(s), &bytes_returned) == FALSE) break; } stream_read_BYTE(s, msgType); stream_seek_BYTE(s); /* bPad */ stream_read_UINT16(s, BodySize); if (BodySize + 4 > (int) bytes_returned) continue; switch (msgType) { case SNDC_FORMATS: if (rdpsnd_server_recv_formats(rdpsnd, s)) { IFCALL(rdpsnd->context.Activated, &rdpsnd->context); } break; default: break; } } stream_free(s); freerdp_thread_quit(thread); return 0; }