diff --git a/libweston/backend-rdp/rdp.c b/libweston/backend-rdp/rdp.c index 099125390..f87815dad 100644 --- a/libweston/backend-rdp/rdp.c +++ b/libweston/backend-rdp/rdp.c @@ -400,7 +400,7 @@ rdp_switch_mode(struct weston_output *output, struct weston_mode *target_mode) local_mode = ensure_matching_mode(output, target_mode); if (!local_mode) { - weston_log("mode %dx%d not available\n", target_mode->width, target_mode->height); + rdp_debug_error(rdpBackend, "mode %dx%d not available\n", target_mode->width, target_mode->height); return -ENOENT; } @@ -444,7 +444,7 @@ rdp_switch_mode(struct weston_output *output, struct weston_mode *target_mode) if (!settings->DesktopResize) { /* too bad this peer does not support desktop resize */ - weston_log("%s: desktop resize is not allowed\n", __func__); + rdp_debug_error(rdpBackend, "%s: desktop resize is not allowed\n", __func__); rdpPeer->peer->Close(rdpPeer->peer); } else { settings->DesktopWidth = target_mode->width; @@ -595,7 +595,7 @@ rdp_output_enable(struct weston_output *base) NULL, output->base.current_mode->width * 4); if (output->shadow_surface == NULL) { - weston_log("Failed to create surface for frame buffer.\n"); + rdp_debug_error(b, "Failed to create surface for frame buffer.\n"); return -1; } @@ -653,7 +653,7 @@ rdp_output_attach_head(struct weston_output *output_base, rdp_debug(b, "Head attaching: %s, index:%d, is_primary: %d\n", head_base->name, h->index, h->monitorMode.monitorDef.is_primary); if (!wl_list_empty(&output_base->head_list)) { - weston_log("attaching more than 1 head to single output (= clone) is not supported\n"); + rdp_debug_error(b, "attaching more than 1 head to single output (= clone) is not supported\n"); return -1; } o->index = h->index; @@ -952,16 +952,17 @@ rdp_client_activity(int fd, uint32_t mask, void *data) { freerdp_peer* client = (freerdp_peer *)data; RdpPeerContext *peerCtx = (RdpPeerContext *)client->context; + struct rdp_backend *rdpBackend = peerCtx->rdpBackend; if (!client->CheckFileDescriptor(client)) { - weston_log("unable to checkDescriptor for %p\n", client); + rdp_debug_error(rdpBackend, "unable to checkDescriptor for %p\n", client); goto out_clean; } if (peerCtx && peerCtx->vcm) { if (!WTSVirtualChannelManagerCheckFileDescriptor(peerCtx->vcm)) { - weston_log("failed to check FreeRDP WTS VC file descriptor for %p\n", client); + rdp_debug_error(rdpBackend, "failed to check FreeRDP WTS VC file descriptor for %p\n", client); goto out_clean; } } @@ -1159,31 +1160,31 @@ xf_peer_activate(freerdp_peer* client) settings = client->settings; if (!settings->SurfaceCommandsEnabled) { - weston_log("client doesn't support required SurfaceCommands\n"); + rdp_debug_error(b, "client doesn't support required SurfaceCommands\n"); return FALSE; } if (b->force_no_compression && settings->CompressionEnabled) { - weston_log("Forcing compression off\n"); + rdp_debug_error(b, "Forcing compression off\n"); settings->CompressionEnabled = FALSE; } /* in RAIL mode, only one peer per backend can be activated */ if (settings->RemoteApplicationMode) { if (b->rdp_peer != client) { - weston_log("Another RAIL connection active, only one connection is allowed.\n"); + rdp_debug_error(b, "Another RAIL connection active, only one connection is allowed.\n"); return FALSE; } if (!settings->HiDefRemoteApp) { /* HiDef is required for RAIL mode. Cookie-cutter window remoting is not supported. */ - weston_log("HiDef-RAIL is required for RAIL.\n"); + rdp_debug_error(b, "HiDef-RAIL is required for RAIL.\n"); return FALSE; } /* in HiDef RAIL mode, RAIL-shell must be used */ if (b->rdprail_shell_api == NULL) { - weston_log("HiDef-RAIL is requested from client, but RAIL-shell is not used\n"); + rdp_debug_error(b, "HiDef-RAIL is requested from client, but RAIL-shell is not used\n"); return FALSE; } } @@ -1213,7 +1214,7 @@ xf_peer_activate(freerdp_peer* client) settings->AudioCapture) { if (!peerCtx->vcm) { - weston_log("Virtual channel is required for RAIL, clipboard, audio playback/capture\n"); + rdp_debug_error(b, "Virtual channel is required for RAIL, clipboard, audio playback/capture\n"); goto error_exit; } @@ -1243,7 +1244,7 @@ xf_peer_activate(freerdp_peer* client) /* multiple monitor is not supported in non-HiDef */ assert(b->output_default); output = b->output_default; - weston_log("%s: DesktopWidth:%d, DesktopHeigh:%d, DesktopScaleFactor:%d\n", __FUNCTION__, + rdp_debug_error(b, "%s: DesktopWidth:%d, DesktopHeigh:%d, DesktopScaleFactor:%d\n", __FUNCTION__, settings->DesktopWidth, settings->DesktopHeight, settings->DesktopScaleFactor); if (output->base.width != (int)settings->DesktopWidth || output->base.height != (int)settings->DesktopHeight) { @@ -1251,7 +1252,7 @@ xf_peer_activate(freerdp_peer* client) /* RDP peers don't dictate their resolution to weston */ if (!settings->DesktopResize) { /* peer does not support desktop resize */ - weston_log("%s: client doesn't support resizing, closing connection\n", __FUNCTION__); + rdp_debug_error(b, "%s: client doesn't support resizing, closing connection\n", __FUNCTION__); goto error_exit; } else { settings->DesktopWidth = output->base.width; @@ -1266,7 +1267,7 @@ xf_peer_activate(freerdp_peer* client) new_mode.height = (int)settings->DesktopHeight; target_mode = ensure_matching_mode(&output->base, &new_mode); if (!target_mode) { - weston_log("client mode not found\n"); + rdp_debug_error(b, "client mode not found\n"); goto error_exit; } weston_output_mode_set_native(&output->base, target_mode, @@ -1286,7 +1287,7 @@ xf_peer_activate(freerdp_peer* client) weston_output = &output->base; - weston_log("%s: OutputWidth:%d, OutputHeight:%d, OutputScaleFactor:%d\n", __FUNCTION__, + rdp_debug(b, "%s: OutputWidth:%d, OutputHeight:%d, OutputScaleFactor:%d\n", __FUNCTION__, weston_output->width, weston_output->height, weston_output->scale); pixman_region32_clear(&peerCtx->regionWestonHeads); @@ -1330,7 +1331,7 @@ xf_peer_activate(freerdp_peer* client) peersItem->seat = zalloc(sizeof(*peersItem->seat)); if (!peersItem->seat) { xkb_keymap_unref(keymap); - weston_log("unable to create a weston_seat\n"); + rdp_debug_error(b, "unable to create a weston_seat\n"); goto error_exit; } @@ -1707,7 +1708,11 @@ xf_input_keyboard_event(rdpInput *input, UINT16 flags, UINT16 code) static FREERDP_CB_RET_TYPE xf_input_unicode_keyboard_event(rdpInput *input, UINT16 flags, UINT16 code) { - weston_log("Client sent a unicode keyboard event (flags:0x%X code:0x%X)\n", flags, code); + RdpPeerContext *peerContext = (RdpPeerContext *)input->context; + struct rdp_backend *b = peerContext->rdpBackend; + + rdp_debug_error(b, "Client sent a unicode keyboard event (flags:0x%X code:0x%X)\n", flags, code); + FREERDP_CB_RETURN(TRUE); } @@ -1774,7 +1779,7 @@ rdp_peer_init(freerdp_peer *client, struct rdp_backend *b) settings->NlaSecurity = FALSE; if (!client->Initialize(client)) { - weston_log("peer initialization failed\n"); + rdp_debug_error(b, "peer initialization failed\n"); goto error_initialize; } @@ -1813,7 +1818,7 @@ rdp_peer_init(freerdp_peer *client, struct rdp_backend *b) input->UnicodeKeyboardEvent = xf_input_unicode_keyboard_event; if (!client->GetFileDescriptor(client, rfds, &rcount)) { - weston_log("unable to retrieve client fds\n"); + rdp_debug_error(b, "unable to retrieve client fds\n"); goto error_initialize; } @@ -1826,7 +1831,7 @@ rdp_peer_init(freerdp_peer *client, struct rdp_backend *b) /* event must be valid when server is successfully opened */ assert(peerCtx->eventVcm); } else { - weston_log("WTSOpenServer is failed! continue without virtual channel.\n"); + rdp_debug_error(b, "WTSOpenServer is failed! continue without virtual channel.\n"); } loop = wl_display_get_event_loop(b->compositor->wl_display); @@ -1878,7 +1883,7 @@ rdp_incoming_peer(freerdp_listener *instance, freerdp_peer *client) { struct rdp_backend *b = (struct rdp_backend *)instance->param4; if (rdp_peer_init(client, b) < 0) { - weston_log("error when treating incoming peer\n"); + rdp_debug_error(b, "error when treating incoming peer\n"); FREERDP_CB_RETURN(FALSE); } @@ -1968,22 +1973,19 @@ static int create_vsock_fd(int port) int socket_fd = socket(AF_VSOCK, SOCK_STREAM | SOCK_CLOEXEC, 0); - if (socket_fd < 0) - { + if (socket_fd < 0) { weston_log("Fail to create vsocket"); return -1; } const int bufferSize = 65536; - if (setsockopt(socket_fd, SOL_SOCKET, SO_SNDBUF, &bufferSize, sizeof(bufferSize)) < 0) - { + if (setsockopt(socket_fd, SOL_SOCKET, SO_SNDBUF, &bufferSize, sizeof(bufferSize)) < 0) { weston_log("Fail to setsockopt SO_SNDBUF"); return -1; } - if (setsockopt(socket_fd, SOL_SOCKET, SO_RCVBUF, &bufferSize, sizeof(bufferSize)) < 0) - { + if (setsockopt(socket_fd, SOL_SOCKET, SO_RCVBUF, &bufferSize, sizeof(bufferSize)) < 0) { weston_log("Fail to setsockopt SO_RCVBUF"); return -1; } @@ -1996,8 +1998,7 @@ static int create_vsock_fd(int port) socklen_t socket_addr_size = sizeof(socket_address); - if (bind(socket_fd, (const struct sockaddr *)&socket_address, socket_addr_size) < 0) - { + if (bind(socket_fd, (const struct sockaddr *)&socket_address, socket_addr_size) < 0) { weston_log("Fail to bind socket to address socket"); close(socket_fd); return -2; @@ -2005,8 +2006,7 @@ static int create_vsock_fd(int port) int status = listen(socket_fd, 1); - if (status != 0) - { + if (status != 0) { weston_log("Fail to listen on socket"); close(socket_fd); return -4; @@ -2084,7 +2084,7 @@ rdp_backend_create(struct weston_compositor *compositor, b->debugLevel = RDP_DEBUG_LEVEL_DEFAULT; } } - weston_log("RDP backend: WESTON_RDP_DEBUG_LEVEL: %d\n", b->debugLevel); + rdp_debug(b, "RDP backend: WESTON_RDP_DEBUG_LEVEL: %d\n", b->debugLevel); /* After here, rdp_debug() is ready to be used */ s = getenv("WESTON_RDP_MONITOR_REFRESH_RATE"); @@ -2122,7 +2122,7 @@ rdp_backend_create(struct weston_compositor *compositor, #if HAVE_OPENSSL rdp_generate_session_tls(b); #else - weston_log("the RDP compositor requires keys and an optional certificate for RDP or TLS security (" + rdp_debug_error(b, "the RDP compositor requires keys and an optional certificate for RDP or TLS security (" "--rdp4-key or --rdp-tls-cert/--rdp-tls-key)\n"); goto err_free_strings; #endif @@ -2130,7 +2130,7 @@ rdp_backend_create(struct weston_compositor *compositor, /* activate TLS only if certificate/key are available */ if (is_tls_enabled(b)) { - weston_log("TLS support activated\n"); + rdp_debug_error(b, "TLS support activated\n"); } else if (!b->rdp_key) { goto err_free_strings; } @@ -2155,15 +2155,15 @@ rdp_backend_create(struct weston_compositor *compositor, b->listener->PeerAccepted = rdp_incoming_peer; b->listener->param4 = b; if (fd > 0) { - weston_log("Using VSOCK for incoming connections: %d\n", fd); + rdp_debug_error(b, "Using VSOCK for incoming connections: %d\n", fd); if (!b->listener->OpenFromSocket(b->listener, fd)) { - weston_log("unable opem from socket fd: %d\n", fd); + rdp_debug_error(b, "unable opem from socket fd: %d\n", fd); goto err_listener; } } else { if (!b->listener->Open(b->listener, config->bind_address, config->port)) { - weston_log("unable to bind rdp socket\n"); + rdp_debug_error(b, "unable to bind rdp socket\n"); goto err_listener; } } @@ -2174,7 +2174,7 @@ rdp_backend_create(struct weston_compositor *compositor, /* get the socket from RDP_FD var */ fd_str = getenv("RDP_FD"); if (!fd_str) { - weston_log("RDP_FD env variable not set\n"); + rdp_debug_error(b, "RDP_FD env variable not set\n"); goto err_output; } @@ -2188,7 +2188,7 @@ rdp_backend_create(struct weston_compositor *compositor, &api, sizeof(api)); if (ret < 0) { - weston_log("Failed to register output API.\n"); + rdp_debug_error(b, "Failed to register output API.\n"); goto err_output; } diff --git a/libweston/backend-rdp/rdp.h b/libweston/backend-rdp/rdp.h index d798e580d..a04ff4613 100644 --- a/libweston/backend-rdp/rdp.h +++ b/libweston/backend-rdp/rdp.h @@ -125,8 +125,10 @@ struct rdp_output; struct rdp_clipboard_data_source; +struct rdp_backend; struct rdp_id_manager { + struct rdp_backend *rdp_backend; UINT32 id; UINT32 id_low_limit; UINT32 id_high_limit; @@ -384,9 +386,9 @@ typedef struct rdp_peer_context RdpPeerContext; #define RDP_DEBUG_LEVEL_DEBUG 4 #define RDP_DEBUG_LEVEL_VERBOSE 5 +/* To enable rdp_debug message, add "--logger-scopes=rdp-backend". */ #define RDP_DEBUG_LEVEL_DEFAULT RDP_DEBUG_LEVEL_INFO -/* To enable rdp_debug message, add "--logger-scopes=rdp-backend". */ #define rdp_debug_verbose(b, ...) \ if (b->debugLevel >= RDP_DEBUG_LEVEL_VERBOSE) \ rdp_debug_print(b->debug, false, __VA_ARGS__) @@ -399,8 +401,13 @@ typedef struct rdp_peer_context RdpPeerContext; #define rdp_debug_continue(b, ...) \ if (b->debugLevel >= RDP_DEBUG_LEVEL_INFO) \ rdp_debug_print(b->debug, true, __VA_ARGS__) +#define rdp_debug_error(b, ...) \ + if (b->debugLevel >= RDP_DEBUG_LEVEL_ERR) \ + rdp_debug_print(b->debug, false, __VA_ARGS__) /* To enable rdp_debug_clipboard message, add "--logger-scopes=rdp-backend-clipboard". */ +#define RDP_DEBUG_CLIPBOARD_LEVEL_DEFAULT RDP_DEBUG_LEVEL_ERR + #define rdp_debug_clipboard_verbose(b, ...) \ if (b->debugClipboardLevel >= RDP_DEBUG_LEVEL_VERBOSE) \ rdp_debug_print(b->debugClipboard, false, __VA_ARGS__) @@ -413,6 +420,9 @@ typedef struct rdp_peer_context RdpPeerContext; #define rdp_debug_clipboard_continue(b, ...) \ if (b->debugClipboardLevel >= RDP_DEBUG_LEVEL_INFO) \ rdp_debug_print(b->debugClipboard, true, __VA_ARGS__) +#define rdp_debug_clipboard_error(b, ...) \ + if (b->debugClipboardLevel >= RDP_DEBUG_LEVEL_ERR) \ + rdp_debug_print(b->debugClipboard, false, __VA_ARGS__) /* To enable rdp_debug message, add "--logger-scopes=rdp-backend". */ @@ -430,7 +440,7 @@ void assert_not_compositor_thread(struct rdp_backend *b); #endif // ENABLE_RDP_THREAD_CHECK BOOL rdp_allocate_shared_memory(struct rdp_backend *b, struct weston_rdp_shared_memory *shared_memory); void rdp_free_shared_memory(struct rdp_backend *b, struct weston_rdp_shared_memory *shared_memory); -BOOL rdp_id_manager_init(struct rdp_id_manager *id_manager, UINT32 low_limit, UINT32 high_limit); +BOOL rdp_id_manager_init(struct rdp_backend *rdp_backend, struct rdp_id_manager *id_manager, UINT32 low_limit, UINT32 high_limit); void rdp_id_manager_free(struct rdp_id_manager *id_manager); BOOL rdp_id_manager_allocate_id(struct rdp_id_manager *id_manager, void *object, UINT32 *new_id); void rdp_id_manager_free_id(struct rdp_id_manager *id_manager, UINT32 id); @@ -475,10 +485,11 @@ rdp_defer_rdp_task_to_display_loop(RdpPeerContext *peerCtx, wl_event_loop_idle_f ASSERT_NOT_COMPOSITOR_THREAD(b); struct wl_event_loop *loop = wl_display_get_event_loop(b->compositor->wl_display); struct wl_event_source *event_source = wl_event_loop_add_idle(loop, func, data); - if (event_source) + if (event_source) { SetEvent(peerCtx->eventVcm); - else - weston_log("%s: wl_event_loop_add_idle failed\n", __func__); + } else { + rdp_debug_error(b, "%s: wl_event_loop_add_idle failed\n", __func__); + } return event_source; } else { /* RDP server is not opened, this must not be used */ diff --git a/libweston/backend-rdp/rdpaudio.c b/libweston/backend-rdp/rdpaudio.c index 96bf37c2f..34ef926cb 100644 --- a/libweston/backend-rdp/rdpaudio.c +++ b/libweston/backend-rdp/rdpaudio.c @@ -298,14 +298,14 @@ rdp_audio_setup_listener(RdpPeerContext *peerCtx) fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0); if (fd < 0) { - weston_log("Couldn't create listener socket.\n"); + rdp_debug_error(b, "Couldn't create listener socket.\n"); return -1; } sink_socket_path = getenv("PULSE_AUDIO_RDP_SINK"); if (sink_socket_path == NULL || sink_socket_path[0] == '\0') { close(fd); - weston_log("Environment variable PULSE_AUDIO_RDP_SINK not set.\n"); + rdp_debug_error(b, "Environment variable PULSE_AUDIO_RDP_SINK not set.\n"); return -1; } @@ -320,7 +320,7 @@ rdp_audio_setup_listener(RdpPeerContext *peerCtx) error = bind(fd, (struct sockaddr *)&s, sizeof(struct sockaddr_un)); if (error != 0) { close(fd); - weston_log("Failed to bind to listener socket (%d).\n", error); + rdp_debug_error(b, "Failed to bind to listener socket (%d).\n", error); return -1; } @@ -343,6 +343,7 @@ rdp_audio_client_confirm_block( UINT16 wtimestamp) { RdpPeerContext *peerCtx = (RdpPeerContext*)context->data; + struct rdp_backend *b = peerCtx->rdpBackend; if (peerCtx->blockInfo[confirmBlockNum].ackReceivedTime != 0) { assert(peerCtx->blockInfo[confirmBlockNum].ackPlayedTime == 0); @@ -363,7 +364,7 @@ rdp_audio_client_confirm_block( uint64_t one = 1; if (write(peerCtx->audioInSem, &one, sizeof(one)) != sizeof(uint64_t)) { - weston_log("RDP Audio error at confirm_block while writing to audioInSem (%s)\n", strerror(errno)); + rdp_debug_error(b, "RDP Audio error at confirm_block while writing to audioInSem (%s)\n", strerror(errno)); return ERROR_INTERNAL_ERROR; } @@ -395,7 +396,7 @@ rdp_audio_handle_version( sizeSent = send(peerCtx->pulseAudioSinkFd, &version, sizeof(version), MSG_DONTWAIT); if (sizeSent != sizeof(version)) { - weston_log("RDP audio error responding to version request sent:%ld. %s\n", + rdp_debug_error(b, "RDP audio error responding to version request sent:%ld. %s\n", sizeSent, strerror(errno)); return -1; } @@ -409,6 +410,7 @@ rdp_audio_handle_transfer( UINT bytesLeft, UINT64 timestamp) { + struct rdp_backend *b = peerCtx->rdpBackend; int nbFrames = bytesLeft / peerCtx->bytesPerFrame; UINT bytesRead = 0; ssize_t sizeRead = 0; @@ -419,7 +421,7 @@ rdp_audio_handle_transfer( peerCtx->audioBuffer = zalloc(bytesLeft); if (!peerCtx->audioBuffer) { - weston_log("RDP Audio error zalloc(%d) failed.\n", bytesLeft); + rdp_debug_error(b, "RDP Audio error zalloc(%d) failed.\n", bytesLeft); return -1; } peerCtx->audioBufferSize = bytesLeft; @@ -434,7 +436,7 @@ rdp_audio_handle_transfer( sizeRead = read(peerCtx->pulseAudioSinkFd, peerCtx->audioBuffer + bytesRead, bytesLeft); if (sizeRead <= 0) { - weston_log("RDP Audio error while reading data from sink socket sizeRead:%ld. %s\n", sizeRead, strerror(errno)); + rdp_debug_error(b, "RDP Audio error while reading data from sink socket sizeRead:%ld. %s\n", sizeRead, strerror(errno)); return -1; } bytesRead += sizeRead; @@ -453,7 +455,7 @@ rdp_audio_handle_transfer( */ uint64_t dummy; if (read(peerCtx->audioInSem, &dummy, sizeof(dummy)) != sizeof(uint64_t)) { - weston_log("RDP Audio error at handle_transfer while reading from audioInSem (%s)\n", strerror(errno)); + rdp_debug_error(b, "RDP Audio error at handle_transfer while reading from audioInSem (%s)\n", strerror(errno)); return -1; } @@ -471,7 +473,7 @@ rdp_audio_handle_transfer( audioBuffer, MIN(nbFrames, AUDIO_FRAMES_PER_RDP_PACKET), 0) != 0) { - weston_log("RDP Audio error while SendSamples\n"); + rdp_debug_error(b, "RDP Audio error while SendSamples\n"); return -1; } @@ -481,7 +483,7 @@ rdp_audio_handle_transfer( */ uint64_t one = 1; if (write(peerCtx->audioInSem, &one, sizeof(one)) != sizeof(uint64_t)) { - weston_log("RDP Audio error at handle_transfer while writing to audioInSem (%s)\n", strerror(errno)); + rdp_debug_error(b, "RDP Audio error at handle_transfer while writing to audioInSem (%s)\n", strerror(errno)); return -1; } } else { @@ -503,6 +505,7 @@ static int rdp_audio_handle_get_latency( RdpPeerContext *peerCtx) { + struct rdp_backend *b = peerCtx->rdpBackend; UINT networkLatency; UINT renderedLatency; ssize_t sizeSent; @@ -531,7 +534,7 @@ rdp_audio_handle_get_latency( sizeSent = send(peerCtx->pulseAudioSinkFd, &renderedLatency, sizeof(renderedLatency), MSG_DONTWAIT); if (sizeSent != sizeof(renderedLatency)) { - weston_log("RDP audio error responding to latency request sent:%ld. %s\n", + rdp_debug_error(b, "RDP audio error responding to latency request sent:%ld. %s\n", sizeSent, strerror(errno)); return -1; } @@ -554,18 +557,18 @@ rdp_audio_pulse_audio_sink_thread(void *context) sigemptyset(&set); if (sigaddset(&set, SIGUSR2) == -1) { - weston_log("Audio sink thread: sigaddset(SIGUSR2) failed.\n"); + rdp_debug_error(b, "Audio sink thread: sigaddset(SIGUSR2) failed.\n"); return NULL; } if (pthread_sigmask(SIG_UNBLOCK, &set, NULL) != 0) { - weston_log("Audio sink thread: pthread_sigmask(SIG_UNBLOCK,SIGUSR2) failed.\n"); + rdp_debug_error(b, "Audio sink thread: pthread_sigmask(SIG_UNBLOCK,SIGUSR2) failed.\n"); return NULL; } act.sa_flags = 0; act.sa_mask = set; act.sa_handler = &signalhandler; if (sigaction(SIGUSR2, &act, NULL) == -1) { - weston_log("Audio sink thread: sigaction(SIGUSR2) failed.\n"); + rdp_debug_error(b, "Audio sink thread: sigaction(SIGUSR2) failed.\n"); return NULL; } @@ -586,7 +589,7 @@ rdp_audio_pulse_audio_sink_thread(void *context) peerCtx->pulseAudioSinkFd = accept(peerCtx->pulseAudioSinkListenerFd, NULL, NULL); if (peerCtx->pulseAudioSinkFd < 0) { - weston_log("Audio sink thread: Listener connection error (%s)\n", strerror(errno)); + rdp_debug_error(b, "Audio sink thread: Listener connection error (%s)\n", strerror(errno)); continue; } else { rdp_debug(b, "Audio sink thread: connection successful on socket (%d).\n", @@ -603,7 +606,7 @@ rdp_audio_pulse_audio_sink_thread(void *context) sizeRead = read(peerCtx->pulseAudioSinkFd, &header, sizeof(header)); /* pulseaudio RDP sink always send sizeof(header) regardless command type. */ if (sizeRead != sizeof(header)) { - weston_log("Audio sink thread: error while reading from sink socket sizeRead:%ld. %s\n", + rdp_debug_error(b, "Audio sink thread: error while reading from sink socket sizeRead:%ld. %s\n", sizeRead, strerror(errno)); break; } else if (header.cmd == RDP_AUDIO_CMD_VERSION) { @@ -628,7 +631,7 @@ rdp_audio_pulse_audio_sink_thread(void *context) peerCtx->accumulatedRenderedLatency = 0; peerCtx->accumulatedRenderedLatencyCount = 0; } else { - weston_log("Audio sink thread: unknown command from sink.\n"); + rdp_debug_error(b, "Audio sink thread: unknown command from sink.\n"); break; } } @@ -684,23 +687,25 @@ rdp_audio_client_activated(RdpsndServerContext* context) context->SetVolume(context, 0x7FFF, 0x7FFF); peerCtx->pulseAudioSinkListenerFd = rdp_audio_setup_listener(peerCtx); - if (peerCtx->pulseAudioSinkListenerFd < 0) - weston_log("RDPAudio - Failed to create listener socket\n"); - else if (pthread_create(&peerCtx->pulseAudioSinkThread, NULL, rdp_audio_pulse_audio_sink_thread, (void*)peerCtx) < 0) - weston_log("RDPAudio - Failed to start Pulse Audio Sink Thread. No audio will be available.\n"); + if (peerCtx->pulseAudioSinkListenerFd < 0) { + rdp_debug_error(b, "RDPAudio - Failed to create listener socket\n"); + } else if (pthread_create(&peerCtx->pulseAudioSinkThread, NULL, rdp_audio_pulse_audio_sink_thread, (void*)peerCtx) < 0) { + rdp_debug_error(b, "RDPAudio - Failed to start Pulse Audio Sink Thread. No audio will be available.\n"); + } } else { - weston_log("RDPAudio - No agreeded format.\n"); + rdp_debug_error(b, "RDPAudio - No agreeded format.\n"); } } int rdp_audio_init(RdpPeerContext *peerCtx) { + struct rdp_backend *b = peerCtx->rdpBackend; char *s; peerCtx->rdpsnd_server_context = rdpsnd_server_context_new(peerCtx->vcm); if (!peerCtx->rdpsnd_server_context) { - weston_log("RDPAudio - Couldn't initialize audio virtual channel.\n"); + rdp_debug_error(b, "RDPAudio - Couldn't initialize audio virtual channel.\n"); return 0; // Continue without audio } @@ -712,14 +717,14 @@ rdp_audio_init(RdpPeerContext *peerCtx) peerCtx->audioInSem = eventfd(256, EFD_SEMAPHORE | EFD_CLOEXEC); if (!peerCtx->audioInSem) { - weston_log("RDPAudio - Couldn't initialize event semaphore.\n"); + rdp_debug_error(b, "RDPAudio - Couldn't initialize event semaphore.\n"); goto Error_Exit; } /* this will be freed by FreeRDP at rdpsnd_server_context_free. */ AUDIO_FORMAT *audio_formats = malloc(sizeof rdp_audio_supported_audio_formats); if (!audio_formats) { - weston_log("RDPAudio - Couldn't allocate memory for audio formats.\n"); + rdp_debug_error(b, "RDPAudio - Couldn't allocate memory for audio formats.\n"); goto Error_Exit; } memcpy(audio_formats, rdp_audio_supported_audio_formats, sizeof rdp_audio_supported_audio_formats); @@ -736,7 +741,7 @@ rdp_audio_init(RdpPeerContext *peerCtx) if (s) { if (strcmp(s, "true") == 0) { peerCtx->rdpsnd_server_context->use_dynamic_virtual_channel = FALSE; - weston_log("RDPAudio - force static channel.\n"); + rdp_debug_error(b, "RDPAudio - force static channel.\n"); } } #endif // HAVE_RDPAUDIO_DYNAMIC_VIRTUAL_CHANNEL diff --git a/libweston/backend-rdp/rdpaudioin.c b/libweston/backend-rdp/rdpaudioin.c index f49a2c112..2b654aba5 100644 --- a/libweston/backend-rdp/rdpaudioin.c +++ b/libweston/backend-rdp/rdpaudioin.c @@ -277,14 +277,14 @@ rdp_audioin_setup_listener(RdpPeerContext *peerCtx) fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0); if (fd < 0) { - weston_log("Couldn't create audioin listener socket.\n"); + rdp_debug_error(b, "Couldn't create audioin listener socket.\n"); return -1; } source_socket_path = getenv("PULSE_AUDIO_RDP_SOURCE"); if (source_socket_path == NULL || source_socket_path[0] == '\0') { close(fd); - weston_log("Environment variable PULSE_AUDIO_RDP_SOURCE not set.\n"); + rdp_debug_error(b, "Environment variable PULSE_AUDIO_RDP_SOURCE not set.\n"); return -1; } @@ -299,7 +299,7 @@ rdp_audioin_setup_listener(RdpPeerContext *peerCtx) error = bind(fd, (struct sockaddr *)&s, sizeof(struct sockaddr_un)); if (error != 0) { close(fd); - weston_log("Failed to bind to listener socket for audioin (%d).\n", error); + rdp_debug_error(b, "Failed to bind to listener socket for audioin (%d).\n", error); return -1; } @@ -338,7 +338,7 @@ rdp_audioin_client_opening(audin_server_context* context) } if (format == -1) { - weston_log("RDPAudioIn - No agreeded format.\n"); + rdp_debug_error(b, "RDPAudioIn - No agreeded format.\n"); return ERROR_INVALID_DATA; } @@ -371,7 +371,7 @@ rdp_audioin_client_receive_samples( struct rdp_backend *b = peerCtx->rdpBackend; if (!peerCtx->isAudioInStreamOpened || peerCtx->pulseAudioSourceFd == -1) { - weston_log("RDPAudioIn - audio stream is not opened.\n"); + rdp_debug_error(b, "RDPAudioIn - audio stream is not opened.\n"); return 0; } @@ -391,7 +391,7 @@ rdp_audioin_client_receive_samples( /* Unblock worker thread to close pipe to pulseaudio */ uint64_t one=1; if (write(peerCtx->closeAudioSourceFd, &one, sizeof(one)) != sizeof(uint64_t)) { - weston_log("RDP AudioIn error at receive_samples while writing to closeAudioSourceFd (%s)\n", strerror(errno)); + rdp_debug_error(b, "RDP AudioIn error at receive_samples while writing to closeAudioSourceFd (%s)\n", strerror(errno)); return ERROR_INTERNAL_ERROR; } @@ -420,18 +420,18 @@ rdp_audioin_source_thread(void *context) sigemptyset(&set); if (sigaddset(&set, SIGUSR2) == -1) { - weston_log("AudioIn source thread: sigaddset(SIGUSR2) failed.\n"); + rdp_debug_error(b, "AudioIn source thread: sigaddset(SIGUSR2) failed.\n"); return NULL; } if (pthread_sigmask(SIG_UNBLOCK, &set, NULL) != 0) { - weston_log("AudioIn source thread: pthread_sigmask(SIG_UNBLOCK,SIGUSR2) failed.\n"); + rdp_debug_error(b, "AudioIn source thread: pthread_sigmask(SIG_UNBLOCK,SIGUSR2) failed.\n"); return NULL; } act.sa_flags = 0; act.sa_mask = set; act.sa_handler = &signalhandler; if (sigaction(SIGUSR2, &act, NULL) == -1) { - weston_log("AudioIn source thread: sigaction(SIGUSR2) failed.\n"); + rdp_debug_error(b, "AudioIn source thread: sigaction(SIGUSR2) failed.\n"); return NULL; } @@ -451,7 +451,7 @@ rdp_audioin_source_thread(void *context) */ peerCtx->pulseAudioSourceFd = accept(peerCtx->pulseAudioSourceListenerFd, NULL, NULL); if (peerCtx->pulseAudioSourceFd < 0) { - weston_log("AudioIn source thread: Listener connection error (%s)\n", strerror(errno)); + rdp_debug_error(b, "AudioIn source thread: Listener connection error (%s)\n", strerror(errno)); continue; } else { rdp_debug(b, "AudioIn connection successful on socket (%d).\n", peerCtx->pulseAudioSourceFd); @@ -462,13 +462,13 @@ rdp_audioin_source_thread(void *context) */ uint64_t dummy; if (read(peerCtx->closeAudioSourceFd, &dummy, sizeof(dummy)) != sizeof(uint64_t)) { - weston_log("RDP AudioIn wait on eventfd failed. thread exiting. %s\n", strerror(errno)); + rdp_debug_error(b, "RDP AudioIn wait on eventfd failed. thread exiting. %s\n", strerror(errno)); break; } peerCtx->audin_server_context->Close(peerCtx->audin_server_context); rdp_debug(b, "RDP AudioIn closed.\n"); } else { - weston_log("Failed to open audio in connection with RDP client.\n"); + rdp_debug_error(b, "Failed to open audio in connection with RDP client.\n"); } close(peerCtx->pulseAudioSourceFd); @@ -490,9 +490,11 @@ rdp_audioin_source_thread(void *context) int rdp_audioin_init(RdpPeerContext *peerCtx) { + struct rdp_backend *b = peerCtx->rdpBackend; + peerCtx->audin_server_context = audin_server_context_new(peerCtx->vcm); if (!peerCtx->audin_server_context) { - weston_log("RDPAudioIn - Couldn't initialize audio virtual channel.\n"); + rdp_debug_error(b, "RDPAudioIn - Couldn't initialize audio virtual channel.\n"); return 0; // Continue without audio } @@ -505,7 +507,7 @@ rdp_audioin_init(RdpPeerContext *peerCtx) // this will be freed by FreeRDP at audin_server_context_free. AUDIO_FORMAT *audio_formats = malloc(sizeof rdp_audioin_supported_audio_formats); if (!audio_formats) { - weston_log("RDPAudioIn - Couldn't allocate memory for audio formats.\n"); + rdp_debug_error(b, "RDPAudioIn - Couldn't allocate memory for audio formats.\n"); goto Error_Exit; } memcpy(audio_formats, rdp_audioin_supported_audio_formats, sizeof rdp_audioin_supported_audio_formats); @@ -521,18 +523,18 @@ rdp_audioin_init(RdpPeerContext *peerCtx) peerCtx->closeAudioSourceFd = eventfd(0, EFD_CLOEXEC); if (peerCtx->closeAudioSourceFd < 0) { - weston_log("RDPAudioIn - Couldn't initialize eventfd.\n"); + rdp_debug_error(b, "RDPAudioIn - Couldn't initialize eventfd.\n"); goto Error_Exit; } peerCtx->pulseAudioSourceListenerFd = rdp_audioin_setup_listener(peerCtx); if (peerCtx->pulseAudioSourceListenerFd < 0) { - weston_log("RDPAudioIn - rdp_audioin_setup_listener failed.\n"); + rdp_debug_error(b, "RDPAudioIn - rdp_audioin_setup_listener failed.\n"); goto Error_Exit; } if (pthread_create(&peerCtx->pulseAudioSourceThread, NULL, rdp_audioin_source_thread, (void*)peerCtx) < 0) { - weston_log("RDPAudioIn - Failed to start Pulse Audio Source Thread. No audio in will be available.\n"); + rdp_debug_error(b, "RDPAudioIn - Failed to start Pulse Audio Source Thread. No audio in will be available.\n"); goto Error_Exit; } diff --git a/libweston/backend-rdp/rdpclip.c b/libweston/backend-rdp/rdpclip.c index 5d70ebd95..bad7e5511 100644 --- a/libweston/backend-rdp/rdpclip.c +++ b/libweston/backend-rdp/rdpclip.c @@ -86,6 +86,49 @@ struct rdp_clipboard_supported_format clipboard_supported_formats[] = { }; #define RDP_NUM_CLIPBOARD_FORMATS ARRAY_LENGTH(clipboard_supported_formats) +enum rdp_clipboard_data_source_state { + RDP_CLIPBOARD_SOURCE_ALLOCATED = 0, + RDP_CLIPBOARD_SOURCE_FORMATLIST_READY, /* format list is obtained from provider */ + RDP_CLIPBOARD_SOURCE_PUBLISHED, /* availablity of some or none clipboard data is notified to comsumer */ + RDP_CLIPBOARD_SOURCE_REQUEST_DATA, /* data request is sent to provider */ + RDP_CLIPBOARD_SOURCE_RECEIVED_DATA, /* data is received from provider, waiting data to be dispatched to consumer */ + RDP_CLIPBOARD_SOURCE_TRANSFERING, /* transfering data to consumer */ + RDP_CLIPBOARD_SOURCE_TRANSFERRED, /* complete transfering data to comsumer */ + RDP_CLIPBOARD_SOURCE_CANCEL_PENDING, /* data transfer cancel is requested */ + RDP_CLIPBOARD_SOURCE_CANCELED, /* data transfer is canceled */ + RDP_CLIPBOARD_SOURCE_FAILED, /* failure occured */ +}; + +static char * +clipboard_data_source_state_to_string(enum rdp_clipboard_data_source_state state) +{ + switch (state) + { + case RDP_CLIPBOARD_SOURCE_ALLOCATED: + return "allocated"; + case RDP_CLIPBOARD_SOURCE_FORMATLIST_READY: + return "format list ready"; + case RDP_CLIPBOARD_SOURCE_PUBLISHED: + return "published"; + case RDP_CLIPBOARD_SOURCE_REQUEST_DATA: + return "request data"; + case RDP_CLIPBOARD_SOURCE_RECEIVED_DATA: + return "received data"; + case RDP_CLIPBOARD_SOURCE_TRANSFERING: + return "transferring"; + case RDP_CLIPBOARD_SOURCE_TRANSFERRED: + return "transferred"; + case RDP_CLIPBOARD_SOURCE_CANCEL_PENDING: + return "cancel pending"; + case RDP_CLIPBOARD_SOURCE_CANCELED: + return "cenceled"; + case RDP_CLIPBOARD_SOURCE_FAILED: + return "failed"; + } + assert(false); + return "unknown"; +} + struct rdp_clipboard_data_source { struct weston_data_source base; struct wl_event_source *event_source; @@ -94,6 +137,7 @@ struct rdp_clipboard_data_source { int refcount; int data_source_fd; int format_index; + enum rdp_clipboard_data_source_state state; UINT32 inflight_write_count; void *inflight_data_to_write; size_t inflight_data_size; @@ -129,8 +173,9 @@ clipboard_process_text(struct rdp_clipboard_data_source *source, BOOL is_send) source->is_data_processed = TRUE; } - rdp_debug_clipboard_verbose(b, "RDP %s (%p): %s (%d bytes)\n", - __func__, source, is_send ? "send" : "receive", (UINT32)source->data_contents.size); + rdp_debug_clipboard_verbose(b, "RDP %s (%p:%s): %s (%d bytes)\n", + __func__, source, clipboard_data_source_state_to_string(source->state), + is_send ? "send" : "receive", (UINT32)source->data_contents.size); return source->data_contents.data; } @@ -222,8 +267,9 @@ clipboard_process_html(struct rdp_clipboard_data_source *source, BOOL is_send) source->is_data_processed = TRUE; } - rdp_debug_clipboard_verbose(b, "RDP %s (%p): %s (%d bytes)\n", - __func__, source, is_send ? "send" : "receive", (UINT32)source->data_contents.size); + rdp_debug_clipboard_verbose(b, "RDP %s (%p:%s): %s (%d bytes)\n", + __func__, source, clipboard_data_source_state_to_string(source->state), + is_send ? "send" : "receive", (UINT32)source->data_contents.size); //rdp_debug_clipboard_verbose(b, "RDP clipboard_process_html (%p): %s \n\"%s\"\n (%d bytes)\n", // source, is_send ? "send" : "receive", // (char *)source->data_contents.data, @@ -233,8 +279,10 @@ clipboard_process_html(struct rdp_clipboard_data_source *source, BOOL is_send) error_return: - weston_log("RDP %s FAILED (%p): %s (%d bytes)\n", - __func__, source, is_send ? "send" : "receive", (UINT32)source->data_contents.size); + source->state = RDP_CLIPBOARD_SOURCE_FAILED; + rdp_debug_clipboard_error(b, "RDP %s FAILED (%p:%s): %s (%d bytes)\n", + __func__, source, clipboard_data_source_state_to_string(source->state), + is_send ? "send" : "receive", (UINT32)source->data_contents.size); //rdp_debug_clipboard_verbose(b, "RDP clipboard_process_html FAILED (%p): %s \n\"%s\"\n (%d bytes)\n", // source, is_send ? "send" : "receive", // (char *)source->data_contents.data, @@ -334,8 +382,9 @@ clipboard_process_bmp(struct rdp_clipboard_data_source *source, BOOL is_send) assert(bmfh); assert(bmih); - rdp_debug_clipboard_verbose(b, "RDP %s (%p): %s (%d bytes)\n", - __func__, source, is_send ? "send" : "receive", + rdp_debug_clipboard_verbose(b, "RDP %s (%p:%s): %s (%d bytes)\n", + __func__, source, clipboard_data_source_state_to_string(source->state), + is_send ? "send" : "receive", (UINT32)source->data_contents.size); rdp_debug_clipboard_verbose_continue(b, " BITMAPFILEHEADER.bfType:0x%x\n", bmfh->bfType); rdp_debug_clipboard_verbose_continue(b, " BITMAPFILEHEADER.bfSize:%d\n", bmfh->bfSize); @@ -388,8 +437,10 @@ clipboard_process_bmp(struct rdp_clipboard_data_source *source, BOOL is_send) error_return: - weston_log("RDP %s FAILED (%p): %s (%d bytes)\n", - __func__, source, is_send ? "send" : "receive", (UINT32)source->data_contents.size); + source->state = RDP_CLIPBOARD_SOURCE_FAILED; + rdp_debug_clipboard_error(b, "RDP %s FAILED (%p:%s): %s (%d bytes)\n", + __func__, source, clipboard_data_source_state_to_string(source->state), + is_send ? "send" : "receive", (UINT32)source->data_contents.size); wl_array_release(&data_contents); @@ -530,7 +581,8 @@ clipboard_data_source_unref(struct rdp_clipboard_data_source *source) assert(source->refcount); source->refcount--; - rdp_debug_clipboard(b, "RDP %s (%p): refcount:%d\n", __func__, source, source->refcount); + rdp_debug_clipboard(b, "RDP %s (%p:%s): refcount:%d\n", + __func__, source, clipboard_data_source_state_to_string(source->state), source->refcount); if (source->refcount > 0) return; @@ -554,7 +606,7 @@ clipboard_data_source_unref(struct rdp_clipboard_data_source *source) free(source); } -/*****************************************\ +/******************************************\ * FreeRDP format data response functions * \******************************************/ @@ -565,8 +617,8 @@ clipboard_client_send_format_data_response(RdpPeerContext *peerCtx, struct rdp_c struct rdp_backend *b = peerCtx->rdpBackend; CLIPRDR_FORMAT_DATA_RESPONSE formatDataResponse = {}; - rdp_debug_clipboard(b, "Client: %s (%p) format_index:%d %s (%d bytes)\n", - __func__, source, source->format_index, + rdp_debug_clipboard(b, "Client: %s (%p:%s) format_index:%d %s (%d bytes)\n", + __func__, source, clipboard_data_source_state_to_string(source->state), source->format_index, clipboard_supported_formats[source->format_index].mime_type, size); formatDataResponse.msgType = CB_FORMAT_DATA_RESPONSE; @@ -589,7 +641,8 @@ clipboard_client_send_format_data_response_fail(RdpPeerContext *peerCtx, struct struct rdp_backend *b = peerCtx->rdpBackend; CLIPRDR_FORMAT_DATA_RESPONSE formatDataResponse = {}; - rdp_debug_clipboard(b, "Client: %s (%p)\n", __func__, source); + rdp_debug_clipboard(b, "Client: %s (%p:%s)\n", + __func__, source, clipboard_data_source_state_to_string(source->state)); formatDataResponse.msgType = CB_FORMAT_DATA_RESPONSE; formatDataResponse.msgFlags = CB_RESPONSE_FAIL; @@ -620,7 +673,8 @@ clipboard_data_source_read(int fd, uint32_t mask, void *arg) int len, size; void *data_to_send; - rdp_debug_clipboard_verbose(b, "RDP %s (%p) fd:%d\n", __func__, source, fd); + rdp_debug_clipboard_verbose(b, "RDP %s (%p:%s) fd:%d\n", + __func__, source, clipboard_data_source_state_to_string(source->state), fd); ASSERT_COMPOSITOR_THREAD(b); @@ -640,13 +694,15 @@ clipboard_data_source_read(int fd, uint32_t mask, void *arg) source->data_contents.size -= 1024; } + source->state = RDP_CLIPBOARD_SOURCE_TRANSFERING; data = (char*)source->data_contents.data + source->data_contents.size; size = source->data_contents.alloc - source->data_contents.size - 1; // -1 leave space for NULL-terminate. len = read(fd, data, size); if (len == 0) { /* all data from source is read, so completed. */ - rdp_debug_clipboard(b, "RDP %s (%p): read completed (%ld bytes)\n", - __func__, source, source->data_contents.size); + source->state = RDP_CLIPBOARD_SOURCE_TRANSFERRED; + rdp_debug_clipboard(b, "RDP %s (%p:%s): read completed (%ld bytes)\n", + __func__, source, clipboard_data_source_state_to_string(source->state), source->data_contents.size); if (!source->data_contents.size) goto error_exit; /* process data before sending to client */ @@ -663,13 +719,15 @@ clipboard_data_source_read(int fd, uint32_t mask, void *arg) assert(source->refcount == 1); clipboard_data_source_unref(source); } else if (len < 0) { - weston_log("RDP %s (%p) read failed (%s)\n", __func__, source, strerror(errno)); + source->state = RDP_CLIPBOARD_SOURCE_FAILED; + rdp_debug_clipboard_error(b, "RDP %s (%p:%s) read failed (%s)\n", + __func__, source, clipboard_data_source_state_to_string(source->state), strerror(errno)); goto error_exit; } else { source->data_contents.size += len; ((char*)source->data_contents.data)[source->data_contents.size] = '\0'; - rdp_debug_clipboard_verbose(b, "RDP %s (%p): read (%zu bytes)\n", - __func__, source, source->data_contents.size); + rdp_debug_clipboard_verbose(b, "RDP %s (%p:%s) read (%zu bytes)\n", + __func__, source, clipboard_data_source_state_to_string(source->state), source->data_contents.size); } return 0; @@ -695,7 +753,8 @@ clipboard_data_source_write(int fd, uint32_t mask, void *arg) size_t data_size; ssize_t size; - rdp_debug_clipboard_verbose(b, "RDP %s (%p) fd:%d\n", __func__, source, fd); + rdp_debug_clipboard_verbose(b, "RDP %s (%p:%s) fd:%d\n", __func__, + source, clipboard_data_source_state_to_string(source->state), fd); ASSERT_COMPOSITOR_THREAD(b); @@ -709,8 +768,8 @@ clipboard_data_source_write(int fd, uint32_t mask, void *arg) if (source->is_canceled == FALSE && source->data_contents.data && source->data_contents.size) { if (source->inflight_data_to_write) { assert(source->inflight_data_size); - rdp_debug_clipboard_verbose(b, "RDP %s: retry write retry count:%d (%p)\n", - __func__, source->inflight_write_count, source); + rdp_debug_clipboard_verbose(b, "RDP %s (%p:%s) retry write retry count:%d\n", + __func__, source, clipboard_data_source_state_to_string(source->state), source->inflight_write_count); data_to_write = source->inflight_data_to_write; data_size = source->inflight_data_size; } else { @@ -722,11 +781,13 @@ clipboard_data_source_write(int fd, uint32_t mask, void *arg) data_size = source->data_contents.size; } while (data_to_write && data_size) { + source->state = RDP_CLIPBOARD_SOURCE_TRANSFERING; size = write(fd, data_to_write, data_size); if (size <= 0) { if (errno != EAGAIN) { - weston_log("RDP %s (%p) write failed %s\n", - __func__, source, strerror(errno)); + source->state = RDP_CLIPBOARD_SOURCE_FAILED; + rdp_debug_clipboard_error(b, "RDP %s (%p:%s) write failed %s\n", + __func__, source, clipboard_data_source_state_to_string(source->state), strerror(errno)); break; } source->inflight_data_to_write = data_to_write; @@ -736,8 +797,9 @@ clipboard_data_source_write(int fd, uint32_t mask, void *arg) wl_event_loop_add_fd(loop, source->data_source_fd, WL_EVENT_WRITABLE, clipboard_data_source_write, source); if (!source->event_source) { - weston_log("RDP %s (%p) wl_event_loop_add_fd failed\n", - __func__, source); + source->state = RDP_CLIPBOARD_SOURCE_FAILED; + rdp_debug_clipboard_error(b, "RDP %s (%p:%s) wl_event_loop_add_fd failed\n", + __func__, source, clipboard_data_source_state_to_string(source->state)); break; } return 0; @@ -745,13 +807,19 @@ clipboard_data_source_write(int fd, uint32_t mask, void *arg) assert(data_size >= (size_t)size); data_size -= size; data_to_write = (char *)data_to_write + size; - rdp_debug_clipboard_verbose(b, "RDP %s (%p) wrote %ld bytes, remaining %ld bytes\n", - __func__, source, size, data_size); - if (!data_size) - rdp_debug_clipboard(b, "RDP %s (%p) write completed (%ld bytes)\n", - __func__, source, source->data_contents.size); + rdp_debug_clipboard_verbose(b, "RDP %s (%p:%s) wrote %ld bytes, remaining %ld bytes\n", + __func__, source, clipboard_data_source_state_to_string(source->state), size, data_size); + if (!data_size) { + source->state = RDP_CLIPBOARD_SOURCE_TRANSFERRED; + rdp_debug_clipboard(b, "RDP %s (%p:%s) write completed (%ld bytes)\n", + __func__, source, clipboard_data_source_state_to_string(source->state), source->data_contents.size); + } } } + } else if (source->is_canceled) { + source->state = RDP_CLIPBOARD_SOURCE_CANCELED; + rdp_debug_clipboard_verbose(b, "RDP %s (%p:%s)\n", + __func__, source, clipboard_data_source_state_to_string(source->state)); } close(source->data_source_fd); @@ -774,7 +842,12 @@ static void clipboard_data_source_accept(struct weston_data_source *base, uint32_t time, const char *mime_type) { - weston_log("RDP %s (base:%p) mime-type:\"%s\"\n", __func__, base, mime_type); + struct rdp_clipboard_data_source *source = (struct rdp_clipboard_data_source *)base; + freerdp_peer *client = (freerdp_peer*)source->context; + RdpPeerContext *peerCtx = (RdpPeerContext *)client->context; + struct rdp_backend *b = peerCtx->rdpBackend; + + rdp_debug(b, "RDP %s (base:%p) mime-type:\"%s\"\n", __func__, base, mime_type); } /* data-device informs the application requested the specified format data in given data_source (= client's clipboard) */ @@ -791,7 +864,8 @@ clipboard_data_source_send(struct weston_data_source *base, CLIPRDR_FORMAT_DATA_REQUEST formatDataRequest = {}; int index; - rdp_debug_clipboard(b, "RDP %s (%p) fd:%d, mime-type:\"%s\"\n", __func__, source, fd, mime_type); + rdp_debug_clipboard(b, "RDP %s (%p:%s) fd:%d, mime-type:\"%s\"\n", + __func__, source, clipboard_data_source_state_to_string(source->state), fd, mime_type); ASSERT_COMPOSITOR_THREAD(b); @@ -799,8 +873,16 @@ clipboard_data_source_send(struct weston_data_source *base, /* Here means server side (Linux application) request clipboard data, but server hasn't completed with previous request yet. If this happens, punt to idle loop and reattempt. */ - weston_log("\n\n\nRDP %s (%p) vs (%p): outstanding RDP data request (client to server)\n\n\n", - __func__, source, peerCtx->clipboard_inflight_client_data_source); + source->state = RDP_CLIPBOARD_SOURCE_FAILED; + rdp_debug_clipboard_error(b, "\n\n\nRDP %s (%p:%s) vs (%p): outstanding RDP data request (client to server)\n\n\n", + __func__, source, clipboard_data_source_state_to_string(source->state), peerCtx->clipboard_inflight_client_data_source); + goto error_return_close_fd; + } + + if (source->base.mime_types.size == 0) { + source->state = RDP_CLIPBOARD_SOURCE_TRANSFERRED; + rdp_debug_clipboard(b, "RDP %s (%p:%s) source has no data\n", + __func__, source, clipboard_data_source_state_to_string(source->state)); goto error_return_close_fd; } @@ -816,11 +898,14 @@ clipboard_data_source_send(struct weston_data_source *base, if (index == source->format_index) { /* data is already in data_contents, no need to pull from client */ assert(source->event_source == NULL); + source->state = RDP_CLIPBOARD_SOURCE_RECEIVED_DATA; source->event_source = wl_event_loop_add_fd(loop, source->data_source_fd, WL_EVENT_WRITABLE, clipboard_data_source_write, source); if (!source->event_source) { - weston_log("RDP %s (%p) wl_event_loop_add_fd failed\n", __func__, source); + source->state = RDP_CLIPBOARD_SOURCE_FAILED; + rdp_debug_clipboard_error(b, "RDP %s (%p:%s) wl_event_loop_add_fd failed\n", + __func__, source, clipboard_data_source_state_to_string(source->state)); goto error_return_unref_source; } } else { @@ -834,16 +919,19 @@ clipboard_data_source_send(struct weston_data_source *base, formatDataRequest.msgType = CB_FORMAT_DATA_REQUEST; formatDataRequest.dataLen = 4; formatDataRequest.requestedFormatId = source->client_format_id_table[index]; - rdp_debug_clipboard(b, "RDP %s (%p) request \"%s\" index:%d formatId:%d %s\n", - __func__, source, mime_type, index, + source->state = RDP_CLIPBOARD_SOURCE_REQUEST_DATA; + rdp_debug_clipboard(b, "RDP %s (%p:%s) request \"%s\" index:%d formatId:%d %s\n", + __func__, source, clipboard_data_source_state_to_string(source->state), mime_type, index, formatDataRequest.requestedFormatId, clipboard_format_id_to_string(formatDataRequest.requestedFormatId, false)); if (peerCtx->clipboard_server_context->ServerFormatDataRequest(peerCtx->clipboard_server_context, &formatDataRequest) != 0) goto error_return_unref_source; } } else { - weston_log("RDP %s (%p) specified format \"%s\" index:%d formatId:%d is not supported by client\n", - __func__, source, mime_type, index, source->client_format_id_table[index]); + source->state = RDP_CLIPBOARD_SOURCE_FAILED; + rdp_debug_clipboard_error(b, "RDP %s (%p:%s) specified format \"%s\" index:%d formatId:%d is not supported by client\n", + __func__, source, clipboard_data_source_state_to_string(source->state), + mime_type, index, source->client_format_id_table[index]); goto error_return_close_fd; } @@ -873,17 +961,22 @@ clipboard_data_source_cancel(struct weston_data_source *base) RdpPeerContext *peerCtx = (RdpPeerContext *)client->context; struct rdp_backend *b = peerCtx->rdpBackend; - rdp_debug_clipboard(b, "RDP %s (%p)\n", __func__, source); + rdp_debug_clipboard(b, "RDP %s (%p:%s)\n", + __func__, source, clipboard_data_source_state_to_string(source->state)); ASSERT_COMPOSITOR_THREAD(b); if (source == peerCtx->clipboard_inflight_client_data_source) { - rdp_debug_clipboard(b, "RDP %s (%p): still inflight\n", __func__, source); - assert(source->refcount > 1); source->is_canceled = TRUE; + source->state = RDP_CLIPBOARD_SOURCE_CANCEL_PENDING; + rdp_debug_clipboard(b, "RDP %s (%p:%s): still inflight\n", + __func__, source, clipboard_data_source_state_to_string(source->state)); + assert(source->refcount > 1); } else { /* everything outside of the base has to be cleaned up */ - rdp_debug_clipboard_verbose(b, "RDP %s (%p): cancelled\n", __func__, source); + source->state = RDP_CLIPBOARD_SOURCE_CANCELED; + rdp_debug_clipboard_verbose(b, "RDP %s (%p:%s)\n", + __func__, source, clipboard_data_source_state_to_string(source->state)); assert(source->event_source == NULL); wl_array_release(&source->data_contents); wl_array_init(&source->data_contents); @@ -914,7 +1007,8 @@ clipboard_data_source_publish(void *arg) struct rdp_backend *b = peerCtx->rdpBackend; struct rdp_clipboard_data_source *source_prev; - rdp_debug_clipboard(b, "RDP %s (%p)\n", __func__, source); + rdp_debug_clipboard(b, "RDP %s (%p:%s)\n", + __func__, source, clipboard_data_source_state_to_string(source->state)); ASSERT_COMPOSITOR_THREAD(b); @@ -927,6 +1021,7 @@ clipboard_data_source_publish(void *arg) source->base.accept = clipboard_data_source_accept; source->base.send = clipboard_data_source_send; source->base.cancel = clipboard_data_source_cancel; + source->state = RDP_CLIPBOARD_SOURCE_PUBLISHED; weston_seat_set_selection(peerCtx->item.seat, &source->base, wl_display_next_serial(b->compositor->wl_display)); @@ -981,7 +1076,11 @@ clipboard_data_source_request(void *arg) if (!source) goto error_exit_response_fail; - rdp_debug_clipboard(b, "RDP %s (%p) allocated\n", __func__, source); + /* By now, the server side data availablity is already notified + to client by clipboard_set_selection(). */ + source->state = RDP_CLIPBOARD_SOURCE_PUBLISHED; + rdp_debug_clipboard(b, "RDP %s (%p:%s)\n", + __func__, source, clipboard_data_source_state_to_string(source->state)); wl_signal_init(&source->base.destroy_signal); wl_array_init(&source->base.mime_types); wl_array_init(&source->data_contents); @@ -997,6 +1096,7 @@ clipboard_data_source_request(void *arg) source->data_source_fd = p[0]; /* Request data from data source */ + source->state = RDP_CLIPBOARD_SOURCE_REQUEST_DATA; selection_data_source->send(selection_data_source, requested_mime_type, p[1]); /* p[1] should be closed by data source */ @@ -1005,7 +1105,9 @@ clipboard_data_source_request(void *arg) wl_event_loop_add_fd(loop, p[0], WL_EVENT_READABLE, clipboard_data_source_read, source); if (!source->event_source) { - weston_log("RDP %s: wl_event_loop_add_fd failed (%p)\n", __func__, source); + source->state = RDP_CLIPBOARD_SOURCE_FAILED; + rdp_debug_clipboard_error(b, "RDP %s (%p:%s) wl_event_loop_add_fd failed.\n", + __func__, source, clipboard_data_source_state_to_string(source->state)); goto error_exit_free_source; } @@ -1038,7 +1140,7 @@ clipboard_set_selection(struct wl_listener *listener, void *data) const char **mime_type; int index, num_supported_format = 0, num_avail_format = 0; - rdp_debug_clipboard(b, "RDP %s (base:%p}\n", __func__, selection_data_source); + rdp_debug_clipboard(b, "RDP %s (base:%p)\n", __func__, selection_data_source); ASSERT_COMPOSITOR_THREAD(b); @@ -1165,7 +1267,9 @@ clipboard_client_format_list(CliprdrServerContext* context, const CLIPRDR_FORMAT source = zalloc(sizeof *source); if (source) { - rdp_debug_clipboard(b, "Client: %s (%p) allocated\n", __func__, source); + source->state = RDP_CLIPBOARD_SOURCE_ALLOCATED; + rdp_debug_clipboard(b, "Client: %s (%p:%s) allocated\n", + __func__, source, clipboard_data_source_state_to_string(source->state)); wl_signal_init(&source->base.destroy_signal); wl_array_init(&source->base.mime_types); wl_array_init(&source->data_contents); @@ -1184,30 +1288,39 @@ clipboard_client_format_list(CliprdrServerContext* context, const CLIPRDR_FORMAT if (s) { p = wl_array_add(&source->base.mime_types, sizeof *p); if (p) { - rdp_debug_clipboard(b, "Client: %s (%p) mine_type:\"%s\" index:%d formatId:%d\n", - __func__, source, s, index, format->formatId); + rdp_debug_clipboard(b, "Client: %s (%p:%s) mine_type:\"%s\" index:%d formatId:%d\n", + __func__, source, clipboard_data_source_state_to_string(source->state), + s, index, format->formatId); *p = s; } else { - rdp_debug_clipboard(b, "Client: %s (%p) wl_array_add failed\n", __func__, source); + rdp_debug_clipboard(b, "Client: %s (%p:%s) wl_array_add failed\n", + __func__, source, clipboard_data_source_state_to_string(source->state)); free(s); } } else { - rdp_debug_clipboard(b, "Client: %s (%p) strdup failed\n", __func__, source); + rdp_debug_clipboard(b, "Client: %s (%p:%s) strdup failed\n", + __func__, source, clipboard_data_source_state_to_string(source->state)); } } } - if (source->base.mime_types.size) { - source->event_source = - rdp_defer_rdp_task_to_display_loop(peerCtx, - clipboard_data_source_publish, - source); - if (source->event_source) - isPublished = TRUE; - else - weston_log("Client: %s (%p) rdp_defer_rdp_task_to_display_loop failed\n", __func__, source); + if (formatList->numFormats != 0 && + source->base.mime_types.size == 0) { + rdp_debug_clipboard(b, "Client: %s (%p:%s) no formats are supported\n", + __func__, source, clipboard_data_source_state_to_string(source->state)); + } + + source->state = RDP_CLIPBOARD_SOURCE_FORMATLIST_READY; + source->event_source = + rdp_defer_rdp_task_to_display_loop(peerCtx, + clipboard_data_source_publish, + source); + if (source->event_source) { + isPublished = TRUE; } else { - rdp_debug_clipboard(b, "Client: %s (%p) no formats are supported\n", __func__, source); + source->state = RDP_CLIPBOARD_SOURCE_FAILED; + rdp_debug_clipboard_error(b, "Client: %s (%p:%s) rdp_defer_rdp_task_to_display_loop failed\n", + __func__, source, clipboard_data_source_state_to_string(source->state)); } } @@ -1216,7 +1329,9 @@ clipboard_client_format_list(CliprdrServerContext* context, const CLIPRDR_FORMAT formatListResponse.msgFlags = source ? CB_RESPONSE_OK : CB_RESPONSE_FAIL; formatListResponse.dataLen = 0; if (peerCtx->clipboard_server_context->ServerFormatListResponse(peerCtx->clipboard_server_context, &formatListResponse) != 0) { - weston_log("Client: %s (%p) ServerFormatListResponse failed\n", __func__, source); + source->state = RDP_CLIPBOARD_SOURCE_FAILED; + rdp_debug_clipboard_error(b, "Client: %s (%p:%s) ServerFormatListResponse failed\n", + __func__, source, clipboard_data_source_state_to_string(source->state)); return -1; } @@ -1237,12 +1352,22 @@ clipboard_client_format_data_response(CliprdrServerContext* context, const CLIPR struct rdp_clipboard_data_source *source = peerCtx->clipboard_inflight_client_data_source; BOOL Success = FALSE; - rdp_debug_clipboard(b, "Client: %s (%p) flags:%d, dataLen:%d\n", - __func__, source, formatDataResponse->msgFlags, formatDataResponse->dataLen); + rdp_debug_clipboard(b, "Client: %s (%p:%s) flags:%d, dataLen:%d\n", + __func__, source, clipboard_data_source_state_to_string(source->state), + formatDataResponse->msgFlags, formatDataResponse->dataLen); ASSERT_NOT_COMPOSITOR_THREAD(b); if (source) { + if (source->event_source || (source->inflight_write_count != 0)) { + /* here means client responded more than once for single data request */ + source->state = RDP_CLIPBOARD_SOURCE_FAILED; + rdp_debug_clipboard_error(b, "Client: %s (%p:%s) middle of write loop:%p, %d\n", + __func__, source, clipboard_data_source_state_to_string(source->state), + source->event_source, source->inflight_write_count); + return -1; + } + if (formatDataResponse->msgFlags == CB_RESPONSE_OK) { /* Recieved data from client, cache to data source */ if (wl_array_add(&source->data_contents, formatDataResponse->dataLen+1)) { @@ -1252,17 +1377,28 @@ clipboard_client_format_data_response(CliprdrServerContext* context, const CLIPR source->data_contents.size = formatDataResponse->dataLen; /* regardless data type, make sure it ends with NULL */ ((char*)source->data_contents.data)[source->data_contents.size] = '\0'; + /* data is ready, waiting to be written to destination */ + source->state = RDP_CLIPBOARD_SOURCE_RECEIVED_DATA; Success = TRUE; + } else { + source->state = RDP_CLIPBOARD_SOURCE_FAILED; } + } else { + source->state = RDP_CLIPBOARD_SOURCE_FAILED; } + rdp_debug_clipboard_verbose(b, "Client: %s (%p:%s)\n", + __func__, source, clipboard_data_source_state_to_string(source->state)); if (Success) { assert(source->event_source == NULL); source->event_source = wl_event_loop_add_fd(loop, source->data_source_fd, WL_EVENT_WRITABLE, clipboard_data_source_write, source); - if (!source->event_source) - weston_log("Client: %s: wl_event_loop_add_fd failed (%p)\n", __func__, source); + if (!source->event_source) { + source->state = RDP_CLIPBOARD_SOURCE_FAILED; + rdp_debug_clipboard_error(b, "Client: %s (%p:%s) wl_event_loop_add_fd failed\n", + __func__, source, clipboard_data_source_state_to_string(source->state)); + } } if (!source->event_source) { @@ -1280,7 +1416,7 @@ clipboard_client_format_data_response(CliprdrServerContext* context, const CLIPR peerCtx->clipboard_inflight_client_data_source = NULL; } } else { - rdp_debug_clipboard(b, "Client: %s client send data without server asking. protocol error.\n", __func__); + rdp_debug_clipboard(b, "Client: %s client send data without server asking. protocol error", __func__); return -1; } @@ -1314,7 +1450,7 @@ clipboard_client_format_data_request(CliprdrServerContext* context, const CLIPRD ASSERT_NOT_COMPOSITOR_THREAD(b); if (peerCtx->clipboard_data_request_event_source) { - weston_log("Client: %s (%p) client requests data while server hasn't responded previous request yet. protocol error.\n", + rdp_debug_clipboard_error(b, "Client: %s (outstanding event:%p) client requests data while server hasn't responded previous request yet. protocol error.\n", __func__, peerCtx->clipboard_data_request_event_source); return -1; } @@ -1326,11 +1462,11 @@ clipboard_client_format_data_request(CliprdrServerContext* context, const CLIPRD peerCtx->clipboard_data_request_event_source = rdp_defer_rdp_task_to_display_loop(peerCtx, clipboard_data_source_request, peerCtx); if (!peerCtx->clipboard_data_request_event_source) { - weston_log("Client: %s rdp_defer_rdp_task_to_display_loop failed\n", __func__); + rdp_debug_clipboard_error(b, "Client: %s rdp_defer_rdp_task_to_display_loop failed\n", __func__); goto error_return; } } else { - weston_log("Client: %s client requests data format the server never reported in format list response. protocol error.\n", __func__); + rdp_debug_clipboard_error(b, "Client: %s client requests data format the server never reported in format list response. protocol error.\n", __func__); return -1; } @@ -1367,14 +1503,16 @@ rdp_clipboard_init(freerdp_peer* client) s = getenv("WESTON_RDP_DEBUG_CLIPBOARD_LEVEL"); if (s) { if (!safe_strtoint(s, &b->debugClipboardLevel)) - b->debugClipboardLevel = RDP_DEBUG_LEVEL_DEFAULT; + b->debugClipboardLevel = RDP_DEBUG_CLIPBOARD_LEVEL_DEFAULT; else if (b->debugClipboardLevel > RDP_DEBUG_LEVEL_VERBOSE) b->debugClipboardLevel = RDP_DEBUG_LEVEL_VERBOSE; } else { - b->debugClipboardLevel = RDP_DEBUG_LEVEL_DEFAULT; + /* by default, clipboard scope is disabled, so when it's enabled, + log with verbose mode to assist debugging */ + b->debugClipboardLevel = RDP_DEBUG_LEVEL_VERBOSE; // RDP_DEBUG_CLIPBOARD_LEVEL_DEFAULT; } } - weston_log("RDP backend: WESTON_RDP_DEBUG_CLIPBOARD_LEVEL: %d\n", b->debugClipboardLevel); + rdp_debug_clipboard(b, "RDP backend: WESTON_RDP_DEBUG_CLIPBOARD_LEVEL: %d\n", b->debugClipboardLevel); peerCtx->clipboard_server_context = cliprdr_server_context_new(peerCtx->vcm); if (!peerCtx->clipboard_server_context) diff --git a/libweston/backend-rdp/rdpdisp.c b/libweston/backend-rdp/rdpdisp.c index 41b9b14bb..a4fffd15b 100644 --- a/libweston/backend-rdp/rdpdisp.c +++ b/libweston/backend-rdp/rdpdisp.c @@ -377,12 +377,12 @@ disp_monitor_validate_and_compute_layout(RdpPeerContext *peerCtx, struct rdp_mon if (monitorMode[i].monitorDef.is_primary) { /* count number of primary */ if (++primaryCount > 1) { - weston_log("%s: RDP client reported unexpected primary count (%d)\n",__func__, primaryCount); + rdp_debug_error(b, "%s: RDP client reported unexpected primary count (%d)\n",__func__, primaryCount); return FALSE; } /* primary must be at (0,0) in client space */ if (monitorMode[i].monitorDef.x != 0 || monitorMode[i].monitorDef.y != 0) { - weston_log("%s: RDP client reported primary is not at (0,0) but (%d,%d).\n", + rdp_debug_error(b, "%s: RDP client reported primary is not at (0,0) but (%d,%d).\n", __func__, monitorMode[i].monitorDef.x, monitorMode[i].monitorDef.y); return FALSE; } @@ -463,7 +463,7 @@ disp_monitor_validate_and_compute_layout(RdpPeerContext *peerCtx, struct rdp_mon if (isScalingUsed && (!isConnected_H && !isConnected_V)) { /* scaling can't be supported in complex monitor placement */ - weston_log("\nWARNING\nWARNING\nWARNING: Scaling is used, but can't be supported in complex monitor placement\nWARNING\nWARNING\n"); + rdp_debug_error(b, "\nWARNING\nWARNING\nWARNING: Scaling is used, but can't be supported in complex monitor placement\nWARNING\nWARNING\n"); isScalingSupported = false; } @@ -537,7 +537,7 @@ disp_monitor_layout_change(DispServerContext* context, const DISPLAY_CONTROL_MON assert(settings->HiDefRemoteApp); if (displayControl->NumMonitors > RDP_MAX_MONITOR) { - weston_log("\nWARNING\nWARNING\nWARNING: client reports more monitors then expected:(%d)\nWARNING\nWARNING\n", + rdp_debug_error(b, "\nWARNING\nWARNING\nWARNING: client reports more monitors then expected:(%d)\nWARNING\nWARNING\n", displayControl->NumMonitors); return; } @@ -677,12 +677,12 @@ xf_peer_adjust_monitor_layout(freerdp_peer* client) /* If not in RAIL mode, or RAIL-shell is not used, only signle mon is allowed */ if (!settings->HiDefRemoteApp || b->rdprail_shell_api == NULL) { if (settings->MonitorCount > 1) { - weston_log("\nWARNING\nWARNING\nWARNING: multiple monitor is not supported in non HiDef RAIL mode\nWARNING\nWARNING\n"); + rdp_debug_error(b, "\nWARNING\nWARNING\nWARNING: multiple monitor is not supported in non HiDef RAIL mode\nWARNING\nWARNING\n"); return FALSE; } } if (settings->MonitorCount > RDP_MAX_MONITOR) { - weston_log("\nWARNING\nWARNING\nWARNING: client reports more monitors then expected:(%d)\nWARNING\nWARNING\n", + rdp_debug_error(b, "\nWARNING\nWARNING\nWARNING: client reports more monitors then expected:(%d)\nWARNING\nWARNING\n", settings->MonitorCount); return FALSE; } diff --git a/libweston/backend-rdp/rdprail.c b/libweston/backend-rdp/rdprail.c index a3e3a6e83..cfad94c2c 100644 --- a/libweston/backend-rdp/rdprail.c +++ b/libweston/backend-rdp/rdprail.c @@ -72,12 +72,12 @@ struct rdp_dispatch_data { #define RDP_DISPATCH_TO_DISPLAY_LOOP(context, arg_type, arg, callback) \ { \ + freerdp_peer *client = (freerdp_peer*)(context)->custom; \ + RdpPeerContext *peerCtx = (RdpPeerContext *)client->context; \ + struct rdp_backend *b = peerCtx->rdpBackend; \ struct rdp_dispatch_data *dispatch_data; \ dispatch_data = (struct rdp_dispatch_data *)malloc(sizeof(*dispatch_data)); \ if (dispatch_data) { \ - freerdp_peer *client = (freerdp_peer*)(context)->custom; \ - RdpPeerContext *peerCtx = (RdpPeerContext *)client->context; \ - struct rdp_backend *b = peerCtx->rdpBackend; \ ASSERT_NOT_COMPOSITOR_THREAD(b); \ dispatch_data->client = client; \ dispatch_data->u_##arg_type = *(arg); \ @@ -87,14 +87,14 @@ struct rdp_dispatch_data { dispatch_data->_base.event_source = \ rdp_defer_rdp_task_to_display_loop(peerCtx, callback, dispatch_data); \ if (!dispatch_data->_base.event_source) { \ - weston_log("%s: rdp_queue_deferred_task failed\n", __func__); \ + rdp_debug_error(b, "%s: rdp_queue_deferred_task failed\n", __func__); \ pthread_mutex_lock(&peerCtx->loop_event_source_list_mutex); \ wl_list_remove(&dispatch_data->_base.link); \ pthread_mutex_unlock(&peerCtx->loop_event_source_list_mutex); \ free(dispatch_data); \ } \ } else { \ - weston_log("%s: malloc failed\n", __func__); \ + rdp_debug_error(b, "%s: malloc failed\n", __func__); \ } \ } @@ -225,7 +225,7 @@ rail_client_Exec_callback(void *arg) &peerCtx->clientExec_destroy_listener); result = RAIL_EXEC_S_OK; } else { - weston_log("%s: fail to launch shell process %s\n", + rdp_debug_error(b, "%s: fail to launch shell process %s\n", __func__, remoteProgramAndArgs); } } @@ -306,7 +306,7 @@ rail_client_Activate_callback(void *arg) if (activate->windowId && activate->enabled) { surface = (struct weston_surface *)hash_table_lookup(peerCtx->windowId.hash_table, activate->windowId); if (!surface) - weston_log("Client: ClientActivate: WindowId:0x%x is not found.\n", activate->windowId); + rdp_debug_error(b, "Client: ClientActivate: WindowId:0x%x is not found.\n", activate->windowId); } b->rdprail_shell_api->request_window_activate(b->rdprail_shell_context, peerCtx->item.seat, surface); } @@ -424,7 +424,7 @@ rail_client_Syscommand_callback(void *arg) surface = (struct weston_surface *)hash_table_lookup(peerCtx->windowId.hash_table, syscommand->windowId); if (!surface) { - weston_log("Client: ClientSyscommand: WindowId:0x%x is not found.\n", syscommand->windowId); + rdp_debug_error(b, "Client: ClientSyscommand: WindowId:0x%x is not found.\n", syscommand->windowId); goto Exit; } @@ -588,7 +588,7 @@ rail_client_ClientSysparam_callback(void *arg) to_rdp_head(base_head_iter)->workareaClient = workareaRectClient; } } else { - weston_log("Client: ClientSysparam: workArea isn't belonging to an output\n"); + rdp_debug_error(b, "Client: ClientSysparam: workArea isn't belonging to an output\n"); } } } @@ -627,14 +627,14 @@ rail_client_ClientGetAppidReq_callback(void *arg) surface = (struct weston_surface *)hash_table_lookup(peerCtx->windowId.hash_table, getAppidReq->windowId); if (!surface) { - weston_log("Client: ClientGetAppidReq: WindowId:0x%x is not found.\n", getAppidReq->windowId); + rdp_debug_error(b, "Client: ClientGetAppidReq: WindowId:0x%x is not found.\n", getAppidReq->windowId); goto Exit; } pid = b->rdprail_shell_api->get_window_app_id( surface, &appId[0], sizeof(appId)-1, &imageName[0], sizeof(imageName)-1); if (appId[0] == '\0') { - weston_log("Client: ClientGetAppidReq: WindowId:0x%x does not have appId, or not top level window.\n", getAppidReq->windowId); + rdp_debug_error(b, "Client: ClientGetAppidReq: WindowId:0x%x does not have appId, or not top level window.\n", getAppidReq->windowId); goto Exit; } @@ -934,7 +934,7 @@ rail_grfx_client_caps_advertise(RdpgfxServerContext* context, const RDPGFX_CAPS_ break; } default: - weston_log(" Version : UNKNOWN(%d)\n", capsSet->version); + rdp_debug_error(b, " Version : UNKNOWN(%d)\n", capsSet->version); } } @@ -982,12 +982,12 @@ gfxredir_client_graphics_redirection_legacy_caps(GfxRedirServerContext* context, rdp_debug(b, "Client: gfxredir_caps: version:%d\n", redirectionCaps->version); /* This is legacy caps callback, version must be 1 */ if (redirectionCaps->version != GFXREDIR_CHANNEL_VERSION_LEGACY) { - weston_log("Client: gfxredir_caps: invalid version:%d\n", redirectionCaps->version); + rdp_debug_error(b, "Client: gfxredir_caps: invalid version:%d\n", redirectionCaps->version); return ERROR_INTERNAL_ERROR; } /* Legacy version 1 client is not supported, so don't set 'activationGraphicsRedirectionCompleted'. */ - weston_log("Client: gfxredir_caps: version 1 is not supported.\n"); + rdp_debug_error(b, "Client: gfxredir_caps: version 1 is not supported.\n"); return CHANNEL_RC_OK; } @@ -1074,7 +1074,7 @@ gfxredir_client_present_buffer_ack(GfxRedirServerContext* context, const GFXREDI rail_state = (struct weston_surface_rail_state *)surface->backend_state; rail_state->isUpdatePending = FALSE; } else { - weston_log("Client: PresentBufferAck: WindowId:0x%lx is not found.\n", presentAck->windowId); + rdp_debug_error(b, "Client: PresentBufferAck: WindowId:0x%lx is not found.\n", presentAck->windowId); } return CHANNEL_RC_OK; @@ -1091,7 +1091,7 @@ rdp_rail_create_cursor(struct weston_surface *surface) ASSERT_COMPOSITOR_THREAD(b); if (peerCtx->cursorSurface) - weston_log("cursor surface already exists old %p vs new %p\n", peerCtx->cursorSurface, surface); + rdp_debug_error(b, "cursor surface already exists old %p vs new %p\n", peerCtx->cursorSurface, surface); peerCtx->cursorSurface = surface; return 0; } @@ -1169,7 +1169,7 @@ rdp_rail_update_cursor(struct weston_surface *surface) int pointerBitsSize = newClientPos.width*cursorBpp*newClientPos.height; BYTE *pointerBits = malloc(pointerBitsSize); if (!pointerBits) { - weston_log("malloc failed for cursor shape\n"); + rdp_debug_error(b, "malloc failed for cursor shape\n"); return -1; } @@ -1179,7 +1179,7 @@ rdp_rail_update_cursor(struct weston_surface *surface) newClientPos.width, newClientPos.height, 0, 0, contentBufferWidth, contentBufferHeight, true /* y-flip */, true /* is_argb */) < 0) { - weston_log("weston_surface_copy_content failed for cursor shape\n"); + rdp_debug_error(b, "weston_surface_copy_content failed for cursor shape\n"); free(pointerBits); return -1; } @@ -1226,12 +1226,12 @@ rdp_rail_create_window(struct wl_listener *listener, void *data) /* negative width/height is not allowed, allow window to be created with zeros */ if (surface->width < 0 || surface->height < 0) { - weston_log("surface width and height are negative\n"); + rdp_debug_error(b, "surface width and height are negative\n"); return; } if (!b || !b->rdp_peer) { - weston_log("CreateWndow(): rdp_peer is not initalized\n"); + rdp_debug_error(b, "CreateWndow(): rdp_peer is not initalized\n"); return; } @@ -1272,7 +1272,7 @@ rdp_rail_create_window(struct wl_listener *listener, void *data) /* windowId can be assigned only after activation completed */ if (!rdp_id_manager_allocate_id(&peerCtx->windowId, (void*)surface, &window_id)) { rail_state->error = true; - weston_log("CreateWindow(): fail to insert windowId.hash_table (windowId:%d surface:%p.\n", + rdp_debug_error(b, "CreateWindow(): fail to insert windowId.hash_table (windowId:%d surface:%p.\n", window_id, surface); return; } @@ -1536,7 +1536,7 @@ rdp_rail_destroy_window(struct wl_listener *listener, void *data) (peerCtx->currentFrameId != peerCtx->acknowledgedFrameId && !peerCtx->isAcknowledgedSuspended)) { if (++waitRetry > 1000) { // timeout after 10 sec. - weston_log("%s: update is still pending in client side (windowId:0x%x)\n", + rdp_debug_error(b, "%s: update is still pending in client side (windowId:0x%x)\n", __func__, window_id); break; } @@ -1624,7 +1624,7 @@ rdp_rail_schedule_update_window(struct wl_listener *listener, void *data) /* negative width/height is not allowed */ if (surface->width < 0 || surface->height < 0) { - weston_log("surface width and height are negative\n"); + rdp_debug_error(b, "surface width and height are negative\n"); return; } @@ -1693,7 +1693,7 @@ rdp_rail_update_window(struct weston_surface *surface, struct update_window_iter } if (!rail_state->isCursor) { if (strncmp(surface->role_name, "wl_pointer-cursor", sizeof("wl_pointer-cursor")) == 0) { - weston_log("!!!cursor role is added after creation - WindowId:0x%x\n", window_id); + rdp_debug_error(b, "!!!cursor role is added after creation - WindowId:0x%x\n", window_id); /* convert to RDP cursor */ rdp_rail_destroy_window(NULL, (void *)surface); @@ -1702,7 +1702,7 @@ rdp_rail_update_window(struct weston_surface *surface, struct update_window_iter rdp_rail_create_window(NULL, (void *)surface); rail_state = (struct weston_surface_rail_state *)surface->backend_state; if (!rail_state || rail_state->window_id == 0) { - weston_log("Fail to convert to RDP cursor - surface:0x%p\n", surface); + rdp_debug_error(b, "Fail to convert to RDP cursor - surface:0x%p\n", surface); return 0; } assert(rail_state->isCursor); @@ -2196,7 +2196,7 @@ rdp_rail_update_window(struct weston_surface *surface, struct update_window_iter copyDamageWidth, copyDamageHeight, damageBox.x1, damageBox.y1, damageWidth, damageHeight, false /* y-flip */, true /* is_argb */) < 0) { - weston_log("weston_surface_copy_content failed for windowId:0x%x\n",window_id); + rdp_debug_error(b, "weston_surface_copy_content failed for windowId:0x%x\n",window_id); return -1; } @@ -2234,7 +2234,7 @@ rdp_rail_update_window(struct weston_surface *surface, struct update_window_iter rail_state->isUpdatePending = TRUE; iter_data->isUpdatePending = TRUE; } else { - weston_log("PresentBuffer failed for windowId:0x%x\n",window_id); + rdp_debug_error(b, "PresentBuffer failed for windowId:0x%x\n",window_id); } } else #endif // HAVE_FREERDP_GFXREDIR_H @@ -2251,7 +2251,7 @@ rdp_rail_update_window(struct weston_surface *surface, struct update_window_iter data = malloc(damageSize); if (!data) { // need better handling to avoid leaking surface on host. - weston_log("Couldn't allocate memory for bitmap update.\n"); + rdp_debug_error(b, "Couldn't allocate memory for bitmap update.\n"); return -1; } @@ -2264,7 +2264,7 @@ rdp_rail_update_window(struct weston_surface *surface, struct update_window_iter if (!alpha) { free(data); // need better handling to avoid leaking surface on host. - weston_log("Couldn't allocate memory for alpha update.\n"); + rdp_debug_error(b, "Couldn't allocate memory for alpha update.\n"); return -1; } @@ -2272,7 +2272,7 @@ rdp_rail_update_window(struct weston_surface *surface, struct update_window_iter data, damageSize, 0, 0, 0, damageBox.x1, damageBox.y1, damageWidth, damageHeight, false /* y-flip */, true /* is_argb */) < 0) { - weston_log("weston_surface_copy_content failed for cursor shape\n"); + rdp_debug_error(b, "weston_surface_copy_content failed for cursor shape\n"); free(data); free(alpha); return -1; @@ -2463,7 +2463,7 @@ rdp_insert_window_zorder_array(struct weston_view *view, UINT32 *windowIdArray, !rail_state->is_minimized && !rail_state->is_minimized_requested) { if (iCurrent >= WindowIdArraySize) { - weston_log("%s: more windows in tree than ID manager tracking (%d vs %d)\n", + rdp_debug_error(b, "%s: more windows in tree than ID manager tracking (%d vs %d)\n", __func__, iCurrent, WindowIdArraySize); return UINT_MAX; } @@ -2498,7 +2498,7 @@ rdp_rail_sync_window_zorder(struct weston_compositor *compositor) numWindowId = peerCtx->windowId.id_used + 1; // +1 for marker window. windowIdArray = zalloc(numWindowId * sizeof(UINT32)); if (!windowIdArray) { - weston_log("%s: zalloc(%ld bytes) failed\n", __func__, numWindowId * sizeof(UINT32)); + rdp_debug_error(b, "%s: zalloc(%ld bytes) failed\n", __func__, numWindowId * sizeof(UINT32)); return; } @@ -2611,7 +2611,7 @@ rdp_rail_peer_activate(freerdp_peer* client) /* HiDef requires graphics pipeline to be supported */ if (settings->SupportGraphicsPipeline == FALSE) { if (settings->HiDefRemoteApp) { - weston_log("HiDef remoting is going to be disabled because client doesn't support graphics pipeline\n"); + rdp_debug_error(b, "HiDef remoting is going to be disabled because client doesn't support graphics pipeline\n"); settings->HiDefRemoteApp = FALSE; } } @@ -3227,25 +3227,27 @@ rdp_drdynvc_destroy(RdpPeerContext* context) BOOL rdp_rail_peer_init(freerdp_peer *client, RdpPeerContext *peerCtx) { + struct rdp_backend *b = peerCtx->rdpBackend; + /* RDP window ID must be within 31 bits range. MSB is reserved and exclude 0. */ - if (!rdp_id_manager_init(&peerCtx->windowId, 0x1, 0x7FFFFFFF)) { - weston_log("unable to create windowId.\n"); + if (!rdp_id_manager_init(b, &peerCtx->windowId, 0x1, 0x7FFFFFFF)) { + rdp_debug_error(b, "unable to create windowId.\n"); goto error_return; } /* RDP surface ID must be within 16 bits range, exclude 0. */ - if (!rdp_id_manager_init(&peerCtx->surfaceId, 0x1, 0xFFFF)) { - weston_log("unable to create windowId.\n"); + if (!rdp_id_manager_init(b, &peerCtx->surfaceId, 0x1, 0xFFFF)) { + rdp_debug_error(b, "unable to create windowId.\n"); goto error_return; } #ifdef HAVE_FREERDP_GFXREDIR_H /* RDP pool ID must be within 32 bits range, exclude 0. */ - if (!rdp_id_manager_init(&peerCtx->poolId, 0x1, 0xFFFFFFFF)) { - weston_log("unable to create windowId.\n"); + if (!rdp_id_manager_init(b, &peerCtx->poolId, 0x1, 0xFFFFFFFF)) { + rdp_debug_error(b, "unable to create windowId.\n"); goto error_return; } /* RDP buffer ID must be within 32 bits range, exclude 0. */ - if (!rdp_id_manager_init(&peerCtx->bufferId, 0x1, 0xFFFFFFFF)) { - weston_log("unable to create windowId.\n"); + if (!rdp_id_manager_init(b, &peerCtx->bufferId, 0x1, 0xFFFFFFFF)) { + rdp_debug_error(b, "unable to create windowId.\n"); goto error_return; } #endif // HAVE_FREERDP_GFXREDIR_H @@ -3371,7 +3373,7 @@ rdp_rail_dump_monitor_binding(struct weston_keyboard *keyboard, } err = fclose(fp); assert(err == 0); - weston_log("%s", str); + rdp_debug_error(b, "%s", str); free(str); } } @@ -3520,12 +3522,12 @@ rdp_rail_dump_window_binding(struct weston_keyboard *keyboard, hash_table_for_each(peerCtx->windowId.hash_table, rdp_rail_dump_window_iter, (void*)&context); err = fclose(fp); assert(err == 0); - weston_log("%s", str); + rdp_debug_error(b, "%s", str); free(str); /* print out compositor's scene graph */ str = weston_compositor_print_scene_graph(b->compositor); - weston_log("%s", str); + rdp_debug_error(b, "%s", str); free(str); } } @@ -3572,7 +3574,7 @@ rdp_rail_set_window_icon(struct weston_surface *surface, pixman_image_t *icon) int targetIconHeight; if (!b || !b->rdp_peer) { - weston_log("set_window_icon(): rdp_peer is not initalized\n"); + rdp_debug_error(b, "set_window_icon(): rdp_peer is not initalized\n"); return; } @@ -3744,7 +3746,7 @@ rdp_rail_notify_app_list(void *rdp_backend, struct weston_rdprail_app_list_data RdpPeerContext *peerCtx; if (!b || !b->rdp_peer) { - weston_log("rdp_rail_notify_app_list(): rdp_peer is not initalized\n"); + rdp_debug_error(b, "rdp_rail_notify_app_list(): rdp_peer is not initalized\n"); return false; // return false only when peer is not ready for possible re-send. } @@ -3908,7 +3910,7 @@ rdp_rail_backend_create(struct rdp_backend *b) int ret = weston_plugin_api_register(b->compositor, WESTON_RDPRAIL_API_NAME, &rdprail_api, sizeof(rdprail_api)); if (ret < 0) { - weston_log("Failed to register rdprail API.\n"); + rdp_debug_error(b, "Failed to register rdprail API.\n"); return -1; } @@ -3916,7 +3918,7 @@ rdp_rail_backend_create(struct rdp_backend *b) dlerror(); /* clear error */ b->libFreeRDPServer = dlopen("libfreerdp-server2.so", RTLD_NOW); if (!b->libFreeRDPServer) - weston_log("dlopen(libfreerdp-server2.so) failed with %s\n", dlerror()); + rdp_debug_error(b, "dlopen(libfreerdp-server2.so) failed with %s\n", dlerror()); #endif // defined(HAVE_FREERDP_RDPAPPLIST_H) || defined(HAVE_FREERDP_GFXREDIR_H)o #ifdef HAVE_FREERDP_RDPAPPLIST_H diff --git a/libweston/backend-rdp/rdputil.c b/libweston/backend-rdp/rdputil.c index 1a126871d..931366884 100644 --- a/libweston/backend-rdp/rdputil.c +++ b/libweston/backend-rdp/rdputil.c @@ -128,7 +128,7 @@ rdp_allocate_shared_memory(struct rdp_backend *b, struct weston_rdp_shared_memor char path[b->shared_memory_mount_path_size + 1 + RDP_SHARED_MEMORY_NAME_SIZE + 1]; if (shared_memory->size <= 0) { - weston_log("%s: invalid size %ld\n", + rdp_debug_error(b, "%s: invalid size %ld\n", __func__, shared_memory->size); goto error_exit; } @@ -139,12 +139,12 @@ rdp_allocate_shared_memory(struct rdp_backend *b, struct weston_rdp_shared_memor if (shared_memory->name[0] == '\0') { int fd_uuid = open("/proc/sys/kernel/random/uuid", O_RDONLY); if (fd_uuid < 0) { - weston_log("%s: open uuid failed with error %s\n", + rdp_debug_error(b, "%s: open uuid failed with error %s\n", __func__, strerror(errno)); goto error_exit; } if (read(fd_uuid, &shared_memory->name[1], 32 + 4) < 0) { - weston_log("%s: read uuid failed with error %s\n", + rdp_debug_error(b, "%s: read uuid failed with error %s\n", __func__, strerror(errno)); goto error_exit; } @@ -156,7 +156,7 @@ rdp_allocate_shared_memory(struct rdp_backend *b, struct weston_rdp_shared_memor (shared_memory->name[0] != '{') || (shared_memory->name[RDP_SHARED_MEMORY_NAME_SIZE - 1] != '}') || (shared_memory->name[RDP_SHARED_MEMORY_NAME_SIZE] != '\0')) { - weston_log("%s: name is not in GUID form \"%s\"\n", + rdp_debug_error(b, "%s: name is not in GUID form \"%s\"\n", __func__, shared_memory->name); goto error_exit; } @@ -167,20 +167,20 @@ rdp_allocate_shared_memory(struct rdp_backend *b, struct weston_rdp_shared_memor fd = open(path, O_CREAT | O_RDWR, 00600); if (fd < 0) { - weston_log("%s: Failed to open \"%s\" with error: %s\n", + rdp_debug_error(b, "%s: Failed to open \"%s\" with error: %s\n", __func__, path, strerror(errno)); goto error_exit; } if (fallocate(fd, 0, 0, shared_memory->size) < 0) { - weston_log("%s: Failed to allocate %d: \"%s\" %ld bytes with error: %s\n", + rdp_debug_error(b, "%s: Failed to allocate %d: \"%s\" %ld bytes with error: %s\n", __func__, fd, path, shared_memory->size, strerror(errno)); goto error_exit; } addr = mmap(NULL, shared_memory->size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); if (addr == MAP_FAILED) { - weston_log("%s: Failed to mmmap %d: \"%s\" %ld bytes with error: %s\n", + rdp_debug_error(b, "%s: Failed to mmmap %d: \"%s\" %ld bytes with error: %s\n", __func__, fd, path, shared_memory->size, strerror(errno)); goto error_exit; } @@ -222,9 +222,10 @@ rdp_free_shared_memory(struct rdp_backend *b, struct weston_rdp_shared_memory *s } BOOL -rdp_id_manager_init(struct rdp_id_manager *id_manager, UINT32 low_limit, UINT32 high_limit) +rdp_id_manager_init(struct rdp_backend *rdp_backend, struct rdp_id_manager *id_manager, UINT32 low_limit, UINT32 high_limit) { assert(low_limit < high_limit); + id_manager->rdp_backend = rdp_backend; id_manager->id_total = high_limit - low_limit; id_manager->id_used = 0; id_manager->id_low_limit = low_limit; @@ -232,7 +233,7 @@ rdp_id_manager_init(struct rdp_id_manager *id_manager, UINT32 low_limit, UINT32 id_manager->id = low_limit; id_manager->hash_table = hash_table_create(); if (!id_manager->hash_table) - weston_log("%s: unable to create hash_table.\n", __func__); + rdp_debug_error(rdp_backend, "%s: unable to create hash_table.\n", __func__); return id_manager->hash_table != NULL; } @@ -240,7 +241,7 @@ void rdp_id_manager_free(struct rdp_id_manager *id_manager) { if (id_manager->id_used != 0) - weston_log("%s: possible id leak: %d\n", __func__, id_manager->id_used); + rdp_debug_error(id_manager->rdp_backend, "%s: possible id leak: %d\n", __func__, id_manager->id_used); if (id_manager->hash_table) { hash_table_destroy(id_manager->hash_table); id_manager->hash_table = NULL; @@ -250,6 +251,7 @@ rdp_id_manager_free(struct rdp_id_manager *id_manager) id_manager->id_high_limit = 0; id_manager->id_total = 0; id_manager->id_used = 0; + id_manager->rdp_backend = NULL; } BOOL diff --git a/rdprail-shell/app-list.c b/rdprail-shell/app-list.c index bc9d4f5d5..ada1e8e0b 100644 --- a/rdprail-shell/app-list.c +++ b/rdprail-shell/app-list.c @@ -180,10 +180,11 @@ attach_app_list_namespace(struct desktop_shell *shell) assert(false == context->isAppListNamespaceAttached); if (context && context->app_list_pidfd > 0) { assert(context->weston_pidfd > 0); - if (setns(context->app_list_pidfd, 0) == -1) - weston_log("attach_app_list_namespace failed %s\n", strerror(errno)); - else + if (setns(context->app_list_pidfd, 0) == -1) { + shell_rdp_debug_error(shell, "attach_app_list_namespace failed %s\n", strerror(errno)); + } else { context->isAppListNamespaceAttached = true; + } } } @@ -194,7 +195,7 @@ detach_app_list_namespace(struct desktop_shell *shell) if (context && context->weston_pidfd > 0 && context->isAppListNamespaceAttached) { if (setns(context->weston_pidfd, 0) == -1) { /* TODO: when failed to go back, this is fatal, should terminate weston and restart? */ - weston_log("detach_app_list_namespace failed %s\n", strerror(errno)); + shell_rdp_debug_error(shell, "detach_app_list_namespace failed %s\n", strerror(errno)); } else { context->isAppListNamespaceAttached = false; } @@ -696,14 +697,14 @@ app_list_monitor_thread(LPVOID arg) shell_rdp_debug(shell, "app_list_monitor_thread: running in system-distro with user-distro: %s\n", shell->distroName); if (unshare(CLONE_FS) < 0) - weston_log("app_list_monitor_thread: unshare(CLONE_FS) failed %s\n", strerror(errno)); + shell_rdp_debug_error(shell, "app_list_monitor_thread: unshare(CLONE_FS) failed %s\n", strerror(errno)); /* obtain pidfd for current process */ pidfd_path = "/proc/self/ns/mnt"; shell_rdp_debug(shell, "app_list_monitor_thread: open(%s)\n", pidfd_path); context->weston_pidfd = open(pidfd_path, O_RDONLY | O_CLOEXEC); if (context->weston_pidfd < 0) { - weston_log("app_list_monitor_thread: open(%s) failed %s\n", pidfd_path, strerror(errno)); + shell_rdp_debug_error(shell, "app_list_monitor_thread: open(%s) failed %s\n", pidfd_path, strerror(errno)); goto Exit; } @@ -712,7 +713,7 @@ app_list_monitor_thread(LPVOID arg) shell_rdp_debug(shell, "app_list_monitor_thread: open(%s)\n", pidfd_path); context->app_list_pidfd = open(pidfd_path, O_RDONLY | O_CLOEXEC); if (context->app_list_pidfd < 0) { - weston_log("app_list_monitor_thread: open(%s) failed %s\n", pidfd_path, strerror(errno)); + shell_rdp_debug_error(shell, "app_list_monitor_thread: open(%s) failed %s\n", pidfd_path, strerror(errno)); goto Exit; } } else { @@ -730,7 +731,7 @@ app_list_monitor_thread(LPVOID arg) for (int i = 0; i < (int)ARRAY_LENGTH(app_list_folder); i++) { fd[num_watch] = inotify_init(); if (fd[num_watch] < 0) { - weston_log("app_list_monitor_thread: inotify_init[%d] failed %s\n", i, strerror(errno)); + shell_rdp_debug_error(shell, "app_list_monitor_thread: inotify_init[%d] failed %s\n", i, strerror(errno)); continue; } @@ -760,7 +761,7 @@ app_list_monitor_thread(LPVOID arg) shell_rdp_debug(shell, "app_list_monitor_thread: inotify_add_watch(%s)\n", folder); wd[num_watch] = inotify_add_watch(fd[num_watch], folder, IN_CREATE|IN_DELETE|IN_MODIFY|IN_MOVED_TO|IN_MOVED_FROM); if (wd[num_watch] < 0) { - weston_log("app_list_monitor_thread: inotify_add_watch failed: %s\n", strerror(errno)); + shell_rdp_debug_error(shell, "app_list_monitor_thread: inotify_add_watch failed: %s\n", strerror(errno)); detach_app_list_namespace(shell); close(fd[num_watch]); fd[num_watch] = 0; @@ -770,7 +771,7 @@ app_list_monitor_thread(LPVOID arg) events[num_events] = GetFileHandleForFileDescriptor(fd[num_watch]); if (!events[num_events]) { - weston_log("app_list_monitor_thread: GetFileHandleForFileDescriptor failed\n"); + shell_rdp_debug_error(shell, "app_list_monitor_thread: GetFileHandleForFileDescriptor failed\n"); inotify_rm_watch(fd[num_watch], wd[num_watch]); wd[num_watch] = 0; close(fd[num_watch]); diff --git a/rdprail-shell/shell.c b/rdprail-shell/shell.c index 46168a15c..c059701be 100644 --- a/rdprail-shell/shell.c +++ b/rdprail-shell/shell.c @@ -371,7 +371,7 @@ shell_surface_set_window_icon(struct weston_desktop_surface *desktop_surface, format = PIXMAN_a8r8g8b8; break; default: - weston_log("shell_surface_set_window_icon(): unsupported bpp: %d\n", bpp); + shell_rdp_debug_error(shsurf->shell, "shell_surface_set_window_icon(): unsupported bpp: %d\n", bpp); return; } image = pixman_image_create_bits_no_clear(format, @@ -634,7 +634,7 @@ static enum weston_keyboard_modifier get_modifier(char *modifier) { if (!modifier) - return MODIFIER_SUPER; + return 0; // default to no binding-modifier. if (!strcmp("ctrl", modifier)) return MODIFIER_CTRL; @@ -645,7 +645,7 @@ get_modifier(char *modifier) else if (!strcmp("none", modifier)) return 0; else - return MODIFIER_SUPER; + return 0; // default to no binding-modifier. } static void @@ -659,12 +659,14 @@ shell_configuration(struct desktop_shell *shell) section = weston_config_get_section(wet_get_config(shell->compositor), "shell", NULL, NULL); + /* default to not allow zap */ weston_config_section_get_bool(section, - "allow-zap", &allow_zap, true); + "allow-zap", &allow_zap, false); shell->allow_zap = allow_zap; + /* set "none" to default to disable optional key-bindings */ weston_config_section_get_string(section, - "binding-modifier", &s, "super"); + "binding-modifier", &s, "none"); shell->binding_modifier = get_modifier(s); free(s); @@ -2014,7 +2016,8 @@ desktop_surface_added(struct weston_desktop_surface *desktop_surface, if (wl_client) wl_client_post_no_memory(wl_client); else - weston_log("%s: no memory to allocate shell surface\n", __func__); + shell_rdp_debug(((struct desktop_shell *)shell), + "%s: no memory to allocate shell surface\n", __func__); return; } @@ -2437,7 +2440,7 @@ desktop_surface_set_parent(struct weston_desktop_surface *desktop_surface, geometry won't be adjusted to relative to parent. */ shsurf->parent = shsurf_parent; } else { - weston_log("RDP shell: parent is not toplevel surface\n"); + shell_rdp_debug_error(shsurf->shell, "RDP shell: parent is not toplevel surface\n"); wl_list_init(&shsurf->children_link); shsurf->parent = NULL; } @@ -2863,6 +2866,7 @@ move_binding(struct weston_pointer *pointer, const struct timespec *time, weston_desktop_surface_get_maximized(shsurf->desktop_surface)) return; + shell_rdp_debug_verbose(shsurf->shell, "%s\n", __func__); surface_move(shsurf, pointer, false); } @@ -2882,6 +2886,7 @@ maximize_binding(struct weston_keyboard *keyboard, const struct timespec *time, if (shsurf == NULL) return; + shell_rdp_debug_verbose(shsurf->shell, "%s\n", __func__); set_maximized(shsurf, !weston_desktop_surface_get_maximized(shsurf->desktop_surface)); } @@ -2905,6 +2910,7 @@ fullscreen_binding(struct weston_keyboard *keyboard, fullscreen = weston_desktop_surface_get_fullscreen(shsurf->desktop_surface); + shell_rdp_debug_verbose(shsurf->shell, "%s: fullscreen:%d\n", __func__, !fullscreen); set_fullscreen(shsurf, !fullscreen, NULL); } @@ -2976,6 +2982,7 @@ resize_binding(struct weston_pointer *pointer, const struct timespec *time, else edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; + shell_rdp_debug_verbose(shsurf->shell, "%s edges:%x\n", __func__, edges); surface_resize(shsurf, pointer, edges); } @@ -3005,76 +3012,12 @@ surface_opacity_binding(struct weston_pointer *pointer, shsurf->view->alpha = 1.0; if (shsurf->view->alpha < step) shsurf->view->alpha = step; + shell_rdp_debug_verbose(shsurf->shell, "%s alpha:%f\n", __func__, shsurf->view->alpha); weston_view_geometry_dirty(shsurf->view); weston_surface_damage(surface); } -static void -do_zoom(struct weston_seat *seat, const struct timespec *time, uint32_t key, - uint32_t axis, double value) -{ - struct weston_compositor *compositor = seat->compositor; - struct weston_pointer *pointer = weston_seat_get_pointer(seat); - struct weston_output *output; - float increment; - - if (!pointer) { - weston_log("Zoom hotkey pressed but seat '%s' contains no pointer.\n", seat->seat_name); - return; - } - - wl_list_for_each(output, &compositor->output_list, link) { - if (pixman_region32_contains_point(&output->region, - wl_fixed_to_double(pointer->x), - wl_fixed_to_double(pointer->y), - NULL)) { - if (key == KEY_PAGEUP) - increment = output->zoom.increment; - else if (key == KEY_PAGEDOWN) - increment = -output->zoom.increment; - else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) - /* For every pixel zoom 20th of a step */ - increment = output->zoom.increment * - -value / 20.0; - else - increment = 0; - - output->zoom.level += increment; - - if (output->zoom.level < 0.0) - output->zoom.level = 0.0; - else if (output->zoom.level > output->zoom.max_level) - output->zoom.level = output->zoom.max_level; - - if (!output->zoom.active) { - if (output->zoom.level <= 0.0) - continue; - weston_output_activate_zoom(output, seat); - } - - output->zoom.spring_z.target = output->zoom.level; - - weston_output_update_zoom(output); - } - } -} - -static void -zoom_axis_binding(struct weston_pointer *pointer, const struct timespec *time, - struct weston_pointer_axis_event *event, - void *data) -{ - do_zoom(pointer->seat, time, 0, event->axis, event->value); -} - -static void -zoom_key_binding(struct weston_keyboard *keyboard, const struct timespec *time, - uint32_t key, void *data) -{ - do_zoom(keyboard->seat, time, key, 0, 0); -} - static void terminate_binding(struct weston_keyboard *keyboard, const struct timespec *time, uint32_t key, void *data) @@ -3233,6 +3176,9 @@ surface_rotate(struct shell_surface *shsurf, struct weston_pointer *pointer) pointer, WESTON_DESKTOP_SHELL_CURSOR_ARROW); } +/* +//TODO: while RAIL can't do arbirary rotation, but can do 0,90,180,270 degree rotation +// maybe it can have a new cap for that ? static void rotate_binding(struct weston_pointer *pointer, const struct timespec *time, uint32_t button, void *data) @@ -3256,8 +3202,10 @@ rotate_binding(struct weston_pointer *pointer, const struct timespec *time, weston_desktop_surface_get_maximized(surface->desktop_surface)) return; + shell_rdp_debug(surface->shell, "%s\n", __func__); surface_rotate(surface, pointer); } +*/ /* Move all fullscreen layers down to the current workspace and hide their * black views. The surfaces' state is set to both fullscreen and lowered, @@ -3886,20 +3834,10 @@ shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) if (!mod) return; - /* This binding is not configurable, but is only enabled if there is a - * valid binding modifier. */ weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, - MODIFIER_SUPER | MODIFIER_ALT, + mod | MODIFIER_ALT, surface_opacity_binding, NULL); - weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, - mod, zoom_axis_binding, - NULL); - - weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, - zoom_key_binding, NULL); - weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, - zoom_key_binding, NULL); weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, maximize_binding, NULL); weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, @@ -3913,12 +3851,14 @@ shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) mod | MODIFIER_SHIFT, resize_binding, shell); - if (ec->capabilities & WESTON_CAP_ROTATION_ANY) - weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, - rotate_binding, NULL); + //TODO: while RAIL can't do arbirary rotation, but can do 0,90,180,270 degree rotation + // maybe it can have a new cap for that ? + //if (ec->capabilities & WESTON_CAP_ROTATION_ANY) + // weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, + // rotate_binding, NULL); weston_compositor_add_key_binding(ec, KEY_K, mod, - force_kill_binding, shell); + force_kill_binding, shell); weston_install_debug_key_binding(ec, mod); } @@ -4158,34 +4098,34 @@ wet_shell_init(struct weston_compositor *ec, shell->compositor = ec; + if (!weston_compositor_add_destroy_listener_once(ec, + &shell->destroy_listener, + shell_destroy)) { + free(shell); + return 0; + } + shell->debug = weston_log_ctx_add_log_scope(ec->weston_log_ctx, "rdprail-shell", "Debug messages from RDP-RAIL shell\n", NULL, NULL, NULL); - debug_level = getenv("WESTON_RDPRAIL_SHELL_DEBUG_LEVEL"); - if (debug_level) { - shell->debugLevel = atoi(debug_level); - if (shell->debugLevel > RDPRAIL_SHELL_DEBUG_LEVEL_VERBOSE) - shell->debugLevel = RDPRAIL_SHELL_DEBUG_LEVEL_VERBOSE; - } else { - shell->debugLevel = RDPRAIL_SHELL_DEBUG_LEVEL_DEFAULT; + if (shell->debug) { + debug_level = getenv("WESTON_RDPRAIL_SHELL_DEBUG_LEVEL"); + if (debug_level) { + shell->debugLevel = atoi(debug_level); + if (shell->debugLevel > RDPRAIL_SHELL_DEBUG_LEVEL_VERBOSE) + shell->debugLevel = RDPRAIL_SHELL_DEBUG_LEVEL_VERBOSE; + } else { + shell->debugLevel = RDPRAIL_SHELL_DEBUG_LEVEL_DEFAULT; + } } weston_log("RDPRAIL-shell: WESTON_RDPRAIL_SHELL_DEBUG_LEVEL: %d.\n", shell->debugLevel); - /* this make sure rdprail-shell to be used with only backend-rdp */ shell->rdprail_api = weston_rdprail_get_api(ec); if (!shell->rdprail_api) { - weston_log("Failed to obrain rdprail API.\n"); - free(shell); - return 0; - } - - if (!weston_compositor_add_destroy_listener_once(ec, - &shell->destroy_listener, - shell_destroy)) { - free(shell); - return 0; + shell_rdp_debug_error(shell, "Failed to obrain rdprail API.\n"); + return -1; } shell_configuration(shell); @@ -4251,24 +4191,32 @@ wet_shell_init(struct weston_compositor *ec, shell->is_appid_with_distro_name = false; else shell->is_appid_with_distro_name = true; + shell_rdp_debug(shell, "WESTON_RDPRAIL_SHELL_DISABLE_APPEND_DISTRONAME_STARTMEN:%d\n", + shell->is_appid_with_distro_name); icon_path = getenv("WSL2_DEFAULT_APP_ICON"); if (icon_path && (strcmp(icon_path, "disabled") != 0)) shell->image_default_app_icon = load_image(icon_path); + shell_rdp_debug(shell, "WSL2_DEFAULT_APP_ICON:%s\n", icon_path); icon_path = getenv("WSL2_DEFAULT_APP_OVERLAY_ICON"); if (icon_path && (strcmp(icon_path, "disabled") != 0)) shell->image_default_app_overlay_icon = load_image(icon_path); + shell_rdp_debug(shell, "WSL2_DEFAULT_APP_OVERLAY_ICON:%s\n", icon_path); if (getenv("WESTON_RDPRAIL_SHELL_DISABLE_BLEND_OVERLAY_ICON_TASKBAR")) shell->is_blend_overlay_icon_taskbar = false; else shell->is_blend_overlay_icon_taskbar = true; + shell_rdp_debug(shell, "WESTON_RDPRAIL_SHELL_DISABLE_BLEND_OVERLAY_ICON_TASKBAR:%d\n", + shell->is_blend_overlay_icon_taskbar); if (getenv("WESTON_RDPRAIL_SHELL_DISABLE_BLEND_OVERLAY_ICON_APPLIST")) shell->is_blend_overlay_icon_app_list = false; else shell->is_blend_overlay_icon_app_list = true; + shell_rdp_debug(shell, "WESTON_RDPRAIL_SHELL_DISABLE_BLEND_OVERLAY_ICON_APPLIST:%d\n", + shell->is_blend_overlay_icon_app_list); if (shell->rdprail_api->shell_initialize_notify) shell->rdp_backend = shell->rdprail_api->shell_initialize_notify(ec, &rdprail_shell_api, (void*)shell, shell->distroName); diff --git a/rdprail-shell/shell.h b/rdprail-shell/shell.h index 366ed76dc..e8508a837 100644 --- a/rdprail-shell/shell.h +++ b/rdprail-shell/shell.h @@ -49,6 +49,9 @@ #define shell_rdp_debug(b, ...) \ if (b->debugLevel >= RDPRAIL_SHELL_DEBUG_LEVEL_INFO) \ shell_rdp_debug_print(b->debug, false, __VA_ARGS__) +#define shell_rdp_debug_error(b, ...) \ + if (b->debugLevel >= RDPRAIL_SHELL_DEBUG_LEVEL_ERR) \ + shell_rdp_debug_print(b->debug, false, __VA_ARGS__) #define is_system_distro() (getenv("WSL2_VM_ID") != NULL)