001/*
002 * To change this template, choose Tools | Templates
003 * and open the template in the editor.
004 */
005package org.anarres.qemu.exec.recipe;
006
007import javax.annotation.Nonnegative;
008import javax.annotation.Nonnull;
009import org.anarres.qemu.exec.QEmuChardevOption;
010import org.anarres.qemu.exec.QEmuMonitorOption;
011import org.anarres.qemu.exec.host.chardev.CharDevice;
012import org.anarres.qemu.exec.host.chardev.TcpCharDevice;
013import org.anarres.qemu.exec.util.QEmuOptionsList;
014
015/**
016 * A recipe for creating a QEmu monitor speaking the QApi protocol.
017 *
018 * @author shevek
019 */
020public class QEmuMonitorRecipe extends QEmuOptionsList implements QEmuRecipe {
021
022    public final QEmuChardevOption chardevOption;
023    public final QEmuMonitorOption monitorOption;
024
025    /** Creates a QEmuMonitor on a given {@link CharDevice}. */
026    public QEmuMonitorRecipe(@Nonnull CharDevice device) {
027        int index = 0;
028        chardevOption = new QEmuChardevOption(device);
029        chardevOption
030                .withId("monitor-" + index);
031        add(chardevOption);
032        monitorOption = new QEmuMonitorOption(chardevOption);
033        add(monitorOption);
034    }
035
036    /** Creates a QEmuMonitor on a given TCP port. */
037    public QEmuMonitorRecipe(@Nonnegative int port) {
038        this(new TcpCharDevice(port));
039    }
040}