// DeviceProximity is an event fired when fresh data is available from a
// proximity sensor (indicates an approximated distance between the device and
// a nearby object).
//
// https://developer.mozilla.org/docs/Web/Events/deviceproximity
349678
func DeviceProximity(listener func(*vecty.Event)) *vecty.EventListener {
	return &vecty.EventListener{Name: "deviceproximity", Listener: listener}
}
337791
func MinProximityEqual(o1, o2 *MinProximityOption) bool {
	if o1 != nil {
		return o1.Equal(o2)
	}
	if o2 != nil {
		return o2.Equal(o1)
	}
	return true
}
264791
func (addr *Address) Device() (*LinkLayerDevice, error) {
	return addr.machineProxy().LinkLayerDevice(addr.doc.DeviceName)
}
718128
func (m *model) DeviceStatistics() map[string]stats.DeviceStatistics {
	res := make(map[string]stats.DeviceStatistics)
	for id := range m.cfg.Devices() {
		res[id.String()] = m.deviceStatRef(id).GetStatistics()
	}
	return res
}
281175
func (ops *vsphereOps) DevicePath(diskPath string) (string, error) {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	vmObj, err := ops.renewVM(ctx, ops.vm)
	if err != nil {
		return "", err
	}

	attached, err := vmObj.IsDiskAttached(ctx, diskPath)
	if err != nil {
		return "", fmt.Errorf("failed to check if disk: %s is attached on vm: %s. err: %v",
			diskPath, vmObj.Name(), err)
	}

	if !attached {
		return "", fmt.Errorf("disk: %s is not attached on vm: %s", diskPath, vmObj.Name())
	}

	diskUUID, err := vmObj.Datacenter.GetVirtualDiskPage83Data(ctx, diskPath)
	if err != nil {
		logrus.Errorf("failed to get device path for disk: %s on vm: %s", diskPath, vmObj.Name())
		return "", err
	}

	return path.Join(diskByIDPath, diskSCSIPrefix+diskUUID), nil
}
331633
func ParseDeviceTopic(topic string) (*DeviceTopic, error) {
	pattern := regexp.MustCompile("^([0-9a-z](?:[_-]?[0-9a-z]){1,35}|\\+)/(devices)/([0-9a-z](?:[_-]?[0-9a-z]){1,35}|\\+)/(events|up|down)([0-9a-z/]+)?$")
	matches := pattern.FindStringSubmatch(topic)
	if len(matches) < 5 {
		return nil, fmt.Errorf("Invalid topic format")
	}
	var appID string
	if matches[1] != simpleWildcard {
		appID = matches[1]
	}
	var devID string
	if matches[3] != simpleWildcard {
		devID = matches[3]
	}
	topicType := DeviceTopicType(matches[4])
	deviceTopic := &DeviceTopic{appID, devID, topicType, ""}
	if (topicType == DeviceUplink || topicType == DeviceEvents) && len(matches) > 5 {
		deviceTopic.Field = strings.Trim(matches[5], "/")
	}
	return deviceTopic, nil
}
868603
func convertProtoDeviceStats(in *proto.DeviceStats) *DeviceStats {
	if in == nil {
		return nil
	}

	ts, err := ptypes.Timestamp(in.Timestamp)
	if err != nil {
		return nil
	}

	return &DeviceStats{
		Summary:   structs.ConvertProtoStatValue(in.Summary),
		Stats:     structs.ConvertProtoStatObject(in.Stats),
		Timestamp: ts,
	}
}
88879
func (ctx *Ctx) CurrentDevice() (device Device, err error) {
	return ctx.device, nil
}
1300519
func (d *Executor) LocalDevices(
	ctx types.Context,
	opts *types.LocalDevicesOpts) (*types.LocalDevices, error) {
	return &types.LocalDevices{
		Driver: Name,
		DeviceMap: map[string]string{
			"/dev/xvda": "/var/log",
			"/dev/xvdb": "/home",
			"/dev/xvdc": "/net/share",
			"/dev/xvdd": "/var/lib/backup",
		},
	}, nil
}
776466
func DeviceOrientation(listener func(*vecty.Event)) *vecty.EventListener {
	return &vecty.EventListener{Name: "deviceorientation", Listener: listener}
}
205024
func convertProtoDevice(in *proto.DetectedDevice) *Device {
	if in == nil {
		return nil
	}

	return &Device{
		ID:         in.ID,
		Healthy:    in.Healthy,
		HealthDesc: in.HealthDescription,
		HwLocality: convertProtoDeviceLocality(in.HwLocality),
	}
}
629224
func DeviceLight(listener func(*vecty.Event)) *vecty.EventListener {
	return &vecty.EventListener{Name: "devicelight", Listener: listener}
}
476360
func LocalDevices(
	ctx types.Context,
	opts *types.LocalDevicesOpts) (*types.LocalDevices, error) {

	f, err := os.Open(procPartitions)
	if err != nil {
		return nil, goof.WithError("error reading "+procPartitions, err)
	}
	defer f.Close()

	devMap := map[string]string{}

	scanner := bufio.NewScanner(f)
	for scanner.Scan() {
		fields := strings.Fields(scanner.Text())
		if len(fields) != 4 {
			continue
		}
		devName := fields[3]
		if !xvdRX.MatchString(devName) {
			continue
		}
		devPath := path.Join("/dev/", devName)
		devMap[devPath] = devPath
	}

	ld := &types.LocalDevices{Driver: fittedcloud.Name}
	if len(devMap) > 0 {
		ld.DeviceMap = devMap
	}

	return ld, nil
}
487973
func NewDeviceAllocator(lastIndex int) DeviceAllocator {
	possibleDevices := []mountDevice{}
	for _, firstChar := range []rune{'b', 'c'} {
		for i := 'a'; i <= 'z'; i++ {
			dev := mountDevice([]rune{firstChar, i})
			possibleDevices = append(possibleDevices, dev)
		}
	}
	return &deviceAllocator{
		possibleDevices: possibleDevices,
		lastIndex:       lastIndex,
	}
}
477610
func (n *nvmlDriver) DeviceInfoByIndex(index uint) (*DeviceInfo, error) {
	device, err := nvml.NewDevice(index)
	if err != nil {
		return nil, err
	}
	deviceMode, err := device.GetDeviceMode()
	if err != nil {
		return nil, err
	}
	return &DeviceInfo{
		UUID:               device.UUID,
		Name:               device.Model,
		MemoryMiB:          device.Memory,
		PowerW:             device.Power,
		BAR1MiB:            device.PCI.BAR1,
		PCIBandwidthMBPerS: device.PCI.Bandwidth,
		PCIBusID:           device.PCI.BusID,
		CoresClockMHz:      device.Clocks.Cores,
		MemoryClockMHz:     device.Clocks.Memory,
		DisplayState:       deviceMode.DisplayInfo.Mode.String(),
		PersistenceMode:    deviceMode.Persistence.String(),
	}, nil
}
815197
func convertProtoDevices(in []*proto.DetectedDevice) []*Device {
	if in == nil {
		return nil
	}

	out := make([]*Device, len(in))
	for i, d := range in {
		out[i] = convertProtoDevice(d)
	}

	return out
}
1308112
func (device *Device) status() error {
	ret := Status(C.cairo_device_status(device.Ptr)).toError()
	return ret
}