aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bluetooth.vala28
-rw-r--r--src/bluez.vala7
-rw-r--r--src/killswitch.vala23
-rw-r--r--src/main.vala2
4 files changed, 34 insertions, 26 deletions
diff --git a/src/bluetooth.vala b/src/bluetooth.vala
index ad5ee09..b6d0e55 100644
--- a/src/bluetooth.vala
+++ b/src/bluetooth.vala
@@ -17,37 +17,35 @@
* Charles Kerr <charles.kerr@canonical.com>
*/
+/**
+ * Base class for the bluetooth backend.
+ */
public class Bluetooth: Object
{
- /***
- **** Properties
- ***/
-
+ /* whether or not our system can be seen by other bluetooth devices */
public bool discoverable { get; protected set; default = false; }
public virtual void try_set_discoverable (bool b) {}
+ /* whether or not there are any bluetooth adapters powered up on the system */
public bool powered { get; protected set; default = false; }
+ /* whether or not bluetooth's been disabled,
+ either by a software setting or physical hardware switch */
public bool blocked { get; protected set; default = true; }
public virtual void try_set_blocked (bool b) {
- kill_switch.try_set_blocked (b);
+ killswitch.try_set_blocked (b);
}
/***
**** Killswitch Implementation
***/
- protected KillSwitch kill_switch;
+ private KillSwitch killswitch;
- public Bluetooth (KillSwitch kill_switch)
+ public Bluetooth (KillSwitch killswitch)
{
- this.kill_switch = kill_switch;
-
- message ("changing blocked to %d", (int)!this.kill_switch.blocked);
- blocked = this.kill_switch.blocked;
- kill_switch.notify["blocked"].connect (() => {
- message ("bluetooth changing blocked to %d", (int)kill_switch.blocked);
- this.blocked = kill_switch.blocked;
- });
+ this.killswitch = killswitch;
+ blocked = killswitch.blocked;
+ killswitch.notify["blocked"].connect (() => blocked = killswitch.blocked );
}
}
diff --git a/src/bluez.vala b/src/bluez.vala
index 178cc57..0f793cc 100644
--- a/src/bluez.vala
+++ b/src/bluez.vala
@@ -17,16 +17,19 @@
* Charles Kerr <charles.kerr@canonical.com>
*/
+/**
+ * Bluetooth implementaion which uses bluez over dbus
+ */
public class Bluez: Bluetooth
{
private org.bluez.Manager manager;
private org.bluez.Adapter default_adapter;
- public Bluez (KillSwitch kill_switch)
+ public Bluez (KillSwitch killswitch)
{
string default_adapter_object_path = null;
- base (kill_switch);
+ base (killswitch);
try
{
diff --git a/src/killswitch.vala b/src/killswitch.vala
index 92b1a3c..cf5c6c8 100644
--- a/src/killswitch.vala
+++ b/src/killswitch.vala
@@ -20,13 +20,24 @@
/**
* Monitors whether or not bluetooth is blocked,
* either by software (e.g., a session configuration setting)
- * or by hardware (e.g., user disabled it via a physical switch on her laptop)
+ * or by hardware (e.g., user disabled it via a physical switch on her laptop).
+ *
+ * The Bluetooth class uses this as a backend for its 'blocked' property.
+ * Other code can't even see this, so use Bluetooth.blocked instead. :)
*/
public class KillSwitch: Object
{
public bool blocked { get; protected set; default = false; }
- public void try_set_blocked (bool blocked)
+ public virtual void try_set_blocked (bool blocked) {}
+}
+
+/**
+ * On Linux systems, monitors /dev/rfkill to watch for bluetooth blockage
+ */
+public class RfKillSwitch: KillSwitch
+{
+ public override void try_set_blocked (bool blocked)
{
return_if_fail (this.blocked != blocked);
@@ -42,10 +53,6 @@ public class KillSwitch: Object
warning ("Could not write rfkill event: %s", strerror(errno));
}
- /***
- **** Past this point, it's all RfKill implementation details...
- ***/
-
private class Entry
{
public uint32 idx;
@@ -68,13 +75,13 @@ public class KillSwitch: Object
return false;
}
- ~KillSwitch ()
+ ~RfKillSwitch ()
{
Source.remove (watch);
Posix.close (fd);
}
- public KillSwitch ()
+ public RfKillSwitch ()
{
entries = new HashTable<uint32,Entry>(direct_hash, direct_equal);
diff --git a/src/main.vala b/src/main.vala
index 7af617d..89c583b 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -7,7 +7,7 @@ main (string[] args)
Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.GNOMELOCALEDIR);
Intl.textdomain (Config.GETTEXT_PACKAGE);
- var bluetooth = new Bluez (new KillSwitch ());
+ var bluetooth = new Bluez (new RfKillSwitch ());
var service = new BluetoothIndicator (bluetooth);
service.run ();