This repository has been archived by the owner on May 16, 2021. It is now read-only.
forked from xbmc/peripheral.joystick
/
JoystickManager.h
113 lines (96 loc) · 3.14 KB
/
JoystickManager.h
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* Copyright (C) 2014-2015 Garrett Brown
* Copyright (C) 2014-2015 Team XBMC
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "JoystickTypes.h"
#include "storage/ButtonMapTypes.h" // for FeatureVector
#include "kodi_peripheral_utils.hpp"
#include "p8-platform/threads/mutex.h"
#include <vector>
namespace JOYSTICK
{
class IJoystickInterface;
class IScannerCallback
{
public:
virtual ~IScannerCallback(void) { }
/*!
* \brief Trigger a scan for joysticks
*/
virtual void TriggerScan(void) = 0;
};
class CJoystickManager
{
private:
CJoystickManager(void);
public:
static CJoystickManager& Get(void);
virtual ~CJoystickManager(void) { Deinitialize(); }
/*!
* \brief Initialize the joystick manager
*
* \param scanner The callback used to trigger a scan
*/
bool Initialize(IScannerCallback* scanner);
/*!
* \brief Deinitialize the joystick manager
*/
void Deinitialize(void);
/*!
* \brief Scan the available interfaces for joysticks
*
* \param joysticks The discovered joysticks; must be deallocated
*
* \return true if the scan succeeded (even if there are no joysticks)
*/
bool PerformJoystickScan(JoystickVector& joysticks);
JoystickPtr GetJoystick(unsigned int index) const;
/*!
* \brief Get all events that have occurred since the last call to GetEvents()
*/
bool GetEvents(std::vector<ADDON::PeripheralEvent>& events);
/*!
* \brief Send an event to a joystick
*
* \param event The event
*
* \return True if the event was handled
*/
bool SendEvent(const ADDON::PeripheralEvent& event);
/*!
* \brief Trigger a scan for joysticks through the callback
*/
void TriggerScan(void);
/*!
* \brief Get the feature mapping known to an interface
*
* \param provider Name of the joystick interface
* \param controllerId Add-on ID of the controller profile being requested
* \param[out] features The features, if any are known to the interface
*/
void GetFeatures(const std::string& provider, const std::string& controllerId, FeatureVector& features);
private:
IScannerCallback* m_scanner;
std::vector<IJoystickInterface*> m_interfaces;
JoystickVector m_joysticks;
unsigned int m_nextJoystickIndex;
mutable P8PLATFORM::CMutex m_interfacesMutex;
mutable P8PLATFORM::CMutex m_joystickMutex;
};
}