private Driver lookupDriver(String driverName) { if (driverName != null) { try { return getDriver(driverName); } catch (ItemNotFoundException e) { log.warn("Specified driver {} not found, falling back.", driverName); } } return null; }
private Driver getPipeconfMergedDriver(DeviceId deviceId) { PiPipeconfId pipeconfId = pipeconfService.ofDevice(deviceId).orElse(null); if (pipeconfId == null) { log.warn("Missing pipeconf for {}, cannot produce a pipeconf merged driver", deviceId); return null; } String mergedDriverName = pipeconfService.getMergedDriver(deviceId, pipeconfId); if (mergedDriverName == null) { log.warn("Unable to get pipeconf merged driver for {} and {}", deviceId, pipeconfId); return null; } try { return getDriver(mergedDriverName); } catch (ItemNotFoundException e) { log.warn("Specified pipeconf merged driver {} for {} not found", mergedDriverName, deviceId); return null; } }
@Override public DriverHandler createHandler(DeviceId deviceId, String... credentials) { checkPermission(DRIVER_WRITE); Driver driver = getDriver(deviceId); return new DefaultDriverHandler(new DefaultDriverData(driver, deviceId)); }
@Override public Driver getDriver(DeviceId deviceId) { checkPermission(DRIVER_READ); Driver driver; // Special processing for devices with pipeconf. if (pipeconfService.ofDevice(deviceId).isPresent()) { // No fallback for pipeconf merged drivers. Returns null if driver // does not exist. return getPipeconfMergedDriver(deviceId); } // Primary source of driver configuration is the network config. BasicDeviceConfig cfg = networkConfigService.getConfig(deviceId, BasicDeviceConfig.class); driver = lookupDriver(cfg != null ? cfg.driver() : null); if (driver != null) { return driver; } // Secondary source of the driver selection is driver annotation. Device device = nullIsNotFound(deviceService.getDevice(deviceId), NO_DEVICE); driver = lookupDriver(device.annotations().value(DRIVER)); if (driver != null) { return driver; } // Tertiary source of the driver selection is the primordial information // obtained from the device. return nullIsNotFound(getDriver(device.manufacturer(), device.hwVersion(), device.swVersion()), NO_DRIVER); }