/*
 *
 * SerLEDMonitor.H header file for class SerLEDMonitor
 *
 */
 
 #ifndef SERLLEDMONITOR_H
 #define SERLLEDMONITOR_H

//c - c++
#include "vector"

//vdr 
 #include "vdr/status.h"
 #include "vdr/thread.h"

//this
#include "SerLED.H"

/** @class SerLEDMonitor
    this class gets events from vdr and sets led status
    @author felix@rauscher-muenchen.de
    @data Feb 2006
*/

class SerLEDMonitor : public cStatus
	{
	private:
//=====================private data members=====================================
	//! led status for replay
		std::vector<SerLED *> _replay;
		std::vector<int> _replay_nr;
	//! led for recording
		std::vector<SerLED *> _rec;
		std::vector<int> _rec_nr;
	//! number of devices currently recording
		int _n_rec;
	//! led indicating that all devices are recording
		std::vector<SerLED *> _all_rec;
		std::vector<int> _all_rec_nr;
	//! number of recordings per device
		std::vector<int> _dev_recording;
		bool _all_recording;
	//! led indicating that cutting is in process
		std::vector<SerLED *> _cutting;
		std::vector<int> _cutting_nr;
		bool _cutting_on;
	//! led indicating that color keys are active
		std::vector<SerLED *> _color[4];
		std::vector<int> _color_nr[4];
		bool _color_active[4];
	//! cut watch thread
		pthread_t _cut_watch;
	//! mutex - only one status update is preocessed at once
		cMutex _mutex;
//====================private member functons===================================
		void deactivate(std::vector<SerLED *> &led, std::vector<int> &nr);
		void activate(std::vector<SerLED *> &led, std::vector<int> &nr);
//=====================private static member function===========================
	/** entry point for flash thread 
	    @pram cl pointer to the caling instance of the class
	*/
		static void * ThreadEntry(SerLEDMonitor *cl);
	public:
//==================static const================================================
	//! Color key numbers
		static const unsigned int red=0,
					  green=1,
					  yellow=2,
					  blue=3;
//===================constructor================================================
	/** default constructor */
		SerLEDMonitor();
//===================public member functions====================================
	/** Add status led for replay
	    @param led Pointer to the led class
	    @param nr state number 
	*/
		inline void AddReplayStatus(SerLED *led, int nr)
			{
			_replay.push_back(led);
			_replay_nr.push_back(nr);
			}
	/** Add status led for recording
	    @param led Pointer to the led class
	    @param nr state number 
	*/
		inline void AddRecordStatus(SerLED *led, int nr)
			{
			_rec.push_back(led);
			_rec_nr.push_back(nr);
			}
	/** Add status led for all devices recording
	    @param led Pointer to the led class
	    @param nr state number 
	*/
		inline void AddAllRecordStatus(SerLED *led, int nr)
			{
			_all_rec.push_back(led);
			_all_rec_nr.push_back(nr);
			}
	/** Add status led for cutting
	    @param led Pointer to the led class
	    @param nr state number 
	*/
		inline void AddCuttingStatus(SerLED *led, int nr)
			{
			_cutting.push_back(led);
			_cutting_nr.push_back(nr);
			}
	/** Add status led for active color key
	    @param led Pointer to the led class
	    @param nr state number 
	    @param c color key
	*/
		inline void AddColorStatus(SerLED *led, int nr, int c)
			{
			_color[c].push_back(led);
			_color_nr[c].push_back(nr);
			}
	/** start thread for whaching on cutting */
		void StartCutWatch();
//===================overloaded functions from class cstatus====================
	/** is called when a recording starts or stops*/
	#if defined(VDRVERSNUM) && VDRVERSNUM >= 10344
		void Recording(const cDevice *Device, const char *Name, const char *FileName, bool On);
	#else
		void Recording(const cDevice *Device, const char *Name);
	#endif
	/** is called when a playback starts or stops*/
	#if defined(VDRVERSNUM) && VDRVERSNUM >= 10344	
		void Replaying(const cControl *Device, const char *Name, const char *FileName, bool On);
	#else
		void Replaying(const cControl *Control, const char *Name);
	#endif
	/** is called when color keys are activated or deactivated*/
		void OsdHelpKeys(const char *Red, const char *Green, const char *Yellow, const char *Blue);
	/** is called whed the osd is cleared */
		void OSDClear();
	};
	
#endif
