Skip to content

Commit

Permalink
Don't use signal select for now
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinresol committed Sep 9, 2021
1 parent 7bc4423 commit 9ddf13e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
4 changes: 2 additions & 2 deletions haxe_libraries/why-dbus.hxml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# @install: lix --silent download "gh://github.com/why-haxe/why-dbus#f84f1971bf49748bb57eef4c06fe1b87c622ea01" into why-dbus/0.0.0/github/f84f1971bf49748bb57eef4c06fe1b87c622ea01
# @install: lix --silent download "gh://github.com/why-haxe/why-dbus#b02b032942338667196c71d811530e5584e06113" into why-dbus/0.0.0/github/b02b032942338667196c71d811530e5584e06113
-lib tink_chunk
-lib tink_xml
-cp ${HAXE_LIBCACHE}/why-dbus/0.0.0/github/f84f1971bf49748bb57eef4c06fe1b87c622ea01/src
-cp ${HAXE_LIBCACHE}/why-dbus/0.0.0/github/b02b032942338667196c71d811530e5584e06113/src
-D why-dbus=0.0.0
1 change: 1 addition & 0 deletions src/org/bluez/GattCharacteristic1.hx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface GattCharacteristic1 {

function readValue(options:Map<String, Variant>):Chunk;
function writeValue(value:Chunk, options:Map<String, Variant>):Void;
// function acquireNotify(options:Map<String, Variant>):Void;
function startNotify():Void;
function stopNotify():Void;
}
37 changes: 17 additions & 20 deletions src/why/bluez/BlueZ.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,25 @@ class BlueZ {
this.destination = cnx.getDestination(DESTINATION);
this.manager = destination.getObject('/').getInterface(org.freedesktop.DBus.ObjectManager);

this.deviceAdded = manager.interfacesAdded.select(tuple -> {
final path = tuple.v0;
final interfaces = tuple.v1;
switch interfaces['org.bluez.Device1'] {
case null: None;
case iface: Some(getDevice(path, iface['Address'].value));
}
this.deviceAdded = new Signal(cb -> {
manager.interfacesAdded.handle((path, interfaces) -> {
switch interfaces['org.bluez.Device1'] {
case null: // skip
case iface: cb(getDevice(path, iface['Address'].value));
}
});
});
this.deviceRemoved = manager.interfacesRemoved.select(tuple -> {
final path = tuple.v0;
final interfaces = tuple.v1;
if(interfaces.contains('org.bluez.Device1')) {
switch devices[path] {
case null:
None;
case device:
devices.remove(path);
Some(device);
this.deviceRemoved = new Signal(cb -> {
manager.interfacesRemoved.handle((path, interfaces) -> {
if(interfaces.contains('org.bluez.Device1')) {
switch devices[path] {
case null: // skip
case device:
devices.remove(path);
cb(device);
}
}
} else {
None;
}
});
});
}

Expand Down
13 changes: 8 additions & 5 deletions tests/Playground.hx
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,13 @@ class Playground {

class EmptyObjectManager implements why.dbus.server.Interface<org.freedesktop.DBus.ObjectManager> {

public final interfacesAdded = Signal.trigger();
public final interfacesRemoved = Signal.trigger();
public final interfacesAdded:why.dbus.server.Signal<ObjectPath, Map<String, Map<String, Variant>>>;
public final interfacesRemoved:why.dbus.server.Signal<ObjectPath, Array<String>>;

public function new() {}
public function new() {
interfacesAdded = null;
interfacesRemoved = null;
}

public function getManagedObjects():tink.core.Promise<Map<ObjectPath, Map<String, Map<String, Variant>>>> {
trace('EmptyObjectManager');
Expand Down Expand Up @@ -216,8 +219,8 @@ class Application implements why.dbus.server.Interface<org.freedesktop.DBus.Obje
public final interfacesRemoved:why.dbus.server.Signal<ObjectPath, Array<String>>;

public function new() {
interfacesAdded = tink.core.Signal.trigger();
interfacesRemoved = tink.core.Signal.trigger();
interfacesAdded = null;
interfacesRemoved = null;
}

public function getManagedObjects():Promise<Map<ObjectPath, Map<String, Map<String, Variant>>>> {
Expand Down

0 comments on commit 9ddf13e

Please sign in to comment.