From: Zach Johnson Date: Mon, 9 Nov 2020 00:54:29 +0000 (-0800) Subject: rusty-gd: convert hci facade to rust_grpcio build targets X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=a8f37c35928504c4bbb099c8b8071500a5232424;p=android-x86%2Fsystem-bt.git rusty-gd: convert hci facade to rust_grpcio build targets also, cleans up some of the temp hacks Bug: 171749953 Tag: #gd-refactor Test: gd/cert/run --rhost Change-Id: I014fe130d2536759a635bf5993d75638dfb9d54a --- diff --git a/gd/Android.bp b/gd/Android.bp index d9766085f..a561d1e77 100644 --- a/gd/Android.bp +++ b/gd/Android.bp @@ -763,11 +763,10 @@ cc_library_host_shared { rtti: true, } -rust_protobuf { - name: "libhci_layer_facade_proto", - crate_name: "hci_layer_facade_proto", +rust_grpcio { + name: "libbt_hci_proto", + crate_name: "bt_hci_proto", proto: "hci/facade/facade.proto", - proto_flags: ["-Iexternal/protobuf/src/"], source_stem: "facade", host_supported: true, } @@ -793,7 +792,6 @@ rust_protobuf { name: "libbt_facade_common_proto", crate_name: "bt_facade_common_proto", proto: "facade/common.proto", - proto_flags: ["-Iexternal/protobuf/src/"], source_stem: "common", host_supported: true, } diff --git a/gd/rust/hci/Android.bp b/gd/rust/hci/Android.bp index 802949ee2..61c121fc9 100644 --- a/gd/rust/hci/Android.bp +++ b/gd/rust/hci/Android.bp @@ -5,11 +5,11 @@ rust_library { edition: "2018", rustlibs: [ "libbt_hal", + "libbt_hci_proto", "libbt_packet", "libbytes", "libfutures", "libgrpcio", - "libhci_layer_facade_proto", "libnum_traits", "libthiserror", "libtokio", diff --git a/gd/rust/hci/src/facade.rs b/gd/rust/hci/src/facade.rs index 3fe06e447..f1c65bb38 100644 --- a/gd/rust/hci/src/facade.rs +++ b/gd/rust/hci/src/facade.rs @@ -1,17 +1,8 @@ //! HCI layer facade -mod facade_grpc; - -/// Refer to the following on why we are doing this and for possible solutions: -/// https://github.com/tikv/grpc-rs/issues/276 -pub mod empty { - pub use protobuf::well_known_types::Empty; -} -use empty::Empty; - -use hci_layer_facade_proto::facade; -use facade_grpc::{HciLayerFacade, create_hci_layer_facade}; -use facade::*; +use bt_hci_proto::empty::Empty; +use bt_hci_proto::facade::*; +use bt_hci_proto::facade_grpc::{create_hci_layer_facade, HciLayerFacade}; use futures::sink::SinkExt; use tokio::runtime::Runtime; @@ -44,12 +35,18 @@ impl HciLayerFacade for HciLayerFacadeService { mut cmd: CommandMsg, sink: UnarySink, ) { - self.rt.block_on(self.hci_exports.enqueue_command_with_complete(cmd.take_command().into())); + self.rt.block_on( + self.hci_exports + .enqueue_command_with_complete(cmd.take_command().into()), + ); let f = sink .success(Empty::default()) .map_err(|e: grpcio::Error| { - println!("failed to handle enqueue_command_with_complete request: {:?}", e) + println!( + "failed to handle enqueue_command_with_complete request: {:?}", + e + ) }) .map(|_| ()); @@ -62,12 +59,18 @@ impl HciLayerFacade for HciLayerFacadeService { mut cmd: CommandMsg, sink: UnarySink, ) { - self.rt.block_on(self.hci_exports.enqueue_command_with_complete(cmd.take_command().into())); + self.rt.block_on( + self.hci_exports + .enqueue_command_with_complete(cmd.take_command().into()), + ); let f = sink .success(Empty::default()) .map_err(|e: grpcio::Error| { - println!("failed to handle enqueue_command_with_status request: {:?}", e) + println!( + "failed to handle enqueue_command_with_status request: {:?}", + e + ) }) .map(|_| ()); @@ -80,12 +83,18 @@ impl HciLayerFacade for HciLayerFacadeService { code: EventCodeMsg, sink: UnarySink, ) { - self.rt.block_on(self.hci_exports.register_event_handler(code.get_code() as u8)); + self.rt.block_on( + self.hci_exports + .register_event_handler(code.get_code() as u8), + ); let f = sink .success(Empty::default()) .map_err(|e: grpcio::Error| { - println!("failed to handle enqueue_command_with_status request: {:?}", e) + println!( + "failed to handle enqueue_command_with_status request: {:?}", + e + ) }) .map(|_| ()); diff --git a/gd/rust/hci/src/facade/facade_grpc.rs b/gd/rust/hci/src/facade/facade_grpc.rs deleted file mode 100644 index dc42fab7e..000000000 --- a/gd/rust/hci/src/facade/facade_grpc.rs +++ /dev/null @@ -1,243 +0,0 @@ -// This file is generated. Do not edit -// @generated - -// https://github.com/Manishearth/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] - -const METHOD_HCI_LAYER_FACADE_ENQUEUE_COMMAND_WITH_COMPLETE: ::grpcio::Method = ::grpcio::Method { - ty: ::grpcio::MethodType::Unary, - name: "/bluetooth.hci.HciLayerFacade/EnqueueCommandWithComplete", - req_mar: ::grpcio::Marshaller { ser: ::grpcio::pb_ser, de: ::grpcio::pb_de }, - resp_mar: ::grpcio::Marshaller { ser: ::grpcio::pb_ser, de: ::grpcio::pb_de }, -}; - -const METHOD_HCI_LAYER_FACADE_ENQUEUE_COMMAND_WITH_STATUS: ::grpcio::Method = ::grpcio::Method { - ty: ::grpcio::MethodType::Unary, - name: "/bluetooth.hci.HciLayerFacade/EnqueueCommandWithStatus", - req_mar: ::grpcio::Marshaller { ser: ::grpcio::pb_ser, de: ::grpcio::pb_de }, - resp_mar: ::grpcio::Marshaller { ser: ::grpcio::pb_ser, de: ::grpcio::pb_de }, -}; - -const METHOD_HCI_LAYER_FACADE_REGISTER_EVENT_HANDLER: ::grpcio::Method = ::grpcio::Method { - ty: ::grpcio::MethodType::Unary, - name: "/bluetooth.hci.HciLayerFacade/RegisterEventHandler", - req_mar: ::grpcio::Marshaller { ser: ::grpcio::pb_ser, de: ::grpcio::pb_de }, - resp_mar: ::grpcio::Marshaller { ser: ::grpcio::pb_ser, de: ::grpcio::pb_de }, -}; - -const METHOD_HCI_LAYER_FACADE_REGISTER_LE_EVENT_HANDLER: ::grpcio::Method = ::grpcio::Method { - ty: ::grpcio::MethodType::Unary, - name: "/bluetooth.hci.HciLayerFacade/RegisterLeEventHandler", - req_mar: ::grpcio::Marshaller { ser: ::grpcio::pb_ser, de: ::grpcio::pb_de }, - resp_mar: ::grpcio::Marshaller { ser: ::grpcio::pb_ser, de: ::grpcio::pb_de }, -}; - -const METHOD_HCI_LAYER_FACADE_SEND_ACL_DATA: ::grpcio::Method = ::grpcio::Method { - ty: ::grpcio::MethodType::Unary, - name: "/bluetooth.hci.HciLayerFacade/SendAclData", - req_mar: ::grpcio::Marshaller { ser: ::grpcio::pb_ser, de: ::grpcio::pb_de }, - resp_mar: ::grpcio::Marshaller { ser: ::grpcio::pb_ser, de: ::grpcio::pb_de }, -}; - -const METHOD_HCI_LAYER_FACADE_FETCH_EVENTS: ::grpcio::Method = ::grpcio::Method { - ty: ::grpcio::MethodType::ServerStreaming, - name: "/bluetooth.hci.HciLayerFacade/FetchEvents", - req_mar: ::grpcio::Marshaller { ser: ::grpcio::pb_ser, de: ::grpcio::pb_de }, - resp_mar: ::grpcio::Marshaller { ser: ::grpcio::pb_ser, de: ::grpcio::pb_de }, -}; - -const METHOD_HCI_LAYER_FACADE_FETCH_LE_SUBEVENTS: ::grpcio::Method = ::grpcio::Method { - ty: ::grpcio::MethodType::ServerStreaming, - name: "/bluetooth.hci.HciLayerFacade/FetchLeSubevents", - req_mar: ::grpcio::Marshaller { ser: ::grpcio::pb_ser, de: ::grpcio::pb_de }, - resp_mar: ::grpcio::Marshaller { ser: ::grpcio::pb_ser, de: ::grpcio::pb_de }, -}; - -const METHOD_HCI_LAYER_FACADE_FETCH_ACL_PACKETS: ::grpcio::Method = ::grpcio::Method { - ty: ::grpcio::MethodType::ServerStreaming, - name: "/bluetooth.hci.HciLayerFacade/FetchAclPackets", - req_mar: ::grpcio::Marshaller { ser: ::grpcio::pb_ser, de: ::grpcio::pb_de }, - resp_mar: ::grpcio::Marshaller { ser: ::grpcio::pb_ser, de: ::grpcio::pb_de }, -}; - -#[derive(Clone)] -pub struct HciLayerFacadeClient { - client: ::grpcio::Client, -} - -impl HciLayerFacadeClient { - pub fn new(channel: ::grpcio::Channel) -> Self { - HciLayerFacadeClient { - client: ::grpcio::Client::new(channel), - } - } - - pub fn enqueue_command_with_complete_opt(&self, req: &super::facade::CommandMsg, opt: ::grpcio::CallOption) -> ::grpcio::Result { - self.client.unary_call(&METHOD_HCI_LAYER_FACADE_ENQUEUE_COMMAND_WITH_COMPLETE, req, opt) - } - - pub fn enqueue_command_with_complete(&self, req: &super::facade::CommandMsg) -> ::grpcio::Result { - self.enqueue_command_with_complete_opt(req, ::grpcio::CallOption::default()) - } - - pub fn enqueue_command_with_complete_async_opt(&self, req: &super::facade::CommandMsg, opt: ::grpcio::CallOption) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver> { - self.client.unary_call_async(&METHOD_HCI_LAYER_FACADE_ENQUEUE_COMMAND_WITH_COMPLETE, req, opt) - } - - pub fn enqueue_command_with_complete_async(&self, req: &super::facade::CommandMsg) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver> { - self.enqueue_command_with_complete_async_opt(req, ::grpcio::CallOption::default()) - } - - pub fn enqueue_command_with_status_opt(&self, req: &super::facade::CommandMsg, opt: ::grpcio::CallOption) -> ::grpcio::Result { - self.client.unary_call(&METHOD_HCI_LAYER_FACADE_ENQUEUE_COMMAND_WITH_STATUS, req, opt) - } - - pub fn enqueue_command_with_status(&self, req: &super::facade::CommandMsg) -> ::grpcio::Result { - self.enqueue_command_with_status_opt(req, ::grpcio::CallOption::default()) - } - - pub fn enqueue_command_with_status_async_opt(&self, req: &super::facade::CommandMsg, opt: ::grpcio::CallOption) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver> { - self.client.unary_call_async(&METHOD_HCI_LAYER_FACADE_ENQUEUE_COMMAND_WITH_STATUS, req, opt) - } - - pub fn enqueue_command_with_status_async(&self, req: &super::facade::CommandMsg) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver> { - self.enqueue_command_with_status_async_opt(req, ::grpcio::CallOption::default()) - } - - pub fn register_event_handler_opt(&self, req: &super::facade::EventCodeMsg, opt: ::grpcio::CallOption) -> ::grpcio::Result { - self.client.unary_call(&METHOD_HCI_LAYER_FACADE_REGISTER_EVENT_HANDLER, req, opt) - } - - pub fn register_event_handler(&self, req: &super::facade::EventCodeMsg) -> ::grpcio::Result { - self.register_event_handler_opt(req, ::grpcio::CallOption::default()) - } - - pub fn register_event_handler_async_opt(&self, req: &super::facade::EventCodeMsg, opt: ::grpcio::CallOption) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver> { - self.client.unary_call_async(&METHOD_HCI_LAYER_FACADE_REGISTER_EVENT_HANDLER, req, opt) - } - - pub fn register_event_handler_async(&self, req: &super::facade::EventCodeMsg) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver> { - self.register_event_handler_async_opt(req, ::grpcio::CallOption::default()) - } - - pub fn register_le_event_handler_opt(&self, req: &super::facade::LeSubeventCodeMsg, opt: ::grpcio::CallOption) -> ::grpcio::Result { - self.client.unary_call(&METHOD_HCI_LAYER_FACADE_REGISTER_LE_EVENT_HANDLER, req, opt) - } - - pub fn register_le_event_handler(&self, req: &super::facade::LeSubeventCodeMsg) -> ::grpcio::Result { - self.register_le_event_handler_opt(req, ::grpcio::CallOption::default()) - } - - pub fn register_le_event_handler_async_opt(&self, req: &super::facade::LeSubeventCodeMsg, opt: ::grpcio::CallOption) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver> { - self.client.unary_call_async(&METHOD_HCI_LAYER_FACADE_REGISTER_LE_EVENT_HANDLER, req, opt) - } - - pub fn register_le_event_handler_async(&self, req: &super::facade::LeSubeventCodeMsg) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver> { - self.register_le_event_handler_async_opt(req, ::grpcio::CallOption::default()) - } - - pub fn send_acl_data_opt(&self, req: &super::facade::AclMsg, opt: ::grpcio::CallOption) -> ::grpcio::Result { - self.client.unary_call(&METHOD_HCI_LAYER_FACADE_SEND_ACL_DATA, req, opt) - } - - pub fn send_acl_data(&self, req: &super::facade::AclMsg) -> ::grpcio::Result { - self.send_acl_data_opt(req, ::grpcio::CallOption::default()) - } - - pub fn send_acl_data_async_opt(&self, req: &super::facade::AclMsg, opt: ::grpcio::CallOption) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver> { - self.client.unary_call_async(&METHOD_HCI_LAYER_FACADE_SEND_ACL_DATA, req, opt) - } - - pub fn send_acl_data_async(&self, req: &super::facade::AclMsg) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver> { - self.send_acl_data_async_opt(req, ::grpcio::CallOption::default()) - } - - pub fn fetch_events_opt(&self, req: &super::empty::Empty, opt: ::grpcio::CallOption) -> ::grpcio::Result<::grpcio::ClientSStreamReceiver> { - self.client.server_streaming(&METHOD_HCI_LAYER_FACADE_FETCH_EVENTS, req, opt) - } - - pub fn fetch_events(&self, req: &super::empty::Empty) -> ::grpcio::Result<::grpcio::ClientSStreamReceiver> { - self.fetch_events_opt(req, ::grpcio::CallOption::default()) - } - - pub fn fetch_le_subevents_opt(&self, req: &super::empty::Empty, opt: ::grpcio::CallOption) -> ::grpcio::Result<::grpcio::ClientSStreamReceiver> { - self.client.server_streaming(&METHOD_HCI_LAYER_FACADE_FETCH_LE_SUBEVENTS, req, opt) - } - - pub fn fetch_le_subevents(&self, req: &super::empty::Empty) -> ::grpcio::Result<::grpcio::ClientSStreamReceiver> { - self.fetch_le_subevents_opt(req, ::grpcio::CallOption::default()) - } - - pub fn fetch_acl_packets_opt(&self, req: &super::empty::Empty, opt: ::grpcio::CallOption) -> ::grpcio::Result<::grpcio::ClientSStreamReceiver> { - self.client.server_streaming(&METHOD_HCI_LAYER_FACADE_FETCH_ACL_PACKETS, req, opt) - } - - pub fn fetch_acl_packets(&self, req: &super::empty::Empty) -> ::grpcio::Result<::grpcio::ClientSStreamReceiver> { - self.fetch_acl_packets_opt(req, ::grpcio::CallOption::default()) - } - pub fn spawn(&self, f: F) where F: ::futures::Future + Send + 'static { - self.client.spawn(f) - } -} - -pub trait HciLayerFacade { - fn enqueue_command_with_complete(&mut self, ctx: ::grpcio::RpcContext, req: super::facade::CommandMsg, sink: ::grpcio::UnarySink); - fn enqueue_command_with_status(&mut self, ctx: ::grpcio::RpcContext, req: super::facade::CommandMsg, sink: ::grpcio::UnarySink); - fn register_event_handler(&mut self, ctx: ::grpcio::RpcContext, req: super::facade::EventCodeMsg, sink: ::grpcio::UnarySink); - fn register_le_event_handler(&mut self, ctx: ::grpcio::RpcContext, req: super::facade::LeSubeventCodeMsg, sink: ::grpcio::UnarySink); - fn send_acl_data(&mut self, ctx: ::grpcio::RpcContext, req: super::facade::AclMsg, sink: ::grpcio::UnarySink); - fn fetch_events(&mut self, ctx: ::grpcio::RpcContext, req: super::empty::Empty, sink: ::grpcio::ServerStreamingSink); - fn fetch_le_subevents(&mut self, ctx: ::grpcio::RpcContext, req: super::empty::Empty, sink: ::grpcio::ServerStreamingSink); - fn fetch_acl_packets(&mut self, ctx: ::grpcio::RpcContext, req: super::empty::Empty, sink: ::grpcio::ServerStreamingSink); -} - -pub fn create_hci_layer_facade(s: S) -> ::grpcio::Service { - let mut builder = ::grpcio::ServiceBuilder::new(); - let mut instance = s.clone(); - builder = builder.add_unary_handler(&METHOD_HCI_LAYER_FACADE_ENQUEUE_COMMAND_WITH_COMPLETE, move |ctx, req, resp| { - instance.enqueue_command_with_complete(ctx, req, resp) - }); - let mut instance = s.clone(); - builder = builder.add_unary_handler(&METHOD_HCI_LAYER_FACADE_ENQUEUE_COMMAND_WITH_STATUS, move |ctx, req, resp| { - instance.enqueue_command_with_status(ctx, req, resp) - }); - let mut instance = s.clone(); - builder = builder.add_unary_handler(&METHOD_HCI_LAYER_FACADE_REGISTER_EVENT_HANDLER, move |ctx, req, resp| { - instance.register_event_handler(ctx, req, resp) - }); - let mut instance = s.clone(); - builder = builder.add_unary_handler(&METHOD_HCI_LAYER_FACADE_REGISTER_LE_EVENT_HANDLER, move |ctx, req, resp| { - instance.register_le_event_handler(ctx, req, resp) - }); - let mut instance = s.clone(); - builder = builder.add_unary_handler(&METHOD_HCI_LAYER_FACADE_SEND_ACL_DATA, move |ctx, req, resp| { - instance.send_acl_data(ctx, req, resp) - }); - let mut instance = s.clone(); - builder = builder.add_server_streaming_handler(&METHOD_HCI_LAYER_FACADE_FETCH_EVENTS, move |ctx, req, resp| { - instance.fetch_events(ctx, req, resp) - }); - let mut instance = s.clone(); - builder = builder.add_server_streaming_handler(&METHOD_HCI_LAYER_FACADE_FETCH_LE_SUBEVENTS, move |ctx, req, resp| { - instance.fetch_le_subevents(ctx, req, resp) - }); - let mut instance = s; - builder = builder.add_server_streaming_handler(&METHOD_HCI_LAYER_FACADE_FETCH_ACL_PACKETS, move |ctx, req, resp| { - instance.fetch_acl_packets(ctx, req, resp) - }); - builder.build() -}