/*
 * See the files COPYING and README for copyright information and how to reach
 * the author.
 *
 *  $Id: pipe.h,v 1.2 2006/01/21 19:37:28 lordjaxom Exp $
 */

#ifndef VDR_BURN_PIPE_H
#define VDR_BURN_PIPE_H

#include "common.h"
#include "environment.h"
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <vdr/tools.h>

class cBurnEnvironment;

// --- cBurnPipe --------------------------------------------------------------

class cBurnPipe: public cListObject
{
private:
	cBurnEnvironment  mEnvironment;
	cString           mWorkDir;
	pid_t             mPid;
	int               mPipe;
	bool              mRunning;

protected:
	virtual int Action(void) = 0;

	void PutEnvironment(const char *Name, const char *Value);
	void SetEnvironment(void) { mEnvironment.Set(); }

public:
	cBurnPipe(void);
	~cBurnPipe();

	void SetWorkdir(const char *WorkDir) { mWorkDir = WorkDir; }
	void SetEnvironment(const cBurnEnvironment &Environment);

	bool Launch(FILE *LogFile);
	bool Exit(bool Wait);

	bool IsRunning(void) const { return mRunning; }

	operator int () { return mPipe; }
};

inline void cBurnPipe::PutEnvironment(const char *Name, const char *Value)
{
	mEnvironment.Put(Name, Value);
}

inline void cBurnPipe::SetEnvironment(const cBurnEnvironment &Environment)
{
	mEnvironment = Environment;
}

// --- cBurnPipes -------------------------------------------------------------

class cBurnPipes: public cList<cBurnPipe>
{
};

#endif // VDR_BURN_PIPE_H

