Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e7248ae9 authored by Zach Johnson's avatar Zach Johnson Committed by Gerrit Code Review
Browse files

Merge changes I112bb45c,I302e80fa

* changes:
  Start the BT testing root service
  Import rootservice facades, for BT testing
parents 257b9ba9 4ade5d72
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -771,3 +771,21 @@ rust_protobuf {
    source_stem: "facade",
    host_supported: true,
}

rust_protobuf {
    name: "libbt_facade_rootservice_proto",
    crate_name: "bt_facade_rootservice_proto",
    proto: "facade/rootservice.proto",
    proto_flags: ["-Iexternal/protobuf/src/"],
    source_stem: "rootservice",
    host_supported: true,
}

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,
}
+21 −2
Original line number Diff line number Diff line
rust_library {
    name: "libbluetooth_with_facades",
    crate_name: "bluetooth_with_facades",
    srcs: ["src/lib.rs"],
    edition: "2018",
    rustlibs: [
      "libbt_facade_rootservice_proto",
      "libbt_facade_common_proto",
      "libfutures",
      "libgrpcio",
      "libprotobuf",
      "libtokio",
    ],
    host_supported: true,
}

rust_binary {
    name: "rusty_bluetooth_stack_with_facade",
    crate_name: "rusty_bt_stack_with_facade",
    name: "bluetooth_with_facades",
    srcs: ["src/main.rs"],
    edition: "2018",
    rustlibs: [
      "libclap",
      "libbluetooth_with_facades",
      "libfutures",
      "libgrpcio",
      "libtokio",
    ],
    host_supported: true,
}
+56 −0
Original line number Diff line number Diff line
//! Bluetooth testing root facade service

mod rootservice_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;
}

pub use bt_facade_rootservice_proto::rootservice;
pub use bt_facade_common_proto::common;

use tokio::runtime::Runtime;

use grpcio::*;

use std::sync::Arc;

/// Bluetooth testing root facade service
#[derive(Clone)]
pub struct RootFacadeService {
    /// Tokio runtime
    pub rt: Arc<Runtime>,
}

use bt_facade_rootservice_proto::rootservice::*;
use rootservice_grpc::create_root_facade;
use rootservice_grpc::RootFacade;

impl RootFacadeService {
    /// Create a new instance of the root facade service
    pub fn create(rt: Arc<Runtime>) -> grpcio::Service {
        create_root_facade(Self { rt })
    }
}

impl RootFacade for RootFacadeService {
    fn start_stack(
        &mut self,
        _ctx: RpcContext<'_>,
        mut _cmd: StartStackRequest,
        _sink: UnarySink<StartStackResponse>,
    ) {
        unimplemented!()
    }

    fn stop_stack(
        &mut self,
        _ctx: RpcContext<'_>,
        mut _cmd: StopStackRequest,
        _sink: UnarySink<StopStackResponse>,
    ) {
        unimplemented!()
    }
}
+37 −1
Original line number Diff line number Diff line
@@ -4,8 +4,27 @@
extern crate clap;
use clap::{App, Arg};

use grpcio::*;

use futures::channel::oneshot;
use futures::executor::block_on;

use bluetooth_with_facades::RootFacadeService;

use std::io::{self, Read};
use std::sync::Arc;
use std::thread;

use tokio::runtime::Runtime;

fn main() {
    let matches = App::new("rusty_bluetooth_stack_with_facade")
    let rt = Arc::new(Runtime::new().unwrap());
    let runtime = Arc::clone(&rt);
    runtime.block_on(async_main(rt));
}

async fn async_main(rt: Arc<Runtime>) {
    let matches = App::new("bluetooth_with_facades")
        .about("The bluetooth stack, with testing facades enabled and exposed via gRPC.")
        .arg(
            Arg::with_name("root-server-port")
@@ -35,4 +54,21 @@ fn main() {
        "root server port: {}, grpc port: {}, signal port {}",
        root_server_port, grpc_port, signal_port
    );

    let env = Arc::new(Environment::new(2));
    let mut server = ServerBuilder::new(env)
        .register_service(RootFacadeService::create(rt))
        .bind("0.0.0.0", root_server_port)
        .build()
        .unwrap();

    let (tx, rx) = oneshot::channel();

    thread::spawn(move || {
        println!("Press ENTER to exit...");
        let _ = io::stdin().read(&mut [0]).unwrap();
        tx.send(())
    });
    block_on(rx).unwrap();
    block_on(server.shutdown()).unwrap();
}
+151 −0
Original line number Diff line number Diff line
// 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_ROOT_FACADE_START_STACK: ::grpcio::Method<super::rootservice::StartStackRequest, super::rootservice::StartStackResponse> = ::grpcio::Method {
    ty: ::grpcio::MethodType::Unary,
    name: "/bluetooth.facade.RootFacade/StartStack",
    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_ROOT_FACADE_STOP_STACK: ::grpcio::Method<super::rootservice::StopStackRequest, super::rootservice::StopStackResponse> = ::grpcio::Method {
    ty: ::grpcio::MethodType::Unary,
    name: "/bluetooth.facade.RootFacade/StopStack",
    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 RootFacadeClient {
    client: ::grpcio::Client,
}

impl RootFacadeClient {
    pub fn new(channel: ::grpcio::Channel) -> Self {
        RootFacadeClient {
            client: ::grpcio::Client::new(channel),
        }
    }

    pub fn start_stack_opt(&self, req: &super::rootservice::StartStackRequest, opt: ::grpcio::CallOption) -> ::grpcio::Result<super::rootservice::StartStackResponse> {
        self.client.unary_call(&METHOD_ROOT_FACADE_START_STACK, req, opt)
    }

    pub fn start_stack(&self, req: &super::rootservice::StartStackRequest) -> ::grpcio::Result<super::rootservice::StartStackResponse> {
        self.start_stack_opt(req, ::grpcio::CallOption::default())
    }

    pub fn start_stack_async_opt(&self, req: &super::rootservice::StartStackRequest, opt: ::grpcio::CallOption) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver<super::rootservice::StartStackResponse>> {
        self.client.unary_call_async(&METHOD_ROOT_FACADE_START_STACK, req, opt)
    }

    pub fn start_stack_async(&self, req: &super::rootservice::StartStackRequest) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver<super::rootservice::StartStackResponse>> {
        self.start_stack_async_opt(req, ::grpcio::CallOption::default())
    }

    pub fn stop_stack_opt(&self, req: &super::rootservice::StopStackRequest, opt: ::grpcio::CallOption) -> ::grpcio::Result<super::rootservice::StopStackResponse> {
        self.client.unary_call(&METHOD_ROOT_FACADE_STOP_STACK, req, opt)
    }

    pub fn stop_stack(&self, req: &super::rootservice::StopStackRequest) -> ::grpcio::Result<super::rootservice::StopStackResponse> {
        self.stop_stack_opt(req, ::grpcio::CallOption::default())
    }

    pub fn stop_stack_async_opt(&self, req: &super::rootservice::StopStackRequest, opt: ::grpcio::CallOption) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver<super::rootservice::StopStackResponse>> {
        self.client.unary_call_async(&METHOD_ROOT_FACADE_STOP_STACK, req, opt)
    }

    pub fn stop_stack_async(&self, req: &super::rootservice::StopStackRequest) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver<super::rootservice::StopStackResponse>> {
        self.stop_stack_async_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 RootFacade {
    fn start_stack(&mut self, ctx: ::grpcio::RpcContext, req: super::rootservice::StartStackRequest, sink: ::grpcio::UnarySink<super::rootservice::StartStackResponse>);
    fn stop_stack(&mut self, ctx: ::grpcio::RpcContext, req: super::rootservice::StopStackRequest, sink: ::grpcio::UnarySink<super::rootservice::StopStackResponse>);
}

pub fn create_root_facade<S: RootFacade + Send + Clone + 'static>(s: S) -> ::grpcio::Service {
    let mut builder = ::grpcio::ServiceBuilder::new();
    let mut instance = s.clone();
    builder = builder.add_unary_handler(&METHOD_ROOT_FACADE_START_STACK, move |ctx, req, resp| {
        instance.start_stack(ctx, req, resp)
    });
    let mut instance = s;
    builder = builder.add_unary_handler(&METHOD_ROOT_FACADE_STOP_STACK, move |ctx, req, resp| {
        instance.stop_stack(ctx, req, resp)
    });
    builder.build()
}

const METHOD_READ_ONLY_PROPERTY_READ_LOCAL_ADDRESS: ::grpcio::Method<super::empty::Empty, super::common::BluetoothAddress> = ::grpcio::Method {
    ty: ::grpcio::MethodType::Unary,
    name: "/bluetooth.facade.ReadOnlyProperty/ReadLocalAddress",
    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 ReadOnlyPropertyClient {
    client: ::grpcio::Client,
}

impl ReadOnlyPropertyClient {
    pub fn new(channel: ::grpcio::Channel) -> Self {
        ReadOnlyPropertyClient {
            client: ::grpcio::Client::new(channel),
        }
    }

    pub fn read_local_address_opt(&self, req: &super::empty::Empty, opt: ::grpcio::CallOption) -> ::grpcio::Result<super::common::BluetoothAddress> {
        self.client.unary_call(&METHOD_READ_ONLY_PROPERTY_READ_LOCAL_ADDRESS, req, opt)
    }

    pub fn read_local_address(&self, req: &super::empty::Empty) -> ::grpcio::Result<super::common::BluetoothAddress> {
        self.read_local_address_opt(req, ::grpcio::CallOption::default())
    }

    pub fn read_local_address_async_opt(&self, req: &super::empty::Empty, opt: ::grpcio::CallOption) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver<super::common::BluetoothAddress>> {
        self.client.unary_call_async(&METHOD_READ_ONLY_PROPERTY_READ_LOCAL_ADDRESS, req, opt)
    }

    pub fn read_local_address_async(&self, req: &super::empty::Empty) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver<super::common::BluetoothAddress>> {
        self.read_local_address_async_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 ReadOnlyProperty {
    fn read_local_address(&mut self, ctx: ::grpcio::RpcContext, req: super::empty::Empty, sink: ::grpcio::UnarySink<super::common::BluetoothAddress>);
}

pub fn create_read_only_property<S: ReadOnlyProperty + Send + Clone + 'static>(s: S) -> ::grpcio::Service {
    let mut builder = ::grpcio::ServiceBuilder::new();
    let mut instance = s;
    builder = builder.add_unary_handler(&METHOD_READ_ONLY_PROPERTY_READ_LOCAL_ADDRESS, move |ctx, req, resp| {
        instance.read_local_address(ctx, req, resp)
    });
    builder.build()
}
Loading