1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:17:44 +00:00

SpiceAgent: Implement FileTransferStatus messages

This commit is contained in:
Caoimhe 2023-05-13 19:59:37 +01:00 committed by Andreas Kling
parent 476774d681
commit af91c75080
3 changed files with 115 additions and 0 deletions

View file

@ -241,4 +241,30 @@ ErrorOr<String> FileTransferStartMessage::debug_description()
return builder.to_string();
}
ErrorOr<FileTransferStatusMessage> FileTransferStatusMessage::read_from_stream(AK::Stream& stream)
{
auto id = TRY(stream.read_value<u32>());
auto status = TRY(stream.read_value<FileTransferStatus>());
return FileTransferStatusMessage(id, status);
}
ErrorOr<void> FileTransferStatusMessage::write_to_stream(AK::Stream& stream)
{
TRY(stream.write_value(id()));
TRY(stream.write_value(status()));
return {};
}
ErrorOr<String> FileTransferStatusMessage::debug_description()
{
StringBuilder builder;
TRY(builder.try_append("FileTransferStatus { "sv));
TRY(builder.try_appendff("id = {}, ", id()));
TRY(builder.try_appendff("status = {}", status()));
TRY(builder.try_append(" }"sv));
return builder.to_string();
}
}

View file

@ -55,6 +55,19 @@ ErrorOr<String> clipboard_data_type_to_mime_type(ClipboardDataType type);
ErrorOr<ClipboardDataType> clipboard_data_type_from_raw_value(u32 value);
ErrorOr<ClipboardDataType> clipboard_data_type_from_mime_type(String const& mime_type);
// Used to describe what state the current file transfer is in
enum class FileTransferStatus : u32 {
CanSendData = 0,
Cancelled,
Error,
Success,
NotEnoughSpace,
SessionLocked,
AgentNotConnected,
Disabled,
__End
};
class Message {
public:
// The spice protocol headers contain a bit of documentation about these, but nothing major:
@ -206,6 +219,29 @@ private:
Metadata m_metadata;
};
// Sent/recieved to indicate the status of the current file transfer.
class FileTransferStatusMessage : public Message {
public:
FileTransferStatusMessage(u32 id, FileTransferStatus status)
: Message(Type::FileTransferStatus)
, m_id(id)
, m_status(status)
{
}
static ErrorOr<FileTransferStatusMessage> read_from_stream(AK::Stream& stream);
ErrorOr<void> write_to_stream(AK::Stream& stream);
ErrorOr<String> debug_description() override;
u32 id() const { return m_id; }
FileTransferStatus const& status() { return m_status; }
private:
u32 m_id { 0 };
FileTransferStatus m_status;
};
}
namespace AK {
@ -246,4 +282,50 @@ struct Formatter<SpiceAgent::ClipboardDataType> : Formatter<StringView> {
return Formatter<StringView>::format(builder, string);
}
};
template<>
struct Formatter<SpiceAgent::FileTransferStatus> : Formatter<StringView> {
ErrorOr<void> format(FormatBuilder& builder, SpiceAgent::FileTransferStatus const& header)
{
auto string = "Unknown"sv;
switch (header) {
case SpiceAgent::FileTransferStatus::AgentNotConnected:
string = "AgentNotConnected"sv;
break;
case SpiceAgent::FileTransferStatus::Cancelled:
string = "Cancelled"sv;
break;
case SpiceAgent::FileTransferStatus::CanSendData:
string = "CanSendData"sv;
break;
case SpiceAgent::FileTransferStatus::Disabled:
string = "Disabled"sv;
break;
case SpiceAgent::FileTransferStatus::Error:
string = "Error"sv;
break;
case SpiceAgent::FileTransferStatus::NotEnoughSpace:
string = "NotEnoughSpace"sv;
break;
case SpiceAgent::FileTransferStatus::SessionLocked:
string = "SessionLocked"sv;
break;
case SpiceAgent::FileTransferStatus::Success:
string = "Success"sv;
break;
default:
break;
}
return Formatter<StringView>::format(builder, string);
}
};
}

View file

@ -154,6 +154,13 @@ ErrorOr<void> SpiceAgent::on_message_received()
break;
}
case Message::Type::FileTransferStatus: {
auto message = TRY(FileTransferStatusMessage::read_from_stream(stream));
dbgln("File transfer {} has been cancelled: {}", message.id(), message.status());
break;
}
case Message::Type::FileTransferStart: {
auto message = TRY(FileTransferStartMessage::read_from_stream(stream));
dbgln("File transfer request received: {}", TRY(message.debug_description()));