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

Commit c1f669a0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge changes I243db01a,Id0a82756,Icdd26add am: a51fe0d8 am: 4eef60a4

parents ede94b35 4eef60a4
Loading
Loading
Loading
Loading
+212 −3
Original line number Original line Diff line number Diff line
//! D-Bus proxy implementations of the APIs.
//! D-Bus proxy implementations of the APIs.


use bt_topshim::btif::{BtDeviceType, BtPropertyType, BtSspVariant, BtTransport, Uuid128Bit};
use bt_topshim::btif::{
    BtDeviceType, BtPropertyType, BtSspVariant, BtStatus, BtTransport, Uuid, Uuid128Bit,
};
use bt_topshim::profiles::gatt::GattStatus;
use bt_topshim::profiles::gatt::GattStatus;
use bt_topshim::profiles::socket::SocketType;


use btstack::bluetooth::{
use btstack::bluetooth::{
    BluetoothDevice, IBluetooth, IBluetoothCallback, IBluetoothConnectionCallback,
    BluetoothDevice, IBluetooth, IBluetoothCallback, IBluetoothConnectionCallback,
@@ -11,6 +14,10 @@ use btstack::bluetooth_gatt::{
    GattWriteRequestStatus, GattWriteType, IBluetoothGatt, IBluetoothGattCallback,
    GattWriteRequestStatus, GattWriteType, IBluetoothGatt, IBluetoothGattCallback,
    IScannerCallback, LePhy, ScanFilter, ScanSettings,
    IScannerCallback, LePhy, ScanFilter, ScanSettings,
};
};
use btstack::socket_manager::{
    BluetoothServerSocket, BluetoothSocket, CallbackId, IBluetoothSocketManager,
    IBluetoothSocketManagerCallbacks, SocketId, SocketResult,
};
use btstack::RPCProxy;
use btstack::RPCProxy;


use btstack::suspend::{ISuspend, ISuspendCallback, SuspendType};
use btstack::suspend::{ISuspend, ISuspendCallback, SuspendType};
@@ -19,7 +26,9 @@ use btstack::uuid::Profile;
use dbus::arg::RefArg;
use dbus::arg::RefArg;
use dbus::nonblock::SyncConnection;
use dbus::nonblock::SyncConnection;


use dbus_projection::{dbus_generated, impl_dbus_arg_enum, ClientDBusProxy, DisconnectWatcher};
use dbus_projection::{
    dbus_generated, impl_dbus_arg_enum, impl_dbus_arg_from_into, ClientDBusProxy, DisconnectWatcher,
};


use dbus_macros::{
use dbus_macros::{
    dbus_method, dbus_propmap, generate_dbus_exporter, generate_dbus_interface_client,
    dbus_method, dbus_propmap, generate_dbus_exporter, generate_dbus_interface_client,
@@ -31,7 +40,7 @@ use manager_service::iface_bluetooth_manager::{


use num_traits::{FromPrimitive, ToPrimitive};
use num_traits::{FromPrimitive, ToPrimitive};


use std::convert::TryInto;
use std::convert::{TryFrom, TryInto};
use std::sync::Arc;
use std::sync::Arc;


use crate::dbus_arg::{DBusArg, DBusArgError, RefArgToRust};
use crate::dbus_arg::{DBusArg, DBusArgError, RefArgToRust};
@@ -43,13 +52,27 @@ fn make_object_path(idx: i32, name: &str) -> dbus::Path {
impl_dbus_arg_enum!(BtDeviceType);
impl_dbus_arg_enum!(BtDeviceType);
impl_dbus_arg_enum!(BtPropertyType);
impl_dbus_arg_enum!(BtPropertyType);
impl_dbus_arg_enum!(BtSspVariant);
impl_dbus_arg_enum!(BtSspVariant);
impl_dbus_arg_enum!(BtStatus);
impl_dbus_arg_enum!(BtTransport);
impl_dbus_arg_enum!(BtTransport);
impl_dbus_arg_enum!(GattStatus);
impl_dbus_arg_enum!(GattStatus);
impl_dbus_arg_enum!(GattWriteRequestStatus);
impl_dbus_arg_enum!(GattWriteRequestStatus);
impl_dbus_arg_enum!(GattWriteType);
impl_dbus_arg_enum!(GattWriteType);
impl_dbus_arg_enum!(LePhy);
impl_dbus_arg_enum!(LePhy);
impl_dbus_arg_enum!(Profile);
impl_dbus_arg_enum!(Profile);
impl_dbus_arg_enum!(SocketType);
impl_dbus_arg_enum!(SuspendType);
impl_dbus_arg_enum!(SuspendType);
impl_dbus_arg_from_into!(Uuid, Vec<u8>);

impl RefArgToRust for Uuid {
    type RustType = Vec<u8>;

    fn ref_arg_to_rust(
        arg: &(dyn dbus::arg::RefArg + 'static),
        name: String,
    ) -> Result<Self::RustType, Box<dyn std::error::Error>> {
        <Vec<u8> as RefArgToRust>::ref_arg_to_rust(arg, name)
    }
}


// Represents Uuid128Bit as an array in D-Bus.
// Represents Uuid128Bit as an array in D-Bus.
impl DBusArg for Uuid128Bit {
impl DBusArg for Uuid128Bit {
@@ -846,6 +869,192 @@ impl IBluetoothGattCallback for IBluetoothGattCallbackDBus {
    fn on_service_changed(&self, addr: String) {}
    fn on_service_changed(&self, addr: String) {}
}
}


#[dbus_propmap(BluetoothServerSocket)]
pub struct BluetoothServerSocketDBus {
    id: SocketId,
    sock_type: SocketType,
    flags: i32,
    psm: Option<i32>,
    channel: Option<i32>,
    name: Option<String>,
    uuid: Option<Uuid>,
}

#[dbus_propmap(BluetoothSocket)]
pub struct BluetoothSocketDBus {
    id: SocketId,
    remote_device: BluetoothDevice,
    sock_type: SocketType,
    flags: i32,
    fd: Option<std::fs::File>,
    port: i32,
    uuid: Option<Uuid>,
    max_rx_size: i32,
    max_tx_size: i32,
}

#[dbus_propmap(SocketResult)]
pub struct SocketResultDBus {
    status: BtStatus,
    id: u64,
}

pub(crate) struct BluetoothSocketManagerDBus {
    client_proxy: ClientDBusProxy,
}

impl BluetoothSocketManagerDBus {
    pub(crate) fn _new(conn: Arc<SyncConnection>, index: i32) -> Self {
        BluetoothSocketManagerDBus {
            client_proxy: ClientDBusProxy::new(
                conn.clone(),
                String::from("org.chromium.bluetooth"),
                make_object_path(index, "adapter"),
                String::from("org.chromium.bluetooth.SocketManager"),
            ),
        }
    }
}

#[generate_dbus_interface_client]
impl IBluetoothSocketManager for BluetoothSocketManagerDBus {
    #[dbus_method("RegisterCallback")]
    fn register_callback(
        &mut self,
        callback: Box<dyn IBluetoothSocketManagerCallbacks + Send>,
    ) -> CallbackId {
        dbus_generated!()
    }

    #[dbus_method("ListenUsingInsecureL2capChannel")]
    fn listen_using_insecure_l2cap_channel(&mut self, callback: CallbackId) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("ListenUsingL2capChannel")]
    fn listen_using_l2cap_channel(&mut self, callback: CallbackId) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("ListenUsingInsecureRfcommWithServiceRecord")]
    fn listen_using_insecure_rfcomm_with_service_record(
        &mut self,
        callback: CallbackId,
        name: String,
        uuid: Uuid,
    ) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("ListenUsingRfcommWithServiceRecord")]
    fn listen_using_rfcomm_with_service_record(
        &mut self,
        callback: CallbackId,
        name: String,
        uuid: Uuid,
    ) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("CreateInsecureL2capChannel")]
    fn create_insecure_l2cap_channel(
        &mut self,
        callback: CallbackId,
        device: BluetoothDevice,
        psm: i32,
    ) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("CreateL2capChannel")]
    fn create_l2cap_channel(
        &mut self,
        callback: CallbackId,
        device: BluetoothDevice,
        psm: i32,
    ) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("CreateInsecureRfcommSocketToServiceRecord")]
    fn create_insecure_rfcomm_socket_to_service_record(
        &mut self,
        callback: CallbackId,
        device: BluetoothDevice,
        uuid: Uuid,
    ) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("CreateRfcommSocketToServiceRecord")]
    fn create_rfcomm_socket_to_service_record(
        &mut self,
        callback: CallbackId,
        device: BluetoothDevice,
        uuid: Uuid,
    ) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("Accept")]
    fn accept(&mut self, callback: CallbackId, id: SocketId, timeout_ms: Option<u32>) -> BtStatus {
        dbus_generated!()
    }

    #[dbus_method("Close")]
    fn close(&mut self, callback: CallbackId, id: SocketId) -> BtStatus {
        dbus_generated!()
    }
}

struct IBluetoothSocketManagerCallbacksDBus {}

impl RPCProxy for IBluetoothSocketManagerCallbacksDBus {
    // Placeholder implementations just to satisfy impl RPCProxy requirements.
    fn register_disconnect(&mut self, _f: Box<dyn Fn(u32) + Send>) -> u32 {
        0
    }
    fn get_object_id(&self) -> String {
        String::from("")
    }
    fn unregister(&mut self, _id: u32) -> bool {
        false
    }
    fn export_for_rpc(self: Box<Self>) {}
}

#[generate_dbus_exporter(export_socket_callback_dbus_intf, "org.chromium.bluetooth.SocketCallback")]
impl IBluetoothSocketManagerCallbacks for IBluetoothSocketManagerCallbacksDBus {
    #[dbus_method("OnIncomingSocketReady")]
    fn on_incoming_socket_ready(&mut self, socket: BluetoothServerSocket, status: BtStatus) {
        dbus_generated!()
    }

    #[dbus_method("OnIncomingSocketClosed")]
    fn on_incoming_socket_closed(&mut self, listener_id: SocketId, reason: BtStatus) {
        dbus_generated!()
    }

    #[dbus_method("OnHandleIncomingConnection")]
    fn on_handle_incoming_connection(
        &mut self,
        listener_id: SocketId,
        connection: BluetoothSocket,
    ) {
        dbus_generated!()
    }

    #[dbus_method("OnOutgoingConnectionResult")]
    fn on_outgoing_connection_result(
        &mut self,
        connecting_id: SocketId,
        result: BtStatus,
        socket: Option<BluetoothSocket>,
    ) {
        dbus_generated!()
    }
}

pub(crate) struct SuspendDBus {
pub(crate) struct SuspendDBus {
    client_proxy: ClientDBusProxy,
    client_proxy: ClientDBusProxy,
}
}
+0 −1
Original line number Original line Diff line number Diff line
@@ -619,7 +619,6 @@ pub fn dbus_propmap(attr: TokenStream, item: TokenStream) -> TokenStream {


                return Ok(#struct_ident {
                return Ok(#struct_ident {
                    #field_idents
                    #field_idents
                    ..Default::default()
                });
                });
            }
            }


+149 −20
Original line number Original line Diff line number Diff line
extern crate bt_shim;
extern crate bt_shim;


use bt_topshim::btif::{BtDeviceType, BtPropertyType, BtSspVariant, BtTransport, Uuid, Uuid128Bit};
use bt_topshim::btif::{
    BtDeviceType, BtPropertyType, BtSspVariant, BtStatus, BtTransport, Uuid, Uuid128Bit,
};
use bt_topshim::profiles::socket::SocketType;
use bt_topshim::profiles::socket::SocketType;


use btstack::bluetooth::{
use btstack::bluetooth::{
    Bluetooth, BluetoothDevice, IBluetooth, IBluetoothCallback, IBluetoothConnectionCallback,
    Bluetooth, BluetoothDevice, IBluetooth, IBluetoothCallback, IBluetoothConnectionCallback,
};
};
use btstack::socket_manager::{BluetoothSocketManager, IBluetoothSocketManager};
use btstack::socket_manager::{
    BluetoothServerSocket, BluetoothSocket, BluetoothSocketManager, CallbackId,
    IBluetoothSocketManager, IBluetoothSocketManagerCallbacks, SocketId, SocketResult,
};
use btstack::suspend::{ISuspend, ISuspendCallback, Suspend, SuspendType};
use btstack::suspend::{ISuspend, ISuspendCallback, Suspend, SuspendType};
use btstack::uuid::Profile;
use btstack::uuid::Profile;
use btstack::RPCProxy;
use btstack::RPCProxy;
@@ -40,6 +45,8 @@ impl RefArgToRust for Uuid {
    }
    }
}
}


impl_dbus_arg_from_into!(BtStatus, u32);

/// A mixin of the several interfaces. The naming of the fields in the mixin must match
/// A mixin of the several interfaces. The naming of the fields in the mixin must match
/// what is listed in the `generate_dbus_exporter` invocation.
/// what is listed in the `generate_dbus_exporter` invocation.
pub struct BluetoothMixin {
pub struct BluetoothMixin {
@@ -342,7 +349,70 @@ impl IBluetooth for IBluetoothDBus {


impl_dbus_arg_enum!(SocketType);
impl_dbus_arg_enum!(SocketType);


#[allow(dead_code)]
#[dbus_propmap(BluetoothServerSocket)]
pub struct BluetoothServerSocketDBus {
    id: SocketId,
    sock_type: SocketType,
    flags: i32,
    psm: Option<i32>,
    channel: Option<i32>,
    name: Option<String>,
    uuid: Option<Uuid>,
}

#[dbus_propmap(BluetoothSocket)]
pub struct BluetoothSocketDBus {
    id: SocketId,
    remote_device: BluetoothDevice,
    sock_type: SocketType,
    flags: i32,
    fd: Option<std::fs::File>,
    port: i32,
    uuid: Option<Uuid>,
    max_rx_size: i32,
    max_tx_size: i32,
}

#[dbus_propmap(SocketResult)]
pub struct SocketResultDBus {
    status: BtStatus,
    id: u64,
}

struct IBluetoothSocketManagerCallbacksDBus {}

#[dbus_proxy_obj(BluetoothSocketCallback, "org.chromium.bluetooth.SocketManagerCallback")]
impl IBluetoothSocketManagerCallbacks for IBluetoothSocketManagerCallbacksDBus {
    #[dbus_method("OnIncomingSocketReady")]
    fn on_incoming_socket_ready(&mut self, socket: BluetoothServerSocket, status: BtStatus) {
        dbus_generated!()
    }

    #[dbus_method("OnIncomingSocketClosed")]
    fn on_incoming_socket_closed(&mut self, listener_id: SocketId, reason: BtStatus) {
        dbus_generated!()
    }

    #[dbus_method("OnHandleIncomingConnection")]
    fn on_handle_incoming_connection(
        &mut self,
        listener_id: SocketId,
        connection: BluetoothSocket,
    ) {
        dbus_generated!()
    }

    #[dbus_method("OnOutgoingConnectionResult")]
    fn on_outgoing_connection_result(
        &mut self,
        connecting_id: SocketId,
        result: BtStatus,
        socket: Option<BluetoothSocket>,
    ) {
        dbus_generated!()
    }
}

struct IBluetoothSocketManagerDBus {}
struct IBluetoothSocketManagerDBus {}


#[generate_dbus_exporter(
#[generate_dbus_exporter(
@@ -352,32 +422,91 @@ struct IBluetoothSocketManagerDBus {}
    socket_mgr
    socket_mgr
)]
)]
impl IBluetoothSocketManager for IBluetoothSocketManagerDBus {
impl IBluetoothSocketManager for IBluetoothSocketManagerDBus {
    #[dbus_method("ConnectSocket")]
    #[dbus_method("RegisterCallback")]
    fn connect_socket(
    fn register_callback(
        &mut self,
        &mut self,
        callback: Box<dyn IBluetoothSocketManagerCallbacks + Send>,
    ) -> CallbackId {
        dbus_generated!()
    }

    #[dbus_method("ListenUsingInsecureL2capChannel")]
    fn listen_using_insecure_l2cap_channel(&mut self, callback: CallbackId) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("ListenUsingL2capChannel")]
    fn listen_using_l2cap_channel(&mut self, callback: CallbackId) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("ListenUsingInsecureRfcommWithServiceRecord")]
    fn listen_using_insecure_rfcomm_with_service_record(
        &mut self,
        callback: CallbackId,
        name: String,
        uuid: Uuid,
    ) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("ListenUsingRfcommWithServiceRecord")]
    fn listen_using_rfcomm_with_service_record(
        &mut self,
        callback: CallbackId,
        name: String,
        uuid: Uuid,
    ) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("CreateInsecureL2capChannel")]
    fn create_insecure_l2cap_channel(
        &mut self,
        callback: CallbackId,
        device: BluetoothDevice,
        device: BluetoothDevice,
        sock_type: SocketType,
        psm: i32,
        uuid: Option<Uuid>,
    ) -> SocketResult {
        port: i32,
        flags: i32,
    ) -> Option<std::fs::File> {
        dbus_generated!()
        dbus_generated!()
    }
    }


    #[dbus_method("CreateSocketChannel")]
    #[dbus_method("CreateL2capChannel")]
    fn create_socket_channel(
    fn create_l2cap_channel(
        &mut self,
        &mut self,
        sock_type: SocketType,
        callback: CallbackId,
        service_name: String,
        device: BluetoothDevice,
        uuid: Option<Uuid>,
        psm: i32,
        port: i32,
    ) -> SocketResult {
        flags: i32,
        dbus_generated!()
    ) -> Option<std::fs::File> {
    }

    #[dbus_method("CreateInsecureRfcommSocketToServiceRecord")]
    fn create_insecure_rfcomm_socket_to_service_record(
        &mut self,
        callback: CallbackId,
        device: BluetoothDevice,
        uuid: Uuid,
    ) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("CreateRfcommSocketToServiceRecord")]
    fn create_rfcomm_socket_to_service_record(
        &mut self,
        callback: CallbackId,
        device: BluetoothDevice,
        uuid: Uuid,
    ) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("Accept")]
    fn accept(&mut self, callback: CallbackId, id: SocketId, timeout_ms: Option<u32>) -> BtStatus {
        dbus_generated!()
        dbus_generated!()
    }
    }


    #[dbus_method("RequestMaximumTxDataLength")]
    #[dbus_method("Close")]
    fn request_maximum_tx_data_length(&mut self, device: BluetoothDevice) {
    fn close(&mut self, callback: CallbackId, id: SocketId) -> BtStatus {
        dbus_generated!()
        dbus_generated!()
    }
    }
}
}
+3 −1
Original line number Original line Diff line number Diff line
@@ -108,7 +108,8 @@ fn main() -> Result<(), Box<dyn Error>> {
        intf.clone(),
        intf.clone(),
        bluetooth_media.clone(),
        bluetooth_media.clone(),
    ))));
    ))));
    let bt_sock_mgr = Arc::new(Mutex::new(Box::new(BluetoothSocketManager::new(intf.clone()))));
    let bt_sock_mgr =
        Arc::new(Mutex::new(Box::new(BluetoothSocketManager::new(intf.clone(), tx.clone()))));


    topstack::get_runtime().block_on(async {
    topstack::get_runtime().block_on(async {
        // Connect to D-Bus system bus.
        // Connect to D-Bus system bus.
@@ -146,6 +147,7 @@ fn main() -> Result<(), Box<dyn Error>> {
            bluetooth_gatt.clone(),
            bluetooth_gatt.clone(),
            bluetooth_media.clone(),
            bluetooth_media.clone(),
            suspend.clone(),
            suspend.clone(),
            bt_sock_mgr.clone(),
        ));
        ));


        // Set up the disconnect watcher to monitor client disconnects.
        // Set up the disconnect watcher to monitor client disconnects.
+3 −3
Original line number Original line Diff line number Diff line
@@ -11,10 +11,10 @@ btif_macros = { path = "btif_macros" }


dbus = "0.9.2"
dbus = "0.9.2"
log = "0.4.14"
log = "0.4.14"
nix = "0.19"
num-derive = "0.3"
num-traits = "0.2"
rand = { version = "0.8.3", features = ["small_rng"] }
rand = { version = "0.8.3", features = ["small_rng"] }
num-traits = "*"
num-derive = "*"

tokio = { version = "1", features = ['bytes', 'fs', 'io-util', 'libc', 'macros', 'memchr', 'mio', 'net', 'num_cpus', 'rt', 'rt-multi-thread', 'sync', 'time', 'tokio-macros'] }
tokio = { version = "1", features = ['bytes', 'fs', 'io-util', 'libc', 'macros', 'memchr', 'mio', 'net', 'num_cpus', 'rt', 'rt-multi-thread', 'sync', 'time', 'tokio-macros'] }


[lib]
[lib]
Loading