diff options
author | Caoimhe <caoimhebyrne06@gmail.com> | 2023-05-13 19:59:37 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-21 18:45:53 +0200 |
commit | af91c750803de47824863c88f42be692d4e9a4c2 (patch) | |
tree | 6ab661580566eddfc3afb984dfd3560fb3fb5972 /Userland | |
parent | 476774d68113275c4658ae47214f6a4bb2000848 (diff) | |
download | serenity-af91c750803de47824863c88f42be692d4e9a4c2.zip |
SpiceAgent: Implement `FileTransferStatus` messages
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Services/SpiceAgent/Message.cpp | 26 | ||||
-rw-r--r-- | Userland/Services/SpiceAgent/Message.h | 82 | ||||
-rw-r--r-- | Userland/Services/SpiceAgent/SpiceAgent.cpp | 7 |
3 files changed, 115 insertions, 0 deletions
diff --git a/Userland/Services/SpiceAgent/Message.cpp b/Userland/Services/SpiceAgent/Message.cpp index c6e58027a1..6bbb430e6e 100644 --- a/Userland/Services/SpiceAgent/Message.cpp +++ b/Userland/Services/SpiceAgent/Message.cpp @@ -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(); +} + } diff --git a/Userland/Services/SpiceAgent/Message.h b/Userland/Services/SpiceAgent/Message.h index 01da14b7e7..3875b89195 100644 --- a/Userland/Services/SpiceAgent/Message.h +++ b/Userland/Services/SpiceAgent/Message.h @@ -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); + } +}; } diff --git a/Userland/Services/SpiceAgent/SpiceAgent.cpp b/Userland/Services/SpiceAgent/SpiceAgent.cpp index 788ce57a02..075f4b6c53 100644 --- a/Userland/Services/SpiceAgent/SpiceAgent.cpp +++ b/Userland/Services/SpiceAgent/SpiceAgent.cpp @@ -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())); |