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 
30 {
31 public:
33  CControllerNode(const CControllerNode& other) { *this = other; }
34  CControllerNode(CControllerNode&& other) = default;
35  CControllerNode& operator=(const CControllerNode& rhs);
36  CControllerNode& operator=(CControllerNode&& rhs) noexcept;
37  ~CControllerNode();
38 
39  void Clear();
40 
48  const ControllerPtr& GetController() const { return m_controller; }
49  void SetController(ControllerPtr controller);
50 
51  void GetControllers(ControllerVector& controllers) const;
52 
56  const std::string& GetPortAddress() const { return m_portAddress; }
57  void SetPortAddress(std::string portAddress);
58 
62  const std::string& GetControllerAddress() const { return m_controllerAddress; }
63  void SetControllerAddress(std::string controllerAddress);
64 
71  const CControllerHub& GetHub() const { return *m_hub; }
72  CControllerHub& GetHub() { return *m_hub; }
73  void SetHub(CControllerHub hub);
74 
78  bool IsValid() const { return static_cast<bool>(m_controller); }
79 
87  bool IsControllerAccepted(const std::string& controllerId) const;
88 
97  bool IsControllerAccepted(const std::string& portAddress, const std::string& controllerId) const;
98 
102  bool ProvidesInput() const;
103 
104 private:
105  ControllerPtr m_controller;
106 
107  // Address of the port this controller is connected to
108  std::string m_portAddress;
109 
110  // Address of this controller: m_portAddress + "/" + m_controller->ID()
111  std::string m_controllerAddress;
112 
113  std::unique_ptr<CControllerHub> m_hub;
114 };
115 
116 using ControllerNodeVec = std::vector<CControllerNode>;
117 } // namespace GAME
118 } // namespace KODI
Node in the controller tree.
Definition: ControllerNode.h:29
const std::string & GetPortAddress() const
Address given to the controller&#39;s port by the implementation.
Definition: ControllerNode.h:56
const std::string & GetControllerAddress() const
Address given to the controller node by the implementation.
Definition: ControllerNode.h:62
bool IsControllerAccepted(const std::string &controllerId) const
Check to see if a controller is compatible with a controller port.
Definition: ControllerNode.cpp:100
Controller configuration window.
Definition: AudioDecoder.h:18
A branch in the controller tree.
Definition: ControllerHub.h:23
bool ProvidesInput() const
Check if this node provides input.
Definition: ControllerNode.cpp:133
const ControllerPtr & GetController() const
Controller profile of this code.
Definition: ControllerNode.h:48
const CControllerHub & GetHub() const
Collection of ports on this controller.
Definition: ControllerNode.h:71
bool IsValid() const
Check if this node has a valid controller profile.
Definition: ControllerNode.h:78