From 568f6aa32e290b4e37b61dfd9985ae81a08e2892 Mon Sep 17 00:00:00 2001 From: Muhammad Asif Date: Tue, 24 Jun 2025 00:19:48 +0500 Subject: agent: use signals to register agent to BlueZ Signed-off-by: Muhammad Asif --- src/bluetooth.vala | 2 ++ src/bluez.vala | 2 +- src/service.vala | 12 ++++++++---- 3 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/bluetooth.vala b/src/bluetooth.vala index da7c176..9b2f9d5 100644 --- a/src/bluetooth.vala +++ b/src/bluetooth.vala @@ -55,5 +55,7 @@ public interface Bluetooth: Object public abstract string get_device_name (ObjectPath path); + public signal void agent_manager_ready (); + public abstract void add_agent (string path); } diff --git a/src/bluez.vala b/src/bluez.vala index fabee5f..6d08004 100644 --- a/src/bluez.vala +++ b/src/bluez.vala @@ -122,7 +122,7 @@ public class Bluez: Bluetooth, Object { manager = bus.get_proxy_sync (BLUEZ_BUSNAME, "/"); agent_manager = bus.get_proxy_sync (BLUEZ_BUSNAME, "/org/bluez"); - add_agent ("/agent"); + agent_manager_ready (); // Find the adapters and watch for changes manager.interfaces_added.connect ((object_path, interfaces_and_properties) => { diff --git a/src/service.vala b/src/service.vala index b79056e..e651811 100644 --- a/src/service.vala +++ b/src/service.vala @@ -29,7 +29,7 @@ public class Service: Object private MainLoop loop; private SimpleActionGroup actions; private HashTable profiles; - private Bluetooth bluez; + private Bluetooth bluetooth; private DBusConnection connection; private uint exported_action_id; private const string OBJECT_PATH = "/org/ayatana/indicator/bluetooth"; @@ -50,10 +50,10 @@ public class Service: Object } } - public Service (Bluetooth bluetooth) + public Service (Bluetooth bluetooth_service) { actions = new SimpleActionGroup (); - bluez = bluetooth; + bluetooth = bluetooth_service; profiles = new HashTable (str_hash, str_equal); profiles.insert ("phone", new Phone (bluetooth, actions)); @@ -83,6 +83,10 @@ public class Service: Object null, null); + bluetooth.agent_manager_ready.connect (() => { + bluetooth.add_agent ("/agent"); + }); + loop = new MainLoop (null, false); loop.run (); @@ -97,7 +101,7 @@ public class Service: Object { try { - connection.register_object ("/agent", new Agent (bluez)); + connection.register_object ("/agent", new Agent (bluetooth)); } catch (GLib.IOError pError) { -- cgit v1.2.3