From 55a768b6af675d1ef2e31bfee97691e03837b63f Mon Sep 17 00:00:00 2001 From: Alwin Esch Date: Fri, 4 Sep 2020 23:38:59 +0200 Subject: [PATCH 1/2] API related code update --- src/addon.cpp | 61 +++++++---------------------------- src/addon.h | 13 +++----- src/xarcade/XArcadeDevice.cpp | 3 +- 3 files changed, 18 insertions(+), 59 deletions(-) diff --git a/src/addon.cpp b/src/addon.cpp index d62464b9..53de67db 100644 --- a/src/addon.cpp +++ b/src/addon.cpp @@ -17,8 +17,6 @@ #include "xarcade/XArcadeTypes.h" #include "xarcade/XArcadeUtils.h" -#include - #include using namespace XARCADE; @@ -45,19 +43,16 @@ ADDON_STATUS CPeripheralXArcade::SetSetting(const std::string& settingName, cons return ADDON_STATUS_OK; } -void CPeripheralXArcade::GetCapabilities(PERIPHERAL_CAPABILITIES &capabilities) +void CPeripheralXArcade::GetCapabilities(kodi::addon::PeripheralCapabilities& capabilities) { - capabilities.provides_joysticks = true; - capabilities.provides_joystick_rumble = false; - capabilities.provides_joystick_power_off = false; - capabilities.provides_buttonmaps = false; + capabilities.SetProvidesJoysticks(true); + capabilities.SetProvidesJoystickRumble(false); + capabilities.SetProvidesJoystickPowerOff(false); + capabilities.SetProvidesButtonmaps(false); } -PERIPHERAL_ERROR CPeripheralXArcade::PerformDeviceScan(unsigned int* peripheral_count, PERIPHERAL_INFO** scan_results) +PERIPHERAL_ERROR CPeripheralXArcade::PerformDeviceScan(std::vector>& scan_results) { - if (peripheral_count == nullptr || scan_results == nullptr) - return PERIPHERAL_ERROR_INVALID_PARAMETERS; - // Close disconnected devices m_devices.erase(std::remove_if(m_devices.begin(), m_devices.end(), [](const DevicePtr& device) @@ -81,50 +76,26 @@ PERIPHERAL_ERROR CPeripheralXArcade::PerformDeviceScan(unsigned int* peripheral_ // Upcast array pointers std::vector peripherals; for (auto& joystick : joysticks) - peripherals.push_back(joystick.get()); - - *peripheral_count = peripherals.size(); - kodi::addon::Peripherals::ToStructs(peripherals, scan_results); + scan_results.emplace_back(joystick); return PERIPHERAL_NO_ERROR; } -void CPeripheralXArcade::FreeScanResults(unsigned int peripheral_count, PERIPHERAL_INFO* scan_results) +PERIPHERAL_ERROR CPeripheralXArcade::GetEvents(std::vector& events) { - kodi::addon::Peripherals::FreeStructs(peripheral_count, scan_results); -} - -PERIPHERAL_ERROR CPeripheralXArcade::GetEvents(unsigned int* event_count, PERIPHERAL_EVENT** events) -{ - if (event_count == nullptr || events == nullptr) - return PERIPHERAL_ERROR_INVALID_PARAMETERS; - - std::vector peripheralEvents; - for (auto& device : m_devices) - device->GetEvents(peripheralEvents); - - *event_count = peripheralEvents.size(); - kodi::addon::PeripheralEvents::ToStructs(peripheralEvents, events); + device->GetEvents(events); return PERIPHERAL_NO_ERROR; } -void CPeripheralXArcade::FreeEvents(unsigned int event_count, PERIPHERAL_EVENT* events) -{ - kodi::addon::PeripheralEvents::FreeStructs(event_count, events); -} - -bool CPeripheralXArcade::SendEvent(const PERIPHERAL_EVENT* event) +bool CPeripheralXArcade::SendEvent(const kodi::addon::PeripheralEvent& event) { return false; } -PERIPHERAL_ERROR CPeripheralXArcade::GetJoystickInfo(unsigned int index, JOYSTICK_INFO* info) +PERIPHERAL_ERROR CPeripheralXArcade::GetJoystickInfo(unsigned int index, kodi::addon::Joystick& info) { - if (info == nullptr) - return PERIPHERAL_ERROR_INVALID_PARAMETERS; - JoystickPtr joystick; for (auto& device : m_devices) @@ -139,19 +110,11 @@ PERIPHERAL_ERROR CPeripheralXArcade::GetJoystickInfo(unsigned int index, JOYSTIC if (joystick) { - joystick->kodi::addon::Joystick::ToStruct(*info); + info = *joystick; return PERIPHERAL_NO_ERROR; } return PERIPHERAL_ERROR_NOT_CONNECTED; } -void CPeripheralXArcade::FreeJoystickInfo(JOYSTICK_INFO* info) -{ - if (!info) - return; - - kodi::addon::Joystick::FreeStruct(*info); -} - ADDONCREATOR(CPeripheralXArcade) // Don't touch this! diff --git a/src/addon.h b/src/addon.h index 648aebed..99c9b235 100644 --- a/src/addon.h +++ b/src/addon.h @@ -27,14 +27,11 @@ class ATTRIBUTE_HIDDEN CPeripheralXArcade ADDON_STATUS GetStatus() override; ADDON_STATUS SetSetting(const std::string& settingName, const kodi::CSettingValue& settingValue) override; - void GetCapabilities(PERIPHERAL_CAPABILITIES &capabilities) override; - PERIPHERAL_ERROR PerformDeviceScan(unsigned int* peripheral_count, PERIPHERAL_INFO** scan_results) override; - void FreeScanResults(unsigned int peripheral_count, PERIPHERAL_INFO* scan_results) override; - PERIPHERAL_ERROR GetEvents(unsigned int* event_count, PERIPHERAL_EVENT** events) override; - void FreeEvents(unsigned int event_count, PERIPHERAL_EVENT* events) override; - bool SendEvent(const PERIPHERAL_EVENT* event) override; - PERIPHERAL_ERROR GetJoystickInfo(unsigned int index, JOYSTICK_INFO* info) override; - void FreeJoystickInfo(JOYSTICK_INFO* info) override; + void GetCapabilities(kodi::addon::PeripheralCapabilities& capabilities) override; + PERIPHERAL_ERROR PerformDeviceScan(std::vector>& scan_results) override; + PERIPHERAL_ERROR GetEvents(std::vector& events) override; + bool SendEvent(const kodi::addon::PeripheralEvent& event) override; + PERIPHERAL_ERROR GetJoystickInfo(unsigned int index, kodi::addon::Joystick& info) override; private: XARCADE::DeviceVector m_devices; diff --git a/src/xarcade/XArcadeDevice.cpp b/src/xarcade/XArcadeDevice.cpp index 0617ff63..72176373 100644 --- a/src/xarcade/XArcadeDevice.cpp +++ b/src/xarcade/XArcadeDevice.cpp @@ -10,8 +10,7 @@ #include "XArcadeDefines.h" #include "utils/CommonDefines.h" // for INVALID_FD -#include -#include +#include #include #include From 60bdbc027e8124d1bd516a725c380682d3c6b1a9 Mon Sep 17 00:00:00 2001 From: Alwin Esch Date: Fri, 4 Sep 2020 23:39:49 +0200 Subject: [PATCH 2/2] increase version to 1.2.0 (API related) --- peripheral.xarcade/addon.xml.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/peripheral.xarcade/addon.xml.in b/peripheral.xarcade/addon.xml.in index a856bbee..a5a597e9 100644 --- a/peripheral.xarcade/addon.xml.in +++ b/peripheral.xarcade/addon.xml.in @@ -1,7 +1,7 @@ @ADDON_DEPENDS@