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

Commit f503112b authored by Rahul Arya's avatar Rahul Arya
Browse files

[Private GATT] Add service change indication

Send indication when attribute schema changes to all registered,
connected clients.

Test: unit
Bug: 255880936
Change-Id: Ie8c0ac8596c43b9b53ed3acd4e6615a689e739de
parent 62fa9093
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -88,3 +88,9 @@ impl<'a, T: ?Sized> Deref for WeakBoxRef<'a, T> {
        self.0
    }
}

impl<'a, T: ?Sized> Clone for WeakBoxRef<'a, T> {
    fn clone(&self) -> Self {
        Self(self.0, self.1.clone())
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -163,7 +163,9 @@ fn on_le_disconnect(tcb_idx: u8) {
    if let Some(conn_id) = with_arbiter(|arbiter| arbiter.on_le_disconnect(TransportIndex(tcb_idx)))
    {
        do_in_rust_thread(move |modules| {
            modules.gatt_module.on_le_disconnect(conn_id);
            if let Err(err) = modules.gatt_module.on_le_disconnect(conn_id) {
                error!("{err:?}")
            }
        })
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -43,3 +43,12 @@ pub struct AdvertiserId(pub u8);
/// The handle of a given ATT attribute
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct AttHandle(pub u16);

impl AttHandle {
    /// The (only) reserved AttHandle
    pub const RESERVED: Self = AttHandle(0);
    /// The smallest valid AttHandle
    pub const MIN: Self = AttHandle(1);
    /// The largest valid AttHandle
    pub const MAX: Self = AttHandle(0xFFFF);
}
+1 −0
Original line number Diff line number Diff line
//! Mocks for the GattDatastore + AttTransport traits, for use in test
pub mod mock_callbacks;
pub mod mock_database_callbacks;
pub mod mock_datastore;
pub mod mock_transport;
+54 −0
Original line number Diff line number Diff line
//! Mocked implementation of GattDatabaseCallbacks for use in test

use std::ops::RangeInclusive;

use crate::{
    core::shared_box::{WeakBox, WeakBoxRef},
    gatt::{
        ids::{AttHandle, ConnectionId},
        server::{
            att_server_bearer::AttServerBearer,
            gatt_database::{AttDatabaseImpl, GattDatabaseCallbacks},
        },
    },
};
use tokio::sync::mpsc::{self, unbounded_channel, UnboundedReceiver};

/// Routes calls to GattDatabaseCallbacks into a channel of MockCallbackEvents
pub struct MockCallbacks(mpsc::UnboundedSender<MockCallbackEvents>);

impl MockCallbacks {
    /// Constructor. Returns self and the RX side of the associated channel.
    pub fn new() -> (Self, UnboundedReceiver<MockCallbackEvents>) {
        let (tx, rx) = unbounded_channel();
        (Self(tx), rx)
    }
}

/// Events representing calls to GattCallbacks
pub enum MockCallbackEvents {
    /// GattDatabaseCallbacks#on_le_connect invoked
    OnLeConnect(ConnectionId, WeakBox<AttServerBearer<AttDatabaseImpl>>),
    /// GattDatabaseCallbacks#on_le_disconnect invoked
    OnLeDisconnect(ConnectionId),
    /// GattDatabaseCallbacks#on_service_change invoked
    OnServiceChange(RangeInclusive<AttHandle>),
}

impl GattDatabaseCallbacks for MockCallbacks {
    fn on_le_connect(
        &self,
        conn_id: ConnectionId,
        bearer: WeakBoxRef<AttServerBearer<AttDatabaseImpl>>,
    ) {
        self.0.send(MockCallbackEvents::OnLeConnect(conn_id, bearer.downgrade())).ok().unwrap();
    }

    fn on_le_disconnect(&self, conn_id: ConnectionId) {
        self.0.send(MockCallbackEvents::OnLeDisconnect(conn_id)).ok().unwrap();
    }

    fn on_service_change(&self, range: RangeInclusive<AttHandle>) {
        self.0.send(MockCallbackEvents::OnServiceChange(range)).ok().unwrap();
    }
}
Loading