Skip to content

Property works with []string but not with []dbus.ObjectPath #240

@yousefvand

Description

@yousefvand
package main

import (
    "fmt"
    "os"

    "github.com/godbus/dbus/v5"
    "github.com/godbus/dbus/v5/introspect"
    "github.com/godbus/dbus/v5/prop"
)

// Type definition of ObjectPath is: type ObjectPath string

func main() {
    conn, err := dbus.SessionBus()
    if err != nil {
        panic(err)
    }
    replyP, errP := conn.RequestName("a.b", dbus.NameFlagDoNotQueue)
    if errP != nil {
        panic(errP)
    }
    if replyP != dbus.RequestNameReplyPrimaryOwner {
        fmt.Fprintln(os.Stderr, "name already taken")
        os.Exit(1)
    }

    propsSpec := map[string]map[string]*prop.Prop{
        "a.b.Test": {
            "Something": {
                Value: []dbus.ObjectPath{}, // PROBLEM
                // Value:    []string{},    // OK
                Writable: false,
            },
        },
    }
    props, err := prop.Export(conn, "/a/b", propsSpec)
    if err != nil {
        _, _ = fmt.Fprintf(os.Stderr, "export propsSpec failed: %v\n", err)
        os.Exit(1)
    }

    var introZ = &introspect.Node{
        Name: "/a/b",
        Interfaces: []introspect.Interface{
            introspect.IntrospectData, prop.IntrospectData,
            {
                Name:       "a.b.Test",
                Properties: props.Introspection("a.b.Test"),
            },
        },
    }

    // Change dbus property
    // props.SetMust("a.b.Test", "Something", []string{"a", "b"}) // OK

    // Change dbus property
    props.SetMust("a.b.Test", "Something",
        []dbus.ObjectPath{dbus.ObjectPath("a"), dbus.ObjectPath("b")}) // PROBLEM

    conn.Export(introspect.NewIntrospectable(&introspect.Node{
        Name: "/a/b",
    }), "/a/b", "org.freedesktop.DBus.Introspectable")

    conn.Export(introspect.NewIntrospectable(introZ), "/a/b",
        "org.freedesktop.DBus.Introspectable")

    fmt.Printf("Listening on %s / %s ...\n", "a.b...", "/a/b...")
    select {} // Don't exit program
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions