xbmc
PortNode.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 #include "games/controllers/types/ControllerNode.h"
13 
14 #include <string>
15 #include <vector>
16 
17 namespace KODI
18 {
19 namespace GAME
20 {
21 class CPhysicalPort;
22 
26 class CPortNode
27 {
28 public:
29  CPortNode() = default;
30  CPortNode(const CPortNode& other) { *this = other; }
31  CPortNode(CPortNode&& other) = default;
32  CPortNode& operator=(const CPortNode& rhs);
33  CPortNode& operator=(CPortNode&& rhs) noexcept;
34  ~CPortNode();
35 
41  bool IsConnected() const { return m_bConnected; }
42  void SetConnected(bool bConnected) { m_bConnected = bConnected; }
43 
49  const CControllerNode& GetActiveController() const;
51  void SetActiveController(unsigned int controllerIndex) { m_active = controllerIndex; }
52  bool SetActiveController(const std::string& controllerId);
53 
59  PORT_TYPE GetPortType() const { return m_portType; }
60  void SetPortType(PORT_TYPE type) { m_portType = type; }
61 
68  const std::string& GetPortID() const { return m_portId; }
69  void SetPortID(std::string portId);
70 
74  const std::string& GetAddress() const { return m_address; }
75  void SetAddress(std::string address);
76 
81  bool IsForceConnected() const { return m_forceConnected; }
82  void SetForceConnected(bool forceConnected) { m_forceConnected = forceConnected; }
83 
90  const ControllerNodeVec& GetCompatibleControllers() const { return m_controllers; }
91  ControllerNodeVec& GetCompatibleControllers() { return m_controllers; }
92  void SetCompatibleControllers(ControllerNodeVec controllers);
93 
101  bool IsControllerAccepted(const std::string& controllerId) const;
102 
111  bool IsControllerAccepted(const std::string& portAddress, const std::string& controllerId) const;
112 
113 private:
114  void GetPort(CPhysicalPort& port) const;
115 
116  bool m_bConnected = false;
117  unsigned int m_active = 0;
118  PORT_TYPE m_portType = PORT_TYPE::UNKNOWN;
119  std::string m_portId;
120  std::string m_address;
121  bool m_forceConnected{true};
122  ControllerNodeVec m_controllers;
123 };
124 
128 using PortVec = std::vector<CPortNode>;
129 } // namespace GAME
130 } // namespace KODI
bool IsControllerAccepted(const std::string &controllerId) const
Check to see if a controller is compatible with this tree.
Definition: PortNode.cpp:103
const CControllerNode & GetActiveController() const
The controller that is active on this port.
Definition: PortNode.cpp:54
Node in the controller tree.
Definition: ControllerNode.h:29
const std::string & GetPortID() const
The hardware or controller port ID.
Definition: PortNode.h:68
const ControllerNodeVec & GetCompatibleControllers() const
Return the controller profiles that are compatible with this port.
Definition: PortNode.h:90
Collection of nodes that can be connected to this port.
Definition: PortNode.h:26
bool IsForceConnected() const
If true, prevents a disconnection option from being shown for this port.
Definition: PortNode.h:81
Controller configuration window.
Definition: AudioDecoder.h:18
Definition: PhysicalPort.h:21
const std::string & GetAddress() const
Address given to the node by the implementation.
Definition: PortNode.h:74
bool IsConnected() const
Connection state of the port.
Definition: PortNode.h:41
PORT_TYPE GetPortType() const
The port type.
Definition: PortNode.h:59