Merge pull request #5039 from CEikermann/patch-1
[vuplus_xbmc] / xbmc / epg / EpgDatabase.h
1 #pragma once
2 /*
3  *      Copyright (C) 2012-2013 Team XBMC
4  *      http://xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include "dbwrappers/Database.h"
23 #include "XBDateTime.h"
24
25 namespace EPG
26 {
27   class CEpg;
28   class CEpgInfoTag;
29   class CEpgContainer;
30
31   /** The EPG database */
32
33   class CEpgDatabase : public CDatabase
34   {
35   public:
36     /*!
37      * @brief Create a new instance of the EPG database.
38      */
39     CEpgDatabase(void) {};
40
41     /*!
42      * @brief Destroy this instance.
43      */
44     virtual ~CEpgDatabase(void) {};
45
46     /*!
47      * @brief Open the database.
48      * @return True if it was opened successfully, false otherwise.
49      */
50     virtual bool Open(void);
51
52     /*!
53      * @brief Get the minimal database version that is required to operate correctly.
54      * @return The minimal database version.
55      */
56     virtual int GetSchemaVersion(void) const { return 7; };
57
58     /*!
59      * @brief Get the default sqlite database filename.
60      * @return The default filename.
61      */
62     const char *GetBaseDBName(void) const { return "Epg"; };
63
64     /*! @name EPG methods */
65     //@{
66
67     /*!
68      * @brief Remove all EPG information from the database
69      * @return True if the EPG information was erased, false otherwise.
70      */
71     virtual bool DeleteEpg(void);
72
73     /*!
74      * @brief Delete an EPG table.
75      * @param table The table to remove.
76      * @return True if the table was removed successfully, false otherwise.
77      */
78     virtual bool Delete(const CEpg &table);
79
80     /*!
81      * @brief Erase all EPG entries older than 1 day.
82      * @return True if the entries were removed successfully, false otherwise.
83      */
84     virtual bool DeleteOldEpgEntries(void);
85
86     /*!
87      * @brief Remove a single EPG entry.
88      * @param tag The entry to remove.
89      * @return True if it was removed successfully, false otherwise.
90      */
91     virtual bool Delete(const CEpgInfoTag &tag);
92
93     /*!
94      * @brief Get all EPG tables from the database. Does not get the EPG tables' entries.
95      * @param container The container to fill.
96      * @return The amount of entries that was added.
97      */
98     virtual int Get(CEpgContainer &container);
99
100     /*!
101      * @brief Get all EPG entries for a table.
102      * @param epg The EPG table to get the entries for.
103      * @return The amount of entries that was added.
104      */
105     virtual int Get(CEpg &epg);
106
107     /*!
108      * @brief Get the last stored EPG scan time.
109      * @param iEpgId The table to update the time for. Use 0 for a global value.
110      * @param lastScan The last scan time or -1 if it wasn't found.
111      * @return True if the time was fetched successfully, false otherwise.
112      */
113     virtual bool GetLastEpgScanTime(int iEpgId, CDateTime *lastScan);
114
115     /*!
116      * @brief Update the last scan time.
117      * @param iEpgId The table to update the time for. Use 0 for a global value.
118      * @param bQueueWrite Don't execute the query immediately but queue it if true.
119      * @return True if it was updated successfully, false otherwise.
120      */
121     virtual bool PersistLastEpgScanTime(int iEpgId = 0, bool bQueueWrite = false);
122
123     bool Persist(const CEpgContainer &epg);
124
125     /*!
126      * @brief Persist an EPG table. It's entries are not persisted.
127      * @param epg The table to persist.
128      * @param bQueueWrite Don't execute the query immediately but queue it if true.
129      * @return The database ID of this entry or 0 if bSingleUpdate is false and the query was queued.
130      */
131     virtual int Persist(const CEpg &epg, bool bQueueWrite = false);
132
133     /*!
134      * @brief Persist an infotag.
135      * @param tag The tag to persist.
136      * @param bSingleUpdate If true, this is a single update and the query will be executed immediately.
137      * @return The database ID of this entry or 0 if bSingleUpdate is false and the query was queued.
138      */
139     virtual int Persist(const CEpgInfoTag &tag, bool bSingleUpdate = true);
140
141     /*!
142      * @return Last EPG id in the database
143      */
144     int GetLastEPGId(void);
145
146     //@}
147
148   protected:
149     /*!
150      * @brief Create the EPG database tables.
151      */
152     virtual void CreateTables();
153
154     /*!
155      * @brief Create the EPG database analytics.
156      */
157     virtual void CreateAnalytics();
158
159     /*!
160      * @brief Update an old version of the database.
161      * @param version The version to update the database from.
162      */
163     virtual void UpdateTables(int version);
164     virtual int GetMinSchemaVersion() const { return 4; }
165   };
166 }