Skip to content

Commit

Permalink
example: prop.go handle unhandle error
Browse files Browse the repository at this point in the history
 - use prop.Export instead of deprecated prop.New
  • Loading branch information
electricface authored and jsouthworth committed Mar 6, 2021
1 parent 93c7a1a commit 19e024a
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions _examples/prop.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func main() {
panic(err)
}
if reply != dbus.RequestNameReplyPrimaryOwner {
fmt.Fprintln(os.Stderr, "name already taken")
_, _ = fmt.Fprintln(os.Stderr, "name already taken")
os.Exit(1)
}
propsSpec := map[string]map[string]*prop.Prop{
Expand All @@ -54,16 +54,27 @@ func main() {
prop.EmitTrue,
func(c *prop.Change) *dbus.Error {
var foo Foo
dbus.Store([]interface{}{c.Value}, &foo)
err := dbus.Store([]interface{}{c.Value}, &foo)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "dbus.Store foo failed: %v\n", err)
}
fmt.Println(c.Name, "changed to", foo)
return nil
},
},
},
}
f := foo("Bar")
conn.Export(f, "/com/github/guelfey/Demo", "com.github.guelfey.Demo")
props := prop.New(conn, "/com/github/guelfey/Demo", propsSpec)
err = conn.Export(f, "/com/github/guelfey/Demo", "com.github.guelfey.Demo")
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "export f failed: %v\n", err)
os.Exit(1)
}
props, err := prop.Export(conn, "/com/github/guelfey/Demo", propsSpec)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "export propsSpec failed: %v\n", err)
os.Exit(1)
}
n := &introspect.Node{
Name: "/com/github/guelfey/Demo",
Interfaces: []introspect.Interface{
Expand All @@ -76,12 +87,16 @@ func main() {
},
},
}
conn.Export(introspect.NewIntrospectable(n), "/com/github/guelfey/Demo",
err = conn.Export(introspect.NewIntrospectable(n), "/com/github/guelfey/Demo",
"org.freedesktop.DBus.Introspectable")
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "export introspect failed: %v\n", err)
os.Exit(1)
}
fmt.Println("Listening on com.github.guelfey.Demo / /com/github/guelfey/Demo ...")

c := make(chan *dbus.Signal)
conn.Signal(c)
for _ = range c {
for range c {
}
}

0 comments on commit 19e024a

Please sign in to comment.