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

Commit 102cead6 authored by Abhishek Pandit-Subedi's avatar Abhishek Pandit-Subedi Committed by Abhishek Pandit-Subedi
Browse files

floss: Enable syslog on btadapterd

Instead of logging via println! in Rust code, start using syslog
instead.

Bug: 190648196
Tag: #floss
Test: Verify btadapterd logs to syslog on ChromeOS
Change-Id: Ida770f304ba9325288a486f2bb3ae242e21b4946
parent 22f35c6a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -14,8 +14,10 @@ dbus = "0.9.2"
dbus-crossroads = "0.4.0"
dbus-tokio = "0.7.3"
futures = "0.3.13"
log = "0.4.14"
num-traits = "*"
tokio = { version = "1", features = ['bytes', 'fs', 'io-util', 'libc', 'macros', 'memchr', 'mio', 'net', 'num_cpus', 'rt', 'rt-multi-thread', 'sync', 'time', 'tokio-macros'] }
syslog = "4.0"

[build-dependencies]
pkg-config = "0.3.19"
+23 −17
Original line number Diff line number Diff line
use bt_topshim::btif::get_btinterface;
use bt_topshim::topstack;

use dbus::channel::MatchingReceiver;
use dbus::message::MatchRule;

use dbus::{channel::MatchingReceiver, message::MatchRule};
use dbus_crossroads::Crossroads;

use dbus_projection::DisconnectWatcher;

use dbus_tokio::connection;

use futures::future;

use btstack::bluetooth::get_bt_dispatcher;
use btstack::bluetooth::{Bluetooth, IBluetooth};
use btstack::bluetooth_gatt::BluetoothGatt;
use btstack::bluetooth_media::BluetoothMedia;
use btstack::Stack;

use log::LevelFilter;
use std::error::Error;
use std::sync::{Arc, Mutex};
use syslog::{BasicLogger, Facility, Formatter3164};

use bt_topshim::{btif::get_btinterface, topstack};
use btstack::{
    bluetooth::{get_bt_dispatcher, Bluetooth, IBluetooth},
    bluetooth_gatt::BluetoothGatt,
    bluetooth_media::BluetoothMedia,
    Stack,
};
use dbus_projection::DisconnectWatcher;

mod dbus_arg;
mod iface_bluetooth;
@@ -49,6 +44,17 @@ fn make_object_name(idx: i32, name: &str) -> String {

/// Runs the Bluetooth daemon serving D-Bus IPC.
fn main() -> Result<(), Box<dyn Error>> {
    let formatter = Formatter3164 {
        facility: Facility::LOG_USER,
        hostname: None,
        process: "btadapterd".into(),
        pid: 0,
    };

    let logger = syslog::unix(formatter).expect("could not connect to syslog");
    let _ = log::set_boxed_logger(Box::new(BasicLogger::new(logger)))
        .map(|()| log::set_max_level(LevelFilter::Info));

    let (tx, rx) = Stack::create_channel();

    let intf = Arc::new(Mutex::new(get_btinterface().unwrap()));
+1 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ bt_shim = { path = "../../shim" }
btif_macros = { path = "btif_macros" }

dbus = "0.9.2"

log = "0.4.14"
num-traits = "*"
num-derive = "*"

+3 −4
Original line number Diff line number Diff line
@@ -9,12 +9,11 @@ use bt_topshim::topstack;

use btif_macros::{btif_callback, btif_callbacks_dispatcher};

use log::{debug, warn};
use num_traits::cast::ToPrimitive;

use std::collections::HashMap;
use std::sync::Arc;
use std::sync::Mutex;

use tokio::sync::mpsc::Sender;

use crate::bluetooth_media::{BluetoothMedia, IBluetoothMedia};
@@ -183,7 +182,7 @@ impl Bluetooth {
        self.hh.as_mut().unwrap().initialize(HHCallbacksDispatcher {
            dispatch: Box::new(move |_cb| {
                // TODO("Implement the callbacks");
                println!("received HH callback");
                debug!("received HH callback");
            }),
        });
    }
@@ -416,7 +415,7 @@ impl IBluetooth for Bluetooth {
        let addr = RawAddress::from_string(device.address.clone());

        if addr.is_none() {
            println!("address {} is not valid", device.address);
            warn!("Can't create bond. Address {} is not valid", device.address);
            return false;
        }

+3 −4
Original line number Diff line number Diff line
@@ -10,11 +10,10 @@ use bt_topshim::profiles::gatt::{
};
use bt_topshim::topstack;

use log::{debug, warn};
use num_traits::cast::{FromPrimitive, ToPrimitive};

use std::collections::HashSet;
use std::sync::{Arc, Mutex};

use tokio::sync::mpsc::Sender;

use crate::{Message, RPCProxy};
@@ -514,7 +513,7 @@ impl BluetoothGatt {
            GattServerCallbacksDispatcher {
                dispatch: Box::new(move |cb| {
                    // TODO(b/193685149): Implement the callbacks
                    println!("received Gatt server callback: {:?}", cb);
                    debug!("received Gatt server callback: {:?}", cb);
                }),
            },
        );
@@ -960,7 +959,7 @@ impl BtifGattClientCallbacks for BluetoothGatt {

        let client = self.context_map.get_by_uuid(&app_uuid.uu);
        if client.is_none() {
            println!("Warning: Client not registered for UUID {:?}", app_uuid.uu);
            warn!("Warning: Client not registered for UUID {:?}", app_uuid.uu);
            return;
        }