| 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 "PhysicalTopology.h" |
| 10 |
|
| 11 |
#include "games/controllers/ControllerDefinitions.h" |
| 12 |
#include "utils/XMLUtils.h" |
| 13 |
#include "utils/log.h" |
| 14 |
|
| 15 |
#include <cstring> |
| 16 |
#include <utility> |
| 17 |
|
| 18 |
#include <tinyxml2.h> |
| 19 |
|
| 20 |
using namespace KODI; |
| 21 |
using namespace GAME; |
| 22 |
|
| 23 |
CPhysicalTopology::CPhysicalTopology(bool bProvidesInput, std::vector<CPhysicalPort> ports) |
| 24 |
: m_bProvidesInput(bProvidesInput), m_ports(std::move(ports)) |
| 25 |
{ |
| 26 |
} |
| 27 |
|
| 28 |
void CPhysicalTopology::Reset() |
| 29 |
{ |
| 30 |
CPhysicalTopology defaultTopology; |
| 31 |
*this = std::move(defaultTopology); |
| 32 |
} |
| 33 |
|
| 34 |
bool CPhysicalTopology::Deserialize(const tinyxml2::XMLElement* pElement) |
| 35 |
{ |
| 36 |
Reset(); |
| 37 |
|
| 38 |
if (pElement == nullptr) |
| 39 |
return false; |
| 40 |
|
| 41 |
m_bProvidesInput = (XMLUtils::GetAttribute(pElement, LAYOUT_XML_ATTR_PROVIDES_INPUT) != "false"); |
| 42 |
|
| 43 |
for (const auto* pChild = pElement->FirstChildElement(); pChild != nullptr; |
| 44 |
pChild = pChild->NextSiblingElement()) |
| 45 |
{ |
| 46 |
if (std::strcmp(pChild->Value(), LAYOUT_XML_ELM_PORT) == 0) |
| 47 |
{ |
| 48 |
CPhysicalPort port; |
| 49 |
if (port.Deserialize(pChild)) |
| 50 |
m_ports.emplace_back(std::move(port)); |
| 51 |
} |
| 52 |
else |
| 53 |
{ |
| 54 |
CLog::Log(LOGDEBUG, "Unknown physical topology tag: <{}>", pChild->Value()); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
return true; |
| 59 |
} |