kodi
Peripheral.h
1 /*
2  * Copyright (C) 2005-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 "games/controllers/ControllerTypes.h"
12 #include "input/joysticks/interfaces/IInputProvider.h"
13 #include "input/keyboard/interfaces/IKeyboardInputProvider.h"
14 #include "input/mouse/interfaces/IMouseInputProvider.h"
15 #include "peripherals/PeripheralTypes.h"
16 
17 #include <map>
18 #include <set>
19 #include <string>
20 #include <vector>
21 
22 class CDateTime;
23 class CSetting;
24 
25 namespace KODI
26 {
27 namespace JOYSTICK
28 {
29 class IButtonMapper;
30 class IDriverHandler;
31 class IDriverReceiver;
32 class IInputHandler;
33 } // namespace JOYSTICK
34 
35 namespace KEYBOARD
36 {
37 class IKeyboardDriverHandler;
38 } // namespace KEYBOARD
39 
40 namespace KEYMAP
41 {
42 class IKeymap;
43 } // namespace KEYMAP
44 
45 namespace MOUSE
46 {
47 class IMouseDriverHandler;
48 } // namespace MOUSE
49 } // namespace KODI
50 
51 namespace PERIPHERALS
52 {
53 class CAddonButtonMapping;
54 class CGUIDialogPeripheralSettings;
55 class CPeripheralBus;
56 class CPeripherals;
57 
61 typedef enum
62 {
63  STATE_SWITCH_TOGGLE,
64  STATE_ACTIVATE_SOURCE,
65  STATE_STANDBY
66 } CecStateChange;
67 
74 {
75  friend class CGUIDialogPeripheralSettings;
76 
77 public:
78  CPeripheral(CPeripherals& manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus);
79  ~CPeripheral(void) override;
80 
81  bool operator==(const CPeripheral& right) const;
82  bool operator!=(const CPeripheral& right) const;
83  bool operator==(const PeripheralScanResult& right) const;
84  bool operator!=(const PeripheralScanResult& right) const;
85 
86  const std::string& FileLocation(void) const { return m_strFileLocation; }
87  const std::string& Location(void) const { return m_strLocation; }
88  int VendorId(void) const { return m_iVendorId; }
89  const char* VendorIdAsString(void) const { return m_strVendorId.c_str(); }
90  int ProductId(void) const { return m_iProductId; }
91  const char* ProductIdAsString(void) const { return m_strProductId.c_str(); }
92  PeripheralType Type(void) const { return m_type; }
93  PeripheralBusType GetBusType(void) const { return m_busType; }
94  const std::string& DeviceName(void) const { return m_strDeviceName; }
95  bool IsHidden(void) const { return m_bHidden; }
96  void SetHidden(bool bSetTo = true) { m_bHidden = bSetTo; }
97  const std::string& GetVersionInfo(void) const { return m_strVersionInfo; }
98 
103  virtual std::string GetIcon() const;
104 
110  bool HasFeature(const PeripheralFeature feature) const;
111 
116  void GetFeatures(std::vector<PeripheralFeature>& features) const;
117 
122  bool Initialise(void);
123 
129  virtual bool InitialiseFeature(const PeripheralFeature feature) { return true; }
130 
134  virtual void OnUserNotification() {}
135 
141  virtual bool TestFeature(PeripheralFeature feature) { return false; }
142 
147  virtual void OnSettingChanged(const std::string& strChangedSetting) {}
148 
152  virtual void OnDeviceRemoved(void) {}
153 
158  virtual void GetSubdevices(PeripheralVector& subDevices) const;
159 
163  virtual bool IsMultiFunctional(void) const;
164 
171  virtual void AddSetting(const std::string& strKey,
172  const std::shared_ptr<const CSetting>& setting,
173  int order);
174 
180  virtual bool HasSetting(const std::string& strKey) const;
181 
185  virtual bool HasSettings(void) const;
186 
190  virtual bool HasConfigurableSettings(void) const;
191 
197  virtual const std::string GetSettingString(const std::string& strKey) const;
198  virtual bool SetSetting(const std::string& strKey, const std::string& strValue);
199  virtual void SetSettingVisible(const std::string& strKey, bool bSetTo);
200  virtual bool IsSettingVisible(const std::string& strKey) const;
201 
202  virtual int GetSettingInt(const std::string& strKey) const;
203  virtual bool SetSetting(const std::string& strKey, int iValue);
204 
205  virtual bool GetSettingBool(const std::string& strKey) const;
206  virtual bool SetSetting(const std::string& strKey, bool bValue);
207 
208  virtual float GetSettingFloat(const std::string& strKey) const;
209  virtual bool SetSetting(const std::string& strKey, float fValue);
210 
211  virtual void PersistSettings(bool bExiting = false);
212  virtual void LoadPersistedSettings(void);
213  virtual void ResetDefaultSettings(void);
214 
215  virtual std::vector<std::shared_ptr<CSetting>> GetSettings(void) const;
216 
217  virtual bool ErrorOccured(void) const { return m_bError; }
218 
219  virtual void RegisterJoystickDriverHandler(KODI::JOYSTICK::IDriverHandler* handler,
220  bool bPromiscuous)
221  {
222  }
223  virtual void UnregisterJoystickDriverHandler(KODI::JOYSTICK::IDriverHandler* handler) {}
224 
225  virtual void RegisterKeyboardDriverHandler(KODI::KEYBOARD::IKeyboardDriverHandler* handler,
226  bool bPromiscuous)
227  {
228  }
229  virtual void UnregisterKeyboardDriverHandler(KODI::KEYBOARD::IKeyboardDriverHandler* handler) {}
230 
231  virtual void RegisterMouseDriverHandler(KODI::MOUSE::IMouseDriverHandler* handler,
232  bool bPromiscuous)
233  {
234  }
235  virtual void UnregisterMouseDriverHandler(KODI::MOUSE::IMouseDriverHandler* handler) {}
236 
237  // implementation of IInputProvider
238  void RegisterInputHandler(KODI::JOYSTICK::IInputHandler* handler, bool bPromiscuous) override;
239  void UnregisterInputHandler(KODI::JOYSTICK::IInputHandler* handler) override;
240 
241  // implementation of IKeyboardInputProvider
242  void RegisterKeyboardHandler(KODI::KEYBOARD::IKeyboardInputHandler* handler,
243  bool bPromiscuous,
244  bool forceDefaultMap) override;
245  void UnregisterKeyboardHandler(KODI::KEYBOARD::IKeyboardInputHandler* handler) override;
246 
247  // implementation of IMouseInputProvider
248  void RegisterMouseHandler(KODI::MOUSE::IMouseInputHandler* handler,
249  bool bPromiscuous,
250  bool forceDefaultMap) override;
251  void UnregisterMouseHandler(KODI::MOUSE::IMouseInputHandler* handler) override;
252 
253  virtual void RegisterJoystickButtonMapper(KODI::JOYSTICK::IButtonMapper* mapper);
254  virtual void UnregisterJoystickButtonMapper(KODI::JOYSTICK::IButtonMapper* mapper);
255 
256  virtual KODI::JOYSTICK::IDriverReceiver* GetDriverReceiver() { return nullptr; }
257 
258  virtual KODI::KEYMAP::IKeymap* GetKeymap(const std::string& controllerId) { return nullptr; }
259 
265  virtual CDateTime LastActive() const;
266 
272  virtual KODI::GAME::ControllerPtr ControllerProfile() const { return m_controllerProfile; }
273 
279  virtual void SetControllerProfile(const KODI::GAME::ControllerPtr& controller)
280  {
281  m_controllerProfile = controller;
282  }
283 
284 protected:
285  virtual void ClearSettings(void);
286 
287  CPeripherals& m_manager;
288  PeripheralType m_type;
289  PeripheralBusType m_busType;
290  PeripheralBusType m_mappedBusType;
291  std::string m_strLocation;
292  std::string m_strDeviceName;
293  std::string m_strSettingsFile;
294  std::string m_strFileLocation;
295  int m_iVendorId;
296  std::string m_strVendorId;
297  int m_iProductId;
298  std::string m_strProductId;
299  std::string m_strVersionInfo;
300  bool m_bInitialised = false;
301  bool m_bHidden = false;
302  bool m_bError = false;
303  std::vector<PeripheralFeature> m_features;
304  PeripheralVector m_subDevices;
305  std::map<std::string, PeripheralDeviceSetting> m_settings;
306  std::set<std::string> m_changedSettings;
307  CPeripheralBus* m_bus;
308  std::map<KODI::JOYSTICK::IInputHandler*, std::unique_ptr<KODI::JOYSTICK::IDriverHandler>>
309  m_inputHandlers;
311  std::unique_ptr<KODI::KEYBOARD::IKeyboardDriverHandler>>
312  m_keyboardHandlers;
313  std::map<KODI::MOUSE::IMouseInputHandler*, std::unique_ptr<KODI::MOUSE::IMouseDriverHandler>>
314  m_mouseHandlers;
315  std::map<KODI::JOYSTICK::IButtonMapper*, std::unique_ptr<CAddonButtonMapping>> m_buttonMappers;
316  KODI::GAME::ControllerPtr m_controllerProfile;
317 };
318 } // namespace PERIPHERALS
Definition: PeripheralTypes.h:326
Definition: IInputHandler.h:16
Interface for classes that can provide mouse input.
Definition: IMouseInputProvider.h:22
Interface for classes that can provide input.
Definition: IInputProvider.h:22
Definition: RetroPlayerInput.h:15
virtual void OnUserNotification()
Briefly activate a feature to notify the user.
Definition: Peripheral.h:134
Definition: GUIDialogPeripheralSettings.h:22
Interface defining methods to handle joystick events for raw driver elements (buttons, hats, axes)
Definition: IDriverHandler.h:23
Setting base class containing all the properties which are common to all settings independent of the ...
Definition: Setting.h:46
Interface for handling input events for keyboards.
Definition: IKeyboardInputHandler.h:28
virtual KODI::GAME::ControllerPtr ControllerProfile() const
Get the controller profile that best represents this peripheral.
Definition: Peripheral.h:272
virtual void SetControllerProfile(const KODI::GAME::ControllerPtr &controller)
Set the controller profile for this peripheral.
Definition: Peripheral.h:279
Definition: AudioDecoder.h:18
Interface for classes that can provide keyboard input.
Definition: IKeyboardInputProvider.h:22
std::shared_ptr< CController > ControllerPtr
Smart pointer to a game controller (CController)
Definition: ControllerTypes.h:25
Interface for handling mouse events.
Definition: IMouseInputHandler.h:24
virtual bool InitialiseFeature(const PeripheralFeature feature)
Initialise one of the features of this peripheral.
Definition: Peripheral.h:129
DateTime class, which uses FileTime as it&#39;s base.
Definition: XBDateTime.h:63
Interface for handling input events for game controllers.
Definition: IInputHandler.h:26
Definition: PeripheralBus.h:36
Interface for handling mouse driver events.
Definition: IMouseDriverHandler.h:22
virtual bool TestFeature(PeripheralFeature feature)
Briefly test one of the features of this peripheral.
Definition: Peripheral.h:141
virtual void OnSettingChanged(const std::string &strChangedSetting)
Called when a setting changed.
Definition: Peripheral.h:147
Button mapper interface to assign the driver&#39;s raw button/hat/axis elements to physical joystick feat...
Definition: IButtonMapper.h:37
Interface for handling keyboard events.
Definition: IKeyboardDriverHandler.h:22
Definition: Peripheral.h:71
Interface for sending input events to joystick drivers.
Definition: IDriverReceiver.h:20
Definition: Peripherals.h:56
Interface for mapping buttons to Kodi actions.
Definition: IKeymap.h:28
virtual void OnDeviceRemoved(void)
Called when this device is removed, before calling the destructor.
Definition: Peripheral.h:152