| 1 |
/* |
| 2 |
* Copyright (C) 2017-2021 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 "games/controllers/ControllerTypes.h" |
| 12 |
|
| 13 |
#include <memory> |
| 14 |
#include <string> |
| 15 |
#include <vector> |
| 16 |
|
| 17 |
namespace KODI |
| 18 |
{ |
| 19 |
namespace GAME |
| 20 |
{ |
| 21 |
class CControllerHub; |
| 22 |
|
| 23 |
/*! |
| 24 |
* \ingroup games |
| 25 |
* |
| 26 |
* \brief Node in the controller tree |
| 27 |
* |
| 28 |
* The node identifies the controller profile, and optionally the available |
| 29 |
* controller ports. |
| 30 |
*/ |
| 31 |
class CControllerNode |
| 32 |
{ |
| 33 |
public: |
| 34 |
CControllerNode(); |
| 35 |
CControllerNode(const CControllerNode& other) { *this = other; } |
| 36 |
CControllerNode(CControllerNode&& other) = default; |
| 37 |
CControllerNode& operator=(const CControllerNode& rhs); |
| 38 |
CControllerNode& operator=(CControllerNode&& rhs) noexcept; |
| 39 |
~CControllerNode(); |
| 40 |
|
| 41 |
void Clear(); |
| 42 |
|
| 43 |
/*! |
| 44 |
* \brief Controller profile of this code |
| 45 |
* |
| 46 |
* \return Controller profile, or empty if this node is invalid |
| 47 |
* |
| 48 |
* \sa IsValid() |
| 49 |
*/ |
| 50 |
const ControllerPtr& GetController() const { return m_controller; } |
| 51 |
void SetController(ControllerPtr controller); |
| 52 |
|
| 53 |
void GetControllers(ControllerVector& controllers) const; |
| 54 |
|
| 55 |
/*! |
| 56 |
* \brief Address given to the controller's port by the implementation |
| 57 |
*/ |
| 58 |
const std::string& GetPortAddress() const { return m_portAddress; } |
| 59 |
void SetPortAddress(std::string portAddress); |
| 60 |
|
| 61 |
/*! |
| 62 |
* \brief Address given to the controller node by the implementation |
| 63 |
*/ |
| 64 |
const std::string& GetControllerAddress() const { return m_controllerAddress; } |
| 65 |
void SetControllerAddress(std::string controllerAddress); |
| 66 |
|
| 67 |
/*! |
| 68 |
* \brief Collection of ports on this controller |
| 69 |
* |
| 70 |
* \return A hub with controller ports, or an empty hub if this controller |
| 71 |
* has no available ports |
| 72 |
*/ |
| 73 |
const CControllerHub& GetHub() const { return *m_hub; } |
| 74 |
CControllerHub& GetHub() { return *m_hub; } |
| 75 |
void SetHub(CControllerHub hub); |
| 76 |
|
| 77 |
/*! |
| 78 |
* \brief Check if this node has a valid controller profile |
| 79 |
*/ |
| 80 |
bool IsValid() const { return static_cast<bool>(m_controller); } |
| 81 |
|
| 82 |
/*! |
| 83 |
* \brief Check to see if a controller is compatible with a controller port |
| 84 |
* |
| 85 |
* \param controllerId The ID of the controller |
| 86 |
* |
| 87 |
* \return True if the controller is compatible with a port, false otherwise |
| 88 |
*/ |
| 89 |
bool IsControllerAccepted(const std::string& controllerId) const; |
| 90 |
|
| 91 |
/*! |
| 92 |
* \brief Check to see if a controller is compatible with a controller port |
| 93 |
* |
| 94 |
* \param portAddress The port address |
| 95 |
* \param controllerId The ID of the controller |
| 96 |
* |
| 97 |
* \return True if the controller is compatible with a port, false otherwise |
| 98 |
*/ |
| 99 |
bool IsControllerAccepted(const std::string& portAddress, const std::string& controllerId) const; |
| 100 |
|
| 101 |
/*! |
| 102 |
* \brief Check if this node provides input |
| 103 |
*/ |
| 104 |
bool ProvidesInput() const; |
| 105 |
|
| 106 |
/*! |
| 107 |
* \brief Get a list of ports that accept player input |
| 108 |
* |
| 109 |
* \param[out] inputPorts The list of input ports |
| 110 |
*/ |
| 111 |
void GetInputPorts(std::vector<std::string>& activePorts) const; |
| 112 |
|
| 113 |
private: |
| 114 |
ControllerPtr m_controller; |
| 115 |
|
| 116 |
// Address of the port this controller is connected to |
| 117 |
std::string m_portAddress; |
| 118 |
|
| 119 |
// Address of this controller: m_portAddress + "/" + m_controller->ID() |
| 120 |
std::string m_controllerAddress; |
| 121 |
|
| 122 |
std::unique_ptr<CControllerHub> m_hub; |
| 123 |
}; |
| 124 |
|
| 125 |
using ControllerNodeVec = std::vector<CControllerNode>; |
| 126 |
} // namespace GAME |
| 127 |
} // namespace KODI |