Thomas Vachuska
Committed by Gerrit Code Review

Fixing a discrepancy in driver manager implementation.

Change-Id: I774a3ed26dc6d34d6bdc5834e8e38d4d1741c5ed
......@@ -45,19 +45,17 @@ public class DefaultDriverProvider implements DriverProvider {
}
/**
* Adds the specified driver to the provider.
* Adds the specified driver to the provider. If a driver with the same
* does not exist yet, the specified one will be added. Otherwise, the
* existing driver will be merged with the new one and the result will be
* registered.
*
* @param driver driver to be provided
* @return registered driver
*/
public void addDriver(Driver driver) {
Driver ddc = drivers.get(driver.name());
if (ddc == null) {
// If we don't have the driver yet, just use the new one.
drivers.put(driver.name(), driver);
} else {
// Otherwise merge the existing driver with the new one and rebind.
drivers.put(driver.name(), ddc.merge(driver));
}
public Driver addDriver(Driver driver) {
return drivers.compute(driver.name(), (name, oldDriver) ->
oldDriver == null ? driver : oldDriver.merge(driver));
}
/**
......
......@@ -89,10 +89,10 @@ public class DriverManager extends DefaultDriverProvider implements DriverAdminS
@Override
public void registerProvider(DriverProvider provider) {
provider.getDrivers().forEach(driver -> {
addDrivers(provider.getDrivers());
Driver d = addDriver(driver);
driverByKey.put(key(driver.manufacturer(),
driver.hwVersion(),
driver.swVersion()), driver);
driver.swVersion()), d);
});
providers.add(provider);
}
......@@ -100,7 +100,7 @@ public class DriverManager extends DefaultDriverProvider implements DriverAdminS
@Override
public void unregisterProvider(DriverProvider provider) {
provider.getDrivers().forEach(driver -> {
removeDrivers(provider.getDrivers());
removeDriver(driver);
driverByKey.remove(key(driver.manufacturer(),
driver.hwVersion(),
driver.swVersion()));
......@@ -111,7 +111,6 @@ public class DriverManager extends DefaultDriverProvider implements DriverAdminS
@Override
public Set<Driver> getDrivers() {
checkPermission(DRIVER_READ);
ImmutableSet.Builder<Driver> builder = ImmutableSet.builder();
drivers.values().forEach(builder::add);
return builder.build();
......@@ -120,7 +119,6 @@ public class DriverManager extends DefaultDriverProvider implements DriverAdminS
@Override
public Set<Driver> getDrivers(Class<? extends Behaviour> withBehaviour) {
checkPermission(DRIVER_READ);
return drivers.values().stream()
.filter(d -> d.hasBehaviour(withBehaviour))
.collect(Collectors.toSet());
......@@ -129,7 +127,6 @@ public class DriverManager extends DefaultDriverProvider implements DriverAdminS
@Override
public Driver getDriver(String driverName) {
checkPermission(DRIVER_READ);
return nullIsNotFound(drivers.get(driverName), NO_DRIVER);
}
......@@ -182,7 +179,6 @@ public class DriverManager extends DefaultDriverProvider implements DriverAdminS
@Override
public DriverHandler createHandler(DeviceId deviceId, String... credentials) {
checkPermission(DRIVER_WRITE);
Driver driver = getDriver(deviceId);
return new DefaultDriverHandler(new DefaultDriverData(driver, deviceId));
}
......