| 1 |
/* |
| 2 |
* Copyright (C) 2017-2018 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 |
#include "GameClientPort.h" |
| 10 |
|
| 11 |
#include "GameClientDevice.h" |
| 12 |
#include "addons/kodi-dev-kit/include/kodi/addon-instance/Game.h" |
| 13 |
#include "games/addons/GameClientTranslator.h" |
| 14 |
#include "games/controllers/Controller.h" |
| 15 |
#include "games/controllers/input/PhysicalTopology.h" |
| 16 |
#include "utils/StringUtils.h" |
| 17 |
|
| 18 |
#include <algorithm> |
| 19 |
|
| 20 |
using namespace KODI; |
| 21 |
using namespace GAME; |
| 22 |
|
| 23 |
CGameClientPort::CGameClientPort(const game_input_port& port) |
| 24 |
: m_type(CGameClientTranslator::TranslatePortType(port.type)), |
| 25 |
m_portId(port.port_id ? port.port_id : ""), |
| 26 |
m_forceConnected(port.force_connected) |
| 27 |
{ |
| 28 |
if (port.accepted_devices != nullptr) |
| 29 |
{ |
| 30 |
for (unsigned int i = 0; i < port.device_count; i++) |
| 31 |
{ |
| 32 |
std::unique_ptr<CGameClientDevice> device(new CGameClientDevice(port.accepted_devices[i])); |
| 33 |
|
| 34 |
if (device->Controller() != CController::EmptyPtr) |
| 35 |
m_acceptedDevices.emplace_back(std::move(device)); |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
CGameClientPort::CGameClientPort(const ControllerVector& controllers) |
| 41 |
: m_type(PORT_TYPE::CONTROLLER), m_portId(DEFAULT_PORT_ID) |
| 42 |
{ |
| 43 |
for (const auto& controller : controllers) |
| 44 |
m_acceptedDevices.emplace_back(new CGameClientDevice(controller)); |
| 45 |
} |
| 46 |
|
| 47 |
CGameClientPort::CGameClientPort(const game_input_port& logicalPort, |
| 48 |
const CPhysicalPort& physicalPort) |
| 49 |
: m_type(PORT_TYPE::CONTROLLER), |
| 50 |
m_portId(physicalPort.ID()), |
| 51 |
m_forceConnected(logicalPort.force_connected) |
| 52 |
{ |
| 53 |
if (logicalPort.accepted_devices != nullptr) |
| 54 |
{ |
| 55 |
for (unsigned int i = 0; i < logicalPort.device_count; i++) |
| 56 |
{ |
| 57 |
// Ensure device is physically compatible |
| 58 |
const game_input_device& deviceStruct = logicalPort.accepted_devices[i]; |
| 59 |
std::string controllerId = deviceStruct.controller_id ? deviceStruct.controller_id : ""; |
| 60 |
|
| 61 |
if (physicalPort.IsCompatible(controllerId)) |
| 62 |
{ |
| 63 |
std::unique_ptr<CGameClientDevice> device(new CGameClientDevice(deviceStruct)); |
| 64 |
|
| 65 |
if (device->Controller() != CController::EmptyPtr) |
| 66 |
m_acceptedDevices.emplace_back(std::move(device)); |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
CGameClientPort::~CGameClientPort() = default; |