package org.bucksch.zeipis.recorder;
import java.io.IOException;

import org.bucksch.zeipis.all.Util;

public class DVBCAShell implements DVBCA
{
  public void start(final DVBCard card, final DVBChannel channel)
    throws CantUseTVCard
  {
    if (card.myDeviceNumber < 0 || card.myDeviceNumber > 9)
       throw new CantUseTVCard("DVB adapter number " + card.myDeviceNumber + " is wrong"); // TODO Misconfiguration()
    Util.debug("Starting CA for DVB card " + card.id() + ", service id " + channel.serviceID);
    try {
      myProcess = Runtime.getRuntime().exec("./JNI/dvbca/ca -adapter " + card.myDeviceNumber + " -serviceid " + channel.serviceID);
    } catch (IOException e) { throw new CantUseTVCard("Could not start 'ca' shell program (to decrypt the channel). It came with zeipis and should be in ./JNI/dvbca/ca (from current directory).", e); }
  }
  public void stop()
    throws CantUseTVCard
  {
    Util.debug("Closing CA");
    myProcess.destroy();
  }
  
  // Data
  protected Process myProcess = null;
}
