#ifndef CDRDAO_H
#define CDRDAO_H

/*
 * @(#)Cdrdao.h
 *
 * This file is part of webCDwriter - Network CD Writing.
 *
 * Copyright (C) 2002 Jörg P. M. Haeger
 *
 * webCDwriter is free software. See CDWserver.cpp for details.
 */

#include "CDstate.h"
#include "Config.h"
#include "Process.h"

/**
 * A cdrdao process.
 *
 * @version 20021022
 * @author Jörg P. M. Haeger
 */
class Cdrdao: public Process {
public:
	enum LineType { none, progress };

private:
	enum LineType lineType;
	struct CDstate *CDstate;
	int fifoPercent, MBwritten, MBtotal;

public:
	Cdrdao(const char *command, struct CDstate *CDstate):
		CDstate(CDstate),
		Process(config.getCdrdaoPath()) {
		addArg(command);
	}

	~Cdrdao() {
	}

	int getFifoPercent() {
		return fifoPercent;
	}

	enum LineType getLineType() {
		return lineType;
	}

	void getProgress(int &current, int &total) {
		current = MBwritten;
		total = MBtotal;
	}

	const char *readLine(int timeout = 0) {
		const char *lineStr = Process::readLine(timeout);
		if (lineStr == NULL)
			return NULL;

		lineType = none;
		int a, b, c = 100;

		if (sscanf(lineStr, "%d DATA %d", &a, &b) == 2) {
			if (CDstate != NULL && a == 1)
				CDstate->firstTrackIsData = 1;
		}
		else
		if (sscanf(lineStr, "Wrote %d of %d MB (Buffer %d",
				&a, &b, &c) >= 2) {
			lineType = progress;
			MBwritten = a;
			MBtotal = b;
			fifoPercent = c;
		}

		return lineStr;
	}
};

#endif
