本文整理汇总了Golang中github.com/godbus/dbus.BusObject类的典型用法代码示例。如果您正苦于以下问题:Golang BusObject类的具体用法?Golang BusObject怎么用?Golang BusObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BusObject类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:igalic,项目名称:mgmt,代码行数:33,代码来源:hostname.go
示例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
}
开发者ID:Luit,项目名称:inhibitor,代码行数:9,代码来源:inhibitor.go
示例3: 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
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:19,代码来源:call.go
示例4: PrintList
func PrintList(obj dbus.BusObject) {
files, err := obj.GetProperty(bus_interface + ".Tracks")
if err != nil {
log.Fatalf("Could not retrieve property: %s", err)
}
current, _ := obj.GetProperty(bus_interface + ".TrackPath")
for i, file := range files.Value().([]string) {
var prefix string
if current.Value() != nil && file == current.Value().(string) {
prefix = "*"
} else {
prefix = " "
}
log.Printf("%s %3d:%s\n", prefix, i, file)
}
}
开发者ID:Luminarys,项目名称:grooved,代码行数:20,代码来源:groovectl.go
示例5: uninhibit
func uninhibit(o dbus.BusObject, cookie uint32) {
c := o.Go("org.gnome.SessionManager.Uninhibit", dbus.FlagNoReplyExpected, nil, cookie)
if c.Err != nil {
log.Print(c.Err)
}
}
开发者ID:Luit,项目名称:inhibitor,代码行数:6,代码来源:inhibitor.go
示例6: 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))
}
开发者ID:Luminarys,项目名称:grooved,代码行数:48,代码来源:groovectl.go
注:本文中的github.com/godbus/dbus.BusObject类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论