#ifndef VGS_PROCTOOLS_PROCCHAIN_H
#define VGS_PROCTOOLS_PROCCHAIN_H

#include "process.h"

namespace proctools 
{

	class chain
	{
		friend class process;

	public:
		chain(const std::string& name);
		virtual ~chain() {}

		bool run(void);
		void stop(void) { m_active = false; }

		process::status_value return_status(void) const;

	protected:
		virtual bool initialize(void) = 0;
		virtual void process_line(const std::string& message) = 0;
		virtual bool finished(const process* proc) = 0;

		void add_process(process* proc);
		bool del_process(process* proc);

		// tools
		void execute(process& proc);
		void execute(const std::string& cmd);
		void make_dir(const std::string& path);
		void make_fifo(const std::string& fifo);

	private:
		std::string           m_name;
		process::list         m_processes;
		bool                  m_active;
		process::status_value m_returnStatus;
		int                   m_returnCode;
	};

	inline
	process::status_value chain::return_status(void) const
	{
		return m_returnStatus;
	}

}

#endif // VGS_PROCTOOLS_PROCCHAIN_H
