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

Commit a1c685bc authored by Sonny Sasaka's avatar Sonny Sasaka Committed by Automerger Merge Worker
Browse files

Merge "Floss: Support callback objects in D-Bus client interface generator"...

Merge "Floss: Support callback objects in D-Bus client interface generator" am: 3aaefb28 am: 5d7c3642

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2003271

Change-Id: I045f9b2dfcea04976ddc58d28a8de733519ff122
parents 484778ce 5d7c3642
Loading
Loading
Loading
Loading
+8 −30
Original line number Diff line number Diff line
@@ -238,27 +238,17 @@ trait DBusExportable {}

#[generate_dbus_interface_client]
impl IBluetooth for BluetoothDBus {
    #[dbus_method("RegisterCallback")]
    fn register_callback(&mut self, callback: Box<dyn IBluetoothCallback + Send>) {
        let callback = {
            let path = dbus::Path::new(callback.get_object_id()).unwrap();
            callback.export_for_rpc();
            path
        };

        self.client_proxy.method_noreturn("RegisterCallback", (callback,))
        dbus_generated!()
    }

    #[dbus_method("RegisterConnectionCallback")]
    fn register_connection_callback(
        &mut self,
        callback: Box<dyn IBluetoothConnectionCallback + Send>,
    ) -> u32 {
        let callback = {
            let path = dbus::Path::new(callback.get_object_id()).unwrap();
            callback.export_for_rpc();
            path
        };

        self.client_proxy.method("RegisterConnectionCallback", (callback,))
        dbus_generated!()
    }

    #[dbus_method("UnregisterConnectionCallback")]
@@ -467,16 +457,9 @@ impl IBluetoothManager for BluetoothManagerDBus {
        dbus_generated!()
    }

    // `generate_dbus_interface_client` doesn't support callback types yet.
    // TODO(b/200732080): Support autogenerate code for callback types.
    #[dbus_method("RegisterCallback")]
    fn register_callback(&mut self, callback: Box<dyn IBluetoothManagerCallback + Send>) {
        let callback = {
            let path = dbus::Path::new(callback.get_object_id()).unwrap();
            callback.export_for_rpc();
            path
        };

        self.client_proxy.method_noreturn("RegisterCallback", (callback,))
        dbus_generated!()
    }

    #[dbus_method("GetFlossEnabled")]
@@ -559,19 +542,14 @@ impl IBluetoothGatt for BluetoothGattDBus {
        // TODO(b/200066804): implement
    }

    #[dbus_method("RegisterClient")]
    fn register_client(
        &mut self,
        app_uuid: String,
        callback: Box<dyn IBluetoothGattCallback + Send>,
        eatt_support: bool,
    ) {
        let callback = {
            let path = dbus::Path::new(callback.get_object_id()).unwrap();
            callback.export_for_rpc();
            path
        };

        self.client_proxy.method_noreturn("RegisterClient", (app_uuid, callback, eatt_support))
        dbus_generated!()
    }

    #[dbus_method("UnregisterClient")]
+43 −3
Original line number Diff line number Diff line
@@ -257,6 +257,8 @@ pub fn generate_dbus_interface_client(_attr: TokenStream, item: TokenStream) ->

            let mut input_list = quote! {};

            let mut object_conversions = quote! {};

            // Iterate on every parameter of a method to build a tuple, e.g.
            // `(param1, param2, param3)`
            for input in &method.sig.inputs {
@@ -265,6 +267,35 @@ pub fn generate_dbus_interface_client(_attr: TokenStream, item: TokenStream) ->
                    if let Pat::Ident(pat_ident) = &*typed.pat {
                        let ident = pat_ident.ident.clone();

                        let is_box = if let Type::Path(type_path) = &**arg_type {
                            if type_path.path.segments[0].ident.to_string().eq("Box") {
                                true
                            } else {
                                false
                            }
                        } else {
                            false
                        };

                        if is_box {
                            // A Box<dyn> parameter means this is an object that should be exported
                            // on D-Bus.
                            object_conversions = quote! {
                                #object_conversions
                                    let #ident = {
                                        let path = dbus::Path::new(#ident.get_object_id()).unwrap();
                                        #ident.export_for_rpc();
                                        path
                                    };
                            };

                            input_list = quote! {
                                #input_list
                                #ident,
                            };
                        } else {
                            // Convert every parameter to its corresponding type recognized by
                            // the D-Bus library.
                            input_list = quote! {
                                #input_list
                                <#arg_type as DBusArg>::to_dbus(#ident).unwrap(),
@@ -272,6 +303,7 @@ pub fn generate_dbus_interface_client(_attr: TokenStream, item: TokenStream) ->
                        }
                    }
                }
            }

            let mut output_as_dbus_arg = quote! {};
            if let ReturnType::Type(_, t) = &method.sig.output {
@@ -301,6 +333,14 @@ pub fn generate_dbus_interface_client(_attr: TokenStream, item: TokenStream) ->
                }
            };

            // Assemble the method body. May have object conversions if there is a param that is
            // a proxy object (`Box<dyn>` type).
            let body = quote! {
                #object_conversions

                #body
            };

            // The method definition is its signature and the body.
            let generated_method = quote! {
                #sig {