Example #1
0
// SysattrValue retrieves the content of a sys attribute file, and returns an empty string if there is no sys attribute value.
// The retrieved value is cached in the device.
// Repeated calls will return the same value and not open the attribute again.
func (d *Device) SysattrValue(sysattr string) string {
	d.lock()
	defer d.unlock()
	s := C.CString(sysattr)
	defer freeCharPtr(s)
	return C.GoString(C.udev_device_get_sysattr_value(d.ptr, s))
}
Example #2
0
// Returns nil on device error, missing entry on sysattr error
func (self Device) SysAttrs(sysAttrs ...string) map[string]string {
	udev := C.udev_new()
	defer C.udev_unref(udev)

	cSysPath := C.CString(self.SysPath)
	defer C.free(unsafe.Pointer(cSysPath))

	udev_device := C.udev_device_new_from_syspath(udev, cSysPath)
	if udev_device == nil {
		return nil
	}
	defer C.udev_device_unref(udev_device)

	// get
	out := make(map[string]string)

	for _, sysAttr := range sysAttrs {
		cSysAttr := C.CString(sysAttr)
		defer C.free(unsafe.Pointer(cSysAttr))

		cValue := C.udev_device_get_sysattr_value(udev_device, cSysAttr)
		if cValue == nil {
			continue
		}

		out[sysAttr] = C.GoString(cValue)
	}

	return out
}
Example #3
0
File: udev.go Project: jessta/udev
func (d Device) SysAttrValue(sysattr string) string {
	return C.GoString(C.udev_device_get_sysattr_value(d.ptr, C.CString(sysattr)))
}