#ifndef PROCESS_H
#define PROCESS_H

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

#include <stdio.h>
#include <stdlib.h>
#include "String.h"

class Process {
	int argsNum, envsNum;
	char *args[256];
	char *envs[10];
	pid_t pid;
	int result;
	int outPipe[2], inPipe[2], errPipe[2];
	class LineReader *inStream;
	FILE *protoStream;
public:
	Process(const char *fileName);
	Process(String &fileName) { init(fileName.getBytes()); }
	~Process();
	void addArg(const char *format, ...);
	void addArg(String &str);
	void addArgs(const char *args);
	void addArgs(String &args) { addArgs(args.getBytes()); }
	void closePipeToChild();
	int getErrorStream();
	int getInputStream();
	int getOutputStream();
	pid_t getPID() { return pid; }
	int getResult();
	int isLineAvailable();
	int read(char *buf, int count);
	virtual const char *readLine(int timeout = 0);
	int run();
	void select();
	void sendTerminateSignal();
	void setInputStream(int fd);
	void setProtoFile(const char *fileName);
	void show();
	void start(const char *workDirName = NULL, int splitOut = 0);
	void terminate();
	const char *toString(char *str);
	int write(const char *buf, int count);

private:
	void closePipes();
	void init(const char *fileName);
};

#endif
