@@ -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
265172void CPeripheralJoystick::PowerOffJoystick (unsigned int index)
0 commit comments