package org.bucksch.zeipis.recorder;

public class DVBTunerShell implements DVBTuner
{
  public DVBTunerShell(DVBCard card)
    throws CantUseTVCard
  {
    myDevice = card;
  }
  public void tuneTo(DVBChannel channel)
    throws CantUseTVCard
  {
    if (myProcess != null)
      throw new CantUseTVCard("Can't tune, card is already in use", new Exception()); // TODO translate

    //XXX String command = "dvbtune -f " + frequency + " -p " + (polarity_v ? "v" : "h") + " -s " + symbolrate + " -c " + myDevice.myDeviceNumber;
    String command = "/usr/bin/szap -r -a " + myDevice.myDeviceNumber + " " + channel.stationShortName();
    //ProcessBuilder pb = new ProcessBuilder("/usr/bin/szap", channel.stationShortName(), "-r", "-a", String.valueOf(myDevice.myDeviceNumber));
    System.out.println("Tuning to " + channel.stationLongName() + " using " + command);
    try {
      myProcess = Runtime.getRuntime().exec(command);
      //myProcess = pb.start();
      System.out.println("Tuned");
    } catch (Exception e) {
      throw new CantUseTVCard("Tuning failed: " + command, e);
    }
  }
  public void done()
  {
    myProcess.destroy();
    myProcess = null;
  }


  // Data
  protected DVBCard myDevice;
  protected Process myProcess = null;
}
