summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Peripheral.h
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Peripheral.h')
-rw-r--r--xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Peripheral.h682
1 files changed, 682 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Peripheral.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Peripheral.h
new file mode 100644
index 0000000..631b9b4
--- /dev/null
+++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Peripheral.h
@@ -0,0 +1,682 @@
1#pragma once
2/*
3 * Copyright (C) 2014-2017 Team Kodi
4 * http://kodi.tv
5 *
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this Program; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#include "../AddonBase.h"
23
24namespace kodi { namespace addon { class CInstancePeripheral; }}
25
26/* indicates a joystick has no preference for port number */
27#define NO_PORT_REQUESTED (-1)
28
29/* joystick's driver button/hat/axis index is unknown */
30#define DRIVER_INDEX_UNKNOWN (-1)
31
32extern "C"
33{
34
35 /// @name Peripheral types
36 ///{
37 typedef enum PERIPHERAL_ERROR
38 {
39 PERIPHERAL_NO_ERROR = 0, // no error occurred
40 PERIPHERAL_ERROR_UNKNOWN = -1, // an unknown error occurred
41 PERIPHERAL_ERROR_FAILED = -2, // the command failed
42 PERIPHERAL_ERROR_INVALID_PARAMETERS = -3, // the parameters of the method are invalid for this operation
43 PERIPHERAL_ERROR_NOT_IMPLEMENTED = -4, // the method that the frontend called is not implemented
44 PERIPHERAL_ERROR_NOT_CONNECTED = -5, // no peripherals are connected
45 PERIPHERAL_ERROR_CONNECTION_FAILED = -6, // peripherals are connected, but command was interrupted
46 } PERIPHERAL_ERROR;
47
48 typedef enum PERIPHERAL_TYPE
49 {
50 PERIPHERAL_TYPE_UNKNOWN,
51 PERIPHERAL_TYPE_JOYSTICK,
52 PERIPHERAL_TYPE_KEYBOARD,
53 } PERIPHERAL_TYPE;
54
55 typedef struct PERIPHERAL_INFO
56 {
57 PERIPHERAL_TYPE type; /*!< @brief type of peripheral */
58 char* name; /*!< @brief name of peripheral */
59 uint16_t vendor_id; /*!< @brief vendor ID of peripheral, 0x0000 if unknown */
60 uint16_t product_id; /*!< @brief product ID of peripheral, 0x0000 if unknown */
61 unsigned int index; /*!< @brief the order in which the add-on identified this peripheral */
62 } ATTRIBUTE_PACKED PERIPHERAL_INFO;
63
64 /*!
65 * @brief Peripheral add-on capabilities.
66 * If a capability is set to true, then the corresponding methods from
67 * kodi_peripheral_dll.h need to be implemented.
68 */
69 typedef struct PERIPHERAL_CAPABILITIES
70 {
71 bool provides_joysticks; /*!< @brief true if the add-on provides joysticks */
72 bool provides_joystick_rumble;
73 bool provides_joystick_power_off;
74 bool provides_buttonmaps; /*!< @brief true if the add-on provides button maps */
75 } ATTRIBUTE_PACKED PERIPHERAL_CAPABILITIES;
76 ///}
77
78 /// @name Event types
79 ///{
80 typedef enum PERIPHERAL_EVENT_TYPE
81 {
82 PERIPHERAL_EVENT_TYPE_NONE, /*!< @brief unknown event */
83 PERIPHERAL_EVENT_TYPE_DRIVER_BUTTON, /*!< @brief state changed for joystick driver button */
84 PERIPHERAL_EVENT_TYPE_DRIVER_HAT, /*!< @brief state changed for joystick driver hat */
85 PERIPHERAL_EVENT_TYPE_DRIVER_AXIS, /*!< @brief state changed for joystick driver axis */
86 PERIPHERAL_EVENT_TYPE_SET_MOTOR, /*!< @brief set the state for joystick rumble motor */
87 } PERIPHERAL_EVENT_TYPE;
88
89 typedef enum JOYSTICK_STATE_BUTTON
90 {
91 JOYSTICK_STATE_BUTTON_UNPRESSED = 0x0, /*!< @brief button is released */
92 JOYSTICK_STATE_BUTTON_PRESSED = 0x1, /*!< @brief button is pressed */
93 } JOYSTICK_STATE_BUTTON;
94
95 typedef enum JOYSTICK_STATE_HAT
96 {
97 JOYSTICK_STATE_HAT_UNPRESSED = 0x0, /*!< @brief no directions are pressed */
98 JOYSTICK_STATE_HAT_LEFT = 0x1, /*!< @brief only left is pressed */
99 JOYSTICK_STATE_HAT_RIGHT = 0x2, /*!< @brief only right is pressed */
100 JOYSTICK_STATE_HAT_UP = 0x4, /*!< @brief only up is pressed */
101 JOYSTICK_STATE_HAT_DOWN = 0x8, /*!< @brief only down is pressed */
102 JOYSTICK_STATE_HAT_LEFT_UP = JOYSTICK_STATE_HAT_LEFT | JOYSTICK_STATE_HAT_UP,
103 JOYSTICK_STATE_HAT_LEFT_DOWN = JOYSTICK_STATE_HAT_LEFT | JOYSTICK_STATE_HAT_DOWN,
104 JOYSTICK_STATE_HAT_RIGHT_UP = JOYSTICK_STATE_HAT_RIGHT | JOYSTICK_STATE_HAT_UP,
105 JOYSTICK_STATE_HAT_RIGHT_DOWN = JOYSTICK_STATE_HAT_RIGHT | JOYSTICK_STATE_HAT_DOWN,
106 } JOYSTICK_STATE_HAT;
107
108 /*!
109 * @brief value in the closed interval [-1.0, 1.0]
110 *
111 * The axis state uses the XInput coordinate system:
112 * - Negative values signify down or to the left
113 * - Positive values signify up or to the right
114 */
115 typedef float JOYSTICK_STATE_AXIS;
116
117 typedef float JOYSTICK_STATE_MOTOR;
118
119 typedef struct PERIPHERAL_EVENT
120 {
121 unsigned int peripheral_index;
122 PERIPHERAL_EVENT_TYPE type;
123 unsigned int driver_index;
124 JOYSTICK_STATE_BUTTON driver_button_state;
125 JOYSTICK_STATE_HAT driver_hat_state;
126 JOYSTICK_STATE_AXIS driver_axis_state;
127 JOYSTICK_STATE_MOTOR motor_state;
128 } ATTRIBUTE_PACKED PERIPHERAL_EVENT;
129 ///}
130
131 /// @name Joystick types
132 ///{
133 typedef struct JOYSTICK_INFO
134 {
135 PERIPHERAL_INFO peripheral; /*!< @brief peripheral info for this joystick */
136 char* provider; /*!< @brief name of the driver or interface providing the joystick */
137 int requested_port; /*!< @brief requested port number (such as for 360 controllers), or NO_PORT_REQUESTED */
138 unsigned int button_count; /*!< @brief number of buttons reported by the driver */
139 unsigned int hat_count; /*!< @brief number of hats reported by the driver */
140 unsigned int axis_count; /*!< @brief number of axes reported by the driver */
141 unsigned int motor_count; /*!< @brief number of motors reported by the driver */
142 bool supports_poweroff; /*!< @brief whether the joystick supports being powered off */
143 } ATTRIBUTE_PACKED JOYSTICK_INFO;
144
145 typedef enum JOYSTICK_DRIVER_PRIMITIVE_TYPE
146 {
147 JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN,
148 JOYSTICK_DRIVER_PRIMITIVE_TYPE_BUTTON,
149 JOYSTICK_DRIVER_PRIMITIVE_TYPE_HAT_DIRECTION,
150 JOYSTICK_DRIVER_PRIMITIVE_TYPE_SEMIAXIS,
151 JOYSTICK_DRIVER_PRIMITIVE_TYPE_MOTOR,
152 } JOYSTICK_DRIVER_PRIMITIVE_TYPE;
153
154 typedef struct JOYSTICK_DRIVER_BUTTON
155 {
156 int index;
157 } ATTRIBUTE_PACKED JOYSTICK_DRIVER_BUTTON;
158
159 typedef enum JOYSTICK_DRIVER_HAT_DIRECTION
160 {
161 JOYSTICK_DRIVER_HAT_UNKNOWN,
162 JOYSTICK_DRIVER_HAT_LEFT,
163 JOYSTICK_DRIVER_HAT_RIGHT,
164 JOYSTICK_DRIVER_HAT_UP,
165 JOYSTICK_DRIVER_HAT_DOWN,
166 } JOYSTICK_DRIVER_HAT_DIRECTION;
167
168 typedef struct JOYSTICK_DRIVER_HAT
169 {
170 int index;
171 JOYSTICK_DRIVER_HAT_DIRECTION direction;
172 } ATTRIBUTE_PACKED JOYSTICK_DRIVER_HAT;
173
174 typedef enum JOYSTICK_DRIVER_SEMIAXIS_DIRECTION
175 {
176 JOYSTICK_DRIVER_SEMIAXIS_NEGATIVE = -1, /*!< @brief negative half of the axis */
177 JOYSTICK_DRIVER_SEMIAXIS_UNKNOWN = 0, /*!< @brief unknown direction */
178 JOYSTICK_DRIVER_SEMIAXIS_POSITIVE = 1, /*!< @brief positive half of the axis */
179 } JOYSTICK_DRIVER_SEMIAXIS_DIRECTION;
180
181 typedef struct JOYSTICK_DRIVER_SEMIAXIS
182 {
183 int index;
184 int center;
185 JOYSTICK_DRIVER_SEMIAXIS_DIRECTION direction;
186 unsigned int range;
187 } ATTRIBUTE_PACKED JOYSTICK_DRIVER_SEMIAXIS;
188
189 typedef struct JOYSTICK_DRIVER_MOTOR
190 {
191 int index;
192 } ATTRIBUTE_PACKED JOYSTICK_DRIVER_MOTOR;
193
194 typedef struct JOYSTICK_DRIVER_PRIMITIVE
195 {
196 JOYSTICK_DRIVER_PRIMITIVE_TYPE type;
197 union
198 {
199 struct JOYSTICK_DRIVER_BUTTON button;
200 struct JOYSTICK_DRIVER_HAT hat;
201 struct JOYSTICK_DRIVER_SEMIAXIS semiaxis;
202 struct JOYSTICK_DRIVER_MOTOR motor;
203 };
204 } ATTRIBUTE_PACKED JOYSTICK_DRIVER_PRIMITIVE;
205
206 typedef enum JOYSTICK_FEATURE_TYPE
207 {
208 JOYSTICK_FEATURE_TYPE_UNKNOWN,
209 JOYSTICK_FEATURE_TYPE_SCALAR,
210 JOYSTICK_FEATURE_TYPE_ANALOG_STICK,
211 JOYSTICK_FEATURE_TYPE_ACCELEROMETER,
212 JOYSTICK_FEATURE_TYPE_MOTOR,
213 } JOYSTICK_FEATURE_TYPE;
214
215 typedef enum JOYSTICK_FEATURE_PRIMITIVE
216 {
217 // Scalar feature
218 JOYSTICK_SCALAR_PRIMITIVE = 0,
219
220 // Analog stick
221 JOYSTICK_ANALOG_STICK_UP = 0,
222 JOYSTICK_ANALOG_STICK_DOWN = 1,
223 JOYSTICK_ANALOG_STICK_RIGHT = 2,
224 JOYSTICK_ANALOG_STICK_LEFT = 3,
225
226 // Accelerometer
227 JOYSTICK_ACCELEROMETER_POSITIVE_X = 0,
228 JOYSTICK_ACCELEROMETER_POSITIVE_Y = 1,
229 JOYSTICK_ACCELEROMETER_POSITIVE_Z = 2,
230
231 // Motor
232 JOYSTICK_MOTOR_PRIMITIVE = 0,
233
234 // Maximum number of primitives
235 JOYSTICK_PRIMITIVE_MAX = 4,
236 } JOYSTICK_FEATURE_PRIMITIVE;
237
238 typedef struct JOYSTICK_FEATURE
239 {
240 char* name;
241 JOYSTICK_FEATURE_TYPE type;
242 struct JOYSTICK_DRIVER_PRIMITIVE primitives[JOYSTICK_PRIMITIVE_MAX];
243 } ATTRIBUTE_PACKED JOYSTICK_FEATURE;
244 ///}
245
246 typedef struct AddonProps_Peripheral
247 {
248 const char* user_path; /*!< @brief path to the user profile */
249 const char* addon_path; /*!< @brief path to this add-on */
250 } ATTRIBUTE_PACKED AddonProps_Peripheral;
251
252 struct AddonInstance_Peripheral;
253
254 typedef struct AddonToKodiFuncTable_Peripheral
255 {
256 KODI_HANDLE kodiInstance;
257 void (*trigger_scan)(void* kodiInstance);
258 void (*refresh_button_maps)(void* kodiInstance, const char* device_name, const char* controller_id);
259 unsigned int (*feature_count)(void* kodiInstance, const char* controller_id, JOYSTICK_FEATURE_TYPE type);
260 } AddonToKodiFuncTable_Peripheral;
261
262 //! @todo Mouse, light gun, multitouch
263
264 typedef struct KodiToAddonFuncTable_Peripheral
265 {
266 kodi::addon::CInstancePeripheral* addonInstance;
267
268 void (__cdecl* get_capabilities)(const AddonInstance_Peripheral* addonInstance, PERIPHERAL_CAPABILITIES* capabilities);
269 PERIPHERAL_ERROR (__cdecl* perform_device_scan)(const AddonInstance_Peripheral* addonInstance, unsigned int* peripheral_count, PERIPHERAL_INFO** scan_results);
270 void (__cdecl* free_scan_results)(const AddonInstance_Peripheral* addonInstance, unsigned int peripheral_count, PERIPHERAL_INFO* scan_results);
271 PERIPHERAL_ERROR (__cdecl* get_events)(const AddonInstance_Peripheral* addonInstance, unsigned int* event_count, PERIPHERAL_EVENT** events);
272 void (__cdecl* free_events)(const AddonInstance_Peripheral* addonInstance, unsigned int event_count, PERIPHERAL_EVENT* events);
273 bool (__cdecl* send_event)(const AddonInstance_Peripheral* addonInstance, const PERIPHERAL_EVENT* event);
274
275 /// @name Joystick operations
276 ///{
277 PERIPHERAL_ERROR (__cdecl* get_joystick_info)(const AddonInstance_Peripheral* addonInstance, unsigned int index, JOYSTICK_INFO* info);
278 void (__cdecl* free_joystick_info)(const AddonInstance_Peripheral* addonInstance, JOYSTICK_INFO* info);
279 PERIPHERAL_ERROR (__cdecl* get_features)(const AddonInstance_Peripheral* addonInstance, const JOYSTICK_INFO* joystick, const char* controller_id, unsigned int* feature_count, JOYSTICK_FEATURE** features);
280 void (__cdecl* free_features)(const AddonInstance_Peripheral* addonInstance, unsigned int feature_count, JOYSTICK_FEATURE* features);
281 PERIPHERAL_ERROR (__cdecl* map_features)(const AddonInstance_Peripheral* addonInstance, const JOYSTICK_INFO* joystick, const char* controller_id, unsigned int feature_count, const JOYSTICK_FEATURE* features);
282 PERIPHERAL_ERROR (__cdecl* get_ignored_primitives)(const AddonInstance_Peripheral* addonInstance, const JOYSTICK_INFO* joystick, unsigned int* feature_count, JOYSTICK_DRIVER_PRIMITIVE** primitives);
283 void (__cdecl* free_primitives)(const AddonInstance_Peripheral* addonInstance, unsigned int, JOYSTICK_DRIVER_PRIMITIVE* primitives);
284 PERIPHERAL_ERROR (__cdecl* set_ignored_primitives)(const AddonInstance_Peripheral* addonInstance, const JOYSTICK_INFO* joystick, unsigned int primitive_count, const JOYSTICK_DRIVER_PRIMITIVE* primitives);
285 void (__cdecl* save_button_map)(const AddonInstance_Peripheral* addonInstance, const JOYSTICK_INFO* joystick);
286 void (__cdecl* revert_button_map)(const AddonInstance_Peripheral* addonInstance, const JOYSTICK_INFO* joystick);
287 void (__cdecl* reset_button_map)(const AddonInstance_Peripheral* addonInstance, const JOYSTICK_INFO* joystick, const char* controller_id);
288 void (__cdecl* power_off_joystick)(const AddonInstance_Peripheral* addonInstance, unsigned int index);
289 ///}
290 } KodiToAddonFuncTable_Peripheral;
291
292 typedef struct AddonInstance_Peripheral
293 {
294 AddonProps_Peripheral props;
295 AddonToKodiFuncTable_Peripheral toKodi;
296 KodiToAddonFuncTable_Peripheral toAddon;
297 } AddonInstance_Peripheral;
298
299} /* extern "C" */
300
301namespace kodi
302{
303namespace addon
304{
305
306 class CInstancePeripheral : public IAddonInstance
307 {
308 public:
309 CInstancePeripheral()
310 : IAddonInstance(ADDON_INSTANCE_PERIPHERAL)
311 {
312 if (CAddonBase::m_interface->globalSingleInstance != nullptr)
313 throw std::logic_error("kodi::addon::CInstancePeripheral: Creation of more as one in single instance way is not allowed!");
314
315 SetAddonStruct(CAddonBase::m_interface->firstKodiInstance);
316 CAddonBase::m_interface->globalSingleInstance = this;
317 }
318
319 CInstancePeripheral(KODI_HANDLE instance)
320 : IAddonInstance(ADDON_INSTANCE_PERIPHERAL)
321 {
322 if (CAddonBase::m_interface->globalSingleInstance != nullptr)
323 throw std::logic_error("kodi::addon::CInstancePeripheral: Creation of multiple together with single instance way is not allowed!");
324
325 SetAddonStruct(instance);
326 }
327
328 ~CInstancePeripheral() override = default;
329
330 /// @name Peripheral operations
331 ///{
332 /*!
333 * @brief Get the list of features that this add-on provides
334 * @param capabilities The add-on's capabilities.
335 * @remarks Valid implementation required.
336 *
337 * Called by the frontend to query the add-on's capabilities and supported
338 * peripherals. All capabilities that the add-on supports should be set to true.
339 *
340 */
341 virtual void GetCapabilities(PERIPHERAL_CAPABILITIES &capabilities) { }
342
343 /*!
344 * @brief Perform a scan for joysticks
345 * @param peripheral_count Assigned to the number of peripherals allocated
346 * @param scan_results Assigned to allocated memory
347 * @return PERIPHERAL_NO_ERROR if successful; peripherals must be freed using
348 * FreeScanResults() in this case
349 *
350 * The frontend calls this when a hardware change is detected. If an add-on
351 * detects a hardware change, it can trigger this function using the
352 * TriggerScan() callback.
353 */
354 virtual PERIPHERAL_ERROR PerformDeviceScan(unsigned int* peripheral_count, PERIPHERAL_INFO** scan_results) { return PERIPHERAL_ERROR_NOT_IMPLEMENTED; }
355
356 /*!
357 * @brief Free the memory allocated in PerformDeviceScan()
358 *
359 * Must be called if PerformDeviceScan() returns PERIPHERAL_NO_ERROR.
360 *
361 * @param peripheral_count The number of events allocated for the events array
362 * @param scan_results The array of allocated peripherals
363 */
364 virtual void FreeScanResults(unsigned int peripheral_count, PERIPHERAL_INFO* scan_results) { }
365
366 /*!
367 * @brief Get all events that have occurred since the last call to GetEvents()
368 * @return PERIPHERAL_NO_ERROR if successful; events must be freed using
369 * FreeEvents() in this case
370 */
371 virtual PERIPHERAL_ERROR GetEvents(unsigned int* event_count, PERIPHERAL_EVENT** events) { return PERIPHERAL_ERROR_NOT_IMPLEMENTED; }
372
373 /*!
374 * @brief Free the memory allocated in GetEvents()
375 *
376 * Must be called if GetEvents() returns PERIPHERAL_NO_ERROR.
377 *
378 * @param event_count The number of events allocated for the events array
379 * @param events The array of allocated events
380 */
381 virtual void FreeEvents(unsigned int event_count, PERIPHERAL_EVENT* events) { }
382
383 /*!
384 * @brief Send an input event to the specified peripheral
385 * @param peripheralIndex The index of the device receiving the input event
386 * @param event The input event
387 * @return true if the event was handled, false otherwise
388 */
389 virtual bool SendEvent(const PERIPHERAL_EVENT* event) { return false; }
390 ///}
391
392 /// @name Joystick operations
393 /*!
394 * @note #define PERIPHERAL_ADDON_JOYSTICKS before including kodi_peripheral_dll.h
395 * in the add-on if the add-on provides joysticks and add provides_joysticks="true"
396 * to the kodi.peripheral extension point node in addon.xml.
397 */
398 ///{
399 /*!
400 * @brief Get extended info about an attached joystick
401 * @param index The joystick's driver index
402 * @param info The container for the allocated joystick info
403 * @return PERIPHERAL_NO_ERROR if successful; array must be freed using
404 * FreeJoystickInfo() in this case
405 */
406 virtual PERIPHERAL_ERROR GetJoystickInfo(unsigned int index, JOYSTICK_INFO* info) { return PERIPHERAL_ERROR_NOT_IMPLEMENTED; }
407
408 /*!
409 * @brief Free the memory allocated in GetJoystickInfo()
410 */
411 virtual void FreeJoystickInfo(JOYSTICK_INFO* info) { }
412
413 /*!
414 * @brief Get the features that allow translating the joystick into the controller profile
415 * @param joystick The device's joystick properties; unknown values may be left at their default
416 * @param controller_id The controller profile being requested, e.g. game.controller.default
417 * @param feature_count The number of features allocated for the features array
418 * @param features The array of allocated features
419 * @return PERIPHERAL_NO_ERROR if successful; array must be freed using
420 * FreeButtonMap() in this case
421 */
422 virtual PERIPHERAL_ERROR GetFeatures(const JOYSTICK_INFO* joystick, const char* controller_id,
423 unsigned int* feature_count, JOYSTICK_FEATURE** features) { return PERIPHERAL_ERROR_NOT_IMPLEMENTED; }
424
425 /*!
426 * @brief Free the memory allocated in GetFeatures()
427 *
428 * Must be called if GetFeatures() returns PERIPHERAL_NO_ERROR.
429 *
430 * @param feature_count The number of features allocated for the features array
431 * @param features The array of allocated features
432 */
433 virtual void FreeFeatures(unsigned int feature_count, JOYSTICK_FEATURE* features) { }
434
435 /*!
436 * @brief Add or update joystick features
437 * @param joystick The device's joystick properties; unknown values may be left at their default
438 * @param controller_id The game controller profile being updated
439 * @param feature_count The number of features in the features array
440 * @param features The array of features
441 * @return PERIPHERAL_NO_ERROR if successful
442 */
443 virtual PERIPHERAL_ERROR MapFeatures(const JOYSTICK_INFO* joystick, const char* controller_id,
444 unsigned int feature_count, const JOYSTICK_FEATURE* features) { return PERIPHERAL_ERROR_NOT_IMPLEMENTED; }
445
446 /*!
447 * @brief Get the driver primitives that should be ignored while mapping the device
448 * @param joystick The device's joystick properties; unknown values may be left at their default
449 * @param primitive_count The number of features allocated for the primitives array
450 * @param primitives The array of allocated driver primitives to be ignored
451 * @return PERIPHERAL_NO_ERROR if successful; array must be freed using
452 * FreePrimitives() in this case
453 */
454 virtual PERIPHERAL_ERROR GetIgnoredPrimitives(const JOYSTICK_INFO* joystick,
455 unsigned int* primitive_count,
456 JOYSTICK_DRIVER_PRIMITIVE** primitives) { return PERIPHERAL_ERROR_NOT_IMPLEMENTED; }
457
458 /*!
459 * @brief Free the memory allocated in GetIgnoredPrimitives()
460 *
461 * Must be called if GetIgnoredPrimitives() returns PERIPHERAL_NO_ERROR.
462 *
463 * @param primitive_count The number of driver primitives allocated for the primitives array
464 * @param primitives The array of allocated driver primitives
465 */
466 virtual void FreePrimitives(unsigned int primitive_count, JOYSTICK_DRIVER_PRIMITIVE* primitives) { }
467
468 /*!
469 * @brief Set the list of driver primitives that are ignored for the device
470 * @param joystick The device's joystick properties; unknown values may be left at their default
471 * @param primitive_count The number of driver features in the primitives array
472 * @param primitives The array of driver primitives to ignore
473 * @return PERIPHERAL_NO_ERROR if successful
474 */
475 virtual PERIPHERAL_ERROR SetIgnoredPrimitives(const JOYSTICK_INFO* joystick,
476 unsigned int primitive_count,
477 const JOYSTICK_DRIVER_PRIMITIVE* primitives) { return PERIPHERAL_ERROR_NOT_IMPLEMENTED; }
478
479 /*!
480 * @brief Save the button map for the given joystick
481 * @param joystick The device's joystick properties
482 */
483 virtual void SaveButtonMap(const JOYSTICK_INFO* joystick) { }
484
485 /*!
486 * @brief Revert the button map to the last time it was loaded or committed to disk
487 * @param joystick The device's joystick properties
488 */
489 virtual void RevertButtonMap(const JOYSTICK_INFO* joystick) { }
490
491 /*!
492 * @brief Reset the button map for the given joystick and controller profile ID
493 * @param joystick The device's joystick properties
494 * @param controller_id The game controller profile being reset
495 */
496 virtual void ResetButtonMap(const JOYSTICK_INFO* joystick, const char* controller_id) { }
497
498 /*!
499 * @brief Powers off the given joystick if supported
500 * @param index The joystick's driver index
501 */
502 virtual void PowerOffJoystick(unsigned int index) { }
503
504 const std::string AddonPath() const
505 {
506 return m_instanceData->props.addon_path;
507 }
508
509 const std::string UserPath() const
510 {
511 return m_instanceData->props.user_path;
512 }
513
514 /*!
515 * @brief Trigger a scan for peripherals
516 *
517 * The add-on calls this if a change in hardware is detected.
518 */
519 void TriggerScan(void)
520 {
521 return m_instanceData->toKodi.trigger_scan(m_instanceData->toKodi.kodiInstance);
522 }
523
524 /*!
525 * @brief Notify the frontend that button maps have changed
526 *
527 * @param[optional] deviceName The name of the device to refresh, or empty/null for all devices
528 * @param[optional] controllerId The controller ID to refresh, or empty/null for all controllers
529 */
530 void RefreshButtonMaps(const std::string& strDeviceName = "", const std::string& strControllerId = "")
531 {
532 return m_instanceData->toKodi.refresh_button_maps(m_instanceData->toKodi.kodiInstance, strDeviceName.c_str(), strControllerId.c_str());
533 }
534
535 /*!
536 * @brief Return the number of features belonging to the specified controller
537 *
538 * @param controllerId The controller ID to enumerate
539 * @param type[optional] Type to filter by, or JOYSTICK_FEATURE_TYPE_UNKNOWN for all features
540 *
541 * @return The number of features matching the request parameters
542 */
543 unsigned int FeatureCount(const std::string& strControllerId, JOYSTICK_FEATURE_TYPE type = JOYSTICK_FEATURE_TYPE_UNKNOWN)
544 {
545 return m_instanceData->toKodi.feature_count(m_instanceData->toKodi.kodiInstance, strControllerId.c_str(), type);
546 }
547
548 private:
549 void SetAddonStruct(KODI_HANDLE instance)
550 {
551 if (instance == nullptr)
552 throw std::logic_error("kodi::addon::CInstancePeripheral: Creation with empty addon structure not allowed, table must be given from Kodi!");
553
554 m_instanceData = static_cast<AddonInstance_Peripheral*>(instance);
555 m_instanceData->toAddon.addonInstance = this;
556
557 m_instanceData->toAddon.get_capabilities = ADDON_GetCapabilities;
558 m_instanceData->toAddon.perform_device_scan = ADDON_PerformDeviceScan;
559 m_instanceData->toAddon.free_scan_results = ADDON_FreeScanResults;
560 m_instanceData->toAddon.get_events = ADDON_GetEvents;
561 m_instanceData->toAddon.free_events = ADDON_FreeEvents;
562 m_instanceData->toAddon.send_event = ADDON_SendEvent;
563
564 m_instanceData->toAddon.get_joystick_info = ADDON_GetJoystickInfo;
565 m_instanceData->toAddon.free_joystick_info = ADDON_FreeJoystickInfo;
566 m_instanceData->toAddon.get_features = ADDON_GetFeatures;
567 m_instanceData->toAddon.free_features = ADDON_FreeFeatures;
568 m_instanceData->toAddon.map_features = ADDON_MapFeatures;
569 m_instanceData->toAddon.get_ignored_primitives = ADDON_GetIgnoredPrimitives;
570 m_instanceData->toAddon.free_primitives = ADDON_FreePrimitives;
571 m_instanceData->toAddon.set_ignored_primitives = ADDON_SetIgnoredPrimitives;
572 m_instanceData->toAddon.save_button_map = ADDON_SaveButtonMap;
573 m_instanceData->toAddon.revert_button_map = ADDON_RevertButtonMap;
574 m_instanceData->toAddon.reset_button_map = ADDON_ResetButtonMap;
575 m_instanceData->toAddon.power_off_joystick = ADDON_PowerOffJoystick;
576 }
577
578 inline static void ADDON_GetCapabilities(const AddonInstance_Peripheral* addonInstance, PERIPHERAL_CAPABILITIES *capabilities)
579 {
580 addonInstance->toAddon.addonInstance->GetCapabilities(*capabilities);
581 }
582
583 inline static PERIPHERAL_ERROR ADDON_PerformDeviceScan(const AddonInstance_Peripheral* addonInstance, unsigned int* peripheral_count, PERIPHERAL_INFO** scan_results)
584 {
585 return addonInstance->toAddon.addonInstance->PerformDeviceScan(peripheral_count, scan_results);
586 }
587
588 inline static void ADDON_FreeScanResults(const AddonInstance_Peripheral* addonInstance, unsigned int peripheral_count, PERIPHERAL_INFO* scan_results)
589 {
590 addonInstance->toAddon.addonInstance->FreeScanResults(peripheral_count, scan_results);
591 }
592
593 inline static PERIPHERAL_ERROR ADDON_GetEvents(const AddonInstance_Peripheral* addonInstance, unsigned int* event_count, PERIPHERAL_EVENT** events)
594 {
595 return addonInstance->toAddon.addonInstance->GetEvents(event_count, events);
596 }
597
598 inline static void ADDON_FreeEvents(const AddonInstance_Peripheral* addonInstance, unsigned int event_count, PERIPHERAL_EVENT* events)
599 {
600 addonInstance->toAddon.addonInstance->FreeEvents(event_count, events);
601 }
602
603 inline static bool ADDON_SendEvent(const AddonInstance_Peripheral* addonInstance, const PERIPHERAL_EVENT* event)
604 {
605 return addonInstance->toAddon.addonInstance->SendEvent(event);
606 }
607
608
609 inline static PERIPHERAL_ERROR ADDON_GetJoystickInfo(const AddonInstance_Peripheral* addonInstance, unsigned int index, JOYSTICK_INFO* info)
610 {
611 return addonInstance->toAddon.addonInstance->GetJoystickInfo(index, info);
612 }
613
614 inline static void ADDON_FreeJoystickInfo(const AddonInstance_Peripheral* addonInstance, JOYSTICK_INFO* info)
615 {
616 addonInstance->toAddon.addonInstance->FreeJoystickInfo(info);
617 }
618
619 inline static PERIPHERAL_ERROR ADDON_GetFeatures(const AddonInstance_Peripheral* addonInstance,
620 const JOYSTICK_INFO* joystick, const char* controller_id,
621 unsigned int* feature_count, JOYSTICK_FEATURE** features)
622 {
623 return addonInstance->toAddon.addonInstance->GetFeatures(joystick, controller_id, feature_count, features);
624 }
625
626 inline static void ADDON_FreeFeatures(const AddonInstance_Peripheral* addonInstance, unsigned int feature_count, JOYSTICK_FEATURE* features)
627 {
628 addonInstance->toAddon.addonInstance->FreeFeatures(feature_count, features);
629 }
630
631 inline static PERIPHERAL_ERROR ADDON_MapFeatures(const AddonInstance_Peripheral* addonInstance,
632 const JOYSTICK_INFO* joystick, const char* controller_id,
633 unsigned int feature_count, const JOYSTICK_FEATURE* features)
634 {
635 return addonInstance->toAddon.addonInstance->MapFeatures(joystick, controller_id, feature_count, features);
636 }
637
638 inline static PERIPHERAL_ERROR ADDON_GetIgnoredPrimitives(const AddonInstance_Peripheral* addonInstance,
639 const JOYSTICK_INFO* joystick, unsigned int* primitive_count,
640 JOYSTICK_DRIVER_PRIMITIVE** primitives)
641 {
642 return addonInstance->toAddon.addonInstance->GetIgnoredPrimitives(joystick, primitive_count, primitives);
643 }
644
645 inline static void ADDON_FreePrimitives(const AddonInstance_Peripheral* addonInstance,
646 unsigned int primitive_count, JOYSTICK_DRIVER_PRIMITIVE* primitives)
647 {
648 addonInstance->toAddon.addonInstance->FreePrimitives(primitive_count, primitives);
649 }
650
651 inline static PERIPHERAL_ERROR ADDON_SetIgnoredPrimitives(const AddonInstance_Peripheral* addonInstance,
652 const JOYSTICK_INFO* joystick, unsigned int primitive_count,
653 const JOYSTICK_DRIVER_PRIMITIVE* primitives)
654 {
655 return addonInstance->toAddon.addonInstance->SetIgnoredPrimitives(joystick, primitive_count, primitives);
656 }
657
658 inline static void ADDON_SaveButtonMap(const AddonInstance_Peripheral* addonInstance, const JOYSTICK_INFO* joystick)
659 {
660 addonInstance->toAddon.addonInstance->SaveButtonMap(joystick);
661 }
662
663 inline static void ADDON_RevertButtonMap(const AddonInstance_Peripheral* addonInstance, const JOYSTICK_INFO* joystick)
664 {
665 addonInstance->toAddon.addonInstance->RevertButtonMap(joystick);
666 }
667
668 inline static void ADDON_ResetButtonMap(const AddonInstance_Peripheral* addonInstance, const JOYSTICK_INFO* joystick, const char* controller_id)
669 {
670 addonInstance->toAddon.addonInstance->ResetButtonMap(joystick, controller_id);
671 }
672
673 inline static void ADDON_PowerOffJoystick(const AddonInstance_Peripheral* addonInstance, unsigned int index)
674 {
675 addonInstance->toAddon.addonInstance->PowerOffJoystick(index);
676 }
677
678 AddonInstance_Peripheral* m_instanceData;
679 };
680
681} /* namespace addon */
682} /* namespace kodi */