<commit_before>// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

//! Data structures for commands of virtio video devices.

use std::io;

use data_model::{Le32, Le64};

use crate::virtio::video::command::QueueType;
use crate::virtio::video::control::*;
use crate::virtio::video::error::VideoError;
use crate::virtio::video::format::*;
use crate::virtio::video::params::Params;
use crate::virtio::video::protocol::*;
use crate::virtio::Writer;

pub trait Response {
    /// Writes an object to virtqueue.
    fn write(&self, w: &mut Writer) -> Result<(), io::Error>;
}

#[derive(Debug)]
pub enum CmdError {
    InvalidResourceId,
    InvalidStreamId,
    InvalidParameter,
    InvalidOperation,
}

/// A response to a `VideoCmd`. These correspond to `VIRTIO_VIDEO_RESP_*`.
#[derive(Debug)]
pub enum CmdResponse {
    NoData,
    QueryCapability(Vec<FormatDesc>),
    ResourceQueue {
        timestamp: u64,
        flags: u32,
        size: u32,
    },
    GetParams {
        queue_type: QueueType,
        params: Params,
    },
    QueryControl(QueryCtrlResponse),
    GetControl(CtrlVal),
    SetControl,
    Error(CmdError),
}

impl From<VideoError> for CmdResponse {
    fn from(error: VideoError) -> Self {
        let cmd_error = match error {
            VideoError::InvalidResourceId { .. } => CmdError::InvalidResourceId,
            VideoError::InvalidStreamId(_) => CmdError::InvalidStreamId,
            VideoError::InvalidParameter => CmdError::InvalidParameter,
            _ => CmdError::InvalidOperation,
        };
        CmdResponse::Error(cmd_error)
    }
}

impl Response for CmdResponse {
    /// Writes a response to virtqueue.
    fn write(&self, w: &mut Writer) -> Result<(), io::Error> {
        use CmdResponse::*;<commit_msg>device: virtio: video: Add dead_code attribute to SetControl<commit_after>// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

//! Data structures for commands of virtio video devices.

use std::io;

use data_model::{Le32, Le64};

use crate::virtio::video::command::QueueType;
use crate::virtio::video::control::*;
use crate::virtio::video::error::VideoError;
use crate::virtio::video::format::*;
use crate::virtio::video::params::Params;
use crate::virtio::video::protocol::*;
use crate::virtio::Writer;

pub trait Response {
    /// Writes an object to virtqueue.
    fn write(&self, w: &mut Writer) -> Result<(), io::Error>;
}

#[derive(Debug)]
pub enum CmdError {
    InvalidResourceId,
    InvalidStreamId,
    InvalidParameter,
    InvalidOperation,
}

/// A response to a `VideoCmd`. These correspond to `VIRTIO_VIDEO_RESP_*`.
#[derive(Debug)]
pub enum CmdResponse {
    NoData,
    QueryCapability(Vec<FormatDesc>),
    ResourceQueue {
        timestamp: u64,
        flags: u32,
        size: u32,
    },
    GetParams {
        queue_type: QueueType,
        params: Params,
    },
    QueryControl(QueryCtrlResponse),
    GetControl(CtrlVal),
    // TODO(alexlau): SetControl is unused, remove this after encoder CL lands.
    #[allow(dead_code)]
    SetControl,
    Error(CmdError),
}

impl From<VideoError> for CmdResponse {
    fn from(error: VideoError) -> Self {
        let cmd_error = match error {
            VideoError::InvalidResourceId { .. } => CmdError::InvalidResourceId,
            VideoError::InvalidStreamId(_) => CmdError::InvalidStreamId,
            VideoError::InvalidParameter => CmdError::InvalidParameter,
            _ => CmdError::InvalidOperation,
        };
        CmdResponse::Error(cmd_error)
    }
}

impl Response for CmdResponse {
    /// Writes a response to virtqueue.
    fn write(&self, w: &mut Writer) -> Result<(), io::Error> {
        use CmdResponse::*;
{'fraction_non_alphanumeric': 0.13010007698229406, 'fraction_numerical': 0.00718501411342058, 'mean_word_length': 3.4446978335233753, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5611786', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1167, 'n_words': 313}