OSDN Git Service

rusty-gd: convert hci facade to rust_grpcio build targets
authorZach Johnson <zachoverflow@google.com>
Mon, 9 Nov 2020 00:54:29 +0000 (16:54 -0800)
committerZach Johnson <zachoverflow@google.com>
Mon, 9 Nov 2020 00:56:24 +0000 (16:56 -0800)
also, cleans up some of the temp hacks

Bug: 171749953
Tag: #gd-refactor
Test: gd/cert/run --rhost
Change-Id: I014fe130d2536759a635bf5993d75638dfb9d54a

gd/Android.bp
gd/rust/hci/Android.bp
gd/rust/hci/src/facade.rs
gd/rust/hci/src/facade/facade_grpc.rs [deleted file]

index d976608..a561d1e 100644 (file)
@@ -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,
 }
index 802949e..61c121f 100644 (file)
@@ -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",
index 3fe06e4..f1c65bb 100644 (file)
@@ -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<Empty>,
     ) {
-        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<Empty>,
     ) {
-        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<Empty>,
     ) {
-        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 (file)
index dc42fab..0000000
+++ /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<super::facade::CommandMsg, super::empty::Empty> = ::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<super::facade::CommandMsg, super::empty::Empty> = ::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<super::facade::EventCodeMsg, super::empty::Empty> = ::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<super::facade::LeSubeventCodeMsg, super::empty::Empty> = ::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<super::facade::AclMsg, super::empty::Empty> = ::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<super::empty::Empty, super::facade::EventMsg> = ::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<super::empty::Empty, super::facade::LeSubeventMsg> = ::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<super::empty::Empty, super::facade::AclMsg> = ::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<super::empty::Empty> {
-        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<super::empty::Empty> {
-        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<super::empty::Empty>> {
-        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<super::empty::Empty>> {
-        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<super::empty::Empty> {
-        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<super::empty::Empty> {
-        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<super::empty::Empty>> {
-        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<super::empty::Empty>> {
-        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<super::empty::Empty> {
-        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<super::empty::Empty> {
-        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<super::empty::Empty>> {
-        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<super::empty::Empty>> {
-        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<super::empty::Empty> {
-        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<super::empty::Empty> {
-        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<super::empty::Empty>> {
-        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<super::empty::Empty>> {
-        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<super::empty::Empty> {
-        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<super::empty::Empty> {
-        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<super::empty::Empty>> {
-        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<super::empty::Empty>> {
-        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<super::facade::EventMsg>> {
-        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<super::facade::EventMsg>> {
-        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<super::facade::LeSubeventMsg>> {
-        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<super::facade::LeSubeventMsg>> {
-        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<super::facade::AclMsg>> {
-        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<super::facade::AclMsg>> {
-        self.fetch_acl_packets_opt(req, ::grpcio::CallOption::default())
-    }
-    pub fn spawn<F>(&self, f: F) where F: ::futures::Future<Output = ()> + 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<super::empty::Empty>);
-    fn enqueue_command_with_status(&mut self, ctx: ::grpcio::RpcContext, req: super::facade::CommandMsg, sink: ::grpcio::UnarySink<super::empty::Empty>);
-    fn register_event_handler(&mut self, ctx: ::grpcio::RpcContext, req: super::facade::EventCodeMsg, sink: ::grpcio::UnarySink<super::empty::Empty>);
-    fn register_le_event_handler(&mut self, ctx: ::grpcio::RpcContext, req: super::facade::LeSubeventCodeMsg, sink: ::grpcio::UnarySink<super::empty::Empty>);
-    fn send_acl_data(&mut self, ctx: ::grpcio::RpcContext, req: super::facade::AclMsg, sink: ::grpcio::UnarySink<super::empty::Empty>);
-    fn fetch_events(&mut self, ctx: ::grpcio::RpcContext, req: super::empty::Empty, sink: ::grpcio::ServerStreamingSink<super::facade::EventMsg>);
-    fn fetch_le_subevents(&mut self, ctx: ::grpcio::RpcContext, req: super::empty::Empty, sink: ::grpcio::ServerStreamingSink<super::facade::LeSubeventMsg>);
-    fn fetch_acl_packets(&mut self, ctx: ::grpcio::RpcContext, req: super::empty::Empty, sink: ::grpcio::ServerStreamingSink<super::facade::AclMsg>);
-}
-
-pub fn create_hci_layer_facade<S: HciLayerFacade + Send + Clone + 'static>(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()
-}