本文整理汇总了Golang中github.com/godbus/dbus.BusObject.Call方法的典型用法代码示例。如果您正苦于以下问题:Golang BusObject.Call方法的具体用法?Golang BusObject.Call怎么用?Golang BusObject.Call使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/godbus/dbus.BusObject
的用法示例。
在下文中一共展示了BusObject.Call方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: updateHostnameProperty
func updateHostnameProperty(object dbus.BusObject, expectedValue, property, setterName string, apply bool) (checkOK bool, err error) {
propertyObject, err := object.GetProperty("org.freedesktop.hostname1." + property)
if err != nil {
return false, errwrap.Wrapf(err, "failed to get org.freedesktop.hostname1.%s", property)
}
if propertyObject.Value() == nil {
return false, errwrap.Errorf("Unexpected nil value received when reading property %s", property)
}
propertyValue, ok := propertyObject.Value().(string)
if !ok {
return false, fmt.Errorf("Received unexpected type as %s value, expected string got '%T'", property, propertyValue)
}
// expected value and actual value match => checkOk
if propertyValue == expectedValue {
return true, nil
}
// nothing to do anymore
if !apply {
return false, nil
}
// attempting to apply the changes
log.Printf("Changing %s: %s => %s", property, propertyValue, expectedValue)
if err := object.Call("org.freedesktop.hostname1."+setterName, 0, expectedValue, false).Err; err != nil {
return false, errwrap.Wrapf(err, "failed to call org.freedesktop.hostname1.%s", setterName)
}
// all good changes should now be applied again
return false, nil
}
示例2: inhibit
func inhibit(o dbus.BusObject, appId, reason string, flags uint32) (cookie uint32) {
c := o.Call("org.gnome.SessionManager.Inhibit", 0, appId, uint32(0), reason, flags)
err := c.Store(&cookie)
if err != nil {
log.Print(err)
return 0
}
return
}
示例3: PrintStatus
func PrintStatus(obj dbus.BusObject) {
title, err := obj.GetProperty(bus_interface + ".TrackTitle")
if err != nil {
log.Fatalf("Could not retrieve property: %s", err)
}
state, err := obj.GetProperty(bus_interface + ".PlaybackStatus")
if err != nil {
log.Fatalf("Could not retrieve property: %s", err)
}
metadata, err := obj.GetProperty(bus_interface + ".TrackMetadata")
if err != nil {
log.Fatalf("Could not retrieve property: %s", err)
}
length, err := obj.GetProperty(bus_interface + ".TrackLength")
if err != nil {
log.Fatalf("Could not retrieve property: %s", err)
}
var pos, percent float64
obj.Call(bus_interface+".TrackPosition", 0).Store(&pos, &percent)
loop, err := obj.GetProperty(bus_interface + ".LoopStatus")
if err != nil {
log.Fatalf("Could not retrieve property: %s", err)
}
log.Printf("Title: %s\n", title.Value().(string))
log.Printf("Tags:\n")
for key, val := range metadata.Value().(map[string]string) {
log.Printf(" %s: %s\n", key, val)
}
pos_time := time.Duration(int64(pos)) * time.Second
len_time := time.Duration(int64(length.Value().(float64))) * time.Second
log.Printf(
"[%s] %s/%s (%.f%%)\n",
state.Value().(string), pos_time.String(), len_time.String(),
percent,
)
log.Printf("loop: %s\n", loop.Value().(string))
}
示例4: Call
// Call calls org.freedesktop.Introspectable.Introspect on a remote object
// and returns the introspection data.
func Call(o dbus.BusObject) (*Node, error) {
var xmldata string
var node Node
err := o.Call("org.freedesktop.DBus.Introspectable.Introspect", 0).Store(&xmldata)
if err != nil {
return nil, err
}
err = xml.NewDecoder(strings.NewReader(xmldata)).Decode(&node)
if err != nil {
return nil, err
}
if node.Name == "" {
node.Name = string(o.Path())
}
return &node, nil
}