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

Commit d0204157 authored by Zach Johnson's avatar Zach Johnson
Browse files

rusty-gd: stub out HCI shim FFI

Bug: 171749953
Tag: #gd-refactor
Test: gd/cert/run --rhost SimpleHalTest
Change-Id: I2e02896d344db953d1bfec6c5c7fdbdc8eb4a00c
parent 2d930b81
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -352,6 +352,7 @@ cc_test {
        "libbluetooth_rust_interop",
        "libbt_shim_ffi",
        "libcxxbridge05",
        "libchrome",
    ],
}

+56 −3
Original line number Diff line number Diff line
@@ -8,14 +8,33 @@ rust_ffi_static {
        "libbt_common",
        "libcxx",
    ],
    static_libs: [
        "libbt_callbacks_cxx",
    ],
    host_supported: true,
}

cc_library_static {
    name: "libbluetooth_rust_interop",
    generated_headers: ["libbt_init_flags_bridge_header", "libbt_shim_bridge_header"],
    generated_sources: ["libbt_init_flags_bridge_code", "libbt_shim_bridge_code"],
    export_generated_headers: ["libbt_init_flags_bridge_header", "libbt_shim_bridge_header"],
    generated_headers: [
        "libbt_init_flags_bridge_header",
        "libbt_shim_bridge_header",
        "libbt_hci_bridge_header",
        "cxx-bridge-header",
    ],
    generated_sources: [
        "libbt_init_flags_bridge_code",
        "libbt_shim_bridge_code",
        "libbt_hci_bridge_code",
    ],
    export_generated_headers: [
        "libbt_init_flags_bridge_header",
        "libbt_shim_bridge_header",
        "libbt_hci_bridge_header",
        "cxx-bridge-header",
    ],
    header_libs: ["libbt_callbacks_cxx_headers"],
    export_header_lib_headers: ["libbt_callbacks_cxx_headers"],
    cflags: [
        "-Wno-unused-const-variable",
    ],
@@ -24,11 +43,31 @@ cc_library_static {
        "//apex_available:platform",
        "com.android.bluetooth.updatable",
    ],
    shared_libs: [
        "libchrome",
    ],
    static_libs: [
        "libbt_shim_ffi",
    ],
}

cc_library_static {
    name: "libbt_callbacks_cxx",
    header_libs: ["libbt_callbacks_cxx_headers"],
    srcs: ["callbacks/callbacks.cc"],
    generated_headers: ["libbt_hci_bridge_header", "cxx-bridge-header"],
    shared_libs: [
        "libchrome",
    ],
    host_supported: true,
}

cc_library_headers {
    name: "libbt_callbacks_cxx_headers",
    local_include_dirs: ["callbacks"],
    host_supported: true,
}

genrule {
    name: "libbt_shim_bridge_header",
    tools: ["cxxbridge"],
@@ -61,4 +100,18 @@ genrule {
    out: ["init_flags.cc"],
}

genrule {
    name: "libbt_hci_bridge_header",
    tools: ["cxxbridge"],
    cmd: "$(location cxxbridge) $(in) --header > $(out)",
    srcs: ["src/hci.rs"],
    out: ["src/hci.rs.h"],
}

genrule {
    name: "libbt_hci_bridge_code",
    tools: ["cxxbridge"],
    cmd: "$(location cxxbridge) $(in) >> $(out)",
    srcs: ["src/hci.rs"],
    out: ["hci.cc"],
}
+1 −0
Original line number Diff line number Diff line
#include "callbacks/callbacks.h"
+26 −0
Original line number Diff line number Diff line
#pragma once

#include "base/callback.h"
#include "rust/cxx.h"

namespace bluetooth {
namespace shim {
namespace rust {

class u8SliceCallback {
 public:
  u8SliceCallback(base::Callback<void(::rust::Slice<uint8_t>)> callback) : callback_(callback) {}

  void Run(::rust::Slice<uint8_t> value) const {
    callback_.Run(value);
  }

 private:
  base::Callback<void(::rust::Slice<uint8_t>)> callback_;
};

}  // namespace rust
}  // namespace shim
}  // namespace bluetooth

#include "src/hci.rs.h"
+35 −0
Original line number Diff line number Diff line
//! Hci shim

#[cxx::bridge(namespace = bluetooth::shim::rust)]
mod ffi {
    extern "C" {
        include!("callbacks/callbacks.h");

        type u8SliceCallback;

        fn Run(&self, data: &[u8]);
    }

    extern "Rust" {
        fn hci_set_acl_callback(callback: UniquePtr<u8SliceCallback>);
        fn hci_send_command(data: &[u8]);
        fn hci_send_acl(data: &[u8]);
        fn hci_register_event(event: u8, callback: UniquePtr<u8SliceCallback>);
        fn hci_register_le_event(subevent: u8, callback: UniquePtr<u8SliceCallback>);
    }
}

fn hci_send_command(_data: &[u8]) {
}

fn hci_send_acl(_data: &[u8]) {
}

fn hci_register_event(_event: u8, _callback: cxx::UniquePtr<ffi::u8SliceCallback>) {
}

fn hci_register_le_event(_subevent: u8, _callback: cxx::UniquePtr<ffi::u8SliceCallback>) {
}

fn hci_set_acl_callback(_callback: cxx::UniquePtr<ffi::u8SliceCallback>) {
}
Loading