xbmc
PVRManager.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/kodi-dev-kit/include/kodi/c-api/addon-instance/pvr/pvr_general.h"
12 #include "interfaces/IAnnouncer.h"
13 #include "pvr/PVRComponentRegistration.h"
14 #include "pvr/epg/EpgContainer.h"
15 #include "pvr/guilib/PVRGUIActionListener.h"
16 #include "pvr/settings/PVRSettings.h"
17 #include "threads/CriticalSection.h"
18 #include "threads/Event.h"
19 #include "threads/Thread.h"
20 #include "utils/EventStream.h"
21 
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 class CFileItem;
27 class CStopWatch;
28 
29 namespace PVR
30 {
31 class CPVRChannel;
32 class CPVRChannelGroup;
33 class CPVRChannelGroupsContainer;
34 class CPVRProviders;
35 class CPVRClient;
36 class CPVRClients;
37 class CPVRDatabase;
38 class CPVRGUIInfo;
39 class CPVRGUIProgressHandler;
40 class CPVRManagerJobQueue;
41 class CPVRPlaybackState;
42 class CPVRRecording;
43 class CPVRRecordings;
44 class CPVRTimers;
45 
46 enum class PVREvent
47 {
48  // PVR Manager states
49  ManagerError = 0,
50  ManagerStopped,
51  ManagerStarting,
52  ManagerStopping,
53  ManagerInterrupted,
54  ManagerStarted,
55 
56  // Channel events
57  ChannelPlaybackStopped,
58 
59  // Channel group events
60  ChannelGroup,
61  ChannelGroupInvalidated,
62  ChannelGroupsInvalidated,
63  ChannelGroupsLoaded,
64 
65  // Recording events
66  RecordingsInvalidated,
67 
68  // Timer events
69  AnnounceReminder,
70  Timers,
71  TimersInvalidated,
72 
73  // EPG events
74  Epg,
75  EpgActiveItem,
76  EpgContainer,
77  EpgItemUpdate,
78  EpgUpdatePending,
79  EpgDeleted,
80 
81  // Saved searches events
82  SavedSearchesInvalidated,
83 
84  // Item events
85  CurrentItem,
86 
87  // Syetem events
88  SystemSleep,
89  SystemWake,
90 };
91 
93 {
94 public:
98  CPVRManager();
99 
103  ~CPVRManager() override;
104 
105  void Announce(ANNOUNCEMENT::AnnouncementFlag flag,
106  const std::string& sender,
107  const std::string& message,
108  const CVariant& data) override;
109 
114  template<class T>
115  T& Get()
116  {
117  return *m_components->GetComponent<T>();
118  }
119 
124  std::shared_ptr<CPVRProviders> Providers() const;
125 
130  std::shared_ptr<CPVRChannelGroupsContainer> ChannelGroups() const;
131 
136  std::shared_ptr<CPVRRecordings> Recordings() const;
137 
142  std::shared_ptr<CPVRTimers> Timers() const;
143 
148  std::shared_ptr<CPVRClients> Clients() const;
149 
155  std::shared_ptr<CPVRClient> GetClient(const CFileItem& item) const;
156 
162  std::shared_ptr<CPVRClient> GetClient(int iClientId) const;
163 
168  std::shared_ptr<CPVRPlaybackState> PlaybackState() const;
169 
174  CPVREpgContainer& EpgContainer();
175 
179  void Init();
180 
184  void Start();
185 
189  void Stop(bool bRestart = false);
190 
194  void Unload();
195 
199  void Deinit();
200 
204  void OnSleep();
205 
209  void OnWake();
210 
215  std::shared_ptr<CPVRDatabase> GetTVDatabase() const;
216 
221  bool IsStarted() const { return GetState() == ManagerState::STATE_STARTED; }
222 
227  bool EpgsCreated() const;
228 
233  void OnPlaybackStarted(const CFileItem& item);
234 
239  void OnPlaybackStopped(const CFileItem& item);
240 
245  void OnPlaybackEnded(const CFileItem& item);
246 
250  void TriggerEpgsCreate();
251 
256  void TriggerRecordingsUpdate(int clientId);
257  void TriggerRecordingsUpdate();
258 
262  void TriggerRecordingsSizeInProgressUpdate();
263 
268  void TriggerTimersUpdate(int clientId);
269  void TriggerTimersUpdate();
270 
275  void TriggerChannelsUpdate(int clientId);
276  void TriggerChannelsUpdate();
277 
282  void TriggerProvidersUpdate(int clientId);
283  void TriggerProvidersUpdate();
284 
289  void TriggerChannelGroupsUpdate(int clientId);
290  void TriggerChannelGroupsUpdate();
291 
295  void TriggerSearchMissingChannelIcons();
296 
300  void TriggerCleanupCachedImages();
301 
306  void TriggerSearchMissingChannelIcons(const std::shared_ptr<CPVRChannelGroup>& group);
307 
311  void LocalizationChanged();
312 
318  bool IsParentalLocked(const std::shared_ptr<CPVRChannel>& channel) const;
319 
325  bool IsParentalLocked(const std::shared_ptr<CPVREpgInfoTag>& epgTag) const;
326 
330  void RestartParentalTimer();
331 
336  bool CreateChannelEpgs();
337 
341  void ConnectionStateChange(CPVRClient* client,
342  const std::string& connectString,
343  PVR_CONNECTION_STATE state,
344  const std::string& message);
345 
349  CEventStream<PVREvent>& Events() { return m_events; }
350 
355  void PublishEvent(PVREvent state);
356 
357 protected:
361  void Process() override;
362 
363 private:
367  bool SetWakeupCommand();
368 
369  enum class ManagerState
370  {
371  STATE_ERROR = 0,
372  STATE_STOPPED,
373  STATE_STARTING,
374  STATE_SSTOPPING,
375  STATE_INTERRUPTED,
376  STATE_STARTED
377  };
378 
382  bool IsInitialising() const { return GetState() == ManagerState::STATE_STARTING; }
383 
388  bool IsStopped() const { return GetState() == ManagerState::STATE_STOPPED; }
389 
394  ManagerState GetState() const;
395 
400  void SetState(ManagerState state);
401 
406  void UpdateComponents(ManagerState stateToCheck);
407 
414  bool UpdateComponents(ManagerState stateToCheck,
415  const std::unique_ptr<CPVRGUIProgressHandler>& progressHandler);
416 
420  void UnloadComponents();
421 
426  bool IsKnownClient(int clientID) const;
427 
431  void ResetProperties();
432 
436  void Clear();
437 
441  void TriggerPlayChannelOnStartup();
442 
443  bool IsCurrentlyParentalLocked(const std::shared_ptr<CPVRChannel>& channel,
444  bool bGenerallyLocked) const;
445 
446  CEventSource<PVREvent> m_events;
447 
450  std::shared_ptr<CPVRProviders> m_providers;
451  std::shared_ptr<CPVRChannelGroupsContainer>
452  m_channelGroups;
453  std::shared_ptr<CPVRRecordings> m_recordings;
454  std::shared_ptr<CPVRTimers> m_timers;
455  std::shared_ptr<CPVRClients> m_addons;
456  std::unique_ptr<CPVRGUIInfo> m_guiInfo;
457  std::shared_ptr<CPVRComponentRegistration> m_components;
458  CPVREpgContainer m_epgContainer;
460 
461  std::vector<std::shared_ptr<CPVRClient>> m_knownClients;
462  std::unique_ptr<CPVRManagerJobQueue> m_pendingUpdates;
463  std::shared_ptr<CPVRDatabase> m_database;
464  mutable CCriticalSection
465  m_critSection;
466  bool m_bFirstStart = true;
467  bool m_bEpgsCreated = false;
469  mutable CCriticalSection m_managerStateMutex;
470  ManagerState m_managerState = ManagerState::STATE_STOPPED;
471  std::unique_ptr<CStopWatch> m_parentalTimer;
472 
473  CCriticalSection
474  m_startStopMutex; // mutex for protecting pvr manager's start/restart/stop sequence */
475 
476  const std::shared_ptr<CPVRPlaybackState> m_playbackState;
477  CPVRGUIActionListener m_actionListener;
478  CPVRSettings m_settings;
479 };
480 } // namespace PVR
Definition: Stopwatch.h:14
Definition: Thread.h:44
Definition: EpgContainer.h:42
Definition: ContextMenuManager.h:24
bool IsStarted() const
Check whether the PVRManager has fully started.
Definition: PVRManager.h:221
Definition: IAnnouncer.h:70
Definition: PVRGUIActionListener.h:21
Definition: Variant.h:29
PVR_CONNECTION_STATE
Definition: pvr_general.h:81
T & Get()
Get a PVR component.
Definition: PVRManager.h:115
CEventStream< PVREvent > & Events()
Query the events available for CEventStream.
Definition: PVRManager.h:349
Definition: SmartPlayList.cpp:137
Definition: PVRManager.h:92
Definition: PVRClient.h:51
Definition: PVRSettings.h:27
Represents a file on a share.
Definition: FileItem.h:102