summaryrefslogtreecommitdiffstats
path: root/xbmc/games/addons/GameClientSubsystem.h
blob: 4711011fd454e5eb0fd172d0103e7363bd3b30d4 (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
/*
 *  Copyright (C) 2017-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 <memory>

struct AddonInstance_Game;
class CCriticalSection;

namespace KODI
{
namespace GAME
{
class CGameClient;
class CGameClientCheevos;
class CGameClientInput;
class CGameClientProperties;
class CGameClientStreams;

struct GameClientSubsystems
{
  std::unique_ptr<CGameClientCheevos> Cheevos;
  std::unique_ptr<CGameClientInput> Input;
  std::unique_ptr<CGameClientProperties> AddonProperties;
  std::unique_ptr<CGameClientStreams> Streams;
};

/*!
 * \brief Base class for game client subsystems
 */
class CGameClientSubsystem
{
protected:
  CGameClientSubsystem(CGameClient& gameClient,
                       AddonInstance_Game& addonStruct,
                       CCriticalSection& clientAccess);

  virtual ~CGameClientSubsystem();

public:
  /*!
   * \brief Create a struct with the allocated subsystems
   *
   * \param gameClient The owner of the subsystems
   * \param gameStruct The game client's add-on function table
   * \param clientAccess Mutex guarding client function access
   *
   * \return A fully-allocated GameClientSubsystems struct
   */
  static GameClientSubsystems CreateSubsystems(CGameClient& gameClient,
                                               AddonInstance_Game& gameStruct,
                                               CCriticalSection& clientAccess);

  /*!
   * \brief Deallocate subsystems
   *
   * \param subsystems The subsystems created by CreateSubsystems()
   */
  static void DestroySubsystems(GameClientSubsystems& subsystems);

protected:
  // Subsystems
  CGameClientCheevos& Cheevos() const;
  CGameClientInput& Input() const;
  CGameClientProperties& AddonProperties() const;
  CGameClientStreams& Streams() const;

  // Construction parameters
  CGameClient& m_gameClient;
  AddonInstance_Game& m_struct;
  CCriticalSection& m_clientAccess;
};

} // namespace GAME
} // namespace KODI