示例#1
0
// Set implements org.freedesktop.Properties.Set.
func (p *Properties) Set(iface, property string, newv dbus.Variant) *dbus.Error {
	p.mut.Lock()
	defer p.mut.Unlock()
	m, ok := p.m[iface]
	if !ok {
		return ErrIfaceNotFound
	}
	prop, ok := m[property]
	if !ok {
		return ErrPropNotFound
	}
	if !prop.Writable {
		return ErrReadOnly
	}
	if newv.Signature() != dbus.SignatureOf(prop.Value) {
		return ErrInvalidArg
	}
	if prop.Callback != nil {
		err := prop.Callback(&Change{p, iface, property, newv.Value()})
		if err != nil {
			return err
		}
	}
	p.set(iface, property, newv.Value())
	return nil
}
示例#2
0
func (m *unitMonitor) generateStatus() serviceStatus {
	status := serviceStatus{
		ID:   getLocalIP(),
		Name: m.name,
		Path: m.path,
	}

	var prop dbus.Variant
	prop = m.getProp("ActiveState")
	if prop.Value() != nil {
		status.ActiveState = prop.Value().(string)
	}

	prop = m.getProp("ActiveEnterTimestamp")
	if prop.Value() != nil {
		status.ActiveEnterTimestamp = prop.Value().(uint64)
	}

	prop = m.getProp("ActiveExitTimestamp")
	if prop.Value() != nil {
		status.ActiveExitTimestamp = prop.Value().(uint64)
	}

	prop = m.getProp("InactiveEnterTimestamp")
	if prop.Value() != nil {
		status.InactiveEnterTimestamp = prop.Value().(uint64)
	}

	prop = m.getProp("InactiveExitTimestamp")
	if prop.Value() != nil {
		status.InactiveExitTimestamp = prop.Value().(uint64)
	}

	return status
}