| 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 "threads/CriticalSection.h" |
| 12 |
|
| 13 |
#include <memory> |
| 14 |
#include <vector> |
| 15 |
|
| 16 |
namespace PVR |
| 17 |
{ |
| 18 |
class CPVRChannel; |
| 19 |
class CPVRChannelGroup; |
| 20 |
class CPVRChannelGroupMember; |
| 21 |
class CPVRChannelGroups; |
| 22 |
class CPVRClient; |
| 23 |
class CPVREpgInfoTag; |
| 24 |
|
| 25 |
class CPVRChannelGroupsContainer |
| 26 |
{ |
| 27 |
public: |
| 28 |
/*! |
| 29 |
* @brief Create a new container for all channel groups |
| 30 |
*/ |
| 31 |
CPVRChannelGroupsContainer(); |
| 32 |
|
| 33 |
/*! |
| 34 |
* @brief Destroy this container. |
| 35 |
*/ |
| 36 |
virtual ~CPVRChannelGroupsContainer(); |
| 37 |
|
| 38 |
/*! |
| 39 |
* @brief Update all channel groups and all channels from PVR database and from given clients. |
| 40 |
* @param clients The PVR clients data should be loaded for. Leave empty for all clients. |
| 41 |
* @return True on success, false otherwise. |
| 42 |
*/ |
| 43 |
bool Update(const std::vector<std::shared_ptr<CPVRClient>>& clients); |
| 44 |
|
| 45 |
/*! |
| 46 |
* @brief Update data with groups and channels from the given clients, sync with local data. |
| 47 |
* @param clients The clients to fetch data from. Leave empty to fetch data from all created clients. |
| 48 |
* @param bChannelsOnly Set to true to only update channels, not the groups themselves. |
| 49 |
* @return True on success, false otherwise. |
| 50 |
*/ |
| 51 |
bool UpdateFromClients(const std::vector<std::shared_ptr<CPVRClient>>& clients, |
| 52 |
bool bChannelsOnly = false); |
| 53 |
|
| 54 |
/*! |
| 55 |
* @brief Unload and destruct all channel groups and all channels in them. |
| 56 |
*/ |
| 57 |
void Unload(); |
| 58 |
|
| 59 |
/*! |
| 60 |
* @brief Get the TV channel groups. |
| 61 |
* @return The TV channel groups. |
| 62 |
*/ |
| 63 |
CPVRChannelGroups* GetTV() const { return Get(false); } |
| 64 |
|
| 65 |
/*! |
| 66 |
* @brief Get the radio channel groups. |
| 67 |
* @return The radio channel groups. |
| 68 |
*/ |
| 69 |
CPVRChannelGroups* GetRadio() const { return Get(true); } |
| 70 |
|
| 71 |
/*! |
| 72 |
* @brief Get the radio or TV channel groups. |
| 73 |
* @param bRadio If true, get the radio channel groups. Get the TV channel groups otherwise. |
| 74 |
* @return The requested groups. |
| 75 |
*/ |
| 76 |
CPVRChannelGroups* Get(bool bRadio) const; |
| 77 |
|
| 78 |
/*! |
| 79 |
* @brief Get the group containing all TV channels. |
| 80 |
* @return The group containing all TV channels. |
| 81 |
*/ |
| 82 |
std::shared_ptr<CPVRChannelGroup> GetGroupAllTV() const { return GetGroupAll(false); } |
| 83 |
|
| 84 |
/*! |
| 85 |
* @brief Get the group containing all radio channels. |
| 86 |
* @return The group containing all radio channels. |
| 87 |
*/ |
| 88 |
std::shared_ptr<CPVRChannelGroup> GetGroupAllRadio() const { return GetGroupAll(true); } |
| 89 |
|
| 90 |
/*! |
| 91 |
* @brief Get the group containing all TV or radio channels. |
| 92 |
* @param bRadio If true, get the group containing all radio channels. Get the group containing all TV channels otherwise. |
| 93 |
* @return The requested group. |
| 94 |
*/ |
| 95 |
std::shared_ptr<CPVRChannelGroup> GetGroupAll(bool bRadio) const; |
| 96 |
|
| 97 |
/*! |
| 98 |
* @brief Get a group given it's ID. |
| 99 |
* @param iGroupId The ID of the group. |
| 100 |
* @return The requested group or NULL if it wasn't found. |
| 101 |
*/ |
| 102 |
std::shared_ptr<CPVRChannelGroup> GetByIdFromAll(int iGroupId) const; |
| 103 |
|
| 104 |
/*! |
| 105 |
* @brief Get a channel given it's database ID. |
| 106 |
* @param iChannelId The ID of the channel. |
| 107 |
* @return The channel or NULL if it wasn't found. |
| 108 |
*/ |
| 109 |
std::shared_ptr<CPVRChannel> GetChannelById(int iChannelId) const; |
| 110 |
|
| 111 |
/*! |
| 112 |
* @brief Get the channel for the given epg tag. |
| 113 |
* @param epgTag The epg tag. |
| 114 |
* @return The channel. |
| 115 |
*/ |
| 116 |
std::shared_ptr<CPVRChannel> GetChannelForEpgTag( |
| 117 |
const std::shared_ptr<const CPVREpgInfoTag>& epgTag) const; |
| 118 |
|
| 119 |
/*! |
| 120 |
* @brief Get a channel given it's path. |
| 121 |
* @param strPath The path. |
| 122 |
* @return The channel or nullptr if it wasn't found. |
| 123 |
*/ |
| 124 |
std::shared_ptr<CPVRChannel> GetByPath(const std::string& strPath) const; |
| 125 |
|
| 126 |
/*! |
| 127 |
* @brief Get a channel group member given it's path. |
| 128 |
* @param strPath The path. |
| 129 |
* @return The channel group member or nullptr if it wasn't found. |
| 130 |
*/ |
| 131 |
std::shared_ptr<CPVRChannelGroupMember> GetChannelGroupMemberByPath( |
| 132 |
const std::string& strPath) const; |
| 133 |
|
| 134 |
/*! |
| 135 |
* @brief Get a channel given it's channel ID from all containers. |
| 136 |
* @param iUniqueChannelId The unique channel id on the client. |
| 137 |
* @param iClientID The ID of the client. |
| 138 |
* @return The channel or NULL if it wasn't found. |
| 139 |
*/ |
| 140 |
std::shared_ptr<CPVRChannel> GetByUniqueID(int iUniqueChannelId, int iClientID) const; |
| 141 |
|
| 142 |
/*! |
| 143 |
* @brief Get the channel group member that was played last. |
| 144 |
* @return The requested channel group member or nullptr. |
| 145 |
*/ |
| 146 |
std::shared_ptr<CPVRChannelGroupMember> GetLastPlayedChannelGroupMember() const; |
| 147 |
|
| 148 |
/*! |
| 149 |
* @brief Erase stale texture db entries and image files. |
| 150 |
* @return number of cleaned up images. |
| 151 |
*/ |
| 152 |
int CleanupCachedImages(); |
| 153 |
|
| 154 |
private: |
| 155 |
CPVRChannelGroupsContainer& operator=(const CPVRChannelGroupsContainer&) = delete; |
| 156 |
CPVRChannelGroupsContainer(const CPVRChannelGroupsContainer&) = delete; |
| 157 |
|
| 158 |
/*! |
| 159 |
* @brief Load all channel groups and all channels from PVR database. |
| 160 |
* @param clients The PVR clients data should be loaded for. Leave empty for all clients. |
| 161 |
* @return True on success, false otherwise. |
| 162 |
*/ |
| 163 |
bool LoadFromDatabase(const std::vector<std::shared_ptr<CPVRClient>>& clients); |
| 164 |
|
| 165 |
CPVRChannelGroups* m_groupsRadio; /*!< all radio channel groups */ |
| 166 |
CPVRChannelGroups* m_groupsTV; /*!< all TV channel groups */ |
| 167 |
CCriticalSection m_critSection; |
| 168 |
bool m_bIsUpdating = false; |
| 169 |
}; |
| 170 |
} |