kodi
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 
28 class CPortNode
29 {
30 public:
31  CPortNode() = default;
32  CPortNode(const CPortNode& other) { *this = other; }
33  CPortNode(CPortNode&& other) = default;
34  CPortNode& operator=(const CPortNode& rhs);
35  CPortNode& operator=(CPortNode&& rhs) noexcept;
36  ~CPortNode();
37 
43  bool IsConnected() const { return m_bConnected; }
44  void SetConnected(bool bConnected) { m_bConnected = bConnected; }
45 
51  const CControllerNode& GetActiveController() const;
53  void SetActiveController(unsigned int controllerIndex) { m_active = controllerIndex; }
54  bool SetActiveController(const std::string& controllerId);
55 
61  PORT_TYPE GetPortType() const { return m_portType; }
62  void SetPortType(PORT_TYPE type) { m_portType = type; }
63 
70  const std::string& GetPortID() const { return m_portId; }
71  void SetPortID(std::string portId);
72 
76  const std::string& GetAddress() const { return m_address; }
77  void SetAddress(std::string address);
78 
83  bool IsForceConnected() const { return m_forceConnected; }
84  void SetForceConnected(bool forceConnected) { m_forceConnected = forceConnected; }
85 
92  const ControllerNodeVec& GetCompatibleControllers() const { return m_controllers; }
93  ControllerNodeVec& GetCompatibleControllers() { return m_controllers; }
94  void SetCompatibleControllers(ControllerNodeVec controllers);
95 
103  bool IsControllerAccepted(const std::string& controllerId) const;
104 
113  bool IsControllerAccepted(const std::string& portAddress, const std::string& controllerId) const;
114 
120  void GetInputPorts(std::vector<std::string>& inputPorts) const;
121 
122 private:
123  void GetPort(CPhysicalPort& port) const;
124 
125  bool m_bConnected = false;
126  unsigned int m_active = 0;
127  PORT_TYPE m_portType = PORT_TYPE::UNKNOWN;
128  std::string m_portId;
129  std::string m_address;
130  bool m_forceConnected{true};
131  ControllerNodeVec m_controllers;
132 };
133 
137 using PortVec = std::vector<CPortNode>;
138 } // namespace GAME
139 } // namespace KODI
bool IsControllerAccepted(const std::string &controllerId) const
Check to see if a controller is compatible with this tree.
Definition: PortNode.cpp:104
const CControllerNode & GetActiveController() const
The controller that is active on this port.
Definition: PortNode.cpp:55
Node in the controller tree.
Definition: ControllerNode.h:31
const std::string & GetPortID() const
The hardware or controller port ID.
Definition: PortNode.h:70
const ControllerNodeVec & GetCompatibleControllers() const
Return the controller profiles that are compatible with this port.
Definition: PortNode.h:92
Collection of nodes that can be connected to this port.
Definition: PortNode.h:28
bool IsForceConnected() const
If true, prevents a disconnection option from being shown for this port.
Definition: PortNode.h:83
Definition: AudioDecoder.h:18
Definition: PhysicalPort.h:27
const std::string & GetAddress() const
Address given to the node by the implementation.
Definition: PortNode.h:76
PORT_TYPE
Type of input provided by a hardware or controller port.
Definition: ControllerTypes.h:39
bool IsConnected() const
Connection state of the port.
Definition: PortNode.h:43
void GetInputPorts(std::vector< std::string > &inputPorts) const
Get a list of ports that accept player input.
Definition: PortNode.cpp:145
PORT_TYPE GetPortType() const
The port type.
Definition: PortNode.h:61