/*
 * cache.h
 */

#ifndef __CACHE_H
#define __CACHE_H

#include "xml-cache.h"
#include "trackinfo.h"
#include "column.h"

#include <vdr/thread.h>

#include <list>
#include <string>


class cCache : public cThread {
private:
        bool active;
        
        std::list<cTrackInfo> tracklist;
	std::list<cTrackInfo>::iterator track;
        
        cXmlCache xmlcache;
        
	static const cColumn *sort_order;
        
        static bool sort_tracklist(const cTrackInfo & lhs,
                const cTrackInfo &rhs);
protected:
        virtual void Action(void);
        virtual void Activate(bool on);
public:
	cCache(void);
        ~cCache();
        void load(void);
        void rebuild(void) { Activate(true); }
        bool is_rebuilding(void) { return active; }
        void sort(const cColumn *columns);
        
        void add_track(const cTrackInfo &trackinfo, bool add_xmlcache = true);
        int get_num_cached(void);
        
	const cTrackInfo *get_next_track(bool reset = false);
};

extern cCache Cache;

#endif /* __CACHE_H */
