Skip to content

Commit 568f6aa

Browse files
agent: use signals to register agent to BlueZ
Signed-off-by: Muhammad Asif <thevancedgamer@mentallysanemainliners.org>
1 parent 5b45748 commit 568f6aa

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/bluetooth.vala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,7 @@ public interface Bluetooth: Object
5555

5656
public abstract string get_device_name (ObjectPath path);
5757

58+
public signal void agent_manager_ready ();
59+
5860
public abstract void add_agent (string path);
5961
}

src/bluez.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public class Bluez: Bluetooth, Object
122122
{
123123
manager = bus.get_proxy_sync (BLUEZ_BUSNAME, "/");
124124
agent_manager = bus.get_proxy_sync (BLUEZ_BUSNAME, "/org/bluez");
125-
add_agent ("/agent");
125+
agent_manager_ready ();
126126

127127
// Find the adapters and watch for changes
128128
manager.interfaces_added.connect ((object_path, interfaces_and_properties) => {

src/service.vala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class Service: Object
2929
private MainLoop loop;
3030
private SimpleActionGroup actions;
3131
private HashTable<string,Profile> profiles;
32-
private Bluetooth bluez;
32+
private Bluetooth bluetooth;
3333
private DBusConnection connection;
3434
private uint exported_action_id;
3535
private const string OBJECT_PATH = "/org/ayatana/indicator/bluetooth";
@@ -50,10 +50,10 @@ public class Service: Object
5050
}
5151
}
5252

53-
public Service (Bluetooth bluetooth)
53+
public Service (Bluetooth bluetooth_service)
5454
{
5555
actions = new SimpleActionGroup ();
56-
bluez = bluetooth;
56+
bluetooth = bluetooth_service;
5757

5858
profiles = new HashTable<string,Profile> (str_hash, str_equal);
5959
profiles.insert ("phone", new Phone (bluetooth, actions));
@@ -83,6 +83,10 @@ public class Service: Object
8383
null,
8484
null);
8585

86+
bluetooth.agent_manager_ready.connect (() => {
87+
bluetooth.add_agent ("/agent");
88+
});
89+
8690
loop = new MainLoop (null, false);
8791
loop.run ();
8892

@@ -97,7 +101,7 @@ public class Service: Object
97101
{
98102
try
99103
{
100-
connection.register_object ("/agent", new Agent (bluez));
104+
connection.register_object ("/agent", new Agent (bluetooth));
101105
}
102106
catch (GLib.IOError pError)
103107
{

0 commit comments

Comments
 (0)