| 1 |
/* |
| 2 |
* Copyright (C) 2015-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 "ControllerTypes.h" |
| 12 |
#include "addons/Addon.h" |
| 13 |
#include "games/controllers/input/PhysicalFeature.h" |
| 14 |
#include "input/joysticks/JoystickTypes.h" |
| 15 |
|
| 16 |
#include <map> |
| 17 |
#include <memory> |
| 18 |
#include <string> |
| 19 |
#include <vector> |
| 20 |
|
| 21 |
namespace KODI |
| 22 |
{ |
| 23 |
namespace GAME |
| 24 |
{ |
| 25 |
class CControllerLayout; |
| 26 |
class CPhysicalTopology; |
| 27 |
|
| 28 |
using JOYSTICK::FEATURE_TYPE; |
| 29 |
|
| 30 |
/*! |
| 31 |
* \ingroup games |
| 32 |
*/ |
| 33 |
class CController : public ADDON::CAddon |
| 34 |
{ |
| 35 |
public: |
| 36 |
explicit CController(const ADDON::AddonInfoPtr& addonInfo); |
| 37 |
|
| 38 |
~CController() override; |
| 39 |
|
| 40 |
static const ControllerPtr EmptyPtr; |
| 41 |
|
| 42 |
// Implementation of IAddon |
| 43 |
bool CanHaveAddonOrInstanceSettings() override { return true; } |
| 44 |
|
| 45 |
/*! |
| 46 |
* \brief Get all controller features |
| 47 |
* |
| 48 |
* \return The features |
| 49 |
*/ |
| 50 |
const std::vector<CPhysicalFeature>& Features(void) const { return m_features; } |
| 51 |
|
| 52 |
/*! |
| 53 |
* \brief Get a feature by its name |
| 54 |
* |
| 55 |
* \param name The feature name |
| 56 |
* |
| 57 |
* \return The feature, or a feature of type FEATURE_TYPE::UNKNOWN if the name is invalid |
| 58 |
*/ |
| 59 |
const CPhysicalFeature& GetFeature(const std::string& name) const; |
| 60 |
|
| 61 |
/*! |
| 62 |
* \brief Get the count of controller features matching the specified types |
| 63 |
* |
| 64 |
* \param type The feature type, or FEATURE_TYPE::UNKNOWN to match all feature types |
| 65 |
* \param inputType The input type, or INPUT_TYPE::UNKNOWN to match all input types |
| 66 |
* |
| 67 |
* \return The feature count |
| 68 |
*/ |
| 69 |
unsigned int FeatureCount(FEATURE_TYPE type = FEATURE_TYPE::UNKNOWN, |
| 70 |
JOYSTICK::INPUT_TYPE inputType = JOYSTICK::INPUT_TYPE::UNKNOWN) const; |
| 71 |
|
| 72 |
/*! |
| 73 |
* \brief Get the features matching the specified type |
| 74 |
* |
| 75 |
* \param type The feature type, or FEATURE_TYPE::UNKNOWN to get all features |
| 76 |
*/ |
| 77 |
void GetFeatures(std::vector<std::string>& features, |
| 78 |
FEATURE_TYPE type = FEATURE_TYPE::UNKNOWN) const; |
| 79 |
|
| 80 |
/*! |
| 81 |
* \brief Get the type of the specified feature |
| 82 |
* |
| 83 |
* \param feature The feature name to look up |
| 84 |
* |
| 85 |
* \return The feature type, or FEATURE_TYPE::UNKNOWN if an invalid feature was specified |
| 86 |
*/ |
| 87 |
FEATURE_TYPE FeatureType(const std::string& feature) const; |
| 88 |
|
| 89 |
/*! |
| 90 |
* \brief Get the input type of the specified feature |
| 91 |
* |
| 92 |
* \param feature The feature name to look up |
| 93 |
* |
| 94 |
* \return The input type of the feature, or INPUT_TYPE::UNKNOWN if unknown |
| 95 |
*/ |
| 96 |
JOYSTICK::INPUT_TYPE GetInputType(const std::string& feature) const; |
| 97 |
|
| 98 |
/*! |
| 99 |
* \brief Load the controller layout |
| 100 |
* |
| 101 |
* \return true if the layout is loaded or was already loaded, false otherwise |
| 102 |
*/ |
| 103 |
bool LoadLayout(void); |
| 104 |
|
| 105 |
/*! |
| 106 |
* \brief Get the controller layout |
| 107 |
*/ |
| 108 |
const CControllerLayout& Layout(void) const { return *m_layout; } |
| 109 |
|
| 110 |
/*! |
| 111 |
* \brief Get the controller's physical topology |
| 112 |
* |
| 113 |
* This defines how controllers physically connect to each other. |
| 114 |
* |
| 115 |
* \return The physical topology of the controller |
| 116 |
*/ |
| 117 |
const CPhysicalTopology& Topology() const; |
| 118 |
|
| 119 |
private: |
| 120 |
std::unique_ptr<CControllerLayout> m_layout; |
| 121 |
std::vector<CPhysicalFeature> m_features; |
| 122 |
bool m_bLoaded = false; |
| 123 |
}; |
| 124 |
|
| 125 |
} // namespace GAME |
| 126 |
} // namespace KODI |