summaryrefslogtreecommitdiffstats
path: root/xbmc/peripherals/bus/virtual/PeripheralBusAddon.h
blob: 696b1890b01772b821b3f3e3174d2f9ed347d5c5 (plain)
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
/*
 *  Copyright (C) 2014-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#pragma once

#include "peripherals/PeripheralTypes.h"
#include "peripherals/bus/PeripheralBus.h"

#include <memory>
#include <string>
#include <vector>

namespace ADDON
{
struct AddonEvent;
class CAddonInfo;
} // namespace ADDON

namespace PERIPHERALS
{
class CPeripheralBusAddon : public CPeripheralBus
{
public:
  explicit CPeripheralBusAddon(CPeripherals& manager);
  ~CPeripheralBusAddon(void) override;

  void UpdateAddons(void);

  /*!
   * \brief Get peripheral add-on that can provide button maps
   */
  bool GetAddonWithButtonMap(PeripheralAddonPtr& addon) const;

  /*!
   * \brief Get peripheral add-on that can provide button maps for the given device
   */
  bool GetAddonWithButtonMap(const CPeripheral* device, PeripheralAddonPtr& addon) const;

  /*!
   * \brief Set the rumble state of a rumble motor
   *
   * \param strLocation The location of the peripheral with the motor
   * \param motorIndex  The index of the motor being rumbled
   * \param magnitude   The amount of vibration in the closed interval [0.0, 1.0]
   *
   * \return true if the rumble motor's state is set, false otherwise
   *
   * TODO: Move declaration to parent class
   */
  bool SendRumbleEvent(const std::string& strLocation, unsigned int motorIndex, float magnitude);

  // Inherited from CPeripheralBus
  bool InitializeProperties(CPeripheral& peripheral) override;
  void Register(const PeripheralPtr& peripheral) override;
  void GetFeatures(std::vector<PeripheralFeature>& features) const override;
  bool HasFeature(const PeripheralFeature feature) const override;
  PeripheralPtr GetPeripheral(const std::string& strLocation) const override;
  PeripheralPtr GetByPath(const std::string& strPath) const override;
  bool SupportsFeature(PeripheralFeature feature) const override;
  unsigned int GetPeripheralsWithFeature(PeripheralVector& results,
                                         const PeripheralFeature feature) const override;
  unsigned int GetNumberOfPeripherals(void) const override;
  unsigned int GetNumberOfPeripheralsWithId(const int iVendorId,
                                            const int iProductId) const override;
  void GetDirectory(const std::string& strPath, CFileItemList& items) const override;
  void ProcessEvents(void) override;
  void EnableButtonMapping() override;
  void PowerOff(const std::string& strLocation) override;

  bool SplitLocation(const std::string& strLocation,
                     PeripheralAddonPtr& addon,
                     unsigned int& peripheralIndex) const;

protected:
  // Inherited from CPeripheralBus
  bool PerformDeviceScan(PeripheralScanResults& results) override;
  void UnregisterRemovedDevices(const PeripheralScanResults& results) override;

private:
  void OnEvent(const ADDON::AddonEvent& event);
  void UnRegisterAddon(const std::string& addonId);

  void PromptEnableAddons(const std::vector<std::shared_ptr<ADDON::CAddonInfo>>& disabledAddons);

  PeripheralAddonVector m_addons;
  PeripheralAddonVector m_failedAddons;
};
using PeripheralBusAddonPtr = std::shared_ptr<CPeripheralBusAddon>;
} // namespace PERIPHERALS