1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/*
* Copyright (C) 2021 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#pragma once
#include "games/controllers/types/ControllerTree.h"
#include <future>
#include <mutex>
#include <string>
class TiXmlElement;
namespace KODI
{
namespace GAME
{
class CPortManager
{
public:
CPortManager();
~CPortManager();
void Initialize(const std::string& profilePath);
void Deinitialize();
void SetControllerTree(const CControllerTree& controllerTree);
void LoadXML();
void SaveXMLAsync();
void Clear();
void ConnectController(const std::string& portAddress,
bool connected,
const std::string& controllerId = "");
const CControllerTree& GetControllerTree() const { return m_controllerTree; }
private:
static void DeserializePorts(const TiXmlElement* pElement, PortVec& ports);
static void DeserializePort(const TiXmlElement* pElement, CPortNode& port);
static void DeserializeControllers(const TiXmlElement* pElement, ControllerNodeVec& controllers);
static void DeserializeController(const TiXmlElement* pElement, CControllerNode& controller);
static void SerializePorts(TiXmlElement& node, const PortVec& ports);
static void SerializePort(TiXmlElement& portNode, const CPortNode& port);
static void SerializeControllers(TiXmlElement& portNode, const ControllerNodeVec& controllers);
static void SerializeController(TiXmlElement& controllerNode, const CControllerNode& controller);
static bool ConnectController(const std::string& portAddress,
bool connected,
const std::string& controllerId,
PortVec& ports);
static bool ConnectController(const std::string& portAddress,
bool connected,
const std::string& controllerId,
CPortNode& port);
static bool ConnectController(const std::string& portAddress,
bool connected,
const std::string& controllerId,
ControllerNodeVec& controllers);
static bool ConnectController(const std::string& portAddress,
bool connected,
const std::string& controllerId,
CControllerNode& controller);
static bool HasState(const CPortNode& port);
static bool HasState(const CControllerNode& controller);
CControllerTree m_controllerTree;
std::string m_xmlPath;
std::vector<std::future<void>> m_saveFutures;
std::mutex m_saveMutex;
};
} // namespace GAME
} // namespace KODI
|