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 CAction;
29 class CKey;
30 
31 namespace tinyxml2
32 {
33 class XMLElement;
34 }
35 
36 namespace KODI
37 {
38 namespace GAME
39 {
40 class CControllerManager;
41 }
42 
43 namespace JOYSTICK
44 {
45 class IButtonMapper;
46 }
47 } // namespace KODI
48 
49 namespace PERIPHERALS
50 {
51 class CEventScanner;
52 
54  public Observable,
56  public IEventScannerCallback,
58 {
59 public:
60  explicit CPeripherals(CInputManager& inputManager,
61  KODI::GAME::CControllerManager& controllerProfiles);
62 
63  ~CPeripherals() override;
64 
68  void Initialise();
69 
73  void Clear();
74 
81  PeripheralPtr GetPeripheralAtLocation(const std::string& strLocation,
82  PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
83 
90  bool HasPeripheralAtLocation(const std::string& strLocation,
91  PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
92 
98  PeripheralBusPtr GetBusWithDevice(const std::string& strLocation) const;
99 
105  bool SupportsFeature(PeripheralFeature feature) const;
106 
114  int GetPeripheralsWithFeature(PeripheralVector& results,
115  const PeripheralFeature feature,
116  PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
117 
118  size_t GetNumberOfPeripherals() const;
119 
126  bool HasPeripheralWithFeature(const PeripheralFeature feature,
127  PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
128 
134  void OnDeviceAdded(const CPeripheralBus& bus, const CPeripheral& peripheral);
135 
141  void OnDeviceDeleted(const CPeripheralBus& bus, const CPeripheral& peripheral);
142 
149  void CreatePeripheral(CPeripheralBus& bus, const PeripheralScanResult& result);
150 
156  void GetSettingsFromMapping(CPeripheral& peripheral) const;
157 
161  void TriggerDeviceScan(const PeripheralBusType type = PERIPHERAL_BUS_UNKNOWN);
162 
168  PeripheralBusPtr GetBusByType(const PeripheralBusType type) const;
169 
175  void GetDirectory(const std::string& strPath, CFileItemList& items) const;
176 
182  PeripheralPtr GetByPath(const std::string& strPath) const;
183 
190  bool OnAction(const CAction& action);
191 
196  bool IsMuted();
197 
203  bool ToggleMute();
204 
210  bool ToggleDeviceState(const CecStateChange mode = STATE_SWITCH_TOGGLE);
211 
217  bool Mute()
218  {
219  return ToggleMute();
220  }
221 
227  bool UnMute()
228  {
229  return ToggleMute();
230  }
231 
238  bool GetNextKeypress(float frameTime, CKey& key);
239 
244  EventPollHandlePtr RegisterEventPoller();
245 
250  EventLockHandlePtr RegisterEventLock();
251 
255  void OnUserNotification();
256 
261  void TestFeature(PeripheralFeature feature);
262 
266  void PowerOffDevices();
267 
268  bool SupportsCEC() const
269  {
270 #if defined(HAVE_LIBCEC)
271  return true;
272 #else
273  return false;
274 #endif
275  }
276 
277  // implementation of IEventScannerCallback
278  void ProcessEvents(void) override;
279 
289  void EnableButtonMapping();
290 
295  PeripheralAddonPtr GetAddonWithButtonMap(const CPeripheral* device);
296 
302  void ResetButtonMaps(const std::string& controllerId);
303 
316  void RegisterJoystickButtonMapper(KODI::JOYSTICK::IButtonMapper* mapper);
317 
322  void UnregisterJoystickButtonMapper(KODI::JOYSTICK::IButtonMapper* mapper);
323 
324  // implementation of ISettingCallback
325  void OnSettingChanged(const std::shared_ptr<const CSetting>& setting) override;
326  void OnSettingAction(const std::shared_ptr<const CSetting>& setting) override;
327 
328  // implementation of IMessageTarget
329  void OnApplicationMessage(KODI::MESSAGING::ThreadMessage* pMsg) override;
330  int GetMessageMask() override;
331 
332  // implementation of IAnnouncer
333  void Announce(ANNOUNCEMENT::AnnouncementFlag flag,
334  const std::string& sender,
335  const std::string& message,
336  const CVariant& data) override;
337 
341  CInputManager& GetInputManager() { return m_inputManager; }
342 
346  KODI::GAME::CControllerManager& GetControllerProfiles() { return m_controllerProfiles; }
347 
351  CCriticalSection& GetAddonInstallMutex() { return m_addonInstallMutex; }
352 
353 private:
354  bool LoadMappings();
355  bool GetMappingForDevice(const CPeripheralBus& bus, PeripheralScanResult& result) const;
356  static void GetSettingsFromMappingsFile(
357  tinyxml2::XMLElement* xmlNode, std::map<std::string, PeripheralDeviceSetting>& m_settings);
358 
359  void OnDeviceChanged();
360 
361  // Construction parameters
362  CInputManager& m_inputManager;
363  KODI::GAME::CControllerManager& m_controllerProfiles;
364 
365 #if !defined(HAVE_LIBCEC)
366  bool m_bMissingLibCecWarningDisplayed = false;
367 #endif
368  std::vector<PeripheralBusPtr> m_busses;
369  std::vector<PeripheralDeviceMapping> m_mappings;
370  std::unique_ptr<CEventScanner> m_eventScanner;
371  mutable CCriticalSection m_critSectionBusses;
372  mutable CCriticalSection m_critSectionMappings;
373  CCriticalSection m_addonInstallMutex;
374 };
375 } // namespace PERIPHERALS
Interface for classes that can map buttons to Kodi actions.
Definition: IButtonMapper.h:19
Definition: PeripheralTypes.h:318
KODI::GAME::CControllerManager & GetControllerProfiles()
Access controller profiles through the construction parameter.
Definition: Peripherals.h:346
bool UnMute()
Try to unmute the audio via a peripheral.
Definition: Peripherals.h:227
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:341
Definition: RetroPlayerInput.h:15
Represents a list of files.
Definition: FileItem.h:721
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: SkinTimerManager.h:18
CCriticalSection & GetAddonInstallMutex()
Get a mutex that allows for add-on install tasks to block on each other.
Definition: Peripherals.h:351
Definition: Variant.h:31
class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:22
Definition: ControllerManager.h:31
Definition: AudioDecoder.h:18
Definition: PeripheralBus.h:34
bool Mute()
Try to mute the audio via a peripheral.
Definition: Peripherals.h:217
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:61
Definition: Observer.h:44
Definition: Key.h:135
Definition: Peripherals.h:53