• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! Shared data-types and utility methods go here.
2 
3 pub mod address;
4 mod ffi;
5 pub mod shared_box;
6 pub mod shared_mutex;
7 pub mod uuid;
8 
9 use std::{pin::Pin, rc::Rc, thread};
10 
11 use bt_common::init_flags::rust_event_loop_is_enabled;
12 use cxx::UniquePtr;
13 
14 use crate::{
15     connection::{LeAclManagerImpl, LeAclManagerShim},
16     gatt::ffi::{AttTransportImpl, GattCallbacksImpl},
17     GlobalModuleRegistry, MainThreadTxMessage, GLOBAL_MODULE_REGISTRY,
18 };
19 
20 use self::ffi::{future_ready, Future, GattServerCallbacks};
21 
start( gatt_server_callbacks: UniquePtr<GattServerCallbacks>, le_acl_manager: UniquePtr<LeAclManagerShim>, on_started: Pin<&'static mut Future>, )22 fn start(
23     gatt_server_callbacks: UniquePtr<GattServerCallbacks>,
24     le_acl_manager: UniquePtr<LeAclManagerShim>,
25     on_started: Pin<&'static mut Future>,
26 ) {
27     if rust_event_loop_is_enabled() {
28         thread::spawn(move || {
29             GlobalModuleRegistry::start(
30                 Rc::new(GattCallbacksImpl(gatt_server_callbacks)),
31                 Rc::new(AttTransportImpl()),
32                 LeAclManagerImpl(le_acl_manager),
33                 || {
34                     future_ready(on_started);
35                 },
36             );
37         });
38     }
39 }
40 
stop()41 fn stop() {
42     let _ = GLOBAL_MODULE_REGISTRY
43         .try_lock()
44         .unwrap()
45         .as_ref()
46         .map(|registry| registry.task_tx.send(MainThreadTxMessage::Stop));
47 }
48