简体   繁体   中英

Vala DBus interface objects how should i register property changes?

So when writing a vala interface for DBus it inherits from Object. yet, most of the properties are like this: public string name { owned get; } public string name { owned get; } as far as i can tell that means that Notify never fires if its value is changed (which i assume it can be, as it reflects an interface in dbus, which most certainly does change.)

sample:

[DBus (name ="org.bluez.Device1")]
public interface Device : Object{

    [DBus (name = "Connected")]
    public abstract bool connected { owned get; }

    [DBus (name = "Connect")]
    public abstract void connect();

    [DBus (name = "Disconnect")]
    public abstract void disconnect();    
}

public void print_device_status(Device device){
    if(device.connected){
        stdout.printf("Device is connected");
    }else{
        stdout.printf("device is disconnected!");
    }
}

int main(string[] args){

    string mac = "dev_14_A5_1A_7F_61_08";


    Device device = Bus.get_proxy_sync(BusType.SYSTEM, "org.bluez", string.join("/","/org/bluez/hci0", mac));

    string message = "";

    device.notify.connect(() => ( print_device_status(device) ));

    if(device.connected){
        device.disconnect();
    }

    device.connect();

    device.disconnect();

    return 0;
}

Compile command: valac --pkg gio-2.0 <file name> -o test

The connect and disconnect methods work as expected, print_device_status is never called. I can only assume it is because notify never fires, and I assume this is because there are no setters on the properties.

I know i can make DBusProxy objects and keep an eye on property changes in those, but that does not quite feel right either.

What is the 'correct' way to solve this?

You should check if that property emits a notification signal by calling org.freedesktop.DBus.Introspectable.Introspect , then you can connect to the org.freedesktop.DBus.Properties.PropertiesChanged DBus signal. More info in the official specification and the Vala samples

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM