xbmc
PVRClients.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 "addons/IAddonManagerCallback.h"
12 #include "addons/kodi-dev-kit/include/kodi/c-api/addon-instance/pvr/pvr_general.h"
13 #include "threads/CriticalSection.h"
14 
15 #include <functional>
16 #include <map>
17 #include <memory>
18 #include <string>
19 #include <vector>
20 
21 class CVariant;
22 
23 namespace ADDON
24 {
25  struct AddonEvent;
26  class CAddonInfo;
27 }
28 
29 namespace PVR
30 {
31 class CPVRChannel;
32 class CPVRChannelGroup;
33 class CPVRChannelGroupMember;
34 class CPVRChannelGroups;
35 class CPVRProvidersContainer;
36 class CPVRClient;
37 class CPVREpg;
38 class CPVRRecordings;
39 class CPVRTimerType;
40 class CPVRTimersContainer;
41 
42 typedef std::map<int, std::shared_ptr<CPVRClient>> CPVRClientMap;
43 
47 struct SBackend
48 {
49  std::string name;
50  std::string version;
51  std::string host;
52  int numTimers = 0;
53  int numRecordings = 0;
54  int numDeletedRecordings = 0;
55  int numProviders = 0;
56  int numChannelGroups = 0;
57  int numChannels = 0;
58  uint64_t diskUsed = 0;
59  uint64_t diskTotal = 0;
60 };
61 
63  {
64  public:
65  CPVRClients();
66  ~CPVRClients() override;
67 
71  void Start();
72 
76  void Stop();
77 
81  void Continue();
82 
88  void UpdateClients(
89  const std::string& changedAddonId = "",
90  ADDON::AddonInstanceId changedInstanceId = ADDON::ADDON_SINGLETON_INSTANCE_ID);
91 
99  bool RequestRestart(const std::string& addonId,
100  ADDON::AddonInstanceId instanceId,
101  bool bDataChanged) override;
102 
109  bool StopClient(int clientId, bool restart);
110 
115  void OnAddonEvent(const ADDON::AddonEvent& event);
116 
121  int CreatedClientAmount() const;
122 
127  bool HasCreatedClients() const;
128 
134  bool IsCreatedClient(int iClientId) const;
135 
141  std::shared_ptr<CPVRClient> GetCreatedClient(int clientId) const;
142 
147  CPVRClientMap GetCreatedClients() const;
148 
153  int GetFirstCreatedClientID();
154 
159  bool HasIgnoredClients() const;
160 
165  int EnabledClientAmount() const;
166 
172  bool IsEnabledClient(int clientId) const;
173 
178  std::vector<CVariant> GetEnabledClientInfos() const;
179 
184  std::vector<CVariant> GetClientProviderInfos() const;
185 
187 
190 
195  std::vector<SBackend> GetBackendProperties() const;
196 
198 
201 
209  bool GetTimers(const std::vector<std::shared_ptr<CPVRClient>>& clients,
210  CPVRTimersContainer* timers,
211  std::vector<int>& failedClients);
212 
219  PVR_ERROR UpdateTimerTypes(const std::vector<std::shared_ptr<CPVRClient>>& clients,
220  std::vector<int>& failedClients);
221 
226  const std::vector<std::shared_ptr<CPVRTimerType>> GetTimerTypes() const;
227 
229 
232 
241  PVR_ERROR GetRecordings(const std::vector<std::shared_ptr<CPVRClient>>& clients,
242  CPVRRecordings* recordings,
243  bool deleted,
244  std::vector<int>& failedClients);
245 
250  PVR_ERROR DeleteAllRecordingsFromTrash();
251 
253 
256 
270  PVR_ERROR SetEPGMaxPastDays(int iPastDays);
271 
285  PVR_ERROR SetEPGMaxFutureDays(int iFutureDays);
286 
288 
291 
300  PVR_ERROR GetChannels(const std::vector<std::shared_ptr<CPVRClient>>& clients,
301  bool bRadio,
302  std::vector<std::shared_ptr<CPVRChannel>>& channels,
303  std::vector<int>& failedClients);
304 
312  PVR_ERROR GetProviders(const std::vector<std::shared_ptr<CPVRClient>>& clients,
313  CPVRProvidersContainer* providers,
314  std::vector<int>& failedClients);
315 
323  PVR_ERROR GetChannelGroups(const std::vector<std::shared_ptr<CPVRClient>>& clients,
324  CPVRChannelGroups* groups,
325  std::vector<int>& failedClients);
326 
335  PVR_ERROR GetChannelGroupMembers(
336  const std::vector<std::shared_ptr<CPVRClient>>& clients,
338  std::vector<std::shared_ptr<CPVRChannelGroupMember>>& groupMembers,
339  std::vector<int>& failedClients);
340 
345  std::vector<std::shared_ptr<CPVRClient>> GetClientsSupportingChannelScan() const;
346 
351  std::vector<std::shared_ptr<CPVRClient>> GetClientsSupportingChannelSettings(bool bRadio) const;
352 
357  bool AnyClientSupportingRecordingsSize() const;
358 
363  bool AnyClientSupportingEPG() const;
364 
369  bool AnyClientSupportingRecordings() const;
371 
376  bool AnyClientSupportingRecordingsDelete() const;
378 
381 
385  void OnSystemSleep();
386 
390  void OnSystemWake();
391 
395  void OnPowerSavingActivated();
396 
400  void OnPowerSavingDeactivated();
401 
403 
411  void ConnectionStateChange(CPVRClient* client,
412  const std::string& strConnectionString,
413  PVR_CONNECTION_STATE newState,
414  const std::string& strMessage);
415 
416  private:
422  std::vector<ADDON::AddonInstanceId> GetKnownInstanceIds(const std::string& addonID) const;
423 
424  bool GetAddonsWithStatus(
425  const std::string& changedAddonId,
426  std::vector<std::pair<std::shared_ptr<ADDON::CAddonInfo>, bool>>& addonsWithStatus) const;
427 
428  std::vector<std::pair<ADDON::AddonInstanceId, bool>> GetInstanceIdsWithStatus(
429  const std::shared_ptr<ADDON::CAddonInfo>& addon, bool addonIsEnabled) const;
430 
436  std::shared_ptr<CPVRClient> GetClient(int clientId) const;
437 
443  bool IsKnownClient(int iClientId) const;
444 
451  PVR_ERROR GetCallableClients(CPVRClientMap& clientsReady,
452  std::vector<int>& clientsNotReady) const;
453 
454  typedef std::function<PVR_ERROR(const std::shared_ptr<CPVRClient>&)> PVRClientFunction;
455 
464  PVR_ERROR ForClients(const char* strFunctionName,
465  const std::vector<std::shared_ptr<CPVRClient>>& clients,
466  const PVRClientFunction& function,
467  std::vector<int>& failedClients) const;
468 
475  PVR_ERROR ForCreatedClients(const char* strFunctionName,
476  const PVRClientFunction& function) const;
477 
485  PVR_ERROR ForCreatedClients(const char* strFunctionName,
486  const PVRClientFunction& function,
487  std::vector<int>& failedClients) const;
488 
489  mutable CCriticalSection m_critSection;
490  CPVRClientMap m_clientMap;
491  };
492 }
Definition: PVRRecordings.h:28
PVR_ERROR
Definition: pvr_general.h:34
Definition: ContextMenuManager.h:24
A container class for channel groups.
Definition: PVRChannelGroups.h:30
Definition: Variant.h:31
PVR_CONNECTION_STATE
Definition: pvr_general.h:81
Definition: PVRClients.h:62
Definition: AddonEvents.h:18
Definition: SmartPlayList.cpp:137
Holds generic data about a backend (number of channels etc.)
Definition: PVRClients.h:47
Class - IAddonMgrCallback This callback should be inherited by any class which manages specific addon...
Definition: IAddonManagerCallback.h:23
Definition: Addon.cpp:39
Definition: PVRProviders.h:23
Definition: PVRTimers.h:32
Definition: PVRChannelGroup.h:52
Definition: PVRClient.h:52