Ejemplo n.º 1
0
// ParentWithSubsystemDevtype returns the parent Device with the given subsystem and devtype,
// or nil if the receiver has no such parent device
func (d *Device) ParentWithSubsystemDevtype(subsystem, devtype string) *Device {
	d.lock()
	defer d.unlock()
	ss, dt := C.CString(subsystem), C.CString(devtype)
	defer freeCharPtr(ss)
	defer freeCharPtr(dt)
	ptr := C.udev_device_get_parent_with_subsystem_devtype(d.ptr, ss, dt)
	if ptr != nil {
		C.udev_device_ref(ptr)
	}
	return d.u.newDevice(ptr)
}
Ejemplo n.º 2
0
func (self Device) ParentWithSubsystemDevType(subsystem string, devtype string) (device Device, err error) {
	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 device, Error{"udev_device_new_from_syspath"}
	}
	defer C.udev_device_unref(udev_device)

	// parent
	cSubsystem := C.CString(subsystem)
	defer C.free(unsafe.Pointer(cSubsystem))

	var cDevType *C.char
	if devtype != "" {
		cDevType = C.CString(devtype)
		defer C.free(unsafe.Pointer(cDevType))
	}

	udev_parent := C.udev_device_get_parent_with_subsystem_devtype(udev_device, cSubsystem, cDevType)
	if udev_parent == nil {
		return device, Error{"udev_device_get_parent"}
	}
	// lifetime tied to udev_device

	// return
	if err := device.fromUdev(udev_parent); err != nil {
		return device, err
	}

	return device, nil
}
Ejemplo n.º 3
0
Archivo: udev.go Proyecto: jessta/udev
func (d Device) ParentWithSubsystemDevType(subsystem string, devType string) Device {
	return Device{C.udev_device_get_parent_with_subsystem_devtype(d.ptr, C.CString(subsystem), C.CString(devType))}
}