| 1 |
/* |
| 2 |
* Copyright (C) 2014-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 "peripherals/PeripheralTypes.h" |
| 12 |
#include "peripherals/bus/PeripheralBus.h" |
| 13 |
|
| 14 |
#include <memory> |
| 15 |
#include <string> |
| 16 |
#include <vector> |
| 17 |
|
| 18 |
namespace ADDON |
| 19 |
{ |
| 20 |
struct AddonEvent; |
| 21 |
class CAddonInfo; |
| 22 |
} // namespace ADDON |
| 23 |
|
| 24 |
namespace PERIPHERALS |
| 25 |
{ |
| 26 |
/*! |
| 27 |
* \ingroup peripherals |
| 28 |
*/ |
| 29 |
class CPeripheralBusAddon : public CPeripheralBus |
| 30 |
{ |
| 31 |
public: |
| 32 |
explicit CPeripheralBusAddon(CPeripherals& manager); |
| 33 |
~CPeripheralBusAddon(void) override; |
| 34 |
|
| 35 |
void UpdateAddons(void); |
| 36 |
|
| 37 |
/*! |
| 38 |
* \brief Get peripheral add-on that can provide button maps |
| 39 |
*/ |
| 40 |
bool GetAddonWithButtonMap(PeripheralAddonPtr& addon) const; |
| 41 |
|
| 42 |
/*! |
| 43 |
* \brief Get peripheral add-on that can provide button maps for the given device |
| 44 |
*/ |
| 45 |
bool GetAddonWithButtonMap(const CPeripheral* device, PeripheralAddonPtr& addon) const; |
| 46 |
|
| 47 |
/*! |
| 48 |
* \brief Set the rumble state of a rumble motor |
| 49 |
* |
| 50 |
* \param strLocation The location of the peripheral with the motor |
| 51 |
* \param motorIndex The index of the motor being rumbled |
| 52 |
* \param magnitude The amount of vibration in the closed interval [0.0, 1.0] |
| 53 |
* |
| 54 |
* \return true if the rumble motor's state is set, false otherwise |
| 55 |
* |
| 56 |
* TODO: Move declaration to parent class |
| 57 |
*/ |
| 58 |
bool SendRumbleEvent(const std::string& strLocation, unsigned int motorIndex, float magnitude); |
| 59 |
|
| 60 |
// Inherited from CPeripheralBus |
| 61 |
bool InitializeProperties(CPeripheral& peripheral) override; |
| 62 |
void Register(const PeripheralPtr& peripheral) override; |
| 63 |
void GetFeatures(std::vector<PeripheralFeature>& features) const override; |
| 64 |
bool HasFeature(const PeripheralFeature feature) const override; |
| 65 |
PeripheralPtr GetPeripheral(const std::string& strLocation) const override; |
| 66 |
PeripheralPtr GetByPath(const std::string& strPath) const override; |
| 67 |
bool SupportsFeature(PeripheralFeature feature) const override; |
| 68 |
unsigned int GetPeripheralsWithFeature(PeripheralVector& results, |
| 69 |
const PeripheralFeature feature) const override; |
| 70 |
unsigned int GetNumberOfPeripherals(void) const override; |
| 71 |
unsigned int GetNumberOfPeripheralsWithId(const int iVendorId, |
| 72 |
const int iProductId) const override; |
| 73 |
void GetDirectory(const std::string& strPath, CFileItemList& items) const override; |
| 74 |
void ProcessEvents(void) override; |
| 75 |
void EnableButtonMapping() override; |
| 76 |
void PowerOff(const std::string& strLocation) override; |
| 77 |
|
| 78 |
bool SplitLocation(const std::string& strLocation, |
| 79 |
PeripheralAddonPtr& addon, |
| 80 |
unsigned int& peripheralIndex) const; |
| 81 |
|
| 82 |
protected: |
| 83 |
// Inherited from CPeripheralBus |
| 84 |
bool PerformDeviceScan(PeripheralScanResults& results) override; |
| 85 |
void UnregisterRemovedDevices(const PeripheralScanResults& results) override; |
| 86 |
|
| 87 |
private: |
| 88 |
void OnEvent(const ADDON::AddonEvent& event); |
| 89 |
void UnRegisterAddon(const std::string& addonId); |
| 90 |
|
| 91 |
void PromptEnableAddons(const std::vector<std::shared_ptr<ADDON::CAddonInfo>>& disabledAddons); |
| 92 |
|
| 93 |
PeripheralAddonVector m_addons; |
| 94 |
PeripheralAddonVector m_failedAddons; |
| 95 |
}; |
| 96 |
using PeripheralBusAddonPtr = std::shared_ptr<CPeripheralBusAddon>; |
| 97 |
} // namespace PERIPHERALS |