
/*
 * See the files COPYING and README for copyright information and how to reach 
 * the author.
 *
 *  $Id: process.h,v 1.2 2004/12/02 15:02:52 lordjaxom Exp $
 */

#ifndef VDR_BURN_PROCESS_H
#define VDR_BURN_PROCESS_H

#include "common.h"
#include <vdr/thread.h>
#include <string.h>

class cBurnJob;

class cBurnProcess:
    public cThread
{
  private:
    eReturnStatus mStatus;
    char *mCmdline;
    BurnProc mProcedure;
    void *mProcData;
    bool mActive;
    bool mBurning;
    bool mVerifying;
    int mProgress;
    int mBurnProgress;
    char *mTempDir;

    int mNumSteps;
    int mCurStep;
    int mSubStep;
    eNextStep mNextStep;

    FILE *mLogFile;

  protected:
    cBurnJob *mJob;
    bool mIsPremastered;

    bool HasNext(void);
    void PutLine(const char *Line);

    virtual void Action(void);
    virtual void Process(int Step, int SubStep, const char *Line) = 0;
    virtual bool Continue(int Step, int SubStep) = 0;

    void SetProgress(int SubSteps, int Percent);
    void SetProgress(int SubSteps, int Subsub, int Subsubs, int Percent);
    void SetCmdline(const char *Format, ...)
        __attribute__ ((format(printf, 2, 3)));
    void SetProcedure(BurnProc Procedure, void *Data);
    void SetStatus(eReturnStatus Status) { mStatus = Status; }
    void SetNextStep(eNextStep Next = nsNext) { mNextStep = Next; }
    void SetBurning(bool Burning, int Progress = 0);
    void SetLogfile(const char *Format, ...)
        __attribute__ ((format(printf, 2, 3)));
    void MakeDirectory(const char *Format, ...)
        __attribute__ ((format(printf, 2, 3)));
    void Execute(const char *Format, ...)
        __attribute__ ((format(printf, 2, 3)));

    virtual double SizeMB();
    virtual void Verify();

    virtual void InitRepeat();
    virtual void SetStep(int Step) { mCurStep = Step; };

  public:
    cBurnProcess(int NumSteps);
    virtual ~cBurnProcess();

    virtual void Repeat();
    virtual void Stop(void);

    int Progress(void) { return mProgress; }
    eReturnStatus Status(void) { return mStatus; }
    bool Burning(int &Progress) const;
    bool Verifying(int &Progress) const;
    bool IsPremastered() { return mIsPremastered; };
    const char *TempDir(void) const { return mTempDir; }
};

#endif // VDR_BURN_PROCESS_H
