1use std::future::Future;
10
11pub use tdisp::TdispGuestOperationError;
14pub use tdisp::devicereport::TdiReportStruct;
15pub use tdisp::serialize_proto::deserialize_command;
16pub use tdisp::serialize_proto::deserialize_response;
17pub use tdisp::serialize_proto::serialize_command;
18pub use tdisp::serialize_proto::serialize_response;
19pub use tdisp_proto::GuestToHostCommand;
20pub use tdisp_proto::GuestToHostCommandExt;
21pub use tdisp_proto::GuestToHostResponse;
22pub use tdisp_proto::GuestToHostResponseExt;
23pub use tdisp_proto::TdispCommandRequestGetDeviceInterfaceInfo;
24pub use tdisp_proto::TdispCommandResponseBind;
25pub use tdisp_proto::TdispCommandResponseGetDeviceInterfaceInfo;
26pub use tdisp_proto::TdispCommandResponseGetTdiReport;
27pub use tdisp_proto::TdispCommandResponseStartTdi;
28pub use tdisp_proto::TdispCommandResponseUnbind;
29pub use tdisp_proto::TdispDeviceInterfaceInfo;
30pub use tdisp_proto::TdispGuestOperationErrorCode;
31pub use tdisp_proto::TdispGuestProtocolType;
32pub use tdisp_proto::TdispGuestUnbindReason;
33pub use tdisp_proto::TdispReportType;
34
35use tdisp_proto::TdispCommandRequestBind;
36use tdisp_proto::TdispCommandRequestGetTdiReport;
37use tdisp_proto::TdispCommandRequestStartTdi;
38use tdisp_proto::TdispCommandRequestUnbind;
39use tdisp_proto::guest_to_host_command::Command;
40
41pub trait TdispVirtualDeviceInterface: Send + Sync {
46 fn send_tdisp_command(
48 &self,
49 payload: GuestToHostCommand,
50 ) -> impl Future<Output = Result<GuestToHostResponse, anyhow::Error>> + Send;
51
52 fn tdisp_get_device_interface_info(
54 &self,
55 ) -> impl Future<Output = anyhow::Result<TdispDeviceInterfaceInfo>> + Send;
56
57 fn tdisp_bind_interface(&self) -> impl Future<Output = anyhow::Result<()>> + Send;
63
64 fn tdisp_start_device(&self) -> impl Future<Output = anyhow::Result<()>> + Send;
67
68 fn tdisp_get_device_report(
70 &self,
71 report_type: &TdispReportType,
72 ) -> impl Future<Output = anyhow::Result<Vec<u8>>> + Send;
73
74 fn tdisp_get_tdi_report(&self) -> impl Future<Output = anyhow::Result<TdiReportStruct>> + Send;
76
77 fn tdisp_get_tdi_device_id(&self) -> impl Future<Output = anyhow::Result<u64>> + Send;
79
80 fn tdisp_unbind(
82 &self,
83 reason: TdispGuestUnbindReason,
84 ) -> impl Future<Output = anyhow::Result<()>> + Send;
85}
86
87pub fn new_get_device_interface_info_command(
89 device_id: u64,
90 guest_protocol_type: TdispGuestProtocolType,
91) -> GuestToHostCommand {
92 GuestToHostCommand {
93 device_id,
94 command: Some(Command::GetDeviceInterfaceInfo(
95 TdispCommandRequestGetDeviceInterfaceInfo {
96 guest_protocol_type: guest_protocol_type as i32,
97 },
98 )),
99 }
100}
101
102pub fn new_bind_command(device_id: u64) -> GuestToHostCommand {
104 GuestToHostCommand {
105 device_id,
106 command: Some(Command::Bind(TdispCommandRequestBind {})),
107 }
108}
109
110pub fn new_start_tdi_command(device_id: u64) -> GuestToHostCommand {
112 GuestToHostCommand {
113 device_id,
114 command: Some(Command::StartTdi(TdispCommandRequestStartTdi {})),
115 }
116}
117
118pub fn new_get_tdi_report_command(
120 device_id: u64,
121 report_type: TdispReportType,
122) -> GuestToHostCommand {
123 GuestToHostCommand {
124 device_id,
125 command: Some(Command::GetTdiReport(TdispCommandRequestGetTdiReport {
126 report_type: report_type as i32,
127 })),
128 }
129}
130
131pub fn new_unbind_command(device_id: u64, reason: TdispGuestUnbindReason) -> GuestToHostCommand {
133 GuestToHostCommand {
134 device_id,
135 command: Some(Command::Unbind(TdispCommandRequestUnbind {
136 unbind_reason: reason as i32,
137 })),
138 }
139}