summaryrefslogtreecommitdiff
path: root/p2pvr/lib/schedules.h
blob: caee1f73be46d30f6bf37943f552f3790d78bf75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef SCHEDULER_H
#define SCHEDULER_H

#include <p2pvr.h>
#include <options.h>
#include "dbClient.h"
#include <genLoader.h>

typedef boost::posix_time::ptime datetime;
class Episode;

class Showing : public IntrusivePtrBase {
	public:
		Showing(unsigned int s, unsigned int e, unsigned int t, datetime start, datetime stop, int p, const Episode * ep);
		// Record what?
		const Episode * episode;
		const unsigned int serviceId;
		const unsigned int eventId;
		int priority;
		// Requires
		const unsigned int transportStreamId;
		const datetime startTime;
		const datetime stopTime;
		const boost::posix_time::time_period period;
};
typedef boost::intrusive_ptr<Showing> ShowingPtr;
typedef std::vector<ShowingPtr> Showings;
typedef Showings::const_iterator ShowingsIter;

class Episode : public IntrusivePtrBase {
	public:
		Episode(const std::string & w);
		int priority;
		const std::string what;
		Showings showings;
};
typedef boost::intrusive_ptr<Episode> EpisodePtr;
typedef std::vector<EpisodePtr> Episodes;
typedef Episodes::const_iterator EpisodesIter;

class EpisodeGroup {
	public:
		EpisodeGroup();

		const Showings & Solve();
		unsigned int tuners;

	protected:
		enum SuggestionResult {
			SuggestionInvalid = 0, SuggestionValid = 1, SuggestionValidAndAccepted = 3
		};
		SuggestionResult SuggestWithFeedback(const Showings &);
		void Suggest(const Showings &);
		virtual void SelectShowings() = 0;

	private:
		bool IsShowingListValid(const Showings & showings) const;
		// chosen set
		time_t sumTimeToStart;
		unsigned int score;
		Showings selected;
};

class Schedules : public P2PVR::Schedules, public DatabaseClient {
	public:
		void DeleteSchedule(int id, const Ice::Current &);
		P2PVR::ScheduleList GetSchedules(const Ice::Current &);
		int UpdateSchedule(const P2PVR::SchedulePtr &, const Ice::Current &);
		void DoReschedule(const Ice::Current &);

		INITOPTIONS;
	protected:
		static void GetEpisodeIntersects(Episodes &, Episodes &);
	private:
		static std::string SchedulerAlgorithm;
};

typedef GenLoader<EpisodeGroup, std::string, const Episodes &> EpisodeGroupLoader;
typedef boost::shared_ptr<EpisodeGroup> EpisodeGroupPtr;

#endif