Skip to content

Commit

Permalink
Merge pull request xbmc#23600 from fuzzard/tinyxml2_input
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins4kodi authored Aug 22, 2023
2 parents 9f7393d + 2a0ea47 commit 7c40a6d
Show file tree
Hide file tree
Showing 35 changed files with 348 additions and 239 deletions.
14 changes: 8 additions & 6 deletions xbmc/games/controllers/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
#include "URL.h"
#include "addons/addoninfo/AddonType.h"
#include "games/controllers/input/PhysicalTopology.h"
#include "utils/XBMCTinyXML.h"
#include "utils/XBMCTinyXML2.h"
#include "utils/XMLUtils.h"
#include "utils/log.h"

#include <algorithm>
#include <cstring>

using namespace KODI;
using namespace GAME;
Expand Down Expand Up @@ -122,16 +123,17 @@ bool CController::LoadLayout(void)

CLog::Log(LOGINFO, "Loading controller layout: {}", CURL::GetRedacted(strLayoutXmlPath));

CXBMCTinyXML xmlDoc;
CXBMCTinyXML2 xmlDoc;
if (!xmlDoc.LoadFile(strLayoutXmlPath))
{
CLog::Log(LOGDEBUG, "Unable to load file: {} at line {}", xmlDoc.ErrorDesc(),
xmlDoc.ErrorRow());
CLog::Log(LOGDEBUG, "Unable to load file: {} at line {}", xmlDoc.ErrorStr(),
xmlDoc.ErrorLineNum());
return false;
}

TiXmlElement* pRootElement = xmlDoc.RootElement();
if (!pRootElement || pRootElement->NoChildren() || pRootElement->ValueStr() != LAYOUT_XML_ROOT)
auto* pRootElement = xmlDoc.RootElement();
if (pRootElement == nullptr || pRootElement->NoChildren() ||
std::strcmp(pRootElement->Value(), LAYOUT_XML_ROOT) != 0)
{
CLog::Log(LOGERROR, "Can't find root <{}> tag", LAYOUT_XML_ROOT);
return false;
Expand Down
15 changes: 9 additions & 6 deletions xbmc/games/controllers/ControllerLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
#include "utils/XMLUtils.h"
#include "utils/log.h"

#include <cstring>
#include <sstream>

#include <tinyxml2.h>

using namespace KODI;
using namespace GAME;

Expand Down Expand Up @@ -87,7 +90,7 @@ std::string CControllerLayout::ImagePath(void) const
return path;
}

void CControllerLayout::Deserialize(const TiXmlElement* pElement,
void CControllerLayout::Deserialize(const tinyxml2::XMLElement* pElement,
const CController* controller,
std::vector<CPhysicalFeature>& features)
{
Expand Down Expand Up @@ -116,10 +119,10 @@ void CControllerLayout::Deserialize(const TiXmlElement* pElement,
if (!image.empty())
m_strImage = image;

for (const TiXmlElement* pChild = pElement->FirstChildElement(); pChild != nullptr;
for (const auto* pChild = pElement->FirstChildElement(); pChild != nullptr;
pChild = pChild->NextSiblingElement())
{
if (pChild->ValueStr() == LAYOUT_XML_ELM_CATEGORY)
if (std::strcmp(pChild->Value(), LAYOUT_XML_ELM_CATEGORY) == 0)
{
// Category
std::string strCategory = XMLUtils::GetAttribute(pChild, LAYOUT_XML_ATTR_CATEGORY_NAME);
Expand All @@ -135,7 +138,7 @@ void CControllerLayout::Deserialize(const TiXmlElement* pElement,
std::istringstream(strCategoryLabelId) >> categoryLabelId;

// Features
for (const TiXmlElement* pFeature = pChild->FirstChildElement(); pFeature != nullptr;
for (const auto* pFeature = pChild->FirstChildElement(); pFeature != nullptr;
pFeature = pFeature->NextSiblingElement())
{
CPhysicalFeature feature;
Expand All @@ -144,7 +147,7 @@ void CControllerLayout::Deserialize(const TiXmlElement* pElement,
features.push_back(feature);
}
}
else if (pChild->ValueStr() == LAYOUT_XML_ELM_TOPOLOGY)
else if (std::strcmp(pChild->Value(), LAYOUT_XML_ELM_TOPOLOGY) == 0)
{
// Topology
CPhysicalTopology topology;
Expand All @@ -153,7 +156,7 @@ void CControllerLayout::Deserialize(const TiXmlElement* pElement,
}
else
{
CLog::Log(LOGDEBUG, "Ignoring <{}> tag", pChild->ValueStr());
CLog::Log(LOGDEBUG, "Ignoring <{}> tag", pChild->Value());
}
}
}
7 changes: 5 additions & 2 deletions xbmc/games/controllers/ControllerLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
#include <string>
#include <vector>

class TiXmlElement;
namespace tinyxml2
{
class XMLElement;
}

namespace KODI
{
Expand Down Expand Up @@ -76,7 +79,7 @@ class CControllerLayout
* \param controller The controller, used to obtain read-only properties
* \param features The deserialized features, if any
*/
void Deserialize(const TiXmlElement* pLayoutElement,
void Deserialize(const tinyxml2::XMLElement* pLayoutElement,
const CController* controller,
std::vector<CPhysicalFeature>& features);

Expand Down
4 changes: 3 additions & 1 deletion xbmc/games/controllers/input/PhysicalFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include <sstream>

#include <tinyxml2.h>

using namespace KODI;
using namespace GAME;
using namespace JOYSTICK;
Expand Down Expand Up @@ -74,7 +76,7 @@ std::string CPhysicalFeature::Label() const
return label;
}

bool CPhysicalFeature::Deserialize(const TiXmlElement* pElement,
bool CPhysicalFeature::Deserialize(const tinyxml2::XMLElement* pElement,
const CController* controller,
FEATURE_CATEGORY category,
int categoryLabelId)
Expand Down
7 changes: 5 additions & 2 deletions xbmc/games/controllers/input/PhysicalFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

#include <string>

class TiXmlElement;
namespace tinyxml2
{
class XMLElement;
}

namespace KODI
{
Expand Down Expand Up @@ -45,7 +48,7 @@ class CPhysicalFeature
JOYSTICK::INPUT_TYPE InputType(void) const { return m_inputType; }
KEYBOARD::KeySymbol Keycode() const { return m_keycode; }

bool Deserialize(const TiXmlElement* pElement,
bool Deserialize(const tinyxml2::XMLElement* pElement,
const CController* controller,
JOYSTICK::FEATURE_CATEGORY category,
int categoryLabelId);
Expand Down
11 changes: 7 additions & 4 deletions xbmc/games/controllers/input/PhysicalTopology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
#include "utils/XMLUtils.h"
#include "utils/log.h"

#include <cstring>
#include <utility>

#include <tinyxml2.h>

using namespace KODI;
using namespace GAME;

Expand All @@ -28,7 +31,7 @@ void CPhysicalTopology::Reset()
*this = std::move(defaultTopology);
}

bool CPhysicalTopology::Deserialize(const TiXmlElement* pElement)
bool CPhysicalTopology::Deserialize(const tinyxml2::XMLElement* pElement)
{
Reset();

Expand All @@ -37,18 +40,18 @@ bool CPhysicalTopology::Deserialize(const TiXmlElement* pElement)

m_bProvidesInput = (XMLUtils::GetAttribute(pElement, LAYOUT_XML_ATTR_PROVIDES_INPUT) != "false");

for (const TiXmlElement* pChild = pElement->FirstChildElement(); pChild != nullptr;
for (const auto* pChild = pElement->FirstChildElement(); pChild != nullptr;
pChild = pChild->NextSiblingElement())
{
if (pChild->ValueStr() == LAYOUT_XML_ELM_PORT)
if (std::strcmp(pChild->Value(), LAYOUT_XML_ELM_PORT) == 0)
{
CPhysicalPort port;
if (port.Deserialize(pChild))
m_ports.emplace_back(std::move(port));
}
else
{
CLog::Log(LOGDEBUG, "Unknown physical topology tag: <{}>", pChild->ValueStr());
CLog::Log(LOGDEBUG, "Unknown physical topology tag: <{}>", pChild->Value());
}
}

Expand Down
7 changes: 5 additions & 2 deletions xbmc/games/controllers/input/PhysicalTopology.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

#include <vector>

class TiXmlElement;
namespace tinyxml2
{
class XMLElement;
}

namespace KODI
{
Expand Down Expand Up @@ -50,7 +53,7 @@ class CPhysicalTopology
*/
const std::vector<CPhysicalPort>& Ports() const { return m_ports; }

bool Deserialize(const TiXmlElement* pElement);
bool Deserialize(const tinyxml2::XMLElement* pElement);

private:
bool m_bProvidesInput = true;
Expand Down
11 changes: 7 additions & 4 deletions xbmc/games/ports/input/PhysicalPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
#include "utils/log.h"

#include <algorithm>
#include <cstring>
#include <utility>

#include <tinyxml2.h>

using namespace KODI;
using namespace GAME;

Expand All @@ -34,7 +37,7 @@ bool CPhysicalPort::IsCompatible(const std::string& controllerId) const
return std::find(m_accepts.begin(), m_accepts.end(), controllerId) != m_accepts.end();
}

bool CPhysicalPort::Deserialize(const TiXmlElement* pElement)
bool CPhysicalPort::Deserialize(const tinyxml2::XMLElement* pElement)
{
if (pElement == nullptr)
return false;
Expand All @@ -43,10 +46,10 @@ bool CPhysicalPort::Deserialize(const TiXmlElement* pElement)

m_portId = XMLUtils::GetAttribute(pElement, LAYOUT_XML_ATTR_PORT_ID);

for (const TiXmlElement* pChild = pElement->FirstChildElement(); pChild != nullptr;
for (const auto* pChild = pElement->FirstChildElement(); pChild != nullptr;
pChild = pChild->NextSiblingElement())
{
if (pChild->ValueStr() == LAYOUT_XML_ELM_ACCEPTS)
if (std::strcmp(pChild->Value(), LAYOUT_XML_ELM_ACCEPTS) == 0)
{
std::string controller = XMLUtils::GetAttribute(pChild, LAYOUT_XML_ATTR_CONTROLLER);

Expand All @@ -58,7 +61,7 @@ bool CPhysicalPort::Deserialize(const TiXmlElement* pElement)
}
else
{
CLog::Log(LOGDEBUG, "Unknown physical topology port tag: <{}>", pChild->ValueStr());
CLog::Log(LOGDEBUG, "Unknown physical topology port tag: <{}>", pChild->Value());
}
}

Expand Down
7 changes: 5 additions & 2 deletions xbmc/games/ports/input/PhysicalPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
#include <string>
#include <vector>

class TiXmlElement;
namespace tinyxml2
{
class XMLElement;
}

namespace KODI
{
Expand Down Expand Up @@ -54,7 +57,7 @@ class CPhysicalPort
*/
bool IsCompatible(const std::string& controllerId) const;

bool Deserialize(const TiXmlElement* pElement);
bool Deserialize(const tinyxml2::XMLElement* pElement);

private:
std::string m_portId;
Expand Down
Loading

0 comments on commit 7c40a6d

Please sign in to comment.