xbmc
Peripheral.h
1 /*
2  * Copyright (C) 2005-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 "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 TiXmlDocument;
23 class CDateTime;
24 class CSetting;
25 class IKeymap;
26 
27 namespace KODI
28 {
29 namespace JOYSTICK
30 {
31 class IButtonMapper;
32 class IDriverHandler;
33 class IDriverReceiver;
34 class IInputHandler;
35 } // namespace JOYSTICK
36 
37 namespace KEYBOARD
38 {
39 class IKeyboardDriverHandler;
40 }
41 
42 namespace MOUSE
43 {
44 class IMouseDriverHandler;
45 }
46 } // namespace KODI
47 
48 namespace PERIPHERALS
49 {
50 class CAddonButtonMapping;
51 class CGUIDialogPeripheralSettings;
52 class CPeripheralBus;
53 class CPeripherals;
54 
55 typedef enum
56 {
57  STATE_SWITCH_TOGGLE,
58  STATE_ACTIVATE_SOURCE,
59  STATE_STANDBY
60 } CecStateChange;
61 
65 {
66  friend class CGUIDialogPeripheralSettings;
67 
68 public:
69  CPeripheral(CPeripherals& manager, const PeripheralScanResult& scanResult, CPeripheralBus* bus);
70  ~CPeripheral(void) override;
71 
72  bool operator==(const CPeripheral& right) const;
73  bool operator!=(const CPeripheral& right) const;
74  bool operator==(const PeripheralScanResult& right) const;
75  bool operator!=(const PeripheralScanResult& right) const;
76 
77  const std::string& FileLocation(void) const { return m_strFileLocation; }
78  const std::string& Location(void) const { return m_strLocation; }
79  int VendorId(void) const { return m_iVendorId; }
80  const char* VendorIdAsString(void) const { return m_strVendorId.c_str(); }
81  int ProductId(void) const { return m_iProductId; }
82  const char* ProductIdAsString(void) const { return m_strProductId.c_str(); }
83  PeripheralType Type(void) const { return m_type; }
84  PeripheralBusType GetBusType(void) const { return m_busType; }
85  const std::string& DeviceName(void) const { return m_strDeviceName; }
86  bool IsHidden(void) const { return m_bHidden; }
87  void SetHidden(bool bSetTo = true) { m_bHidden = bSetTo; }
88  const std::string& GetVersionInfo(void) const { return m_strVersionInfo; }
89 
94  virtual std::string GetIcon() const;
95 
101  bool HasFeature(const PeripheralFeature feature) const;
102 
107  void GetFeatures(std::vector<PeripheralFeature>& features) const;
108 
113  bool Initialise(void);
114 
120  virtual bool InitialiseFeature(const PeripheralFeature feature) { return true; }
121 
125  virtual void OnUserNotification() {}
126 
132  virtual bool TestFeature(PeripheralFeature feature) { return false; }
133 
138  virtual void OnSettingChanged(const std::string& strChangedSetting) {}
139 
143  virtual void OnDeviceRemoved(void) {}
144 
149  virtual void GetSubdevices(PeripheralVector& subDevices) const;
150 
154  virtual bool IsMultiFunctional(void) const;
155 
162  virtual void AddSetting(const std::string& strKey,
163  const std::shared_ptr<const CSetting>& setting,
164  int order);
165 
171  virtual bool HasSetting(const std::string& strKey) const;
172 
176  virtual bool HasSettings(void) const;
177 
181  virtual bool HasConfigurableSettings(void) const;
182 
188  virtual const std::string GetSettingString(const std::string& strKey) const;
189  virtual bool SetSetting(const std::string& strKey, const std::string& strValue);
190  virtual void SetSettingVisible(const std::string& strKey, bool bSetTo);
191  virtual bool IsSettingVisible(const std::string& strKey) const;
192 
193  virtual int GetSettingInt(const std::string& strKey) const;
194  virtual bool SetSetting(const std::string& strKey, int iValue);
195 
196  virtual bool GetSettingBool(const std::string& strKey) const;
197  virtual bool SetSetting(const std::string& strKey, bool bValue);
198 
199  virtual float GetSettingFloat(const std::string& strKey) const;
200  virtual bool SetSetting(const std::string& strKey, float fValue);
201 
202  virtual void PersistSettings(bool bExiting = false);
203  virtual void LoadPersistedSettings(void);
204  virtual void ResetDefaultSettings(void);
205 
206  virtual std::vector<std::shared_ptr<CSetting>> GetSettings(void) const;
207 
208  virtual bool ErrorOccured(void) const { return m_bError; }
209 
210  virtual void RegisterJoystickDriverHandler(KODI::JOYSTICK::IDriverHandler* handler,
211  bool bPromiscuous)
212  {
213  }
214  virtual void UnregisterJoystickDriverHandler(KODI::JOYSTICK::IDriverHandler* handler) {}
215 
216  virtual void RegisterKeyboardDriverHandler(KODI::KEYBOARD::IKeyboardDriverHandler* handler,
217  bool bPromiscuous)
218  {
219  }
220  virtual void UnregisterKeyboardDriverHandler(KODI::KEYBOARD::IKeyboardDriverHandler* handler) {}
221 
222  virtual void RegisterMouseDriverHandler(KODI::MOUSE::IMouseDriverHandler* handler,
223  bool bPromiscuous)
224  {
225  }
226  virtual void UnregisterMouseDriverHandler(KODI::MOUSE::IMouseDriverHandler* handler) {}
227 
228  // implementation of IInputProvider
229  void RegisterInputHandler(KODI::JOYSTICK::IInputHandler* handler, bool bPromiscuous) override;
230  void UnregisterInputHandler(KODI::JOYSTICK::IInputHandler* handler) override;
231 
232  // implementation of IKeyboardInputProvider
233  void RegisterKeyboardHandler(KODI::KEYBOARD::IKeyboardInputHandler* handler,
234  bool bPromiscuous) override;
235  void UnregisterKeyboardHandler(KODI::KEYBOARD::IKeyboardInputHandler* handler) override;
236 
237  // implementation of IMouseInputProvider
238  void RegisterMouseHandler(KODI::MOUSE::IMouseInputHandler* handler, bool bPromiscuous) override;
239  void UnregisterMouseHandler(KODI::MOUSE::IMouseInputHandler* handler) override;
240 
241  virtual void RegisterJoystickButtonMapper(KODI::JOYSTICK::IButtonMapper* mapper);
242  virtual void UnregisterJoystickButtonMapper(KODI::JOYSTICK::IButtonMapper* mapper);
243 
244  virtual KODI::JOYSTICK::IDriverReceiver* GetDriverReceiver() { return nullptr; }
245 
246  virtual IKeymap* GetKeymap(const std::string& controllerId) { return nullptr; }
247 
253  virtual CDateTime LastActive();
254 
260  virtual KODI::GAME::ControllerPtr ControllerProfile() const
261  {
262  return KODI::GAME::ControllerPtr{};
263  }
264 
265 protected:
266  virtual void ClearSettings(void);
267 
268  CPeripherals& m_manager;
269  PeripheralType m_type;
270  PeripheralBusType m_busType;
271  PeripheralBusType m_mappedBusType;
272  std::string m_strLocation;
273  std::string m_strDeviceName;
274  std::string m_strSettingsFile;
275  std::string m_strFileLocation;
276  int m_iVendorId;
277  std::string m_strVendorId;
278  int m_iProductId;
279  std::string m_strProductId;
280  std::string m_strVersionInfo;
281  bool m_bInitialised;
282  bool m_bHidden;
283  bool m_bError;
284  std::vector<PeripheralFeature> m_features;
285  PeripheralVector m_subDevices;
286  std::map<std::string, PeripheralDeviceSetting> m_settings;
287  std::set<std::string> m_changedSettings;
288  CPeripheralBus* m_bus;
289  std::map<KODI::JOYSTICK::IInputHandler*, std::unique_ptr<KODI::JOYSTICK::IDriverHandler>>
290  m_inputHandlers;
292  std::unique_ptr<KODI::KEYBOARD::IKeyboardDriverHandler>>
293  m_keyboardHandlers;
294  std::map<KODI::MOUSE::IMouseInputHandler*, std::unique_ptr<KODI::MOUSE::IMouseDriverHandler>>
295  m_mouseHandlers;
296  std::map<KODI::JOYSTICK::IButtonMapper*, std::unique_ptr<CAddonButtonMapping>> m_buttonMappers;
297 };
298 } // namespace PERIPHERALS
Interface for classes that can map buttons to Kodi actions.
Definition: IButtonMapper.h:16
Definition: PeripheralTypes.h:318
Definition: IInputHandler.h:16
Interface for classes that can provide mouse input.
Definition: IMouseInputProvider.h:21
Interface for classes that can provide input.
Definition: IInputProvider.h:21
Definition: RetroPlayerInput.h:15
virtual void OnUserNotification()
Briefly activate a feature to notify the user.
Definition: Peripheral.h:125
Definition: GUIDialogPeripheralSettings.h:17
Interface defining methods to handle joystick events for raw driver elements (buttons, hats, axes)
Definition: IDriverHandler.h:21
Interface for mapping buttons to Kodi actions.
Definition: IKeymap.h:22
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:27
virtual KODI::GAME::ControllerPtr ControllerProfile() const
Get the controller profile that best represents this peripheral.
Definition: Peripheral.h:260
Controller configuration window.
Definition: AudioDecoder.h:18
Interface for classes that can provide keyboard input.
Definition: IKeyboardInputProvider.h:21
Interface for handling mouse events.
Definition: IMouseInputHandler.h:23
virtual bool InitialiseFeature(const PeripheralFeature feature)
Initialise one of the features of this peripheral.
Definition: Peripheral.h:120
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:25
Definition: PeripheralBus.h:34
Interface for handling mouse driver events.
Definition: IMouseDriverHandler.h:21
virtual bool TestFeature(PeripheralFeature feature)
Briefly test one of the features of this peripheral.
Definition: Peripheral.h:132
virtual void OnSettingChanged(const std::string &strChangedSetting)
Called when a setting changed.
Definition: Peripheral.h:138
Button mapper interface to assign the driver&#39;s raw button/hat/axis elements to physical joystick feat...
Definition: IButtonMapper.h:33
Interface for handling keyboard events.
Definition: IKeyboardDriverHandler.h:21
Definition: Peripheral.h:62
Interface for sending input events to joystick drivers.
Definition: IDriverReceiver.h:19
Definition: Peripherals.h:49
virtual void OnDeviceRemoved(void)
Called when this device is removed, before calling the destructor.
Definition: Peripheral.h:143