virtio: video: use thiserror in the command module

This reduces the code a little bit.

BUG=b:161774071
TEST=arc.VideoDecodeAccel.h264_vm passes on hatch
TEST=arc.VideoEncodeAccel.h264_360p_i420_vm passes on hatch

Change-Id: I547d0d26a1a69bc50af4df9b6bb2b4016ff760c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2983089
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: David Staessens <dstaessens@chromium.org>
This commit is contained in:
Alexandre Courbot 2021-06-23 10:52:29 +09:00 committed by Commit Bot
parent 1e3022c922
commit 520ec1bb2f

View file

@ -5,8 +5,8 @@
//! Data structures for commands of virtio video devices.
use std::convert::{TryFrom, TryInto};
use std::fmt;
use std::io;
use thiserror::Error as ThisError;
use base::error;
use data_model::Le32;
@ -19,38 +19,22 @@ use crate::virtio::video::protocol::*;
use crate::virtio::Reader;
/// An error indicating a failure while reading a request from the guest.
#[derive(Debug)]
#[derive(Debug, ThisError)]
pub enum ReadCmdError {
/// Failure while reading an object.
IoError(io::Error),
/// Invalid arguement is passed,
/// Failed to read an object.
#[error("failed to read object: {0}")]
IoError(#[from] io::Error),
/// Invalid argument is passed.
#[error("invalid argument passed to command")]
InvalidArgument,
/// The type of the command was invalid.
#[error("invalid command type: {0}")]
InvalidCmdType(u32),
/// The type of the requested control was unsupported.
#[error("unsupported control type: {0}")]
UnsupportedCtrlType(u32),
}
impl fmt::Display for ReadCmdError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::ReadCmdError::*;
match self {
IoError(e) => write!(f, "failed to read an object: {}", e),
InvalidArgument => write!(f, "invalid arguement is passed in command"),
InvalidCmdType(t) => write!(f, "invalid command type: {}", t),
UnsupportedCtrlType(t) => write!(f, "unsupported control type: {}", t),
}
}
}
impl std::error::Error for ReadCmdError {}
impl From<io::Error> for ReadCmdError {
fn from(e: io::Error) -> ReadCmdError {
ReadCmdError::IoError(e)
}
}
#[derive(PartialEq, Eq, PartialOrd, Ord, N, Clone, Copy, Debug)]
#[repr(u32)]
pub enum QueueType {