| 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 |
#include "PhysicalPort.h" |
| 10 |
|
| 11 |
#include "games/controllers/ControllerDefinitions.h" |
| 12 |
#include "utils/XMLUtils.h" |
| 13 |
#include "utils/log.h" |
| 14 |
|
| 15 |
#include <algorithm> |
| 16 |
#include <cstring> |
| 17 |
#include <utility> |
| 18 |
|
| 19 |
#include <tinyxml2.h> |
| 20 |
|
| 21 |
using namespace KODI; |
| 22 |
using namespace GAME; |
| 23 |
|
| 24 |
CPhysicalPort::CPhysicalPort(std::string portId, std::vector<std::string> accepts) |
| 25 |
: m_portId(std::move(portId)), m_accepts(std::move(accepts)) |
| 26 |
{ |
| 27 |
} |
| 28 |
|
| 29 |
void CPhysicalPort::Reset() |
| 30 |
{ |
| 31 |
CPhysicalPort defaultPort; |
| 32 |
*this = std::move(defaultPort); |
| 33 |
} |
| 34 |
|
| 35 |
bool CPhysicalPort::IsCompatible(const std::string& controllerId) const |
| 36 |
{ |
| 37 |
return std::find(m_accepts.begin(), m_accepts.end(), controllerId) != m_accepts.end(); |
| 38 |
} |
| 39 |
|
| 40 |
bool CPhysicalPort::Deserialize(const tinyxml2::XMLElement* pElement) |
| 41 |
{ |
| 42 |
if (pElement == nullptr) |
| 43 |
return false; |
| 44 |
|
| 45 |
Reset(); |
| 46 |
|
| 47 |
m_portId = XMLUtils::GetAttribute(pElement, LAYOUT_XML_ATTR_PORT_ID); |
| 48 |
|
| 49 |
for (const auto* pChild = pElement->FirstChildElement(); pChild != nullptr; |
| 50 |
pChild = pChild->NextSiblingElement()) |
| 51 |
{ |
| 52 |
if (std::strcmp(pChild->Value(), LAYOUT_XML_ELM_ACCEPTS) == 0) |
| 53 |
{ |
| 54 |
std::string controller = XMLUtils::GetAttribute(pChild, LAYOUT_XML_ATTR_CONTROLLER); |
| 55 |
|
| 56 |
if (!controller.empty()) |
| 57 |
m_accepts.emplace_back(std::move(controller)); |
| 58 |
else |
| 59 |
CLog::Log(LOGWARNING, "<{}> tag is missing \"{}\" attribute", LAYOUT_XML_ELM_ACCEPTS, |
| 60 |
LAYOUT_XML_ATTR_CONTROLLER); |
| 61 |
} |
| 62 |
else |
| 63 |
{ |
| 64 |
CLog::Log(LOGDEBUG, "Unknown physical topology port tag: <{}>", pChild->Value()); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
return true; |
| 69 |
} |