xbmc
ControllerNode.h
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 
32 {
33 public:
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 
50  const ControllerPtr& GetController() const { return m_controller; }
51  void SetController(ControllerPtr controller);
52 
53  void GetControllers(ControllerVector& controllers) const;
54 
58  const std::string& GetPortAddress() const { return m_portAddress; }
59  void SetPortAddress(std::string portAddress);
60 
64  const std::string& GetControllerAddress() const { return m_controllerAddress; }
65  void SetControllerAddress(std::string controllerAddress);
66 
73  const CControllerHub& GetHub() const { return *m_hub; }
74  CControllerHub& GetHub() { return *m_hub; }
75  void SetHub(CControllerHub hub);
76 
80  bool IsValid() const { return static_cast<bool>(m_controller); }
81 
89  bool IsControllerAccepted(const std::string& controllerId) const;
90 
99  bool IsControllerAccepted(const std::string& portAddress, const std::string& controllerId) const;
100 
104  bool ProvidesInput() const;
105 
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
Node in the controller tree.
Definition: ControllerNode.h:31
const std::string & GetPortAddress() const
Address given to the controller&#39;s port by the implementation.
Definition: ControllerNode.h:58
const std::string & GetControllerAddress() const
Address given to the controller node by the implementation.
Definition: ControllerNode.h:64
bool IsControllerAccepted(const std::string &controllerId) const
Check to see if a controller is compatible with a controller port.
Definition: ControllerNode.cpp:101
Definition: AudioDecoder.h:18
std::shared_ptr< CController > ControllerPtr
Smart pointer to a game controller (CController)
Definition: ControllerTypes.h:25
A branch in the controller tree.
Definition: ControllerHub.h:25
bool ProvidesInput() const
Check if this node provides input.
Definition: ControllerNode.cpp:134
void GetInputPorts(std::vector< std::string > &activePorts) const
Get a list of ports that accept player input.
Definition: ControllerNode.cpp:139
const ControllerPtr & GetController() const
Controller profile of this code.
Definition: ControllerNode.h:50
const CControllerHub & GetHub() const
Collection of ports on this controller.
Definition: ControllerNode.h:73
bool IsValid() const
Check if this node has a valid controller profile.
Definition: ControllerNode.h:80
std::vector< ControllerPtr > ControllerVector
Vector of smart pointers to a game controller (CController)
Definition: ControllerTypes.h:32