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

Commit 93ef121c authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes Id26bbbb2,Ib993c4d8,Ic6a79ab9,I6e46ee55,Ie3e2e890, ...

* changes:
  floss: Handle register_disconnect for btmanagerd
  floss: Refactor btmanagerd to get rid of select!
  floss: Create PID file when gd shim is init
  Use init flag for hci device if property not found
  floss: Accept --hci init flag
  gd: Alarm should take const ref, not mut
parents 4efee13d 6328874f
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include "init_flags.h"

#include <cstdlib>
#include <string>

#include "common/strings.h"
@@ -27,6 +28,7 @@ namespace bluetooth {
namespace common {

bool InitFlags::logging_debug_enabled_for_all = false;
int InitFlags::hci_adapter = 0;
std::unordered_map<std::string, bool> InitFlags::logging_debug_explicit_tag_settings = {};

bool ParseBoolFlag(const std::vector<std::string>& flag_pair, const std::string& flag, bool* variable) {
@@ -41,6 +43,19 @@ bool ParseBoolFlag(const std::vector<std::string>& flag_pair, const std::string&
  return true;
}

bool ParseIntFlag(const std::vector<std::string>& flag_pair, const std::string& flag, int* variable) {
  if (flag != flag_pair[0]) {
    return false;
  }
  auto value = Int64FromString(flag_pair[1]);
  if (!value || *value > INT32_MAX) {
    return false;
  }

  *variable = *value;
  return true;
}

void InitFlags::Load(const char** flags) {
  const char** flags_copy = flags;
  SetAll(false);
@@ -52,6 +67,9 @@ void InitFlags::Load(const char** flags) {
      continue;
    }

    // Parse adapter index (defaults to 0)
    ParseIntFlag(flag_pair, "--hci", &hci_adapter);

    ParseBoolFlag(flag_pair, "INIT_logging_debug_enabled_for_all", &logging_debug_enabled_for_all);
    if ("INIT_logging_debug_enabled_for_tags" == flag_pair[0]) {
      auto tags = StringSplit(flag_pair[1], ",");
+5 −0
Original line number Diff line number Diff line
@@ -41,11 +41,16 @@ class InitFlags final {
    return logging_debug_enabled_for_all;
  }

  inline static int GetAdapterIndex() {
    return hci_adapter;
  }

  static void SetAllForTesting();

 private:
  static void SetAll(bool value);
  static bool logging_debug_enabled_for_all;
  static int hci_adapter;
  // save both log allow list and block list in the map to save hashing time
  static std::unordered_map<std::string, bool> logging_debug_explicit_tag_settings;
};
+6 −6
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ impl Alarm {
    }

    /// Reset the alarm to duration, starting from now
    pub fn reset(&mut self, duration: Duration) {
    pub fn reset(&self, duration: Duration) {
        self.fd
            .get_ref()
            .set(Expiration::OneShot(TimeSpec::from(duration)), TimerSetTimeFlags::empty())
@@ -26,12 +26,12 @@ impl Alarm {
    }

    /// Stop the alarm if it is currently started
    pub fn cancel(&mut self) {
    pub fn cancel(&self) {
        self.reset(Duration::from_millis(0));
    }

    /// Completes when the alarm has expired
    pub async fn expired(&mut self) {
    pub async fn expired(&self) {
        let mut read_ready = self.fd.readable().await.unwrap();
        read_ready.clear_ready();
        drop(read_ready);
@@ -94,7 +94,7 @@ mod tests {
        let runtime = tokio::runtime::Runtime::new().unwrap();
        runtime.block_on(async {
            let timer = Instant::now();
            let mut alarm = Alarm::new();
            let alarm = Alarm::new();
            alarm.reset(Duration::from_millis(10));
            alarm.expired().await;

@@ -106,7 +106,7 @@ mod tests {
    fn alarm_cancel_after_expired() {
        let runtime = tokio::runtime::Runtime::new().unwrap();
        runtime.block_on(async {
            let mut alarm = Alarm::new();
            let alarm = Alarm::new();
            alarm.reset(Duration::from_millis(10));
            tokio::time::sleep(Duration::from_millis(30)).await;
            alarm.cancel();
@@ -131,7 +131,7 @@ mod tests {
        let runtime = tokio::runtime::Runtime::new().unwrap();
        runtime.block_on(async {
            let timer = Instant::now();
            let mut alarm = Alarm::new();
            let alarm = Alarm::new();
            alarm.reset(Duration::from_millis(10));
            alarm.expired().await;
            let ready_in_10_ms = async {
+26 −8
Original line number Diff line number Diff line
use log::error;
use log::{error, info};

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

@@ -12,29 +12,35 @@ const BLUEZ_INIT_TARGET: &str = "bluetoothd";
/// Implementation of IBluetoothManager.
pub struct BluetoothManager {
    manager_context: ManagerContext,
    callbacks: Vec<Box<dyn IBluetoothManagerCallback + Send>>,
    callbacks: Vec<(u32, Box<dyn IBluetoothManagerCallback + Send>)>,
    callbacks_last_id: u32,
}

impl BluetoothManager {
    pub(crate) fn new(manager_context: ManagerContext) -> BluetoothManager {
        BluetoothManager { manager_context, callbacks: vec![] }
        BluetoothManager { manager_context, callbacks: vec![], callbacks_last_id: 0 }
    }

    pub(crate) fn callback_hci_device_change(&self, hci_device: i32, present: bool) {
        for callback in &self.callbacks {
        for (_, callback) in &self.callbacks {
            callback.on_hci_device_changed(hci_device, present);
        }
    }

    pub(crate) fn callback_hci_enabled_change(&self, hci_device: i32, enabled: bool) {
        for callback in &self.callbacks {
        for (_, callback) in &self.callbacks {
            callback.on_hci_enabled_changed(hci_device, enabled);
        }
    }

    pub(crate) fn callback_disconnected(&mut self, id: u32) {
        self.callbacks.retain(|x| x.0 != id);
    }
}

impl IBluetoothManager for BluetoothManager {
    fn start(&mut self, hci_interface: i32) {
        info!("Starting {}", hci_interface);
        if !config_util::modify_hci_n_enabled(hci_interface, true) {
            error!("Config is not successfully modified");
        }
@@ -42,6 +48,7 @@ impl IBluetoothManager for BluetoothManager {
    }

    fn stop(&mut self, hci_interface: i32) {
        info!("Stopping {}", hci_interface);
        if !config_util::modify_hci_n_enabled(hci_interface, false) {
            error!("Config is not successfully modified");
        }
@@ -55,9 +62,20 @@ impl IBluetoothManager for BluetoothManager {
        result
    }

    fn register_callback(&mut self, callback: Box<dyn IBluetoothManagerCallback + Send>) {
        // TODO: Handle callback disconnects.
        self.callbacks.push(callback);
    fn register_callback(&mut self, mut callback: Box<dyn IBluetoothManagerCallback + Send>) {
        let tx = self.manager_context.proxy.get_tx();

        self.callbacks_last_id += 1;
        let id = self.callbacks_last_id;

        callback.register_disconnect(Box::new(move || {
            let tx = tx.clone();
            tokio::spawn(async move {
                let _result = tx.send(state_machine::Message::CallbackDisconnected(id)).await;
            });
        }));

        self.callbacks.push((id, callback));
    }

    fn get_floss_enabled(&mut self) -> bool {
+342 −213

File changed.

Preview size limit exceeded, changes collapsed.

Loading