1 //! Bluetooth common library
2
3 use init_flags::{
4 get_log_level_for_tag, LOG_TAG_DEBUG, LOG_TAG_ERROR, LOG_TAG_FATAL, LOG_TAG_INFO,
5 LOG_TAG_NOTICE, LOG_TAG_VERBOSE, LOG_TAG_WARN,
6 };
7
8 /// Provides waking timer abstractions
9 pub mod time;
10
11 /// Provides parameters
12 pub mod parameter_provider;
13
14 pub mod bridge;
15
16 #[macro_use]
17 mod ready;
18
19 #[cfg(test)]
20 #[macro_use]
21 mod asserts;
22
23 /// Provides runtime configured-at-startup flags
24 pub mod init_flags;
25
26 /// Provides runtime configured system properties. Stubbed for non-Android.
27 pub mod sys_prop;
28
get_log_level() -> log::Level29 fn get_log_level() -> log::Level {
30 match get_log_level_for_tag("bluetooth_core") {
31 LOG_TAG_FATAL => log::Level::Error,
32 LOG_TAG_ERROR => log::Level::Error,
33 LOG_TAG_WARN => log::Level::Warn,
34 LOG_TAG_NOTICE => log::Level::Info,
35 LOG_TAG_INFO => log::Level::Info,
36 LOG_TAG_DEBUG => log::Level::Debug,
37 LOG_TAG_VERBOSE => log::Level::Trace,
38 _ => log::Level::Info, // default level
39 }
40 }
41
42 /// Inits logging for Android
43 #[cfg(target_os = "android")]
init_logging()44 pub fn init_logging() {
45 android_logger::init_once(
46 android_logger::Config::default().with_tag("bt").with_min_level(get_log_level()),
47 );
48 log::set_max_level(get_log_level().to_level_filter())
49 }
50
51 /// Inits logging for host
52 #[cfg(not(target_os = "android"))]
init_logging()53 pub fn init_logging() {
54 env_logger::Builder::new()
55 .filter(None, get_log_level().to_level_filter())
56 .parse_default_env()
57 .try_init()
58 .ok();
59 log::set_max_level(get_log_level().to_level_filter())
60 }
61
62 /// Indicates the object can be converted to a GRPC service
63 pub trait GrpcFacade {
64 /// Convert the object into the service
into_grpc(self) -> grpcio::Service65 fn into_grpc(self) -> grpcio::Service;
66 }
67
68 /// Useful for distinguishing between BT classic & LE in functions that support both
69 #[derive(Debug, Clone, Copy)]
70 pub enum Bluetooth {
71 /// Classic BT we all know and love, started in the 90s.
72 Classic,
73 /// Bluetooth low energy from the 2010s. Also known as BLE, BTLE, etc.
74 Le,
75 }
76