xbmc
Peripherals.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 "IEventScannerCallback.h"
12 #include "bus/PeripheralBus.h"
13 #include "devices/Peripheral.h"
14 #include "interfaces/IAnnouncer.h"
15 #include "messaging/IMessageTarget.h"
16 #include "settings/lib/ISettingCallback.h"
17 #include "threads/CriticalSection.h"
18 #include "threads/Thread.h"
19 #include "utils/Observer.h"
20 
21 #include <memory>
22 #include <vector>
23 
24 class CFileItemList;
25 class CInputManager;
26 class CSetting;
27 class CSettingsCategory;
28 class TiXmlElement;
29 class CAction;
30 class CKey;
31 
32 namespace KODI
33 {
34 namespace GAME
35 {
36 class CControllerManager;
37 }
38 
39 namespace JOYSTICK
40 {
41 class IButtonMapper;
42 }
43 } // namespace KODI
44 
45 namespace PERIPHERALS
46 {
47 class CEventScanner;
48 
50  public Observable,
52  public IEventScannerCallback,
54 {
55 public:
56  explicit CPeripherals(CInputManager& inputManager,
57  KODI::GAME::CControllerManager& controllerProfiles);
58 
59  ~CPeripherals() override;
60 
64  void Initialise();
65 
69  void Clear();
70 
77  PeripheralPtr GetPeripheralAtLocation(const std::string& strLocation,
78  PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
79 
86  bool HasPeripheralAtLocation(const std::string& strLocation,
87  PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
88 
94  PeripheralBusPtr GetBusWithDevice(const std::string& strLocation) const;
95 
101  bool SupportsFeature(PeripheralFeature feature) const;
102 
110  int GetPeripheralsWithFeature(PeripheralVector& results,
111  const PeripheralFeature feature,
112  PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
113 
114  size_t GetNumberOfPeripherals() const;
115 
122  bool HasPeripheralWithFeature(const PeripheralFeature feature,
123  PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
124 
130  void OnDeviceAdded(const CPeripheralBus& bus, const CPeripheral& peripheral);
131 
137  void OnDeviceDeleted(const CPeripheralBus& bus, const CPeripheral& peripheral);
138 
145  void CreatePeripheral(CPeripheralBus& bus, const PeripheralScanResult& result);
146 
152  void GetSettingsFromMapping(CPeripheral& peripheral) const;
153 
157  void TriggerDeviceScan(const PeripheralBusType type = PERIPHERAL_BUS_UNKNOWN);
158 
164  PeripheralBusPtr GetBusByType(const PeripheralBusType type) const;
165 
171  void GetDirectory(const std::string& strPath, CFileItemList& items) const;
172 
178  PeripheralPtr GetByPath(const std::string& strPath) const;
179 
186  bool OnAction(const CAction& action);
187 
192  bool IsMuted();
193 
199  bool ToggleMute();
200 
206  bool ToggleDeviceState(const CecStateChange mode = STATE_SWITCH_TOGGLE);
207 
213  bool Mute()
214  {
215  return ToggleMute();
216  }
217 
223  bool UnMute()
224  {
225  return ToggleMute();
226  }
227 
234  bool GetNextKeypress(float frameTime, CKey& key);
235 
240  EventPollHandlePtr RegisterEventPoller();
241 
246  EventLockHandlePtr RegisterEventLock();
247 
251  void OnUserNotification();
252 
257  void TestFeature(PeripheralFeature feature);
258 
262  void PowerOffDevices();
263 
264  bool SupportsCEC() const
265  {
266 #if defined(HAVE_LIBCEC)
267  return true;
268 #else
269  return false;
270 #endif
271  }
272 
273  // implementation of IEventScannerCallback
274  void ProcessEvents(void) override;
275 
285  void EnableButtonMapping();
286 
291  PeripheralAddonPtr GetAddonWithButtonMap(const CPeripheral* device);
292 
298  void ResetButtonMaps(const std::string& controllerId);
299 
312  void RegisterJoystickButtonMapper(KODI::JOYSTICK::IButtonMapper* mapper);
313 
318  void UnregisterJoystickButtonMapper(KODI::JOYSTICK::IButtonMapper* mapper);
319 
320  // implementation of ISettingCallback
321  void OnSettingChanged(const std::shared_ptr<const CSetting>& setting) override;
322  void OnSettingAction(const std::shared_ptr<const CSetting>& setting) override;
323 
324  // implementation of IMessageTarget
325  void OnApplicationMessage(KODI::MESSAGING::ThreadMessage* pMsg) override;
326  int GetMessageMask() override;
327 
328  // implementation of IAnnouncer
329  void Announce(ANNOUNCEMENT::AnnouncementFlag flag,
330  const std::string& sender,
331  const std::string& message,
332  const CVariant& data) override;
333 
337  CInputManager& GetInputManager() { return m_inputManager; }
338 
342  KODI::GAME::CControllerManager& GetControllerProfiles() { return m_controllerProfiles; }
343 
344 private:
345  bool LoadMappings();
346  bool GetMappingForDevice(const CPeripheralBus& bus, PeripheralScanResult& result) const;
347  static void GetSettingsFromMappingsFile(
348  TiXmlElement* xmlNode, std::map<std::string, PeripheralDeviceSetting>& m_settings);
349 
350  void OnDeviceChanged();
351 
352  // Construction parameters
353  CInputManager& m_inputManager;
354  KODI::GAME::CControllerManager& m_controllerProfiles;
355 
356 #if !defined(HAVE_LIBCEC)
357  bool m_bMissingLibCecWarningDisplayed = false;
358 #endif
359  std::vector<PeripheralBusPtr> m_busses;
360  std::vector<PeripheralDeviceMapping> m_mappings;
361  std::unique_ptr<CEventScanner> m_eventScanner;
362  mutable CCriticalSection m_critSectionBusses;
363  mutable CCriticalSection m_critSectionMappings;
364 };
365 } // namespace PERIPHERALS
Interface for classes that can map buttons to Kodi actions.
Definition: IButtonMapper.h:16
Definition: PeripheralTypes.h:318
KODI::GAME::CControllerManager & GetControllerProfiles()
Access controller profiles through the construction parameter.
Definition: Peripherals.h:342
bool UnMute()
Try to unmute the audio via a peripheral.
Definition: Peripherals.h:223
A class wishing to receive messages should implement this and call.
Definition: IMessageTarget.h:23
Main input processing class.
Definition: InputManager.h:63
CInputManager & GetInputManager()
Access the input manager passed to the constructor.
Definition: Peripherals.h:337
Definition: RetroPlayerInput.h:15
Represents a list of files.
Definition: FileItem.h:713
Definition: IAnnouncer.h:70
Definition: ISettingCallback.h:16
Setting base class containing all the properties which are common to all settings independent of the ...
Definition: Setting.h:46
Definition: ThreadMessage.h:25
Definition: Variant.h:29
class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:22
Definition: ControllerManager.h:22
Controller configuration window.
Definition: AudioDecoder.h:18
Definition: PeripheralBus.h:34
bool Mute()
Try to mute the audio via a peripheral.
Definition: Peripherals.h:213
Definition: IEventScannerCallback.h:13
Button mapper interface to assign the driver&#39;s raw button/hat/axis elements to physical joystick feat...
Definition: IButtonMapper.h:33
Definition: Peripheral.h:62
Definition: Observer.h:44
Definition: Key.h:135
Definition: Peripherals.h:49