Debian Codegraph @

xbmc/games/controllers/ControllerManager.h

raw
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 #pragma once
10
11 #include "ControllerTypes.h"
12 #include "addons/IAddon.h"
13 #include "threads/CriticalSection.h"
14
15 #include <map>
16 #include <set>
17 #include <string>
18
19 namespace ADDON
20 {
21 struct AddonEvent;
22 } // namespace ADDON
23
24 namespace KODI
25 {
26 namespace GAME
27 {
28 /*!
29 * \ingroup games
30 */
31 class CControllerManager
32 {
33 public:
34 CControllerManager(ADDON::CAddonMgr& addonManager);
35 ~CControllerManager();
36
37 /*!
38 * \brief Get a controller
39 *
40 * A cache is used to avoid reloading controllers each time they are
41 * requested.
42 *
43 * \param controllerId The controller's ID
44 *
45 * \return The controller, or empty if the controller isn't installed or
46 * can't be loaded
47 */
48 ControllerPtr GetController(const std::string& controllerId);
49
50 /*!
51 * \brief Get the default controller
52 *
53 * \return The default controller, or empty if the controller failed to load
54 */
55 ControllerPtr GetDefaultController();
56
57 /*!
58 * \brief Get the default keyboard
59 *
60 * \return The keyboard controller, or empty if the controller failed to load
61 */
62 ControllerPtr GetDefaultKeyboard();
63
64 /*!
65 * \brief Get the default mouse
66 *
67 * \return The mouse controller, or empty if the controller failed to load
68 */
69 ControllerPtr GetDefaultMouse();
70
71 /*!
72 * \brief Get installed controllers
73 *
74 * \return The installed controllers that loaded successfully
75 */
76 ControllerVector GetControllers();
77
78 /*!
79 * \brief Translate a feature on a controller into its localized name
80 *
81 * \param controllerId The controller ID that the feature belongs to
82 * \param featureName The feature name
83 *
84 * \return The localized feature name, or empty if the controller or feature
85 * doesn't exist
86 */
87 std::string TranslateFeature(const std::string& controllerId, const std::string& featureName);
88
89 private:
90 // Add-on event handler
91 void OnEvent(const ADDON::AddonEvent& event);
92
93 // Utility functions
94 ControllerPtr LoadController(const ADDON::AddonPtr& addon);
95
96 // Construction parameters
97 ADDON::CAddonMgr& m_addonManager;
98
99 // Controller state
100 std::map<std::string, ControllerPtr> m_cache;
101 std::set<std::string> m_failedControllers; // Controllers that failed to load
102
103 // Synchronization parameters
104 CCriticalSection m_mutex;
105 };
106 } // namespace GAME
107 } // namespace KODI