#include "rdp_worker/adapter/rdp_adapter_runtime.hpp" #include namespace rdp_worker::adapter { RdpAdapterRuntime::RdpAdapterRuntime(std::shared_ptr logger) : logger_(std::move(logger)), freerdp_(logger_) {} bool RdpAdapterRuntime::Start(const runtime::ConnectionSpec& spec) { logger_->Info("rdp_adapter.runtime_start substrate=freerdp resource_id=" + spec.resource_id + " host=" + spec.host + " render_quality_profile=" + spec.render_quality_profile); lifecycle_logged_ = true; return freerdp_.Start(spec); } void RdpAdapterRuntime::Disconnect(bool terminate) { logger_->Info("rdp_adapter.runtime_disconnect terminate=" + (terminate ? std::string("true") : std::string("false"))); freerdp_.Disconnect(terminate); } bool RdpAdapterRuntime::IsConnected() const { return freerdp_.IsConnected(); } bool RdpAdapterRuntime::PumpEvents(std::chrono::milliseconds timeout) { if (!lifecycle_logged_) { logger_->Info("rdp_adapter.event_pump_start substrate=freerdp"); lifecycle_logged_ = true; } return freerdp_.PumpEvents(timeout); } int RdpAdapterRuntime::DesktopWidth() const { return freerdp_.DesktopWidth(); } int RdpAdapterRuntime::DesktopHeight() const { return freerdp_.DesktopHeight(); } bool RdpAdapterRuntime::SendFocusEvent(bool focused) { TraceClientEnvelope("input", "focus", focused ? "focus_in" : "focus_out"); return freerdp_.SendFocusEvent(focused); } bool RdpAdapterRuntime::SendKeyboardInput(uint16_t scan_code, bool key_down, bool extended) { TraceClientEnvelope("input", "keyboard", key_down ? "key_down" : "key_up"); return freerdp_.SendKeyboardInput(scan_code, key_down, extended); } bool RdpAdapterRuntime::SendMouseMove(double normalized_x, double normalized_y) { TraceClientEnvelope("input", "mouse", "move"); return freerdp_.SendMouseMove(normalized_x, normalized_y); } bool RdpAdapterRuntime::SendMouseButton(const std::string& button, bool pressed, double normalized_x, double normalized_y) { TraceClientEnvelope("input", "mouse", pressed ? "button_down" : "button_up"); return freerdp_.SendMouseButton(button, pressed, normalized_x, normalized_y); } bool RdpAdapterRuntime::SendMouseWheel(int wheel_delta, bool horizontal, double normalized_x, double normalized_y) { TraceClientEnvelope("input", "mouse", "wheel"); return freerdp_.SendMouseWheel(wheel_delta, horizontal, normalized_x, normalized_y); } bool RdpAdapterRuntime::SetClipboardText(const std::string& text) { TraceClientEnvelope("clipboard", "text", "client_to_server"); return freerdp_.SetClipboardText(text); } void RdpAdapterRuntime::MarkInputAppliedForGraphicsTrace(const std::string& correlation_id) { freerdp_.MarkInputAppliedForGraphicsTrace(correlation_id); } std::optional RdpAdapterRuntime::CaptureFullFrameNotification( const std::string& state, const std::string& capture_source) { auto notification = freerdp_.CaptureFullFrameNotification(state, capture_source); if (notification.has_value()) { TraceAdapterEvent(event_router_.DescribeRenderNotification(*notification)); } return notification; } std::optional RdpAdapterRuntime::PopRenderNotification() { auto notification = freerdp_.PopRenderNotification(); if (notification.has_value()) { TraceAdapterEvent(event_router_.DescribeRenderNotification(*notification)); } return notification; } std::optional RdpAdapterRuntime::PopClipboardNotification() { auto notification = freerdp_.PopClipboardNotification(); if (notification.has_value()) { TraceAdapterEvent(event_router_.DescribeClipboardNotification(*notification)); } return notification; } const std::string& RdpAdapterRuntime::RenderQualityProfile() const { return freerdp_.RenderQualityProfile(); } const AdapterEventRouter& RdpAdapterRuntime::EventRouter() const { return event_router_; } void RdpAdapterRuntime::TraceClientEnvelope(std::string_view envelope_type, std::string_view payload_kind, std::string_view payload_action) { const auto descriptor = event_router_.DescribeClientEnvelope(envelope_type, payload_kind, payload_action); if (descriptor.channel == AdapterChannel::kInput && descriptor.normalized_type == "input.pointer_move") { return; } TraceAdapterEvent(descriptor); } void RdpAdapterRuntime::TraceAdapterEvent(const AdapterEventDescriptor& descriptor) { if (descriptor.channel == AdapterChannel::kDisplay && descriptor.normalized_type != "display.resize" && descriptor.normalized_type != "display.baseline_full_bgra") { return; } logger_->Info(AdapterEventDescriptorLogLine(descriptor)); } } // namespace rdp_worker::adapter