private Driver buildMergedDriver(PiPipeconfId pipeconfId, String baseDriverName, String newDriverName) { final Driver baseDriver = getDriver(baseDriverName); if (baseDriver == null) { log.error("Base driver {} not found, cannot build a merged one", baseDriverName); return null; } final PiPipeconf pipeconf = pipeconfs.get(pipeconfId); if (pipeconf == null) { log.error("Pipeconf {} is not registered, cannot build a merged driver", pipeconfId); return null; } // extract the behaviours from the pipipeconf. final Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours = new HashMap<>(); pipeconf.behaviours().forEach( b -> behaviours.put(b, pipeconf.implementation(b).get())); final Driver piPipeconfDriver = new DefaultDriver( newDriverName, baseDriver.parents(), baseDriver.manufacturer(), baseDriver.hwVersion(), baseDriver.swVersion(), behaviours, new HashMap<>()); // take the base driver created with the behaviours of the PiPeconf and // merge it with the base driver that was assigned to the device return piPipeconfDriver.merge(baseDriver); }
private void printDriver(Driver driver, boolean first) { if (outputJson()) { json(driver); } else if (nameOnly) { print("%s", driver.name()); } else { List<Driver> parents = Optional.ofNullable(driver.parents()) .orElse(ImmutableList.of()); List<String> parentsNames = parents.stream() .map(Driver::name).collect(Collectors.toList()); if (first) { print(FMT, driver.name(), parentsNames, driver.manufacturer(), driver.hwVersion(), driver.swVersion()); } else { print(" Inherited from %s", driver.name()); } driver.behaviours().forEach(b -> printBehaviour(b, driver)); driver.properties().forEach((k, v) -> print(FMT_P, k, v)); //recursion call to print each parent parents.stream().forEach(parent -> printDriver(parent, false)); } }