summaryrefslogtreecommitdiff
path: root/p2pvr/daemon/schedules.h
blob: f1fcde2c7cf80b841338fe96e7987899cfe0b2d8 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef SCHEDULER_H
#define SCHEDULER_H

#include <p2pvr.h>
#include <options.h>
#include <abstractDatabaseClient.h>
#include <factory.h>
#include <intrusivePtrBase.h>
#include <logger.h>

namespace P2PVR {
typedef boost::posix_time::ptime datetime;
class Episode;

class Showing : public IntrusivePtrBase {
	public:
		Showing(unsigned int e, unsigned int t, unsigned int sc, datetime start, datetime stop, int p, const Episode * ep);
		// Record what?
		const Episode * episode;
		const unsigned int eventUid;
		int priority;
		const unsigned int scheduleId;
		// 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 SchedulesI : public Schedules, public IceTray::AbstractDatabaseClient {
	public:
		class Options : public IceTray::Options {
			public:
				Options();

				ICETRAY_OPTIONS_DECLARE;

				std::string SchedulerAlgorithm;
		};

		SchedulesI(IceTray::DatabasePoolPtr);

		void DeleteSchedule(int id, const Ice::Current &);
		SchedulePtr GetSchedule(int id, const Ice::Current &);
		ScheduleList GetSchedules(const Ice::Current &);
		ScheduledToRecordList GetScheduledToRecord(const Ice::Current &);
		Ice::Int NewSchedule(const SchedulePtr &, const Ice::Current &);
		void UpdateSchedule(const SchedulePtr &, const Ice::Current &);
		void DoReschedule(const Ice::Current &);

	protected:
		static void GetEpisodeIntersects(Episodes &, Episodes &);

	private:
		IceTray::OptionsResolver<Options> options;
		static IceTray::Logging::LoggerPtr logger;
};

typedef AdHoc::Factory<EpisodeGroup, const Episodes &> EpisodeGroupFactory;
typedef boost::shared_ptr<EpisodeGroup> EpisodeGroupPtr;
}

#endif