| 1 |
/* |
| 2 |
* Copyright (C) 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/types/ControllerTree.h" |
| 12 |
|
| 13 |
#include <future> |
| 14 |
#include <mutex> |
| 15 |
#include <string> |
| 16 |
|
| 17 |
namespace tinyxml2 |
| 18 |
{ |
| 19 |
class XMLElement; |
| 20 |
} |
| 21 |
|
| 22 |
namespace KODI |
| 23 |
{ |
| 24 |
namespace GAME |
| 25 |
{ |
| 26 |
/*! |
| 27 |
* \ingroup games |
| 28 |
*/ |
| 29 |
class CPortManager |
| 30 |
{ |
| 31 |
public: |
| 32 |
CPortManager(); |
| 33 |
~CPortManager(); |
| 34 |
|
| 35 |
void Initialize(const std::string& profilePath); |
| 36 |
void Deinitialize(); |
| 37 |
|
| 38 |
void SetControllerTree(const CControllerTree& controllerTree); |
| 39 |
void LoadXML(); |
| 40 |
void SaveXMLAsync(); |
| 41 |
void Clear(); |
| 42 |
|
| 43 |
void ConnectController(const std::string& portAddress, |
| 44 |
bool connected, |
| 45 |
const std::string& controllerId = ""); |
| 46 |
|
| 47 |
const CControllerTree& GetControllerTree() const { return m_controllerTree; } |
| 48 |
|
| 49 |
private: |
| 50 |
static void DeserializePorts(const tinyxml2::XMLElement* pElement, PortVec& ports); |
| 51 |
static void DeserializePort(const tinyxml2::XMLElement* pElement, CPortNode& port); |
| 52 |
static void DeserializeControllers(const tinyxml2::XMLElement* pElement, |
| 53 |
ControllerNodeVec& controllers); |
| 54 |
static void DeserializeController(const tinyxml2::XMLElement* pElement, |
| 55 |
CControllerNode& controller); |
| 56 |
|
| 57 |
static void SerializePorts(tinyxml2::XMLElement& node, const PortVec& ports); |
| 58 |
static void SerializePort(tinyxml2::XMLElement& portNode, const CPortNode& port); |
| 59 |
static void SerializeControllers(tinyxml2::XMLElement& portNode, |
| 60 |
const ControllerNodeVec& controllers); |
| 61 |
static void SerializeController(tinyxml2::XMLElement& controllerNode, |
| 62 |
const CControllerNode& controller); |
| 63 |
|
| 64 |
static bool ConnectController(const std::string& portAddress, |
| 65 |
bool connected, |
| 66 |
const std::string& controllerId, |
| 67 |
PortVec& ports); |
| 68 |
static bool ConnectController(const std::string& portAddress, |
| 69 |
bool connected, |
| 70 |
const std::string& controllerId, |
| 71 |
CPortNode& port); |
| 72 |
static bool ConnectController(const std::string& portAddress, |
| 73 |
bool connected, |
| 74 |
const std::string& controllerId, |
| 75 |
ControllerNodeVec& controllers); |
| 76 |
static bool ConnectController(const std::string& portAddress, |
| 77 |
bool connected, |
| 78 |
const std::string& controllerId, |
| 79 |
CControllerNode& controller); |
| 80 |
|
| 81 |
static bool HasState(const CPortNode& port); |
| 82 |
static bool HasState(const CControllerNode& controller); |
| 83 |
|
| 84 |
CControllerTree m_controllerTree; |
| 85 |
std::string m_xmlPath; |
| 86 |
|
| 87 |
std::vector<std::future<void>> m_saveFutures; |
| 88 |
std::mutex m_saveMutex; |
| 89 |
}; |
| 90 |
} // namespace GAME |
| 91 |
} // namespace KODI |