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 CPVRChannelGroupInternal;
33 class CPVRChannelGroup;
34 class CPVRChannelGroupMember;
35 class CPVRChannelGroups;
36 class CPVRProvidersContainer;
37 class CPVRClient;
38 class CPVREpg;
39 class CPVRRecordings;
40 class CPVRTimerType;
41 class CPVRTimersContainer;
42 
43 typedef std::map<int, std::shared_ptr<CPVRClient>> CPVRClientMap;
44 
48 struct SBackend
49 {
50  std::string name;
51  std::string version;
52  std::string host;
53  int numTimers = 0;
54  int numRecordings = 0;
55  int numDeletedRecordings = 0;
56  int numProviders = 0;
57  int numChannelGroups = 0;
58  int numChannels = 0;
59  uint64_t diskUsed = 0;
60  uint64_t diskTotal = 0;
61 };
62 
64  {
65  public:
66  CPVRClients();
67  ~CPVRClients() override;
68 
72  void Start();
73 
77  void Stop();
78 
82  void Continue();
83 
89  void UpdateClients(
90  const std::string& changedAddonId = "",
91  ADDON::AddonInstanceId changedInstanceId = ADDON::ADDON_SINGLETON_INSTANCE_ID);
92 
100  bool RequestRestart(const std::string& addonId,
101  ADDON::AddonInstanceId instanceId,
102  bool bDataChanged) override;
103 
110  bool StopClient(int clientId, bool restart);
111 
116  void OnAddonEvent(const ADDON::AddonEvent& event);
117 
122  int CreatedClientAmount() const;
123 
128  bool HasCreatedClients() const;
129 
135  bool IsCreatedClient(int iClientId) const;
136 
142  std::shared_ptr<CPVRClient> GetCreatedClient(int clientId) const;
143 
148  CPVRClientMap GetCreatedClients() const;
149 
154  int GetFirstCreatedClientID();
155 
160  bool HasIgnoredClients() const;
161 
166  int EnabledClientAmount() const;
167 
173  bool IsEnabledClient(int clientId) const;
174 
179  std::vector<CVariant> GetEnabledClientInfos() const;
180 
185  std::vector<CVariant> GetClientProviderInfos() const;
186 
188 
191 
196  std::vector<SBackend> GetBackendProperties() const;
197 
199 
202 
210  bool GetTimers(const std::vector<std::shared_ptr<CPVRClient>>& clients,
211  CPVRTimersContainer* timers,
212  std::vector<int>& failedClients);
213 
219  PVR_ERROR GetTimerTypes(std::vector<std::shared_ptr<CPVRTimerType>>& results) const;
220 
222 
225 
234  PVR_ERROR GetRecordings(const std::vector<std::shared_ptr<CPVRClient>>& clients,
235  CPVRRecordings* recordings,
236  bool deleted,
237  std::vector<int>& failedClients);
238 
243  PVR_ERROR DeleteAllRecordingsFromTrash();
244 
246 
249 
263  PVR_ERROR SetEPGMaxPastDays(int iPastDays);
264 
278  PVR_ERROR SetEPGMaxFutureDays(int iFutureDays);
279 
281 
284 
293  PVR_ERROR GetChannels(const std::vector<std::shared_ptr<CPVRClient>>& clients,
294  bool bRadio,
295  std::vector<std::shared_ptr<CPVRChannel>>& channels,
296  std::vector<int>& failedClients);
297 
305  PVR_ERROR GetProviders(const std::vector<std::shared_ptr<CPVRClient>>& clients,
306  CPVRProvidersContainer* providers,
307  std::vector<int>& failedClients);
308 
316  PVR_ERROR GetChannelGroups(const std::vector<std::shared_ptr<CPVRClient>>& clients,
317  CPVRChannelGroups* groups,
318  std::vector<int>& failedClients);
319 
328  PVR_ERROR GetChannelGroupMembers(
329  const std::vector<std::shared_ptr<CPVRClient>>& clients,
331  std::vector<std::shared_ptr<CPVRChannelGroupMember>>& groupMembers,
332  std::vector<int>& failedClients);
333 
338  std::vector<std::shared_ptr<CPVRClient>> GetClientsSupportingChannelScan() const;
339 
344  std::vector<std::shared_ptr<CPVRClient>> GetClientsSupportingChannelSettings(bool bRadio) const;
345 
350  bool AnyClientSupportingRecordingsSize() const;
351 
356  bool AnyClientSupportingEPG() const;
357 
362  bool AnyClientSupportingRecordings() const;
364 
369  bool AnyClientSupportingRecordingsDelete() const;
371 
374 
378  void OnSystemSleep();
379 
383  void OnSystemWake();
384 
388  void OnPowerSavingActivated();
389 
393  void OnPowerSavingDeactivated();
394 
396 
404  void ConnectionStateChange(CPVRClient* client,
405  const std::string& strConnectionString,
406  PVR_CONNECTION_STATE newState,
407  const std::string& strMessage);
408 
409  private:
415  std::vector<ADDON::AddonInstanceId> GetKnownInstanceIds(const std::string& addonID) const;
416 
417  bool GetAddonsWithStatus(
418  const std::string& changedAddonId,
419  std::vector<std::pair<std::shared_ptr<ADDON::CAddonInfo>, bool>>& addonsWithStatus) const;
420 
421  std::vector<std::pair<ADDON::AddonInstanceId, bool>> GetInstanceIdsWithStatus(
422  const std::shared_ptr<ADDON::CAddonInfo>& addon, bool addonIsEnabled) const;
423 
429  std::shared_ptr<CPVRClient> GetClient(int clientId) const;
430 
436  bool IsKnownClient(int iClientId) const;
437 
444  PVR_ERROR GetCallableClients(CPVRClientMap& clientsReady,
445  std::vector<int>& clientsNotReady) const;
446 
447  typedef std::function<PVR_ERROR(const std::shared_ptr<CPVRClient>&)> PVRClientFunction;
448 
457  PVR_ERROR ForClients(const char* strFunctionName,
458  const std::vector<std::shared_ptr<CPVRClient>>& clients,
459  const PVRClientFunction& function,
460  std::vector<int>& failedClients) const;
461 
468  PVR_ERROR ForCreatedClients(const char* strFunctionName,
469  const PVRClientFunction& function) const;
470 
478  PVR_ERROR ForCreatedClients(const char* strFunctionName,
479  const PVRClientFunction& function,
480  std::vector<int>& failedClients) const;
481 
482  mutable CCriticalSection m_critSection;
483  CPVRClientMap m_clientMap;
484  };
485 }
Definition: PVRRecordings.h:28
PVR_ERROR
Definition: pvr_general.h:34
Definition: ContextMenuManager.h:24
A container class for channel groups.
Definition: PVRChannelGroups.h:26
Definition: Variant.h:29
PVR_CONNECTION_STATE
Definition: pvr_general.h:81
Definition: PVRClients.h:63
Definition: AddonEvents.h:18
Definition: SmartPlayList.cpp:137
Holds generic data about a backend (number of channels etc.)
Definition: PVRClients.h:48
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:46
Definition: PVRClient.h:51