Loading system/gd/rust/linux/client/src/dbus_iface.rs +8 −30 Original line number Diff line number Diff line Loading @@ -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")] Loading Loading @@ -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")] Loading Loading @@ -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")] Loading system/gd/rust/linux/dbus_projection/dbus_macros/src/lib.rs +43 −3 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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(), Loading @@ -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 { Loading Loading @@ -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 { Loading Loading
system/gd/rust/linux/client/src/dbus_iface.rs +8 −30 Original line number Diff line number Diff line Loading @@ -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")] Loading Loading @@ -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")] Loading Loading @@ -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")] Loading
system/gd/rust/linux/dbus_projection/dbus_macros/src/lib.rs +43 −3 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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(), Loading @@ -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 { Loading Loading @@ -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 { Loading