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

Commit eb1e5ed2 authored by Sonny Sasaka's avatar Sonny Sasaka Committed by Gerrit Code Review
Browse files

Merge "Floss: Refactor btmanagerd bin and lib"

parents 513d1a64 3264378f
Loading
Loading
Loading
Loading
+10 −21
Original line number Diff line number Diff line
mod bluetooth_manager;
mod bluetooth_manager_dbus;
mod config_util;
mod dbus_arg;
mod dbus_iface;
mod powerd_suspend_manager;
mod service_watcher;
mod state_machine;

use crate::bluetooth_manager::BluetoothManager;
use crate::powerd_suspend_manager::PowerdSuspendManager;
// The manager binary (btmanagerd) is a fairly barebone bin file that depends on the manager_service
// library which implements most of the logic. The code is separated in this way so that we can
// apply certain linker flags (which is applied to the library but not the binary).
// Please keep main.rs logic light and write the heavy logic in the manager_service library instead.

use dbus::channel::MatchingReceiver;
use dbus::message::MatchRule;
use dbus_crossroads::Crossroads;
use dbus_projection::DisconnectWatcher;
use dbus_tokio::connection;
use log::LevelFilter;
use manager_service::bluetooth_manager::{BluetoothManager, ManagerContext};
use manager_service::powerd_suspend_manager::PowerdSuspendManager;
use manager_service::{bluetooth_manager_dbus, config_util, state_machine};
use std::sync::atomic::AtomicBool;
use std::sync::{Arc, Mutex};
use syslog::{BasicLogger, Facility, Formatter3164};

#[derive(Clone)]
struct ManagerContext {
    proxy: state_machine::StateMachineProxy,
    floss_enabled: Arc<AtomicBool>,
}

#[tokio::main]
pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let formatter = Formatter3164 {
@@ -62,10 +53,8 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {

    let context = state_machine::start_new_state_machine_context(invoker);
    let proxy = context.get_proxy();
    let manager_context = ManagerContext {
        proxy: proxy,
        floss_enabled: Arc::new(AtomicBool::new(config_util::is_floss_enabled())),
    };
    let manager_context =
        ManagerContext::new(proxy, Arc::new(AtomicBool::new(config_util::is_floss_enabled())));

    // The resource is a task that should be spawned onto a tokio compatible
    // reactor ASAP. If the resource ever finishes, you lost connection to D-Bus.
+19 −7
Original line number Diff line number Diff line
use log::{error, info, warn};

use manager_service::iface_bluetooth_manager::{
    AdapterWithEnabled, IBluetoothManager, IBluetoothManagerCallback,
};

use std::collections::HashMap;
use std::process::Command;
use std::sync::atomic::Ordering;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;

use crate::{config_util, state_machine, ManagerContext};
use crate::iface_bluetooth_manager::{
    AdapterWithEnabled, IBluetoothManager, IBluetoothManagerCallback,
};
use crate::{config_util, state_machine};

const BLUEZ_INIT_TARGET: &str = "bluetoothd";

#[derive(Clone)]
pub struct ManagerContext {
    proxy: state_machine::StateMachineProxy,
    floss_enabled: Arc<AtomicBool>,
}

impl ManagerContext {
    pub fn new(proxy: state_machine::StateMachineProxy, floss_enabled: Arc<AtomicBool>) -> Self {
        Self { proxy, floss_enabled }
    }
}

/// Implementation of IBluetoothManager.
pub struct BluetoothManager {
    manager_context: ManagerContext,
@@ -20,7 +32,7 @@ pub struct BluetoothManager {
}

impl BluetoothManager {
    pub(crate) fn new(manager_context: ManagerContext) -> BluetoothManager {
    pub fn new(manager_context: ManagerContext) -> BluetoothManager {
        BluetoothManager {
            manager_context,
            callbacks: HashMap::new(),
+3 −3
Original line number Diff line number Diff line
@@ -4,11 +4,11 @@ use dbus_macros::{dbus_method, dbus_propmap, dbus_proxy_obj, generate_dbus_expor
use dbus_projection::{dbus_generated, DisconnectWatcher};

use btstack::RPCProxy;
use manager_service::iface_bluetooth_manager::{
    AdapterWithEnabled, IBluetoothManager, IBluetoothManagerCallback,
};

use crate::dbus_arg::{DBusArg, DBusArgError, RefArgToRust};
use crate::iface_bluetooth_manager::{
    AdapterWithEnabled, IBluetoothManager, IBluetoothManagerCallback,
};

#[dbus_propmap(AdapterWithEnabled)]
pub struct AdapterWithEnabledDbus {
Loading