Skip to content

Commit a1b2b48

Browse files
authored
Merge pull request #186 from AlwinEsch/Matrix-change
[Matrix] API related update
2 parents 2b2e5cf + 66715a5 commit a1b2b48

File tree

12 files changed

+59
-158
lines changed

12 files changed

+59
-158
lines changed

peripheral.joystick/addon.xml.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<addon
33
id="peripheral.joystick"
4-
version="1.6.1"
4+
version="1.7.0"
55
name="Joystick Support"
66
provider-name="Team Kodi">
77
<requires>@ADDON_DEPENDS@</requires>

src/addon.cpp

Lines changed: 32 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -73,193 +73,100 @@ CPeripheralJoystick::~CPeripheralJoystick()
7373
delete m_scanner;
7474
}
7575

76-
void CPeripheralJoystick::GetCapabilities(PERIPHERAL_CAPABILITIES& capabilities)
76+
void CPeripheralJoystick::GetCapabilities(kodi::addon::PeripheralCapabilities& capabilities)
7777
{
78-
capabilities.provides_joysticks = true;
79-
capabilities.provides_buttonmaps = true;
78+
capabilities.SetProvidesJoysticks(true);
79+
capabilities.SetProvidesButtonmaps(true);
8080
}
8181

82-
PERIPHERAL_ERROR CPeripheralJoystick::PerformDeviceScan(unsigned int* peripheral_count, PERIPHERAL_INFO** scan_results)
82+
PERIPHERAL_ERROR CPeripheralJoystick::PerformDeviceScan(std::vector<std::shared_ptr<kodi::addon::Peripheral>>& scan_results)
8383
{
84-
if (!peripheral_count || !scan_results)
85-
return PERIPHERAL_ERROR_INVALID_PARAMETERS;
86-
8784
JoystickVector joysticks;
8885
if (!CJoystickManager::Get().PerformJoystickScan(joysticks))
8986
return PERIPHERAL_ERROR_FAILED;
9087

9188
// Upcast array pointers
92-
std::vector<kodi::addon::Peripheral*> peripherals;
93-
for (JoystickVector::const_iterator it = joysticks.begin(); it != joysticks.end(); ++it)
94-
peripherals.push_back(it->get());
95-
96-
*peripheral_count = static_cast<unsigned int>(peripherals.size());
97-
kodi::addon::Peripherals::ToStructs(peripherals, scan_results);
89+
for (const auto& it : joysticks)
90+
scan_results.emplace_back(it);
9891

9992
return PERIPHERAL_NO_ERROR;
10093
}
10194

102-
void CPeripheralJoystick::FreeScanResults(unsigned int peripheral_count, PERIPHERAL_INFO* scan_results)
103-
{
104-
kodi::addon::Peripherals::FreeStructs(peripheral_count, scan_results);
105-
}
106-
107-
PERIPHERAL_ERROR CPeripheralJoystick::GetEvents(unsigned int* event_count, PERIPHERAL_EVENT** events)
95+
PERIPHERAL_ERROR CPeripheralJoystick::GetEvents(std::vector<kodi::addon::PeripheralEvent>& events)
10896
{
109-
if (!event_count || !events)
110-
return PERIPHERAL_ERROR_INVALID_PARAMETERS;
111-
11297
PERIPHERAL_ERROR result = PERIPHERAL_ERROR_FAILED;
11398

114-
std::vector<kodi::addon::PeripheralEvent> peripheralEvents;
115-
if (CJoystickManager::Get().GetEvents(peripheralEvents))
116-
{
117-
*event_count = static_cast<unsigned int>(peripheralEvents.size());
118-
kodi::addon::PeripheralEvents::ToStructs(peripheralEvents, events);
99+
if (CJoystickManager::Get().GetEvents(events))
119100
result = PERIPHERAL_NO_ERROR;
120-
}
121101

122102
CJoystickManager::Get().ProcessEvents();
123103

124104
return result;
125105
}
126106

127-
void CPeripheralJoystick::FreeEvents(unsigned int event_count, PERIPHERAL_EVENT* events)
107+
bool CPeripheralJoystick::SendEvent(const kodi::addon::PeripheralEvent& event)
128108
{
129-
kodi::addon::PeripheralEvents::FreeStructs(event_count, events);
130-
}
131-
132-
bool CPeripheralJoystick::SendEvent(const PERIPHERAL_EVENT* event)
133-
{
134-
bool bHandled = false;
135-
136-
if (event != nullptr)
137-
bHandled = CJoystickManager::Get().SendEvent(kodi::addon::PeripheralEvent(*event));
138-
139-
return bHandled;
109+
return CJoystickManager::Get().SendEvent(event);
140110
}
141111

142-
PERIPHERAL_ERROR CPeripheralJoystick::GetJoystickInfo(unsigned int index, JOYSTICK_INFO* info)
112+
PERIPHERAL_ERROR CPeripheralJoystick::GetJoystickInfo(unsigned int index, kodi::addon::Joystick& info)
143113
{
144-
if (!info)
145-
return PERIPHERAL_ERROR_INVALID_PARAMETERS;
146-
147114
JoystickPtr joystick = CJoystickManager::Get().GetJoystick(index);
148115
if (!joystick)
149116
return PERIPHERAL_ERROR_NOT_CONNECTED;
150117

151-
// Need to be explicit because we're using typedef struct { ... }T instead of struct T{ ... }
152-
joystick->kodi::addon::Joystick::ToStruct(*info);
118+
info = *joystick;
153119

154120
return PERIPHERAL_NO_ERROR;
155121
}
156122

157-
void CPeripheralJoystick::FreeJoystickInfo(JOYSTICK_INFO* info)
158-
{
159-
if (!info)
160-
return;
161-
162-
kodi::addon::Joystick::FreeStruct(*info);
163-
}
164-
165-
PERIPHERAL_ERROR CPeripheralJoystick::GetFeatures(const JOYSTICK_INFO* joystick, const char* controller_id,
166-
unsigned int* feature_count, JOYSTICK_FEATURE** features)
123+
PERIPHERAL_ERROR CPeripheralJoystick::GetFeatures(const kodi::addon::Joystick& joystick,
124+
const std::string& controller_id,
125+
std::vector<kodi::addon::JoystickFeature>& features)
167126
{
168-
if (!joystick || !controller_id || !feature_count || !features)
169-
return PERIPHERAL_ERROR_INVALID_PARAMETERS;
170-
171-
FeatureVector featureVector;
172-
CStorageManager::Get().GetFeatures(kodi::addon::Joystick(*joystick), controller_id, featureVector);
173-
174-
*feature_count = static_cast<unsigned int>(featureVector.size());
175-
kodi::addon::JoystickFeatures::ToStructs(featureVector, features);
127+
CStorageManager::Get().GetFeatures(joystick, controller_id, features);
176128

177129
return PERIPHERAL_NO_ERROR;
178130
}
179131

180-
void CPeripheralJoystick::FreeFeatures(unsigned int feature_count, JOYSTICK_FEATURE* features)
181-
{
182-
kodi::addon::JoystickFeatures::FreeStructs(feature_count, features);
183-
}
184-
185-
PERIPHERAL_ERROR CPeripheralJoystick::MapFeatures(const JOYSTICK_INFO* joystick, const char* controller_id,
186-
unsigned int feature_count, const JOYSTICK_FEATURE* features)
132+
PERIPHERAL_ERROR CPeripheralJoystick::MapFeatures(const kodi::addon::Joystick& joystick,
133+
const std::string& controller_id,
134+
const std::vector<kodi::addon::JoystickFeature>& features)
187135
{
188-
if (!joystick || !controller_id || (feature_count > 0 && !features))
189-
return PERIPHERAL_ERROR_INVALID_PARAMETERS;
190-
191-
FeatureVector featureVector(features, features + feature_count);
192-
bool bSuccess = CStorageManager::Get().MapFeatures(kodi::addon::Joystick(*joystick), controller_id, featureVector);
136+
bool bSuccess = CStorageManager::Get().MapFeatures(joystick, controller_id, features);
193137

194138
return bSuccess ? PERIPHERAL_NO_ERROR : PERIPHERAL_ERROR_FAILED;
195139
}
196140

197-
PERIPHERAL_ERROR CPeripheralJoystick::GetIgnoredPrimitives(const JOYSTICK_INFO* joystick,
198-
unsigned int* primitive_count,
199-
JOYSTICK_DRIVER_PRIMITIVE** primitives)
141+
PERIPHERAL_ERROR CPeripheralJoystick::GetIgnoredPrimitives(const kodi::addon::Joystick& joystick,
142+
std::vector<kodi::addon::DriverPrimitive>& primitives)
200143
{
201-
if (joystick == nullptr || primitive_count == nullptr || primitives == nullptr)
202-
return PERIPHERAL_ERROR_INVALID_PARAMETERS;
203-
204-
PrimitiveVector primitiveVector;
205-
CStorageManager::Get().GetIgnoredPrimitives(kodi::addon::Joystick(*joystick), primitiveVector);
206-
207-
*primitive_count = static_cast<unsigned int>(primitiveVector.size());
208-
kodi::addon::DriverPrimitives::ToStructs(primitiveVector, primitives);
144+
CStorageManager::Get().GetIgnoredPrimitives(joystick, primitives);
209145

210146
return PERIPHERAL_NO_ERROR;
211147
}
212148

213-
void CPeripheralJoystick::FreePrimitives(unsigned int primitive_count, JOYSTICK_DRIVER_PRIMITIVE* primitives)
149+
PERIPHERAL_ERROR CPeripheralJoystick::SetIgnoredPrimitives(const kodi::addon::Joystick& joystick,
150+
const std::vector<kodi::addon::DriverPrimitive>& primitives)
214151
{
215-
kodi::addon::DriverPrimitives::FreeStructs(primitive_count, primitives);
216-
}
217-
218-
PERIPHERAL_ERROR CPeripheralJoystick::SetIgnoredPrimitives(const JOYSTICK_INFO* joystick,
219-
unsigned int primitive_count,
220-
const JOYSTICK_DRIVER_PRIMITIVE* primitives)
221-
{
222-
if (joystick == nullptr || (primitive_count > 0 && primitives == nullptr))
223-
return PERIPHERAL_ERROR_INVALID_PARAMETERS;
224-
225-
PrimitiveVector primitiveVector;
226-
227-
for (unsigned int i = 0; i < primitive_count; i++)
228-
primitiveVector.emplace_back(*(primitives + i));
229-
230-
bool bSuccess = CStorageManager::Get().SetIgnoredPrimitives(kodi::addon::Joystick(*joystick), primitiveVector);
152+
bool bSuccess = CStorageManager::Get().SetIgnoredPrimitives(joystick, primitives);
231153

232154
return bSuccess ? PERIPHERAL_NO_ERROR : PERIPHERAL_ERROR_FAILED;
233155
}
234156

235-
void CPeripheralJoystick::SaveButtonMap(const JOYSTICK_INFO* joystick)
157+
void CPeripheralJoystick::SaveButtonMap(const kodi::addon::Joystick& joystick)
236158
{
237-
if (joystick == nullptr)
238-
return;
239-
240-
kodi::addon::Joystick addonJoystick(*joystick);
241-
242-
CStorageManager::Get().SaveButtonMap(addonJoystick);
159+
CStorageManager::Get().SaveButtonMap(joystick);
243160
}
244161

245-
void CPeripheralJoystick::RevertButtonMap(const JOYSTICK_INFO* joystick)
162+
void CPeripheralJoystick::RevertButtonMap(const kodi::addon::Joystick& joystick)
246163
{
247-
if (joystick == nullptr)
248-
return;
249-
250-
kodi::addon::Joystick addonJoystick(*joystick);
251-
252-
CStorageManager::Get().RevertButtonMap(addonJoystick);
164+
CStorageManager::Get().RevertButtonMap(joystick);
253165
}
254166

255-
void CPeripheralJoystick::ResetButtonMap(const JOYSTICK_INFO* joystick, const char* controller_id)
167+
void CPeripheralJoystick::ResetButtonMap(const kodi::addon::Joystick& joystick, const std::string& controller_id)
256168
{
257-
if (!joystick || !controller_id)
258-
return;
259-
260-
kodi::addon::Joystick addonJoystick(*joystick);
261-
262-
CStorageManager::Get().ResetButtonMap(addonJoystick, controller_id);
169+
CStorageManager::Get().ResetButtonMap(joystick, controller_id);
263170
}
264171

265172
void CPeripheralJoystick::PowerOffJoystick(unsigned int index)

src/addon.h

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,24 @@ class DLL_PRIVATE CPeripheralJoystick
2929
ADDON_STATUS GetStatus() override;
3030
ADDON_STATUS SetSetting(const std::string& settingName, const kodi::CSettingValue& settingValue) override;
3131

32-
void GetCapabilities(PERIPHERAL_CAPABILITIES &capabilities) override;
33-
PERIPHERAL_ERROR PerformDeviceScan(unsigned int* peripheral_count, PERIPHERAL_INFO** scan_results) override;
34-
void FreeScanResults(unsigned int peripheral_count, PERIPHERAL_INFO* scan_results) override;
35-
PERIPHERAL_ERROR GetEvents(unsigned int* event_count, PERIPHERAL_EVENT** events) override;
36-
void FreeEvents(unsigned int event_count, PERIPHERAL_EVENT* events) override;
37-
bool SendEvent(const PERIPHERAL_EVENT* event) override;
38-
PERIPHERAL_ERROR GetJoystickInfo(unsigned int index, JOYSTICK_INFO* info) override;
39-
void FreeJoystickInfo(JOYSTICK_INFO* info) override;
40-
PERIPHERAL_ERROR GetFeatures(const JOYSTICK_INFO* joystick, const char* controller_id,
41-
unsigned int* feature_count, JOYSTICK_FEATURE** features) override;
42-
void FreeFeatures(unsigned int feature_count, JOYSTICK_FEATURE* features) override;
43-
PERIPHERAL_ERROR MapFeatures(const JOYSTICK_INFO* joystick, const char* controller_id,
44-
unsigned int feature_count, const JOYSTICK_FEATURE* features) override;
45-
PERIPHERAL_ERROR GetIgnoredPrimitives(const JOYSTICK_INFO* joystick,
46-
unsigned int* primitive_count,
47-
JOYSTICK_DRIVER_PRIMITIVE** primitives) override;
48-
void FreePrimitives(unsigned int primitive_count, JOYSTICK_DRIVER_PRIMITIVE* primitives) override;
49-
PERIPHERAL_ERROR SetIgnoredPrimitives(const JOYSTICK_INFO* joystick,
50-
unsigned int primitive_count,
51-
const JOYSTICK_DRIVER_PRIMITIVE* primitives) override;
52-
void SaveButtonMap(const JOYSTICK_INFO* joystick) override;
53-
void RevertButtonMap(const JOYSTICK_INFO* joystick) override;
54-
void ResetButtonMap(const JOYSTICK_INFO* joystick, const char* controller_id) override;
32+
void GetCapabilities(kodi::addon::PeripheralCapabilities& capabilities) override;
33+
PERIPHERAL_ERROR PerformDeviceScan(std::vector<std::shared_ptr<kodi::addon::Peripheral>>& scan_results) override;
34+
PERIPHERAL_ERROR GetEvents(std::vector<kodi::addon::PeripheralEvent>& events) override;
35+
bool SendEvent(const kodi::addon::PeripheralEvent& event) override;
36+
PERIPHERAL_ERROR GetJoystickInfo(unsigned int index, kodi::addon::Joystick& info) override;
37+
PERIPHERAL_ERROR GetFeatures(const kodi::addon::Joystick& joystick,
38+
const std::string& controller_id,
39+
std::vector<kodi::addon::JoystickFeature>& features) override;
40+
PERIPHERAL_ERROR MapFeatures(const kodi::addon::Joystick& joystick,
41+
const std::string& controller_id,
42+
const std::vector<kodi::addon::JoystickFeature>& features) override;
43+
PERIPHERAL_ERROR GetIgnoredPrimitives(const kodi::addon::Joystick& joystick,
44+
std::vector<kodi::addon::DriverPrimitive>& primitives) override;
45+
PERIPHERAL_ERROR SetIgnoredPrimitives(const kodi::addon::Joystick& joystick,
46+
const std::vector<kodi::addon::DriverPrimitive>& primitives) override;
47+
void SaveButtonMap(const kodi::addon::Joystick& joystick) override;
48+
void RevertButtonMap(const kodi::addon::Joystick& joystick) override;
49+
void ResetButtonMap(const kodi::addon::Joystick& joystick, const std::string& controller_id) override;
5550
void PowerOffJoystick(unsigned int index) override;
5651

5752
private:

src/api/Joystick.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include "JoystickTypes.h"
1212

13-
#include <kodi/addon-instance/PeripheralUtils.h>
13+
#include <kodi/addon-instance/Peripheral.h>
1414

1515
#include <string>
1616
#include <vector>

src/api/JoystickManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "JoystickTypes.h"
1212
#include "buttonmapper/ButtonMapTypes.h"
1313

14-
#include <kodi/addon-instance/PeripheralUtils.h>
14+
#include <kodi/addon-instance/peripheral/PeripheralUtils.h>
1515

1616
#include <mutex>
1717
#include <set>

src/buttonmapper/ButtonMapTranslator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#pragma once
1010

11-
#include <kodi/addon-instance/PeripheralUtils.h>
11+
#include <kodi/addon-instance/peripheral/PeripheralUtils.h>
1212

1313
#include <string>
1414

src/buttonmapper/ButtonMapTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#pragma once
1010

11-
#include <kodi/addon-instance/PeripheralUtils.h>
11+
#include <kodi/addon-instance/peripheral/PeripheralUtils.h>
1212

1313
#include <map>
1414
#include <memory>

src/buttonmapper/ButtonMapUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "ButtonMapUtils.h"
1010

11-
#include <kodi/addon-instance/PeripheralUtils.h>
11+
#include <kodi/addon-instance/peripheral/PeripheralUtils.h>
1212

1313
#include <array>
1414
#include <map>

src/buttonmapper/ButtonMapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "ControllerTransformer.h"
1212
#include "storage/IDatabase.h"
1313

14-
#include <kodi/addon-instance/PeripheralUtils.h>
14+
#include <kodi/addon-instance/peripheral/PeripheralUtils.h>
1515

1616
#include <algorithm>
1717
#include <iterator>

src/buttonmapper/ControllerTransformer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "storage/Device.h"
1313
#include "utils/CommonMacros.h"
1414

15-
#include <kodi/addon-instance/PeripheralUtils.h>
15+
#include <kodi/addon-instance/peripheral/PeripheralUtils.h>
1616

1717
#include <algorithm>
1818

0 commit comments

Comments
 (0)