11 #include "../AddonBase.h"
12 #include "peripheral/PeripheralUtils.h"
227 if (CAddonBase::m_interface->globalSingleInstance !=
nullptr)
228 throw std::logic_error(
"kodi::addon::CInstancePeripheral: Creation of more as one in single "
229 "instance way is not allowed!");
231 SetAddonStruct(CAddonBase::m_interface->firstKodiInstance);
232 CAddonBase::m_interface->globalSingleInstance =
this;
279 !kodiVersion.empty() ? kodiVersion
282 if (CAddonBase::m_interface->globalSingleInstance !=
nullptr)
283 throw std::logic_error(
"kodi::addon::CInstancePeripheral: Creation of multiple together with "
284 "single instance way is not allowed!");
286 SetAddonStruct(instance);
358 std::vector<std::shared_ptr<kodi::addon::Peripheral>>& scan_results)
439 const std::string& controller_id,
440 std::vector<kodi::addon::JoystickFeature>& features)
456 const std::string& controller_id,
457 const std::vector<kodi::addon::JoystickFeature>& features)
489 const std::vector<kodi::addon::DriverPrimitive>& primitives)
516 const std::string& controller_id)
542 const std::string
AddonPath()
const {
return m_instanceData->props->addon_path; }
554 const std::string
UserPath()
const {
return m_instanceData->props->user_path; }
564 return m_instanceData->toKodi->trigger_scan(m_instanceData->toKodi->kodiInstance);
576 void RefreshButtonMaps(
const std::string& deviceName =
"",
const std::string& controllerId =
"")
578 return m_instanceData->toKodi->refresh_button_maps(m_instanceData->toKodi->kodiInstance,
579 deviceName.c_str(), controllerId.c_str());
595 return m_instanceData->toKodi->feature_count(m_instanceData->toKodi->kodiInstance,
596 controllerId.c_str(), type);
610 return m_instanceData->toKodi->feature_type(m_instanceData->toKodi->kodiInstance,
611 controllerId.c_str(), featureName.c_str());
618 void SetAddonStruct(KODI_HANDLE instance)
620 if (instance ==
nullptr)
621 throw std::logic_error(
"kodi::addon::CInstancePeripheral: Creation with empty addon "
622 "structure not allowed, table must be given from Kodi!");
625 m_instanceData->toAddon->addonInstance =
this;
627 m_instanceData->toAddon->get_capabilities = ADDON_GetCapabilities;
628 m_instanceData->toAddon->perform_device_scan = ADDON_PerformDeviceScan;
629 m_instanceData->toAddon->free_scan_results = ADDON_FreeScanResults;
630 m_instanceData->toAddon->get_events = ADDON_GetEvents;
631 m_instanceData->toAddon->free_events = ADDON_FreeEvents;
632 m_instanceData->toAddon->send_event = ADDON_SendEvent;
634 m_instanceData->toAddon->get_joystick_info = ADDON_GetJoystickInfo;
635 m_instanceData->toAddon->free_joystick_info = ADDON_FreeJoystickInfo;
636 m_instanceData->toAddon->get_features = ADDON_GetFeatures;
637 m_instanceData->toAddon->free_features = ADDON_FreeFeatures;
638 m_instanceData->toAddon->map_features = ADDON_MapFeatures;
639 m_instanceData->toAddon->get_ignored_primitives = ADDON_GetIgnoredPrimitives;
640 m_instanceData->toAddon->free_primitives = ADDON_FreePrimitives;
641 m_instanceData->toAddon->set_ignored_primitives = ADDON_SetIgnoredPrimitives;
642 m_instanceData->toAddon->save_button_map = ADDON_SaveButtonMap;
643 m_instanceData->toAddon->revert_button_map = ADDON_RevertButtonMap;
644 m_instanceData->toAddon->reset_button_map = ADDON_ResetButtonMap;
645 m_instanceData->toAddon->power_off_joystick = ADDON_PowerOffJoystick;
651 if (!addonInstance || !capabilities)
655 static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
656 ->GetCapabilities(peripheralCapabilities);
661 unsigned int* peripheral_count,
664 if (!addonInstance || !peripheral_count || !scan_results)
667 std::vector<std::shared_ptr<kodi::addon::Peripheral>> peripherals;
668 PERIPHERAL_ERROR err =
static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
669 ->PerformDeviceScan(peripherals);
672 *peripheral_count =
static_cast<unsigned int>(peripherals.size());
673 kodi::addon::Peripherals::ToStructs(peripherals, scan_results);
680 unsigned int peripheral_count,
686 kodi::addon::Peripherals::FreeStructs(peripheral_count, scan_results);
690 unsigned int* event_count,
693 if (!addonInstance || !event_count || !events)
696 std::vector<kodi::addon::PeripheralEvent> peripheralEvents;
697 PERIPHERAL_ERROR err =
static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
698 ->GetEvents(peripheralEvents);
701 *event_count =
static_cast<unsigned int>(peripheralEvents.size());
702 kodi::addon::PeripheralEvents::ToStructs(peripheralEvents, events);
709 unsigned int event_count,
715 kodi::addon::PeripheralEvents::FreeStructs(event_count, events);
721 if (!addonInstance || !event)
723 return static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
731 if (!addonInstance || !info)
735 PERIPHERAL_ERROR err =
static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
736 ->GetJoystickInfo(index, addonInfo);
739 addonInfo.ToStruct(*info);
751 kodi::addon::Joystick::FreeStruct(*info);
756 const char* controller_id,
757 unsigned int* feature_count,
760 if (!addonInstance || !joystick || !controller_id || !feature_count || !features)
764 std::vector<kodi::addon::JoystickFeature> featuresVector;
766 PERIPHERAL_ERROR err =
static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
767 ->GetFeatures(addonJoystick, controller_id, featuresVector);
770 *feature_count =
static_cast<unsigned int>(featuresVector.size());
771 kodi::addon::JoystickFeatures::ToStructs(featuresVector, features);
778 unsigned int feature_count,
784 kodi::addon::JoystickFeatures::FreeStructs(feature_count, features);
789 const char* controller_id,
790 unsigned int feature_count,
793 if (!addonInstance || !joystick || !controller_id || (feature_count > 0 && !features))
797 std::vector<kodi::addon::JoystickFeature> primitiveVector;
799 for (
unsigned int i = 0; i < feature_count; i++)
800 primitiveVector.emplace_back(*(features + i));
802 return static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
803 ->MapFeatures(addonJoystick, controller_id, primitiveVector);
809 unsigned int* primitive_count,
812 if (!addonInstance || !joystick || !primitive_count || !primitives)
816 std::vector<kodi::addon::DriverPrimitive> primitiveVector;
818 PERIPHERAL_ERROR err =
static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
819 ->GetIgnoredPrimitives(addonJoystick, primitiveVector);
822 *primitive_count =
static_cast<unsigned int>(primitiveVector.size());
823 kodi::addon::DriverPrimitives::ToStructs(primitiveVector, primitives);
830 unsigned int primitive_count,
836 kodi::addon::DriverPrimitives::FreeStructs(primitive_count, primitives);
842 unsigned int primitive_count,
845 if (!addonInstance || !joystick || (primitive_count > 0 && !primitives))
849 std::vector<kodi::addon::DriverPrimitive> primitiveVector;
851 for (
unsigned int i = 0; i < primitive_count; i++)
852 primitiveVector.emplace_back(*(primitives + i));
854 return static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
855 ->SetIgnoredPrimitives(addonJoystick, primitiveVector);
861 if (!addonInstance || !joystick)
865 static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
866 ->SaveButtonMap(addonJoystick);
872 if (!addonInstance || !joystick)
876 static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
877 ->RevertButtonMap(addonJoystick);
882 const char* controller_id)
884 if (!addonInstance || !joystick || !controller_id)
888 static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
889 ->ResetButtonMap(addonJoystick, controller_id);
898 static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
899 ->PowerOffJoystick(index);
Definition: Peripheral.h:216
Definition: AddonBase.h:186
Definition: PeripheralUtils.h:569
Definition: PeripheralUtils.h:133
Definition: PeripheralUtils.h:369
@ ADDON_INSTANCE_PERIPHERAL
Peripheral instance, see kodi::addon::CInstancePeripheral.
Definition: versions.h:229
PERIPHERAL_ERROR
Definition: peripheral.h:36
@ PERIPHERAL_ERROR_INVALID_PARAMETERS
-3 : The parameters of the method are invalid for this operation
Definition: peripheral.h:47
@ PERIPHERAL_NO_ERROR
0 : No error occurred
Definition: peripheral.h:38
@ PERIPHERAL_ERROR_NOT_IMPLEMENTED
-4 : The method that the frontend called is not implemented
Definition: peripheral.h:50
JOYSTICK_FEATURE_TYPE
Definition: peripheral.h:494
@ JOYSTICK_FEATURE_TYPE_UNKNOWN
Unknown type.
Definition: peripheral.h:496
unsigned int FeatureCount(const std::string &controllerId, JOYSTICK_FEATURE_TYPE type=JOYSTICK_FEATURE_TYPE_UNKNOWN)
Return the number of features belonging to the specified controller.
Definition: Peripheral.h:592
void RefreshButtonMaps(const std::string &deviceName="", const std::string &controllerId="")
Notify the frontend that button maps have changed.
Definition: Peripheral.h:576
void TriggerScan(void)
Trigger a scan for peripherals.
Definition: Peripheral.h:562
JOYSTICK_FEATURE_TYPE FeatureType(const std::string &controllerId, const std::string &featureName)
Return the type of the feature.
Definition: Peripheral.h:608
const std::string UserPath() const
Used to get the full path to the add-on's user profile.
Definition: Peripheral.h:554
const std::string AddonPath() const
Used to get the full path where the add-on is installed.
Definition: Peripheral.h:542
virtual void RevertButtonMap(const kodi::addon::Joystick &joystick)
Revert the button map to the last time it was loaded or committed to disk.
Definition: Peripheral.h:507
virtual PERIPHERAL_ERROR MapFeatures(const kodi::addon::Joystick &joystick, const std::string &controller_id, const std::vector< kodi::addon::JoystickFeature > &features)
Add or update joystick features.
Definition: Peripheral.h:455
virtual PERIPHERAL_ERROR SetIgnoredPrimitives(const kodi::addon::Joystick &joystick, const std::vector< kodi::addon::DriverPrimitive > &primitives)
Set the list of driver primitives that are ignored for the device.
Definition: Peripheral.h:487
virtual void SaveButtonMap(const kodi::addon::Joystick &joystick)
Save the button map for the given joystick.
Definition: Peripheral.h:500
virtual void PowerOffJoystick(unsigned int index)
Powers off the given joystick if supported.
Definition: Peripheral.h:525
virtual void ResetButtonMap(const kodi::addon::Joystick &joystick, const std::string &controller_id)
Reset the button map for the given joystick and controller profile ID.
Definition: Peripheral.h:515
virtual PERIPHERAL_ERROR GetFeatures(const kodi::addon::Joystick &joystick, const std::string &controller_id, std::vector< kodi::addon::JoystickFeature > &features)
Get the features that allow translating the joystick into the controller profile.
Definition: Peripheral.h:438
virtual PERIPHERAL_ERROR GetIgnoredPrimitives(const kodi::addon::Joystick &joystick, std::vector< kodi::addon::DriverPrimitive > &primitives)
Get the driver primitives that should be ignored while mapping the device.
Definition: Peripheral.h:473
virtual PERIPHERAL_ERROR GetJoystickInfo(unsigned int index, kodi::addon::Joystick &info)
Get extended info about an attached joystick.
Definition: Peripheral.h:421
virtual bool SendEvent(const kodi::addon::PeripheralEvent &event)
Send an input event to the peripheral.
Definition: Peripheral.h:387
virtual PERIPHERAL_ERROR GetEvents(std::vector< kodi::addon::PeripheralEvent > &events)
Get all events that have occurred since the last call to GetEvents().
Definition: Peripheral.h:375
virtual void GetCapabilities(kodi::addon::PeripheralCapabilities &capabilities)
Get the list of features that this add-on provides.
Definition: Peripheral.h:339
virtual PERIPHERAL_ERROR PerformDeviceScan(std::vector< std::shared_ptr< kodi::addon::Peripheral >> &scan_results)
Perform a scan for joysticks.
Definition: Peripheral.h:357
CInstancePeripheral()
Peripheral class constructor.
Definition: Peripheral.h:224
CInstancePeripheral(KODI_HANDLE instance, const std::string &kodiVersion="")
Peripheral addon class constructor used to support multiple instance types.
Definition: Peripheral.h:277
~CInstancePeripheral() override=default
Destructor.
std::string ATTRIBUTE_HIDDEN GetKodiTypeVersion(int type)
To get used version inside Kodi itself about asked type.
Definition: AddonBase.h:630
Definition: peripheral.h:697
Driver primitive struct.
Definition: peripheral.h:469
Mapping between higher-level controller feature and its driver primitives.
Definition: peripheral.h:594
Info specific to joystick peripherals.
Definition: peripheral.h:239
Peripheral add-on capabilities.
Definition: peripheral.h:100
Event information.
Definition: peripheral.h:214
Information shared between peripherals.
Definition: peripheral.h:88