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 cxx::UniquePtr;
12
13 use crate::{
14 connection::{LeAclManagerImpl, LeAclManagerShim},
15 gatt::ffi::{AttTransportImpl, GattCallbacksImpl},
16 GlobalModuleRegistry, MainThreadTxMessage, GLOBAL_MODULE_REGISTRY,
17 };
18
19 use self::ffi::{future_ready, Future, GattServerCallbacks};
20
start( gatt_server_callbacks: UniquePtr<GattServerCallbacks>, le_acl_manager: UniquePtr<LeAclManagerShim>, on_started: Pin<&'static mut Future>, )21 fn start(
22 gatt_server_callbacks: UniquePtr<GattServerCallbacks>,
23 le_acl_manager: UniquePtr<LeAclManagerShim>,
24 on_started: Pin<&'static mut Future>,
25 ) {
26 thread::spawn(move || {
27 GlobalModuleRegistry::start(
28 Rc::new(GattCallbacksImpl(gatt_server_callbacks)),
29 Rc::new(AttTransportImpl()),
30 LeAclManagerImpl(le_acl_manager),
31 || {
32 future_ready(on_started);
33 },
34 );
35 });
36 }
37
stop()38 fn stop() {
39 let _ = GLOBAL_MODULE_REGISTRY
40 .try_lock()
41 .unwrap()
42 .as_ref()
43 .map(|registry| registry.task_tx.send(MainThreadTxMessage::Stop));
44 }
45