kodi
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 44; }
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) const;
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() const;
191 
193 
196 
201  bool DeleteChannelGroups();
202 
208  bool Delete(const CPVRChannelGroup& group);
209 
215  int GetLocalGroups(CPVRChannelGroups& results) const;
216 
223  int Get(CPVRChannelGroups& results,
224  const std::vector<std::shared_ptr<CPVRClient>>& clients) const;
225 
232  std::vector<std::shared_ptr<CPVRChannelGroupMember>> Get(
233  const CPVRChannelGroup& group,
234  const std::vector<std::shared_ptr<CPVRClient>>& clients) const;
235 
241  bool Persist(CPVRChannelGroup& group);
242 
247  bool ResetEPG();
248 
251 
258  std::vector<std::shared_ptr<CPVRTimerInfoTag>> GetTimers(
259  CPVRTimers& timers, const std::vector<std::shared_ptr<CPVRClient>>& clients) const;
260 
266  bool Persist(CPVRTimerInfoTag& timer);
267 
273  bool Delete(const CPVRTimerInfoTag& timer);
274 
279  bool DeleteTimers();
281 
284 
291  bool UpdateLastWatched(const CPVRChannel& channel, int groupId);
292 
298  bool UpdateLastWatched(const CPVRChannelGroup& group);
300 
306  bool UpdateLastOpened(const CPVRChannelGroup& group);
308 
309  private:
313  void CreateTables() override;
314  void CreateAnalytics() override;
319  void UpdateTables(int version) override;
320  int GetMinSchemaVersion() const override { return 11; }
321 
322  int GetGroups(CPVRChannelGroups& results, const std::string& query) const;
323 
324  bool PersistGroupMembers(const CPVRChannelGroup& group);
325 
326  bool PersistChannels(const CPVRChannelGroup& group);
327 
328  bool RemoveChannelsFromGroup(const CPVRChannelGroup& group);
329 
330  mutable CCriticalSection m_critSection;
331  };
332 }
int GetLocalGroups(CPVRChannelGroups &results) const
Get all local channel groups.
Definition: PVRDatabase.cpp:748
bool Persist(const CPVRClient &client)
Add or update a client entry in the database.
Definition: PVRDatabase.cpp:383
int GetPriority(const CPVRClient &client) const
Get the priority for a given client from the database.
Definition: PVRDatabase.cpp:413
Definition: PVRChannel.h:35
Definition: ContextMenuManager.h:24
bool QueueDeleteQuery(const CPVRChannel &channel)
Remove a channel entry from the database.
Definition: PVRDatabase.cpp:627
bool DeleteChannelGroups()
Remove all channel groups from the database.
Definition: PVRDatabase.cpp:679
Definition: PVRProvider.h:32
bool Delete(const CPVRClient &client)
Remove a client entry from the database.
Definition: PVRDatabase.cpp:398
bool ResetEPG()
Reset all epg ids to 0.
Definition: PVRDatabase.cpp:952
bool Open() override
Open the database.
Definition: PVRDatabase.cpp:111
void Unlock()
Unlock the database.
Definition: PVRDatabase.cpp:128
A container class for channel groups.
Definition: PVRChannelGroups.h:30
bool DeleteProviders()
Remove all providers from the database.
Definition: PVRDatabase.cpp:433
bool UpdateLastOpened(const CPVRChannelGroup &group)
Updates the last opened timestamp for the channel group.
Definition: PVRDatabase.cpp:1098
std::vector< std::shared_ptr< CPVRTimerInfoTag > > GetTimers(CPVRTimers &timers, const std::vector< std::shared_ptr< CPVRClient >> &clients) const
Get the timers.
Definition: PVRDatabase.cpp:1109
Definition: PVRChannelGroupMember.h:23
bool DeleteClients()
Remove all client entries from the database.
Definition: PVRDatabase.cpp:375
CPVRDatabase()=default
Create a new instance of the PVR database.
Definition: Database.h:26
Definition: PVRTimers.h:68
Definition: PVRTimerInfoTag.h:33
void Lock()
Lock the database.
Definition: PVRDatabase.cpp:123
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:557
Definition: PVRProviders.h:61
Definition: PVRDatabase.h:33
const char * GetBaseDBName() const override
Get the default sqlite database filename.
Definition: PVRDatabase.h:73
bool UpdateLastWatched(const CPVRChannel &channel, int groupId)
Updates the last watched timestamp for the channel.
Definition: PVRDatabase.cpp:1080
Definition: PVRChannelGroup.h:52
int GetMaxProviderId() const
Get the maximum provider id in the database.
Definition: PVRDatabase.cpp:547
void Close() override
Close the database.
Definition: PVRDatabase.cpp:117
Definition: PVRClient.h:52
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:1231
bool DeleteChannels()
Remove all channels from the database.
Definition: PVRDatabase.cpp:619