summaryrefslogtreecommitdiffstats
path: root/xbmc/platform/Platform.h
blob: ebb441c54eeb791b53d2f527be239d92d74145ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 *  Copyright (C) 2016-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#pragma once

#include "utils/ComponentContainer.h"

//! \brief Base class for services.
class IPlatformService
{
public:
  virtual ~IPlatformService() = default;
};

/**\brief Class for the Platform object
 *
 * Contains methods to retrieve platform specific information
 * and methods for doing platform specific environment preparation/initialisation
 */
class CPlatform : public CComponentContainer<IPlatformService>
{
public:
  /**\brief Creates the Platform object
   *
   *@return the platform object
  */
  static CPlatform *CreateInstance();

  /**\brief C'tor */
  CPlatform() = default;

  /**\brief D'tor */
  virtual ~CPlatform() = default;

  /**\brief Called at an early stage of application startup
   *
   * This method can be used to do platform specific environment preparation
   * or initialisation (like setting environment variables for example)
   */
  virtual bool InitStageOne() { return true; }

  /**\brief Called at a middle stage of application startup
   *
   * This method can be used for starting platform specific services that
   * do not depend on windowing/gui. (eg macos XBMCHelper)
   */
  virtual bool InitStageTwo() { return true; }

  /**\brief Called at a late stage of application startup
   *
   * This method can be used for starting platform specific Window/GUI related
   * services/components. (eg , WS-Discovery Daemons)
   */
  virtual bool InitStageThree() { return true; }

  /**\brief Called at a late stage of application shutdown
   *
   * This method should be used to cleanup resources allocated in InitStageOne
   */
  virtual void DeinitStageOne() {}

  /**\brief Called at a middle stage of application shutdown
   *
   * This method should be used to cleanup resources allocated in InitStageTwo
   */
  virtual void DeinitStageTwo() {}

  /**\brief Called at an early stage of application shutdown
   *
   * This method should be used to cleanup resources allocated in InitStageThree
   */
  virtual void DeinitStageThree() {}

  /**\brief Flag whether disabled add-ons - installed via packagemanager or manually - should be
   * offered for configuration and activation on kodi startup for this platform
   */
  virtual bool IsConfigureAddonsAtStartupEnabled() { return false; }

  /**\brief Flag whether this platform supports user installation of binary add-ons.
   */
  virtual bool SupportsUserInstalledBinaryAddons() { return true; }

  /**\brief Print platform specific info to log
   *
   * Logs platform specific system info during application creation startup
   */
  virtual void PlatformSyslog() {}

  /**\brief Get a platform service instance.
   */
  template<class T>
  std::shared_ptr<T> GetService()
  {
    return this->GetComponent<T>();
  }
};