summaryrefslogtreecommitdiff
path: root/system/gd/rust/topshim/src/controller.rs
blob: 198492822d9adf570d7af8fd1b16758a4fcc78cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#[cxx::bridge(namespace = bluetooth::topshim::rust)]
mod ffi {
    pub struct RustRawAddress {
        address: [u8; 6],
    }

    unsafe extern "C++" {
        include!("controller/controller_shim.h");

        type ControllerIntf;

        fn GetControllerInterface() -> UniquePtr<ControllerIntf>;
        fn read_local_addr(self: &ControllerIntf) -> RustRawAddress;
    }
}

pub struct Controller {
    internal: cxx::UniquePtr<ffi::ControllerIntf>,
}

unsafe impl Send for Controller {}

impl Controller {
    pub fn new() -> Controller {
        let intf = ffi::GetControllerInterface();
        Controller { internal: intf }
    }

    pub fn read_local_addr(&mut self) -> [u8; 6] {
        self.internal.read_local_addr().address
    }
}