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

Commit 4ade5d72 authored by Zach Johnson's avatar Zach Johnson
Browse files

Start the BT testing root service

Bug: 171749953
Tag: #gd-refactor
Test: gd/cert/run --host
Change-Id: I112bb45c2dcabcf6c4e8bb488f9a22810fd9fed3
parent 5a913cd4
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -20,7 +20,10 @@ rust_binary {
    edition: "2018",
    rustlibs: [
      "libclap",
      "libbluetooth_with_facades"
      "libbluetooth_with_facades",
      "libfutures",
      "libgrpcio",
      "libtokio",
    ],
    host_supported: true,
}
+36 −0
Original line number Diff line number Diff line
@@ -4,7 +4,26 @@
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 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(
@@ -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();
}