/*
 * (c) 2005 Research Group Dr. Fuhrmann, University of Karlsruhe, Germany
 * All rights reserved.
 *
 * Author:
 *         Stefan Denk <denk@ira.uka.de>
 *         Kendy Kutzner <kutzner@ira.uka.de>
 *
 * $Id: clientthread.h,v 1.5 2006/01/05 10:31:45 denk Exp $
 *
 */

#ifndef _CLIENTTHREAD_H_
#define _CLIENTTHREAD_H_

// vdr
#include <thread.h>
#include <channels.h>

// vidtrans
#include "videosource.h"
#include "vtmain.h"

/** One client.
 * Contact the server and gets one (part of a) file.
 * Talks to csubserverthread on the other end.
 */

class clientthread : public cThread {
	public:
		/// Construct a client thread.
		clientthread(time_t start, time_t stop, const cChannel * channel, cvideosource source, int threadnumber, int total, const char * name);
		/// return a socket file descriptor (protocol independent - both IPv4 and IPv6 work)
		int tcp_connect(const char *hostname, const char *port);
		void Action();
		/**
		 * State of the thread
		 */
		enum status {
			running,    ///< Thread was started and is running now.
			successful, ///< Thread has sucessfully finished its task. Thread is not running any more.
			failure,    ///< Thread has unsucessfully finished its task. Thread is not running any more.
		};
		/// Fetch the state
		status state(){return _state;}
		///\bug are these really needed?
		void setstate(status st){_state = st;}
		string getchannelname(){return _channel->Name();}
		time_t getstarttime(){return _start;}
		int getthreadnumber(){return _threadnumber;}
	private:
		/// Save start time.
		time_t _start;
		time_t _stop;
		const cChannel * _channel;
		cvideosource _source;
		status _state;
		int _threadnumber;
		int _total;
		/// In this directory the recording will be saved.
		const char * _dldir;
		const char * _name;
		/// Copy the download directory from the main thread.
		void copydownloaddir();
};



#endif // _CLIENTTHREAD_H_
