~ubuntu-branches/ubuntu/maverick/vdr-plugin-live/maverick

« back to all changes in this revision

Viewing changes to recordings.h

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Schmidt
  • Date: 2007-07-02 21:02:17 UTC
  • Revision ID: james.westby@ubuntu.com-20070702210217-d34t69xf1qosqgvc
Tags: upstream-0.1.0
ImportĀ upstreamĀ versionĀ 0.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef VDR_LIVE_RECORDINGS_H
 
2
#define VDR_LIVE_RECORDINGS_H
 
3
 
 
4
#include <ctime>
 
5
#include <map>
 
6
#include <vector>
 
7
#include <boost/shared_ptr.hpp>
 
8
#include <vdr/recording.h>
 
9
 
 
10
namespace vdrlive {
 
11
 
 
12
        // Forward declations from epg_events.h
 
13
        class EpgEvent;
 
14
        typedef boost::shared_ptr<EpgEvent> EpgEventPtr;
 
15
 
 
16
        class RecordingsManager;
 
17
        typedef boost::shared_ptr<RecordingsManager> RecordingsManagerPtr;
 
18
 
 
19
        class RecordingsManager
 
20
        {
 
21
                friend RecordingsManagerPtr LiveRecordingsManager();
 
22
 
 
23
                public:
 
24
                        /**
 
25
                         *      generates a Md5 hash from a cRecording entry. It can be used
 
26
                         *  to reidentify a recording.
 
27
                         */
 
28
                        std::string Md5Hash(const cRecording* recording) const;
 
29
 
 
30
                        /**
 
31
                         *  fetches a cRecording from VDR's Recordings collection. Returns
 
32
                         *  NULL if recording was not found
 
33
                         */
 
34
                        const cRecording* GetByMd5Hash(const std::string& hash) const;
 
35
 
 
36
                private:
 
37
                        RecordingsManager();
 
38
 
 
39
                        cThreadLock m_recordingsLock;
 
40
        };
 
41
 
 
42
 
 
43
        class RecordingsTree
 
44
        {
 
45
                public:
 
46
 
 
47
                        class RecordingsItem;
 
48
 
 
49
                        typedef boost::shared_ptr< RecordingsItem > RecordingsItemPtr;
 
50
                        typedef std::multimap< std::string, RecordingsItemPtr > Map;
 
51
 
 
52
                        class RecordingsItem
 
53
                        {
 
54
                                friend class RecordingsTree;
 
55
 
 
56
                                public:
 
57
                                        virtual ~RecordingsItem();
 
58
 
 
59
                                        virtual time_t StartTime() const = 0;
 
60
                                        virtual bool IsDir() const = 0;
 
61
                                        virtual bool IsArchived() const = 0;
 
62
                                        virtual const std::string& Name() const { return m_name; }
 
63
                                        virtual const std::string Id() const = 0;
 
64
                                        virtual const std::string ArchiveId() const = 0;
 
65
 
 
66
                                        virtual const cRecording* Recording() const { return 0; }
 
67
                                        virtual const cRecordingInfo* RecInfo() const { return 0; }
 
68
 
 
69
                                protected:
 
70
                                        RecordingsItem(const std::string& name);
 
71
 
 
72
                                private:
 
73
                                        std::string m_name;
 
74
                                        Map m_entries;
 
75
                        };
 
76
 
 
77
                        class RecordingsItemDir : public RecordingsItem
 
78
                        {
 
79
                                public:
 
80
                                        RecordingsItemDir();
 
81
                                        RecordingsItemDir(const std::string& name, int level);
 
82
 
 
83
                                        virtual ~RecordingsItemDir();
 
84
 
 
85
                                        virtual time_t StartTime() const { return 0; }
 
86
                                        virtual bool IsDir() const { return true; }
 
87
                                        virtual bool IsArchived() const { return false; }
 
88
                                        virtual const std::string Id() const { std::string e; return e; }
 
89
                                        virtual const std::string ArchiveId() const { std::string e; return e; }
 
90
 
 
91
                                private:
 
92
                                        int m_level;
 
93
                        };
 
94
 
 
95
                        class RecordingsItemRec : public RecordingsItem
 
96
                        {
 
97
                                public:
 
98
                                        RecordingsItemRec(const std::string& id, const std::string& name, cRecording* recording);
 
99
 
 
100
                                        virtual ~RecordingsItemRec();
 
101
 
 
102
                                        virtual time_t StartTime() const;
 
103
                                        virtual bool IsDir() const { return false; }
 
104
                                        virtual bool IsArchived() const ;
 
105
                                        virtual const std::string Id() const { return m_id; }
 
106
                                        virtual const std::string ArchiveId() const;
 
107
 
 
108
                                        virtual const cRecording* Recording() const { return m_recording; }
 
109
                                        virtual const cRecordingInfo* RecInfo() const { return m_recording->Info(); }
 
110
 
 
111
                                private:
 
112
                                        cRecording *m_recording;
 
113
                                        std::string m_id;
 
114
                        };
 
115
 
 
116
                        RecordingsTree(RecordingsManagerPtr recManPtr);
 
117
 
 
118
                        virtual ~RecordingsTree();
 
119
 
 
120
                        Map::iterator begin(const std::vector< std::string >& path);
 
121
                        Map::iterator end(const std::vector< std::string >&path);
 
122
 
 
123
                        int MaxLevel() const { return m_maxLevel; }
 
124
 
 
125
                        static EpgEventPtr CreateEpgEvent(const RecordingsItemPtr recItem);
 
126
 
 
127
                private:
 
128
                        int m_maxLevel;
 
129
                        RecordingsItemPtr m_root;
 
130
                        RecordingsManagerPtr m_recManPtr;
 
131
 
 
132
                        Map::iterator findDir(RecordingsItemPtr& dir, const std::string& dirname);
 
133
        };
 
134
 
 
135
        /**
 
136
         *      return singleton instance of RecordingsManager as a shared Pointer.
 
137
         *  This ensures that after last use of the RecordingsManager it is
 
138
         *  deleted. After deletion of the original RecordingsManager a repeated
 
139
         *  call to this function creates a new RecordingsManager which is again
 
140
         *      kept alive as long references to it exist.
 
141
         */
 
142
        RecordingsManagerPtr LiveRecordingsManager();
 
143
 
 
144
} // namespace vdrlive
 
145
 
 
146
#endif // VDR_LIVE_RECORDINGS_H