| 1 |
/* |
| 2 |
* Copyright (C) 2017-2024 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 "utils/Observer.h" |
| 12 |
|
| 13 |
#include <memory> |
| 14 |
#include <string> |
| 15 |
#include <vector> |
| 16 |
|
| 17 |
namespace KODI |
| 18 |
{ |
| 19 |
namespace JOYSTICK |
| 20 |
{ |
| 21 |
class IInputHandler; |
| 22 |
class IInputProvider; |
| 23 |
class IInputReceiver; |
| 24 |
} // namespace JOYSTICK |
| 25 |
|
| 26 |
namespace KEYMAP |
| 27 |
{ |
| 28 |
class IKeymap; |
| 29 |
class IKeymapEnvironment; |
| 30 |
|
| 31 |
/*! |
| 32 |
* \ingroup keymap |
| 33 |
*/ |
| 34 |
class CKeymapHandling : public Observer |
| 35 |
{ |
| 36 |
public: |
| 37 |
CKeymapHandling(JOYSTICK::IInputProvider* inputProvider, |
| 38 |
bool pPromiscuous, |
| 39 |
const IKeymapEnvironment* environment); |
| 40 |
|
| 41 |
~CKeymapHandling() override; |
| 42 |
|
| 43 |
/*! |
| 44 |
* \brief Unregister the input provider |
| 45 |
* |
| 46 |
* Call this if the input provider is invalidated, such as if a user |
| 47 |
* disconnects a controller. This prevents accessing the invalidated |
| 48 |
* input provider when keymaps are unloaded upon destruction. |
| 49 |
*/ |
| 50 |
void UnregisterInputProvider() { m_inputProvider = nullptr; } |
| 51 |
|
| 52 |
/*! |
| 53 |
* \brief |
| 54 |
*/ |
| 55 |
JOYSTICK::IInputReceiver* GetInputReceiver(const std::string& controllerId) const; |
| 56 |
|
| 57 |
/*! |
| 58 |
* \brief |
| 59 |
*/ |
| 60 |
IKeymap* GetKeymap(const std::string& controllerId) const; |
| 61 |
|
| 62 |
// implementation of Observer |
| 63 |
void Notify(const Observable& obs, const ObservableMessage msg) override; |
| 64 |
|
| 65 |
private: |
| 66 |
void LoadKeymaps(); |
| 67 |
void UnloadKeymaps(); |
| 68 |
|
| 69 |
// Construction parameter |
| 70 |
JOYSTICK::IInputProvider* m_inputProvider; |
| 71 |
const bool m_pPromiscuous; |
| 72 |
const IKeymapEnvironment* const m_environment; |
| 73 |
|
| 74 |
std::vector<std::unique_ptr<IKeymap>> m_keymaps; |
| 75 |
std::vector<std::unique_ptr<JOYSTICK::IInputHandler>> m_inputHandlers; |
| 76 |
}; |
| 77 |
} // namespace KEYMAP |
| 78 |
} // namespace KODI |