• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 use crate::usb::xhci::scatter_gather_buffer::Error as BufferError;
6 use crate::usb::xhci::xhci_transfer::Error as XhciTransferError;
7 use crate::utils::Error as UtilsError;
8 use msg_socket::MsgError;
9 use std::fmt::{self, Display};
10 use usb_util::error::Error as UsbUtilError;
11 
12 #[derive(Debug)]
13 pub enum Error {
14     AddToEventLoop(UtilsError),
15     StartAsyncJobQueue(UtilsError),
16     QueueAsyncJob(UtilsError),
17     CreateLibUsbContext(UsbUtilError),
18     GetActiveConfig(UsbUtilError),
19     SetActiveConfig(UsbUtilError),
20     SetInterfaceAltSetting(UsbUtilError),
21     ClearHalt(UsbUtilError),
22     GetEndpointType,
23     CreateControlSock(std::io::Error),
24     SetupControlSock(std::io::Error),
25     ReadControlSock(MsgError),
26     WriteControlSock(MsgError),
27     GetXhciTransferType(XhciTransferError),
28     TransferComplete(XhciTransferError),
29     ReadBuffer(BufferError),
30     WriteBuffer(BufferError),
31     BufferLen(BufferError),
32     /// Cannot get interface descriptor for (interface, altsetting).
33     GetInterfaceDescriptor((i32, u16)),
34     GetEndpointDescriptor(u8),
35     BadXhciTransferState,
36     BadBackendProviderState,
37 }
38 
39 impl Display for Error {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result40     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
41         use self::Error::*;
42 
43         match self {
44             AddToEventLoop(e) => write!(f, "failed to add to event loop: {}", e),
45             StartAsyncJobQueue(e) => write!(f, "failed to start async job queue: {}", e),
46             QueueAsyncJob(e) => write!(f, "failed to queue async job: {}", e),
47             CreateLibUsbContext(e) => write!(f, "failed to create libusb context: {:?}", e),
48             GetActiveConfig(e) => write!(f, "failed to get active config: {:?}", e),
49             SetActiveConfig(e) => write!(f, "failed to set active config: {:?}", e),
50             SetInterfaceAltSetting(e) => write!(f, "failed to set interface alt setting: {:?}", e),
51             ClearHalt(e) => write!(f, "failed to clear halt: {:?}", e),
52             GetEndpointType => write!(f, "failed to get endpoint type"),
53             CreateControlSock(e) => write!(f, "failed to create contro sock: {}", e),
54             SetupControlSock(e) => write!(f, "failed to setup control sock: {}", e),
55             ReadControlSock(e) => write!(f, "failed to read control sock: {}", e),
56             WriteControlSock(e) => write!(f, "failed to write control sock: {}", e),
57             GetXhciTransferType(e) => write!(f, "failed to get xhci transfer type: {}", e),
58             TransferComplete(e) => write!(f, "xhci transfer completed: {}", e),
59             ReadBuffer(e) => write!(f, "failed to read buffer: {}", e),
60             WriteBuffer(e) => write!(f, "failed to write buffer: {}", e),
61             BufferLen(e) => write!(f, "failed to get buffer length: {}", e),
62             GetInterfaceDescriptor((i, alt_setting)) => write!(
63                 f,
64                 "failed to get interface descriptor for interface {}, alt setting {}",
65                 i, alt_setting
66             ),
67             GetEndpointDescriptor(ep_idx) => {
68                 write!(f, "failed to get endpoint descriptor for ep: {}", ep_idx)
69             }
70             BadXhciTransferState => write!(f, "xhci transfer is in a bad state"),
71             BadBackendProviderState => write!(f, "backend provider is in a bad state"),
72         }
73     }
74 }
75 
76 pub type Result<T> = std::result::Result<T, Error>;
77