xbmc
PVRDatabase.h
1 /*
2  * Copyright (C) 2012-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "dbwrappers/Database.h"
12 #include "threads/CriticalSection.h"
13 
14 #include <map>
15 #include <vector>
16 
17 namespace PVR
18 {
19  class CPVRChannel;
20  class CPVRChannelGroup;
21  class CPVRChannelGroupMember;
22  class CPVRChannelGroups;
23  class CPVRProvider;
24  class CPVRProviders;
25  class CPVRClient;
26  class CPVRTimerInfoTag;
27  class CPVRTimers;
28 
31  static constexpr int CHANNEL_COMMIT_QUERY_COUNT_LIMIT = 10000;
32 
33  class CPVRDatabase : public CDatabase
34  {
35  public:
39  CPVRDatabase() = default;
40  ~CPVRDatabase() override = default;
41 
46  bool Open() override;
47 
51  void Close() override;
52 
56  void Lock();
57 
61  void Unlock();
62 
67  int GetSchemaVersion() const override { return 40; }
68 
73  const char* GetBaseDBName() const override { return "TV"; }
74 
77 
82  bool DeleteClients();
83 
89  bool Persist(const CPVRClient& client);
90 
96  bool Delete(const CPVRClient& client);
97 
103  int GetPriority(const CPVRClient& client);
104 
107 
112  bool DeleteChannels();
113 
121  int Get(bool bRadio,
122  const std::vector<std::shared_ptr<CPVRClient>>& clients,
123  std::map<std::pair<int, int>, std::shared_ptr<CPVRChannel>>& results) const;
124 
131  bool Persist(CPVRChannel& channel, bool bCommit);
132 
138  bool QueueDeleteQuery(const CPVRChannel& channel);
139 
141 
144 
150  bool QueueDeleteQuery(const CPVRChannelGroupMember& groupMember);
151 
153 
156 
161  bool DeleteProviders();
162 
169  bool Persist(CPVRProvider& provider, bool updateRecord = false);
170 
176  bool Delete(const CPVRProvider& provider);
177 
184  bool Get(CPVRProviders& results, const std::vector<std::shared_ptr<CPVRClient>>& clients) const;
185 
190  int GetMaxProviderId();
191 
193 
196 
201  bool DeleteChannelGroups();
202 
208  bool Delete(const CPVRChannelGroup& group);
209 
215  int Get(CPVRChannelGroups& results) const;
216 
223  std::vector<std::shared_ptr<CPVRChannelGroupMember>> Get(
224  const CPVRChannelGroup& group,
225  const std::vector<std::shared_ptr<CPVRClient>>& clients) const;
226 
232  bool Persist(CPVRChannelGroup& group);
233 
238  bool ResetEPG();
239 
242 
249  std::vector<std::shared_ptr<CPVRTimerInfoTag>> GetTimers(
250  CPVRTimers& timers, const std::vector<std::shared_ptr<CPVRClient>>& clients) const;
251 
257  bool Persist(CPVRTimerInfoTag& timer);
258 
264  bool Delete(const CPVRTimerInfoTag& timer);
265 
270  bool DeleteTimers();
272 
275 
281  bool UpdateLastWatched(const CPVRChannel& channel);
282 
288  bool UpdateLastWatched(const CPVRChannelGroup& group);
290 
296  bool UpdateLastOpened(const CPVRChannelGroup& group);
298 
299  private:
303  void CreateTables() override;
304  void CreateAnalytics() override;
309  void UpdateTables(int version) override;
310  int GetMinSchemaVersion() const override { return 11; }
311 
312  bool PersistGroupMembers(const CPVRChannelGroup& group);
313 
314  bool PersistChannels(const CPVRChannelGroup& group);
315 
316  bool RemoveChannelsFromGroup(const CPVRChannelGroup& group);
317 
318  mutable CCriticalSection m_critSection;
319  };
320 }
bool Persist(const CPVRClient &client)
Add or update a client entry in the database.
Definition: PVRDatabase.cpp:317
Definition: PVRChannel.h:35
Definition: ContextMenuManager.h:24
bool QueueDeleteQuery(const CPVRChannel &channel)
Remove a channel entry from the database.
Definition: PVRDatabase.cpp:560
bool DeleteChannelGroups()
Remove all channel groups from the database.
Definition: PVRDatabase.cpp:612
Definition: PVRProvider.h:32
bool Delete(const CPVRClient &client)
Remove a client entry from the database.
Definition: PVRDatabase.cpp:332
bool ResetEPG()
Reset all epg ids to 0.
Definition: PVRDatabase.cpp:864
bool Open() override
Open the database.
Definition: PVRDatabase.cpp:115
void Unlock()
Unlock the database.
Definition: PVRDatabase.cpp:132
A container class for channel groups.
Definition: PVRChannelGroups.h:26
bool DeleteProviders()
Remove all providers from the database.
Definition: PVRDatabase.cpp:367
bool UpdateLastOpened(const CPVRChannelGroup &group)
Updates the last opened timestamp for the channel group.
Definition: PVRDatabase.cpp:1002
std::vector< std::shared_ptr< CPVRTimerInfoTag > > GetTimers(CPVRTimers &timers, const std::vector< std::shared_ptr< CPVRClient >> &clients) const
Get the timers.
Definition: PVRDatabase.cpp:1013
Definition: PVRChannelGroupMember.h:23
bool DeleteClients()
Remove all client entries from the database.
Definition: PVRDatabase.cpp:309
CPVRDatabase()=default
Create a new instance of the PVR database.
Definition: Database.h:26
Definition: PVRTimers.h:68
Definition: PVRTimerInfoTag.h:33
bool UpdateLastWatched(const CPVRChannel &channel)
Updates the last watched timestamp for the channel.
Definition: PVRDatabase.cpp:984
void Lock()
Lock the database.
Definition: PVRDatabase.cpp:127
int GetPriority(const CPVRClient &client)
Get the priority for a given client from the database.
Definition: PVRDatabase.cpp:347
Definition: SmartPlayList.cpp:137
int Get(bool bRadio, const std::vector< std::shared_ptr< CPVRClient >> &clients, std::map< std::pair< int, int >, std::shared_ptr< CPVRChannel >> &results) const
Get channels from the database.
Definition: PVRDatabase.cpp:491
Definition: PVRProviders.h:61
Definition: PVRDatabase.h:33
const char * GetBaseDBName() const override
Get the default sqlite database filename.
Definition: PVRDatabase.h:73
int GetMaxProviderId()
Get the maximum provider id in the database.
Definition: PVRDatabase.cpp:481
Definition: PVRChannelGroup.h:46
void Close() override
Close the database.
Definition: PVRDatabase.cpp:121
Definition: PVRClient.h:51
int GetSchemaVersion() const override
Get the minimal database version that is required to operate correctly.
Definition: PVRDatabase.h:67
bool DeleteTimers()
Remove all timer entries from the database.
Definition: PVRDatabase.cpp:1135
bool DeleteChannels()
Remove all channels from the database.
Definition: PVRDatabase.cpp:552