Files
rdp-proxy/workers/rdp-worker/src/adapter/adapter_event_router.cpp
T
2026-04-28 22:29:50 +03:00

105 lines
3.7 KiB
C++

#include "rdp_worker/adapter/adapter_event_router.hpp"
#include "rdp_worker/common/json.hpp"
namespace rdp_worker::adapter {
namespace {
AdapterEventDescriptor MakeDescriptor(AdapterChannel channel,
std::string_view type,
bool adapter_origin) {
return AdapterEventDescriptor{
channel,
type,
adapter_origin,
IsReliable(channel),
IsDroppable(channel),
};
}
} // namespace
AdapterEventDescriptor AdapterEventRouter::DescribeRenderNotification(
const runtime::RenderNotification& notification) const {
if (notification.type == "session_frame") {
const auto update_kind = common::GetString(notification.payload, "frame_update_kind").value_or("full");
return MakeDescriptor(
AdapterChannel::kDisplay,
update_kind == "region" ? "display.region_bgra" : "display.baseline_full_bgra",
true);
}
if (notification.type == "session_cursor_updated") {
return MakeDescriptor(AdapterChannel::kCursor, "cursor.update", true);
}
if (notification.type == "session_render_resized") {
return MakeDescriptor(AdapterChannel::kDisplay, "display.resize", true);
}
if (notification.type == "session_render_dirty") {
return MakeDescriptor(AdapterChannel::kDisplay, "display.dirty", true);
}
return MakeDescriptor(AdapterChannel::kTelemetry, notification.type, true);
}
AdapterEventDescriptor AdapterEventRouter::DescribeClipboardNotification(
const runtime::ClipboardNotification&) const {
return MakeDescriptor(AdapterChannel::kClipboard, "clipboard.server_text", true);
}
AdapterEventDescriptor AdapterEventRouter::DescribeClientEnvelope(std::string_view envelope_type,
std::string_view payload_kind,
std::string_view payload_action) const {
if (envelope_type == "input") {
if (payload_kind == "mouse" && payload_action == "move") {
return MakeDescriptor(AdapterChannel::kInput, "input.pointer_move", false);
}
if (payload_kind == "mouse") {
return MakeDescriptor(AdapterChannel::kInput, "input.pointer", false);
}
if (payload_kind == "keyboard") {
return MakeDescriptor(AdapterChannel::kInput, "input.keyboard", false);
}
if (payload_kind == "focus") {
return MakeDescriptor(AdapterChannel::kInput, "input.focus", false);
}
return MakeDescriptor(AdapterChannel::kInput, "input.unknown", false);
}
if (envelope_type == "clipboard") {
return MakeDescriptor(AdapterChannel::kClipboard, "clipboard.client_text", false);
}
if (envelope_type == "file_upload") {
return MakeDescriptor(AdapterChannel::kFileTransfer, "file_upload.client_to_server", false);
}
if (envelope_type == "control") {
return MakeDescriptor(AdapterChannel::kControl, "control.command", false);
}
return MakeDescriptor(AdapterChannel::kTelemetry, envelope_type, false);
}
std::string AdapterEventDescriptorLogLine(const AdapterEventDescriptor& descriptor) {
std::string line;
line.reserve(160);
line += "adapter_event channel=";
line += ChannelName(descriptor.channel);
line += " type=";
line += descriptor.normalized_type;
line += " origin=";
line += descriptor.adapter_origin ? "adapter" : "client";
line += " reliable=";
line += descriptor.reliable ? "true" : "false";
line += " droppable=";
line += descriptor.droppable ? "true" : "false";
return line;
}
} // namespace rdp_worker::adapter