/*
 * Softcam plugin to VDR (C++)
 *
 * This code is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
 */

#ifndef ___CAM_H
#define ___CAM_H

#include "filter.h"

// ----------------------------------------------------------------

class cDevice;
class cChannel;
class cSystem;
class cEcmData;
class cEcmInfo;
class cLogger;

// ----------------------------------------------------------------

class cCam : public cAction {
private:
  int cardNum;
  cDevice *device;
  int camDev;
  bool softCSA, ff;
  //
  int prg, source, transponder, newprg, newSource, newTransponder;
  int ignorePrg, ignoreSource, ignoreTransponder;
  cSystem *sys;
  cFilter *filter;
  int lastPri;
  bool sync, noKey;
  int mode, lastsync, startecm;
  unsigned char parity;
  int count, resendTime, receive, switchTime;
  //
  cList<cEcmInfo> ecmList;
  cEcmInfo *ecm;
  //
  cLogger *logger;
  int loggerTime;
  cEcmInfo *loggerEcm;
  cSystem *loggerSys;
  //
  unsigned char lastEvenCW[8], lastOddCW[8];
  int dolog;
#ifdef DEBUG_TURN
  int turns;
#endif
  //
  void WriteCW(int index, bool resend);
  void SetLogger(cEcmInfo *e, bool force=false);
  void DeleteLogger(void);
  void DeleteSys(void);
  cEcmInfo *NewEcm(void);
  cEcmInfo *JumpEcm(void);
  void StopEcm(void);
  bool UpdateEcm(void);
  void EcmOk(void);
  void EcmFail(void);
  void ParseCAInfo(void);
protected:
  virtual void Process(cFilter *filter, unsigned char *data, int len);
public:
  cCam(const cDevice *dev, int CardNum, int CamDev);
  virtual ~cCam();
  void SetChannel(int Prg, int Source=0, int Transponder=0);
  int ProvidesCa(const unsigned short *ids);
  void IgnoreChannel(int Prg, int Source, int Transponder);
  int CurrentPrg(void) { return prg; }
  char *CurrentKeyStr(void);
  };

#endif // ___CAM_H
