summaryrefslogtreecommitdiffstats
path: root/xbmc/games/controllers/Controller.h
blob: 2dd7c18b4f8b61655d6c55c3c189a2f0f174eb93 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 *  Copyright (C) 2015-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 "ControllerTypes.h"
#include "addons/Addon.h"
#include "games/controllers/input/PhysicalFeature.h"
#include "input/joysticks/JoystickTypes.h"

#include <map>
#include <memory>
#include <string>
#include <vector>

namespace KODI
{
namespace GAME
{
class CControllerLayout;
class CPhysicalTopology;

using JOYSTICK::FEATURE_TYPE;

class CController : public ADDON::CAddon
{
public:
  explicit CController(const ADDON::AddonInfoPtr& addonInfo);

  ~CController() override;

  static const ControllerPtr EmptyPtr;

  /*!
   * \brief Get all controller features
   *
   * \return The features
   */
  const std::vector<CPhysicalFeature>& Features(void) const { return m_features; }

  /*!
   * \brief Get a feature by its name
   *
   * \param name The feature name
   *
   * \return The feature, or a feature of type FEATURE_TYPE::UNKNOWN if the name is invalid
   */
  const CPhysicalFeature& GetFeature(const std::string& name) const;

  /*!
   * \brief Get the count of controller features matching the specified types
   *
   * \param type The feature type, or FEATURE_TYPE::UNKNOWN to match all feature types
   * \param inputType The input type, or INPUT_TYPE::UNKNOWN to match all input types
   *
   * \return The feature count
   */
  unsigned int FeatureCount(FEATURE_TYPE type = FEATURE_TYPE::UNKNOWN,
                            JOYSTICK::INPUT_TYPE inputType = JOYSTICK::INPUT_TYPE::UNKNOWN) const;

  /*!
   * \brief Get the features matching the specified type
   *
   * \param type The feature type, or FEATURE_TYPE::UNKNOWN to get all features
   */
  void GetFeatures(std::vector<std::string>& features,
                   FEATURE_TYPE type = FEATURE_TYPE::UNKNOWN) const;

  /*!
   * \brief Get the type of the specified feature
   *
   * \param feature The feature name to look up
   *
   * \return The feature type, or FEATURE_TYPE::UNKNOWN if an invalid feature was specified
   */
  FEATURE_TYPE FeatureType(const std::string& feature) const;

  /*!
   * \brief Get the input type of the specified feature
   *
   * \param feature The feature name to look up
   *
   * \return The input type of the feature, or INPUT_TYPE::UNKNOWN if unknown
   */
  JOYSTICK::INPUT_TYPE GetInputType(const std::string& feature) const;

  /*!
   * \brief Load the controller layout
   *
   * \return true if the layout is loaded or was already loaded, false otherwise
   */
  bool LoadLayout(void);

  /*!
   * \brief Get the controller layout
   */
  const CControllerLayout& Layout(void) const { return *m_layout; }

  /*!
   * \brief Get the controller's physical topology
   *
   * This defines how controllers physically connect to each other.
   *
   * \return The physical topology of the controller
   */
  const CPhysicalTopology& Topology() const;

private:
  std::unique_ptr<CControllerLayout> m_layout;
  std::vector<CPhysicalFeature> m_features;
  bool m_bLoaded = false;
};

} // namespace GAME
} // namespace KODI