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

Commit 1a3a86ed authored by Katherine Lai's avatar Katherine Lai
Browse files

Floss: Add Callbacks:get_by_id_mut

Change the default Callbacks:get_by_id to not return mut and
provide the mut version so callers can choose to not use mut
when not needed.

Bug: 193685791
Tag: #floss
Test: emerge-dedede floss
Change-Id: I69839212d649a1e7acc28e54e8e9c9e679856c47
parent f657aa62
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -579,7 +579,7 @@ impl Advertisers {
        &mut self,
        s: &AdvertisingSetInfo,
    ) -> Option<&mut Box<dyn IAdvertisingSetCallback + Send>> {
        self.callbacks.get_by_id(s.callback_id())
        self.callbacks.get_by_id_mut(s.callback_id())
    }

    /// Removes an advertiser callback and unregisters all advertising sets associated with that callback.
+2 −5
Original line number Diff line number Diff line
@@ -185,7 +185,7 @@ impl ContextMap {
        &mut self,
        callback_id: u32,
    ) -> Option<&mut GattClientCallback> {
        self.callbacks.get_by_id(callback_id)
        self.callbacks.get_by_id_mut(callback_id)
    }
}

@@ -293,10 +293,7 @@ impl ServerContextMap {
        }
    }

    fn get_callback_from_callback_id(
        &mut self,
        callback_id: u32,
    ) -> Option<&mut GattServerCallback> {
    fn get_callback_from_callback_id(&self, callback_id: u32) -> Option<&GattServerCallback> {
        self.callbacks.get_by_id(callback_id)
    }

+6 −1
Original line number Diff line number Diff line
@@ -62,7 +62,12 @@ impl<T: RPCProxy + Send + ?Sized> Callbacks<T> {
    }

    /// Returns the callback object based on the given id.
    pub fn get_by_id(&mut self, id: u32) -> Option<&mut Box<T>> {
    pub fn get_by_id(&self, id: u32) -> Option<&Box<T>> {
        self.callbacks.get(&id)
    }

    /// Returns the mut callback object based on the given id.
    pub fn get_by_id_mut(&mut self, id: u32) -> Option<&mut Box<T>> {
        self.callbacks.get_mut(&id)
    }

+4 −4
Original line number Diff line number Diff line
@@ -1048,13 +1048,13 @@ impl BluetoothSocketManager {
    pub fn handle_actions(&mut self, action: SocketActions) {
        match action {
            SocketActions::OnIncomingSocketReady(cbid, server_socket, status) => {
                if let Some(callback) = self.callbacks.get_by_id(cbid) {
                if let Some(callback) = self.callbacks.get_by_id_mut(cbid) {
                    callback.on_incoming_socket_ready(server_socket, status);
                }
            }

            SocketActions::OnIncomingSocketClosed(cbid, socket_id, status) => {
                if let Some(callback) = self.callbacks.get_by_id(cbid) {
                if let Some(callback) = self.callbacks.get_by_id_mut(cbid) {
                    callback.on_incoming_socket_closed(socket_id, status);

                    // Also make sure to remove the socket from listening list.
@@ -1065,13 +1065,13 @@ impl BluetoothSocketManager {
            }

            SocketActions::OnHandleIncomingConnection(cbid, socket_id, socket) => {
                if let Some(callback) = self.callbacks.get_by_id(cbid) {
                if let Some(callback) = self.callbacks.get_by_id_mut(cbid) {
                    callback.on_handle_incoming_connection(socket_id, socket);
                }
            }

            SocketActions::OnOutgoingConnectionResult(cbid, socket_id, status, socket) => {
                if let Some(callback) = self.callbacks.get_by_id(cbid) {
                if let Some(callback) = self.callbacks.get_by_id_mut(cbid) {
                    callback.on_outgoing_connection_result(socket_id, status, socket);
                }
            }