001/*
002 * To change this license header, choose License Headers in Project Properties.
003 * To change this template file, choose Tools | Templates
004 * and open the template in the editor.
005 */
006package org.anarres.qemu.exec;
007
008import java.util.Arrays;
009import java.util.List;
010import javax.annotation.CheckForNull;
011import javax.annotation.Nonnegative;
012import javax.annotation.Nonnull;
013
014/**
015 *
016 * @author shevek
017 */
018public class QEmuBootOption extends AbstractQEmuOption {
019
020    public static enum BootDevice {
021
022        Floppy0("a"),
023        Floppy1("b"),
024        HardDisk0("c"),
025        HardDisk1("d"),
026        Network0("n"),
027        Network1("o"),
028        Network2("p"),
029        Network3("q");
030        private final String letter;
031        /* pp */ BootDevice(String letter) {
032            this.letter = letter;
033        }
034    }
035
036    public final List<BootDevice> bootDevices;
037    // once
038    @CheckForNull
039    public String splashName;
040    @CheckForNull
041    public Integer splashTime;
042    @CheckForNull
043    public Boolean menu;
044    @CheckForNull
045    public Integer rebootTimeout;
046    @CheckForNull
047    public Boolean strict;
048
049    public QEmuBootOption(List<BootDevice> bootDevices) {
050        this.bootDevices = bootDevices;
051    }
052
053    public QEmuBootOption(BootDevice... bootDevices) {
054        this(Arrays.asList(bootDevices));
055    }
056
057    @Nonnull
058    public QEmuBootOption withSplash(@Nonnull String splashName, @Nonnegative int splashTime) {
059        this.splashName = splashName;
060        this.splashTime = splashTime;
061        return this;
062    }
063
064    @CheckForNull
065    private String toString(@CheckForNull Boolean value) {
066        if (value == null)
067            return null;
068        if (value)
069            return "on";
070        return "off";
071    }
072
073    @Override
074    public void appendTo(List<? super String> line) {
075        StringBuilder buf = new StringBuilder("order=");
076        for (BootDevice bootDevice : bootDevices)
077            buf.append(bootDevice.letter);
078        appendTo(buf, "splash", splashName);
079        appendTo(buf, "splashTime", splashTime);
080        appendTo(buf, "strict", toString(menu));
081        appendTo(buf, "order", rebootTimeout);
082        appendTo(buf, "strict", toString(strict));
083        add(line, "-boot", buf);
084    }
085}