devices/serial/sys/
linux.rs

1// Copyright 2022 The ChromiumOS Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use std::io;
6
7use base::Event;
8use base::FileSync;
9use base::RawDescriptor;
10use hypervisor::ProtectionType;
11
12use crate::serial_device::SerialInput;
13use crate::serial_device::SerialOptions;
14use crate::sys::serial_device::SerialDevice;
15use crate::Serial;
16
17// TODO(b/234469655): Remove type alias once ReadNotifier is implemented for
18// PipeConnection.
19pub(crate) type InStreamType = Box<dyn SerialInput>;
20
21impl SerialDevice for Serial {
22    /// Constructs a Serial device ready for input and output.
23    ///
24    /// The stream `input` should not block, instead returning 0 bytes if are no bytes available.
25    fn new(
26        _protection_type: ProtectionType,
27        interrupt_evt: Event,
28        input: Option<Box<dyn SerialInput>>,
29        out: Option<Box<dyn io::Write + Send>>,
30        _sync: Option<Box<dyn FileSync + Send>>,
31        options: SerialOptions,
32        _keep_rds: Vec<RawDescriptor>,
33    ) -> Serial {
34        Serial::new_common(interrupt_evt, input, out, options.out_timestamp)
35    }
36}