/*
 * dispatcher.h
 */

#ifndef __DISPATCHER_H
#define __DISPATCHER_H

#include "audioreceiver.h"

#include <vdr/device.h>
#include <vdr/thread.h>
#include <vdr/status.h>


class cDispatcher : public cThread, cStatus {
private:
        bool active;
        int counter;
        cAudioReceiver **audioreceivers;
        
        void attach_receivers(void);
        
        int get_transponder_of_first_receiver(int device_number);
	/*
	 * returns the transponder of the first attached audioreceiver on the
	 * given device
	 */
        void detach_receivers(int detach_device_number, int devices_remaining);
        /*
         * detaches all audioreceivers on the given device_number, until
         * devices_remaining are remaining.
         * if detach_device_number == -1, all audioreceivers are
         * detached.
         */
        
        bool check_free_disc_space(void);
protected:
        virtual void Activate(bool on);
        virtual void Action(void);
        
        virtual void ChannelSwitch(const cDevice *device, int channel_number);
public:
	cDispatcher(void);
	~cDispatcher();
        
        void stop(void) { Activate(false); }
        void start(void) { Activate(true); }
        bool is_active(void) { return active; }
        
        int get_recording_receivers(void);
        int get_recording_status(const cChannel *channel);
        int get_attached_receivers(int device_number);
        /*
         * returns the number of the attached audioreceivers on the given
         * device. if device_number == -1, the number of all attached
         * audioreceivers is returned.
         */
};

#endif /* __DISPATCHER_H */
