コード例 #1
0
ファイル: hostname.go プロジェクト: igalic/mgmt
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
0
ファイル: inhibitor.go プロジェクト: Luit/inhibitor
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
0
ファイル: groovectl.go プロジェクト: Luminarys/grooved
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
0
ファイル: call.go プロジェクト: Clarifai/kubernetes
// 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
}