/*
 * (c) 2005 Research Group Dr. Fuhrmann, University of Karlsruhe, Germany
 * All rights reserved.
 *
 * Author:
 *         Stefan Denk <denk@ira.uka.de>
 *
 * $Id: watchdog.h,v 1.3 2005/12/27 12:12:33 kutzner Exp $
 *
 */

#ifndef _WATCHDOG_H_
#define _WATCHDOG_H_

// vdr

#include <thread.h>


/** The speed control.
 * This thread keeps a rough watch over the bytes transferred per second by the subserver threads.
 * Whenever a subserver thread sends out data, it tells watchdog the amount sent and is then put asleep.
 * Every second, asecondpassed is called from vtmain (perpetual timer) to decrement the bytes sent by speedlimit bytes.
 */

class watchdog : public cThread {
	public:
		/** Construct this thread*/
		watchdog(int speedlimit);
		unsigned long getsleeptime(ssize_t bytessent);
		void asecondpassed(void);
		ssize_t incrementbpsused(ssize_t byvalue);
		ssize_t decrementbpsused(ssize_t byvalue);
		ssize_t getbpsused(void);
		cMutex mutex;
		void Action();
	private:
		ssize_t bpsused;
		int _speedlimit;
};


#endif // _WATCHDOG_H_
