summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Peripheral.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
committermanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
commitbe933ef2241d79558f91796cc5b3a161f72ebf9c (patch)
treefe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Peripheral.h
parent5f8335c1e49ce108ef3481863833c98efa00411b (diff)
downloadkodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.gz
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.bz2
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.zip
sync with upstream
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.h847
1 files changed, 0 insertions, 847 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
deleted file mode 100644
index 2067d51..0000000
--- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Peripheral.h
+++ /dev/null
@@ -1,847 +0,0 @@
1/*
2 * Copyright (C) 2014-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9#pragma once
10
11#include "../AddonBase.h"
12
13namespace kodi { namespace addon { class CInstancePeripheral; }}
14
15/* indicates a joystick has no preference for port number */
16#define NO_PORT_REQUESTED (-1)
17
18/* joystick's driver button/hat/axis index is unknown */
19#define DRIVER_INDEX_UNKNOWN (-1)
20
21extern "C"
22{
23
24 /// @name Peripheral types
25 ///{
26
27 /*!
28 * @brief API error codes
29 */
30 typedef enum PERIPHERAL_ERROR
31 {
32 PERIPHERAL_NO_ERROR = 0, // no error occurred
33 PERIPHERAL_ERROR_UNKNOWN = -1, // an unknown error occurred
34 PERIPHERAL_ERROR_FAILED = -2, // the command failed
35 PERIPHERAL_ERROR_INVALID_PARAMETERS = -3, // the parameters of the method are invalid for this operation
36 PERIPHERAL_ERROR_NOT_IMPLEMENTED = -4, // the method that the frontend called is not implemented
37 PERIPHERAL_ERROR_NOT_CONNECTED = -5, // no peripherals are connected
38 PERIPHERAL_ERROR_CONNECTION_FAILED = -6, // peripherals are connected, but command was interrupted
39 } PERIPHERAL_ERROR;
40
41 /*!
42 * @brief Peripheral types
43 */
44 typedef enum PERIPHERAL_TYPE
45 {
46 PERIPHERAL_TYPE_UNKNOWN,
47 PERIPHERAL_TYPE_JOYSTICK,
48 PERIPHERAL_TYPE_KEYBOARD,
49 } PERIPHERAL_TYPE;
50
51 /*!
52 * @brief Information shared between peripherals
53 */
54 typedef struct PERIPHERAL_INFO
55 {
56 PERIPHERAL_TYPE type; /*!< @brief type of peripheral */
57 char* name; /*!< @brief name of peripheral */
58 uint16_t vendor_id; /*!< @brief vendor ID of peripheral, 0x0000 if unknown */
59 uint16_t product_id; /*!< @brief product ID of peripheral, 0x0000 if unknown */
60 unsigned int index; /*!< @brief the order in which the add-on identified this peripheral */
61 } ATTRIBUTE_PACKED PERIPHERAL_INFO;
62
63 /*!
64 * @brief Peripheral add-on capabilities.
65 */
66 typedef struct PERIPHERAL_CAPABILITIES
67 {
68 bool provides_joysticks; /*!< @brief true if the add-on provides joysticks */
69 bool provides_joystick_rumble;
70 bool provides_joystick_power_off;
71 bool provides_buttonmaps; /*!< @brief true if the add-on provides button maps */
72 } ATTRIBUTE_PACKED PERIPHERAL_CAPABILITIES;
73 ///}
74
75 /// @name Event types
76 ///{
77
78 /*!
79 * @brief Types of events that can be sent and received
80 */
81 typedef enum PERIPHERAL_EVENT_TYPE
82 {
83 PERIPHERAL_EVENT_TYPE_NONE, /*!< @brief unknown event */
84 PERIPHERAL_EVENT_TYPE_DRIVER_BUTTON, /*!< @brief state changed for joystick driver button */
85 PERIPHERAL_EVENT_TYPE_DRIVER_HAT, /*!< @brief state changed for joystick driver hat */
86 PERIPHERAL_EVENT_TYPE_DRIVER_AXIS, /*!< @brief state changed for joystick driver axis */
87 PERIPHERAL_EVENT_TYPE_SET_MOTOR, /*!< @brief set the state for joystick rumble motor */
88 } PERIPHERAL_EVENT_TYPE;
89
90 /*!
91 * @brief States a button can have
92 */
93 typedef enum JOYSTICK_STATE_BUTTON
94 {
95 JOYSTICK_STATE_BUTTON_UNPRESSED = 0x0, /*!< @brief button is released */
96 JOYSTICK_STATE_BUTTON_PRESSED = 0x1, /*!< @brief button is pressed */
97 } JOYSTICK_STATE_BUTTON;
98
99 /*!
100 * @brief States a D-pad (also called a hat) can have
101 */
102 typedef enum JOYSTICK_STATE_HAT
103 {
104 JOYSTICK_STATE_HAT_UNPRESSED = 0x0, /*!< @brief no directions are pressed */
105 JOYSTICK_STATE_HAT_LEFT = 0x1, /*!< @brief only left is pressed */
106 JOYSTICK_STATE_HAT_RIGHT = 0x2, /*!< @brief only right is pressed */
107 JOYSTICK_STATE_HAT_UP = 0x4, /*!< @brief only up is pressed */
108 JOYSTICK_STATE_HAT_DOWN = 0x8, /*!< @brief only down is pressed */
109 JOYSTICK_STATE_HAT_LEFT_UP = JOYSTICK_STATE_HAT_LEFT | JOYSTICK_STATE_HAT_UP,
110 JOYSTICK_STATE_HAT_LEFT_DOWN = JOYSTICK_STATE_HAT_LEFT | JOYSTICK_STATE_HAT_DOWN,
111 JOYSTICK_STATE_HAT_RIGHT_UP = JOYSTICK_STATE_HAT_RIGHT | JOYSTICK_STATE_HAT_UP,
112 JOYSTICK_STATE_HAT_RIGHT_DOWN = JOYSTICK_STATE_HAT_RIGHT | JOYSTICK_STATE_HAT_DOWN,
113 } JOYSTICK_STATE_HAT;
114
115 /*!
116 * @brief Axis value in the closed interval [-1.0, 1.0]
117 *
118 * The axis state uses the XInput coordinate system:
119 * - Negative values signify down or to the left
120 * - Positive values signify up or to the right
121 */
122 typedef float JOYSTICK_STATE_AXIS;
123
124 /*!
125 * @brief Motor value in the closed interval [0.0, 1.0]
126 */
127 typedef float JOYSTICK_STATE_MOTOR;
128
129 /*!
130 * @brief Event information
131 */
132 typedef struct PERIPHERAL_EVENT
133 {
134 /*! @brief Index of the peripheral handling/receiving the event */
135 unsigned int peripheral_index;
136
137 /*! @brief Type of the event used to determine which enum field to access below */
138 PERIPHERAL_EVENT_TYPE type;
139
140 /*! @brief The index of the event source */
141 unsigned int driver_index;
142
143 JOYSTICK_STATE_BUTTON driver_button_state;
144 JOYSTICK_STATE_HAT driver_hat_state;
145 JOYSTICK_STATE_AXIS driver_axis_state;
146 JOYSTICK_STATE_MOTOR motor_state;
147 } ATTRIBUTE_PACKED PERIPHERAL_EVENT;
148 ///}
149
150 /// @name Joystick types
151 ///{
152
153 /*!
154 * @brief Info specific to joystick peripherals
155 */
156 typedef struct JOYSTICK_INFO
157 {
158 PERIPHERAL_INFO peripheral; /*!< @brief peripheral info for this joystick */
159 char* provider; /*!< @brief name of the driver or interface providing the joystick */
160 int requested_port; /*!< @brief requested port number (such as for 360 controllers), or NO_PORT_REQUESTED */
161 unsigned int button_count; /*!< @brief number of buttons reported by the driver */
162 unsigned int hat_count; /*!< @brief number of hats reported by the driver */
163 unsigned int axis_count; /*!< @brief number of axes reported by the driver */
164 unsigned int motor_count; /*!< @brief number of motors reported by the driver */
165 bool supports_poweroff; /*!< @brief whether the joystick supports being powered off */
166 } ATTRIBUTE_PACKED JOYSTICK_INFO;
167
168 /*!
169 * @brief Driver input primitives
170 *
171 * Mapping lower-level driver values to higher-level controller features is
172 * non-injective; two triggers can share a single axis.
173 *
174 * To handle this, driver values are subdivided into "primitives" that map
175 * injectively to higher-level features.
176 */
177 typedef enum JOYSTICK_DRIVER_PRIMITIVE_TYPE
178 {
179 JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN,
180 JOYSTICK_DRIVER_PRIMITIVE_TYPE_BUTTON,
181 JOYSTICK_DRIVER_PRIMITIVE_TYPE_HAT_DIRECTION,
182 JOYSTICK_DRIVER_PRIMITIVE_TYPE_SEMIAXIS,
183 JOYSTICK_DRIVER_PRIMITIVE_TYPE_MOTOR,
184 JOYSTICK_DRIVER_PRIMITIVE_TYPE_KEY,
185 JOYSTICK_DRIVER_PRIMITIVE_TYPE_MOUSE_BUTTON,
186 JOYSTICK_DRIVER_PRIMITIVE_TYPE_RELPOINTER_DIRECTION,
187 } JOYSTICK_DRIVER_PRIMITIVE_TYPE;
188
189 /*!
190 * @brief Button primitive
191 */
192 typedef struct JOYSTICK_DRIVER_BUTTON
193 {
194 int index;
195 } ATTRIBUTE_PACKED JOYSTICK_DRIVER_BUTTON;
196
197 /*!
198 * @brief Hat direction
199 */
200 typedef enum JOYSTICK_DRIVER_HAT_DIRECTION
201 {
202 JOYSTICK_DRIVER_HAT_UNKNOWN,
203 JOYSTICK_DRIVER_HAT_LEFT,
204 JOYSTICK_DRIVER_HAT_RIGHT,
205 JOYSTICK_DRIVER_HAT_UP,
206 JOYSTICK_DRIVER_HAT_DOWN,
207 } JOYSTICK_DRIVER_HAT_DIRECTION;
208
209 /*!
210 * @brief Hat direction primitive
211 */
212 typedef struct JOYSTICK_DRIVER_HAT
213 {
214 int index;
215 JOYSTICK_DRIVER_HAT_DIRECTION direction;
216 } ATTRIBUTE_PACKED JOYSTICK_DRIVER_HAT;
217
218 /*!
219 * @brief Semiaxis direction
220 */
221 typedef enum JOYSTICK_DRIVER_SEMIAXIS_DIRECTION
222 {
223 JOYSTICK_DRIVER_SEMIAXIS_NEGATIVE = -1, /*!< @brief negative half of the axis */
224 JOYSTICK_DRIVER_SEMIAXIS_UNKNOWN = 0, /*!< @brief unknown direction */
225 JOYSTICK_DRIVER_SEMIAXIS_POSITIVE = 1, /*!< @brief positive half of the axis */
226 } JOYSTICK_DRIVER_SEMIAXIS_DIRECTION;
227
228 /*!
229 * @brief Semiaxis primitive
230 */
231 typedef struct JOYSTICK_DRIVER_SEMIAXIS
232 {
233 int index;
234 int center;
235 JOYSTICK_DRIVER_SEMIAXIS_DIRECTION direction;
236 unsigned int range;
237 } ATTRIBUTE_PACKED JOYSTICK_DRIVER_SEMIAXIS;
238
239 /*!
240 * @brief Motor primitive
241 */
242 typedef struct JOYSTICK_DRIVER_MOTOR
243 {
244 int index;
245 } ATTRIBUTE_PACKED JOYSTICK_DRIVER_MOTOR;
246
247 /*!
248 * @brief Keyboard key primitive
249 */
250 typedef struct JOYSTICK_DRIVER_KEY
251 {
252 char keycode[16];
253 } ATTRIBUTE_PACKED JOYSTICK_DRIVER_KEY;
254
255 /*!
256 * @brief Mouse buttons
257 */
258 typedef enum JOYSTICK_DRIVER_MOUSE_INDEX
259 {
260 JOYSTICK_DRIVER_MOUSE_INDEX_UNKNOWN,
261 JOYSTICK_DRIVER_MOUSE_INDEX_LEFT,
262 JOYSTICK_DRIVER_MOUSE_INDEX_RIGHT,
263 JOYSTICK_DRIVER_MOUSE_INDEX_MIDDLE,
264 JOYSTICK_DRIVER_MOUSE_INDEX_BUTTON4,
265 JOYSTICK_DRIVER_MOUSE_INDEX_BUTTON5,
266 JOYSTICK_DRIVER_MOUSE_INDEX_WHEEL_UP,
267 JOYSTICK_DRIVER_MOUSE_INDEX_WHEEL_DOWN,
268 JOYSTICK_DRIVER_MOUSE_INDEX_HORIZ_WHEEL_LEFT,
269 JOYSTICK_DRIVER_MOUSE_INDEX_HORIZ_WHEEL_RIGHT,
270 } JOYSTICK_DRIVER_MOUSE_INDEX;
271
272 /*!
273 * @brief Mouse button primitive
274 */
275 typedef struct JOYSTICK_DRIVER_MOUSE_BUTTON
276 {
277 JOYSTICK_DRIVER_MOUSE_INDEX button;
278 } ATTRIBUTE_PACKED JOYSTICK_DRIVER_MOUSE_BUTTON;
279
280 /*!
281 * @brief Relative pointer direction
282 */
283 typedef enum JOYSTICK_DRIVER_RELPOINTER_DIRECTION
284 {
285 JOYSTICK_DRIVER_RELPOINTER_UNKNOWN,
286 JOYSTICK_DRIVER_RELPOINTER_LEFT,
287 JOYSTICK_DRIVER_RELPOINTER_RIGHT,
288 JOYSTICK_DRIVER_RELPOINTER_UP,
289 JOYSTICK_DRIVER_RELPOINTER_DOWN,
290 } JOYSTICK_DRIVER_RELPOINTER_DIRECTION;
291
292 /*!
293 * @brief Relative pointer direction primitive
294 */
295 typedef struct JOYSTICK_DRIVER_RELPOINTER
296 {
297 JOYSTICK_DRIVER_RELPOINTER_DIRECTION direction;
298 } ATTRIBUTE_PACKED JOYSTICK_DRIVER_RELPOINTER;
299
300 /*!
301 * @brief Driver primitive struct
302 */
303 typedef struct JOYSTICK_DRIVER_PRIMITIVE
304 {
305 JOYSTICK_DRIVER_PRIMITIVE_TYPE type;
306 union
307 {
308 struct JOYSTICK_DRIVER_BUTTON button;
309 struct JOYSTICK_DRIVER_HAT hat;
310 struct JOYSTICK_DRIVER_SEMIAXIS semiaxis;
311 struct JOYSTICK_DRIVER_MOTOR motor;
312 struct JOYSTICK_DRIVER_KEY key;
313 struct JOYSTICK_DRIVER_MOUSE_BUTTON mouse;
314 struct JOYSTICK_DRIVER_RELPOINTER relpointer;
315 };
316 } ATTRIBUTE_PACKED JOYSTICK_DRIVER_PRIMITIVE;
317
318 /*!
319 * @brief Controller feature
320 *
321 * Controller features are an abstraction over driver values. Each feature
322 * maps to one or more driver primitives.
323 */
324 typedef enum JOYSTICK_FEATURE_TYPE
325 {
326 JOYSTICK_FEATURE_TYPE_UNKNOWN,
327 JOYSTICK_FEATURE_TYPE_SCALAR,
328 JOYSTICK_FEATURE_TYPE_ANALOG_STICK,
329 JOYSTICK_FEATURE_TYPE_ACCELEROMETER,
330 JOYSTICK_FEATURE_TYPE_MOTOR,
331 JOYSTICK_FEATURE_TYPE_RELPOINTER,
332 JOYSTICK_FEATURE_TYPE_ABSPOINTER,
333 JOYSTICK_FEATURE_TYPE_WHEEL,
334 JOYSTICK_FEATURE_TYPE_THROTTLE,
335 JOYSTICK_FEATURE_TYPE_KEY,
336 } JOYSTICK_FEATURE_TYPE;
337
338 /*!
339 * @brief Indices used to access a feature's driver primitives
340 */
341 typedef enum JOYSTICK_FEATURE_PRIMITIVE
342 {
343 // Scalar feature (a button, hat direction or semiaxis)
344 JOYSTICK_SCALAR_PRIMITIVE = 0,
345
346 // Analog stick
347 JOYSTICK_ANALOG_STICK_UP = 0,
348 JOYSTICK_ANALOG_STICK_DOWN = 1,
349 JOYSTICK_ANALOG_STICK_RIGHT = 2,
350 JOYSTICK_ANALOG_STICK_LEFT = 3,
351
352 // Accelerometer
353 JOYSTICK_ACCELEROMETER_POSITIVE_X = 0,
354 JOYSTICK_ACCELEROMETER_POSITIVE_Y = 1,
355 JOYSTICK_ACCELEROMETER_POSITIVE_Z = 2,
356
357 // Motor
358 JOYSTICK_MOTOR_PRIMITIVE = 0,
359
360 // Wheel
361 JOYSTICK_WHEEL_LEFT = 0,
362 JOYSTICK_WHEEL_RIGHT = 1,
363
364 // Throttle
365 JOYSTICK_THROTTLE_UP = 0,
366 JOYSTICK_THROTTLE_DOWN = 1,
367
368 // Key
369 JOYSTICK_KEY_PRIMITIVE = 0,
370
371 // Mouse button
372 JOYSTICK_MOUSE_BUTTON = 0,
373
374 // Relative pointer direction
375 JOYSTICK_RELPOINTER_UP = 0,
376 JOYSTICK_RELPOINTER_DOWN = 1,
377 JOYSTICK_RELPOINTER_RIGHT = 2,
378 JOYSTICK_RELPOINTER_LEFT = 3,
379
380 // Maximum number of primitives
381 JOYSTICK_PRIMITIVE_MAX = 4,
382 } JOYSTICK_FEATURE_PRIMITIVE;
383
384 /*!
385 * @brief Mapping between higher-level controller feature and its driver primitives
386 */
387 typedef struct JOYSTICK_FEATURE
388 {
389 char* name;
390 JOYSTICK_FEATURE_TYPE type;
391 struct JOYSTICK_DRIVER_PRIMITIVE primitives[JOYSTICK_PRIMITIVE_MAX];
392 } ATTRIBUTE_PACKED JOYSTICK_FEATURE;
393 ///}
394
395 typedef struct AddonProps_Peripheral
396 {
397 const char* user_path; /*!< @brief path to the user profile */
398 const char* addon_path; /*!< @brief path to this add-on */
399 } ATTRIBUTE_PACKED AddonProps_Peripheral;
400
401 struct AddonInstance_Peripheral;
402
403 typedef struct AddonToKodiFuncTable_Peripheral
404 {
405 KODI_HANDLE kodiInstance;
406 void (*trigger_scan)(void* kodiInstance);
407 void (*refresh_button_maps)(void* kodiInstance, const char* device_name, const char* controller_id);
408 unsigned int (*feature_count)(void* kodiInstance, const char* controller_id, JOYSTICK_FEATURE_TYPE type);
409 JOYSTICK_FEATURE_TYPE (*feature_type)(void* kodiInstance, const char* controller_id, const char* feature_name);
410 } AddonToKodiFuncTable_Peripheral;
411
412 //! @todo Mouse, light gun, multitouch
413
414 typedef struct KodiToAddonFuncTable_Peripheral
415 {
416 kodi::addon::CInstancePeripheral* addonInstance;
417
418 void (__cdecl* get_capabilities)(const AddonInstance_Peripheral* addonInstance, PERIPHERAL_CAPABILITIES* capabilities);
419 PERIPHERAL_ERROR (__cdecl* perform_device_scan)(const AddonInstance_Peripheral* addonInstance, unsigned int* peripheral_count, PERIPHERAL_INFO** scan_results);
420 void (__cdecl* free_scan_results)(const AddonInstance_Peripheral* addonInstance, unsigned int peripheral_count, PERIPHERAL_INFO* scan_results);
421 PERIPHERAL_ERROR (__cdecl* get_events)(const AddonInstance_Peripheral* addonInstance, unsigned int* event_count, PERIPHERAL_EVENT** events);
422 void (__cdecl* free_events)(const AddonInstance_Peripheral* addonInstance, unsigned int event_count, PERIPHERAL_EVENT* events);
423 bool (__cdecl* send_event)(const AddonInstance_Peripheral* addonInstance, const PERIPHERAL_EVENT* event);
424
425 /// @name Joystick operations
426 ///{
427 PERIPHERAL_ERROR (__cdecl* get_joystick_info)(const AddonInstance_Peripheral* addonInstance, unsigned int index, JOYSTICK_INFO* info);
428 void (__cdecl* free_joystick_info)(const AddonInstance_Peripheral* addonInstance, JOYSTICK_INFO* info);
429 PERIPHERAL_ERROR (__cdecl* get_features)(const AddonInstance_Peripheral* addonInstance, const JOYSTICK_INFO* joystick, const char* controller_id, unsigned int* feature_count, JOYSTICK_FEATURE** features);
430 void (__cdecl* free_features)(const AddonInstance_Peripheral* addonInstance, unsigned int feature_count, JOYSTICK_FEATURE* features);
431 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);
432 PERIPHERAL_ERROR (__cdecl* get_ignored_primitives)(const AddonInstance_Peripheral* addonInstance, const JOYSTICK_INFO* joystick, unsigned int* feature_count, JOYSTICK_DRIVER_PRIMITIVE** primitives);
433 void (__cdecl* free_primitives)(const AddonInstance_Peripheral* addonInstance, unsigned int, JOYSTICK_DRIVER_PRIMITIVE* primitives);
434 PERIPHERAL_ERROR (__cdecl* set_ignored_primitives)(const AddonInstance_Peripheral* addonInstance, const JOYSTICK_INFO* joystick, unsigned int primitive_count, const JOYSTICK_DRIVER_PRIMITIVE* primitives);
435 void (__cdecl* save_button_map)(const AddonInstance_Peripheral* addonInstance, const JOYSTICK_INFO* joystick);
436 void (__cdecl* revert_button_map)(const AddonInstance_Peripheral* addonInstance, const JOYSTICK_INFO* joystick);
437 void (__cdecl* reset_button_map)(const AddonInstance_Peripheral* addonInstance, const JOYSTICK_INFO* joystick, const char* controller_id);
438 void (__cdecl* power_off_joystick)(const AddonInstance_Peripheral* addonInstance, unsigned int index);
439 ///}
440 } KodiToAddonFuncTable_Peripheral;
441
442 typedef struct AddonInstance_Peripheral
443 {
444 AddonProps_Peripheral props;
445 AddonToKodiFuncTable_Peripheral toKodi;
446 KodiToAddonFuncTable_Peripheral toAddon;
447 } AddonInstance_Peripheral;
448
449} /* extern "C" */
450
451namespace kodi
452{
453namespace addon
454{
455
456 class ATTRIBUTE_HIDDEN CInstancePeripheral : public IAddonInstance
457 {
458 public:
459 CInstancePeripheral()
460 : IAddonInstance(ADDON_INSTANCE_PERIPHERAL, GetKodiTypeVersion(ADDON_INSTANCE_PERIPHERAL))
461 {
462 if (CAddonBase::m_interface->globalSingleInstance != nullptr)
463 throw std::logic_error("kodi::addon::CInstancePeripheral: Creation of more as one in single instance way is not allowed!");
464
465 SetAddonStruct(CAddonBase::m_interface->firstKodiInstance);
466 CAddonBase::m_interface->globalSingleInstance = this;
467 }
468
469 explicit CInstancePeripheral(KODI_HANDLE instance, const std::string& kodiVersion = "")
470 : IAddonInstance(ADDON_INSTANCE_PERIPHERAL,
471 !kodiVersion.empty() ? kodiVersion
472 : GetKodiTypeVersion(ADDON_INSTANCE_PERIPHERAL))
473 {
474 if (CAddonBase::m_interface->globalSingleInstance != nullptr)
475 throw std::logic_error("kodi::addon::CInstancePeripheral: Creation of multiple together with single instance way is not allowed!");
476
477 SetAddonStruct(instance);
478 }
479
480 ~CInstancePeripheral() override = default;
481
482 /// @name Peripheral operations
483 ///{
484 /*!
485 * @brief Get the list of features that this add-on provides
486 * @param capabilities The add-on's capabilities.
487 * @remarks Valid implementation required.
488 *
489 * Called by the frontend to query the add-on's capabilities and supported
490 * peripherals. All capabilities that the add-on supports should be set to true.
491 *
492 */
493 virtual void GetCapabilities(PERIPHERAL_CAPABILITIES &capabilities) { }
494
495 /*!
496 * @brief Perform a scan for joysticks
497 * @param peripheral_count Assigned to the number of peripherals allocated
498 * @param scan_results Assigned to allocated memory
499 * @return PERIPHERAL_NO_ERROR if successful; peripherals must be freed using
500 * FreeScanResults() in this case
501 *
502 * The frontend calls this when a hardware change is detected. If an add-on
503 * detects a hardware change, it can trigger this function using the
504 * TriggerScan() callback.
505 */
506 virtual PERIPHERAL_ERROR PerformDeviceScan(unsigned int* peripheral_count, PERIPHERAL_INFO** scan_results) { return PERIPHERAL_ERROR_NOT_IMPLEMENTED; }
507
508 /*!
509 * @brief Free the memory allocated in PerformDeviceScan()
510 *
511 * Must be called if PerformDeviceScan() returns PERIPHERAL_NO_ERROR.
512 *
513 * @param peripheral_count The number of events allocated for the events array
514 * @param scan_results The array of allocated peripherals
515 */
516 virtual void FreeScanResults(unsigned int peripheral_count, PERIPHERAL_INFO* scan_results) { }
517
518 /*!
519 * @brief Get all events that have occurred since the last call to GetEvents()
520 * @return PERIPHERAL_NO_ERROR if successful; events must be freed using
521 * FreeEvents() in this case
522 */
523 virtual PERIPHERAL_ERROR GetEvents(unsigned int* event_count, PERIPHERAL_EVENT** events) { return PERIPHERAL_ERROR_NOT_IMPLEMENTED; }
524
525 /*!
526 * @brief Free the memory allocated in GetEvents()
527 *
528 * Must be called if GetEvents() returns PERIPHERAL_NO_ERROR.
529 *
530 * @param event_count The number of events allocated for the events array
531 * @param events The array of allocated events
532 */
533 virtual void FreeEvents(unsigned int event_count, PERIPHERAL_EVENT* events) { }
534
535 /*!
536 * @brief Send an input event to the peripheral
537 * @param event The input event
538 * @return true if the event was handled, false otherwise
539 */
540 virtual bool SendEvent(const PERIPHERAL_EVENT* event) { return false; }
541 ///}
542
543 /// @name Joystick operations
544 /*!
545 * @note #define PERIPHERAL_ADDON_JOYSTICKS before including kodi_peripheral_dll.h
546 * in the add-on if the add-on provides joysticks and add provides_joysticks="true"
547 * to the kodi.peripheral extension point node in addon.xml.
548 */
549 ///{
550 /*!
551 * @brief Get extended info about an attached joystick
552 * @param index The joystick's driver index
553 * @param info The container for the allocated joystick info
554 * @return PERIPHERAL_NO_ERROR if successful; array must be freed using
555 * FreeJoystickInfo() in this case
556 */
557 virtual PERIPHERAL_ERROR GetJoystickInfo(unsigned int index, JOYSTICK_INFO* info) { return PERIPHERAL_ERROR_NOT_IMPLEMENTED; }
558
559 /*!
560 * @brief Free the memory allocated in GetJoystickInfo()
561 */
562 virtual void FreeJoystickInfo(JOYSTICK_INFO* info) { }
563
564 /*!
565 * @brief Get the features that allow translating the joystick into the controller profile
566 * @param joystick The device's joystick properties; unknown values may be left at their default
567 * @param controller_id The controller profile being requested, e.g. game.controller.default
568 * @param feature_count The number of features allocated for the features array
569 * @param features The array of allocated features
570 * @return PERIPHERAL_NO_ERROR if successful; array must be freed using
571 * FreeButtonMap() in this case
572 */
573 virtual PERIPHERAL_ERROR GetFeatures(const JOYSTICK_INFO* joystick, const char* controller_id,
574 unsigned int* feature_count, JOYSTICK_FEATURE** features) { return PERIPHERAL_ERROR_NOT_IMPLEMENTED; }
575
576 /*!
577 * @brief Free the memory allocated in GetFeatures()
578 *
579 * Must be called if GetFeatures() returns PERIPHERAL_NO_ERROR.
580 *
581 * @param feature_count The number of features allocated for the features array
582 * @param features The array of allocated features
583 */
584 virtual void FreeFeatures(unsigned int feature_count, JOYSTICK_FEATURE* features) { }
585
586 /*!
587 * @brief Add or update joystick features
588 * @param joystick The device's joystick properties; unknown values may be left at their default
589 * @param controller_id The game controller profile being updated
590 * @param feature_count The number of features in the features array
591 * @param features The array of features
592 * @return PERIPHERAL_NO_ERROR if successful
593 */
594 virtual PERIPHERAL_ERROR MapFeatures(const JOYSTICK_INFO* joystick, const char* controller_id,
595 unsigned int feature_count, const JOYSTICK_FEATURE* features) { return PERIPHERAL_ERROR_NOT_IMPLEMENTED; }
596
597 /*!
598 * @brief Get the driver primitives that should be ignored while mapping the device
599 * @param joystick The device's joystick properties; unknown values may be left at their default
600 * @param primitive_count The number of features allocated for the primitives array
601 * @param primitives The array of allocated driver primitives to be ignored
602 * @return PERIPHERAL_NO_ERROR if successful; array must be freed using
603 * FreePrimitives() in this case
604 */
605 virtual PERIPHERAL_ERROR GetIgnoredPrimitives(const JOYSTICK_INFO* joystick,
606 unsigned int* primitive_count,
607 JOYSTICK_DRIVER_PRIMITIVE** primitives) { return PERIPHERAL_ERROR_NOT_IMPLEMENTED; }
608
609 /*!
610 * @brief Free the memory allocated in GetIgnoredPrimitives()
611 *
612 * Must be called if GetIgnoredPrimitives() returns PERIPHERAL_NO_ERROR.
613 *
614 * @param primitive_count The number of driver primitives allocated for the primitives array
615 * @param primitives The array of allocated driver primitives
616 */
617 virtual void FreePrimitives(unsigned int primitive_count, JOYSTICK_DRIVER_PRIMITIVE* primitives) { }
618
619 /*!
620 * @brief Set the list of driver primitives that are ignored for the device
621 * @param joystick The device's joystick properties; unknown values may be left at their default
622 * @param primitive_count The number of driver features in the primitives array
623 * @param primitives The array of driver primitives to ignore
624 * @return PERIPHERAL_NO_ERROR if successful
625 */
626 virtual PERIPHERAL_ERROR SetIgnoredPrimitives(const JOYSTICK_INFO* joystick,
627 unsigned int primitive_count,
628 const JOYSTICK_DRIVER_PRIMITIVE* primitives) { return PERIPHERAL_ERROR_NOT_IMPLEMENTED; }
629
630 /*!
631 * @brief Save the button map for the given joystick
632 * @param joystick The device's joystick properties
633 */
634 virtual void SaveButtonMap(const JOYSTICK_INFO* joystick) { }
635
636 /*!
637 * @brief Revert the button map to the last time it was loaded or committed to disk
638 * @param joystick The device's joystick properties
639 */
640 virtual void RevertButtonMap(const JOYSTICK_INFO* joystick) { }
641
642 /*!
643 * @brief Reset the button map for the given joystick and controller profile ID
644 * @param joystick The device's joystick properties
645 * @param controller_id The game controller profile being reset
646 */
647 virtual void ResetButtonMap(const JOYSTICK_INFO* joystick, const char* controller_id) { }
648
649 /*!
650 * @brief Powers off the given joystick if supported
651 * @param index The joystick's driver index
652 */
653 virtual void PowerOffJoystick(unsigned int index) { }
654
655 const std::string AddonPath() const
656 {
657 return m_instanceData->props.addon_path;
658 }
659
660 const std::string UserPath() const
661 {
662 return m_instanceData->props.user_path;
663 }
664
665 /*!
666 * @brief Trigger a scan for peripherals
667 *
668 * The add-on calls this if a change in hardware is detected.
669 */
670 void TriggerScan(void)
671 {
672 return m_instanceData->toKodi.trigger_scan(m_instanceData->toKodi.kodiInstance);
673 }
674
675 /*!
676 * @brief Notify the frontend that button maps have changed
677 *
678 * @param[optional] deviceName The name of the device to refresh, or empty/null for all devices
679 * @param[optional] controllerId The controller ID to refresh, or empty/null for all controllers
680 */
681 void RefreshButtonMaps(const std::string& deviceName = "", const std::string& controllerId = "")
682 {
683 return m_instanceData->toKodi.refresh_button_maps(m_instanceData->toKodi.kodiInstance, deviceName.c_str(), controllerId.c_str());
684 }
685
686 /*!
687 * @brief Return the number of features belonging to the specified controller
688 *
689 * @param controllerId The controller ID to enumerate
690 * @param type[optional] Type to filter by, or JOYSTICK_FEATURE_TYPE_UNKNOWN for all features
691 *
692 * @return The number of features matching the request parameters
693 */
694 unsigned int FeatureCount(const std::string& controllerId, JOYSTICK_FEATURE_TYPE type = JOYSTICK_FEATURE_TYPE_UNKNOWN)
695 {
696 return m_instanceData->toKodi.feature_count(m_instanceData->toKodi.kodiInstance, controllerId.c_str(), type);
697 }
698
699 /*!
700 * @brief Return the type of the feature
701 *
702 * @param controllerId The controller ID to check
703 * @param featureName The feature to check
704 *
705 * @return The type of the specified feature, or JOYSTICK_FEATURE_TYPE_UNKNOWN
706 * if unknown
707 */
708 JOYSTICK_FEATURE_TYPE FeatureType(const std::string& controllerId, const std::string &featureName)
709 {
710 return m_instanceData->toKodi.feature_type(m_instanceData->toKodi.kodiInstance, controllerId.c_str(), featureName.c_str());
711 }
712
713 private:
714 void SetAddonStruct(KODI_HANDLE instance)
715 {
716 if (instance == nullptr)
717 throw std::logic_error("kodi::addon::CInstancePeripheral: Creation with empty addon structure not allowed, table must be given from Kodi!");
718
719 m_instanceData = static_cast<AddonInstance_Peripheral*>(instance);
720 m_instanceData->toAddon.addonInstance = this;
721
722 m_instanceData->toAddon.get_capabilities = ADDON_GetCapabilities;
723 m_instanceData->toAddon.perform_device_scan = ADDON_PerformDeviceScan;
724 m_instanceData->toAddon.free_scan_results = ADDON_FreeScanResults;
725 m_instanceData->toAddon.get_events = ADDON_GetEvents;
726 m_instanceData->toAddon.free_events = ADDON_FreeEvents;
727 m_instanceData->toAddon.send_event = ADDON_SendEvent;
728
729 m_instanceData->toAddon.get_joystick_info = ADDON_GetJoystickInfo;
730 m_instanceData->toAddon.free_joystick_info = ADDON_FreeJoystickInfo;
731 m_instanceData->toAddon.get_features = ADDON_GetFeatures;
732 m_instanceData->toAddon.free_features = ADDON_FreeFeatures;
733 m_instanceData->toAddon.map_features = ADDON_MapFeatures;
734 m_instanceData->toAddon.get_ignored_primitives = ADDON_GetIgnoredPrimitives;
735 m_instanceData->toAddon.free_primitives = ADDON_FreePrimitives;
736 m_instanceData->toAddon.set_ignored_primitives = ADDON_SetIgnoredPrimitives;
737 m_instanceData->toAddon.save_button_map = ADDON_SaveButtonMap;
738 m_instanceData->toAddon.revert_button_map = ADDON_RevertButtonMap;
739 m_instanceData->toAddon.reset_button_map = ADDON_ResetButtonMap;
740 m_instanceData->toAddon.power_off_joystick = ADDON_PowerOffJoystick;
741 }
742
743 inline static void ADDON_GetCapabilities(const AddonInstance_Peripheral* addonInstance, PERIPHERAL_CAPABILITIES *capabilities)
744 {
745 addonInstance->toAddon.addonInstance->GetCapabilities(*capabilities);
746 }
747
748 inline static PERIPHERAL_ERROR ADDON_PerformDeviceScan(const AddonInstance_Peripheral* addonInstance, unsigned int* peripheral_count, PERIPHERAL_INFO** scan_results)
749 {
750 return addonInstance->toAddon.addonInstance->PerformDeviceScan(peripheral_count, scan_results);
751 }
752
753 inline static void ADDON_FreeScanResults(const AddonInstance_Peripheral* addonInstance, unsigned int peripheral_count, PERIPHERAL_INFO* scan_results)
754 {
755 addonInstance->toAddon.addonInstance->FreeScanResults(peripheral_count, scan_results);
756 }
757
758 inline static PERIPHERAL_ERROR ADDON_GetEvents(const AddonInstance_Peripheral* addonInstance, unsigned int* event_count, PERIPHERAL_EVENT** events)
759 {
760 return addonInstance->toAddon.addonInstance->GetEvents(event_count, events);
761 }
762
763 inline static void ADDON_FreeEvents(const AddonInstance_Peripheral* addonInstance, unsigned int event_count, PERIPHERAL_EVENT* events)
764 {
765 addonInstance->toAddon.addonInstance->FreeEvents(event_count, events);
766 }
767
768 inline static bool ADDON_SendEvent(const AddonInstance_Peripheral* addonInstance, const PERIPHERAL_EVENT* event)
769 {
770 return addonInstance->toAddon.addonInstance->SendEvent(event);
771 }
772
773
774 inline static PERIPHERAL_ERROR ADDON_GetJoystickInfo(const AddonInstance_Peripheral* addonInstance, unsigned int index, JOYSTICK_INFO* info)
775 {
776 return addonInstance->toAddon.addonInstance->GetJoystickInfo(index, info);
777 }
778
779 inline static void ADDON_FreeJoystickInfo(const AddonInstance_Peripheral* addonInstance, JOYSTICK_INFO* info)
780 {
781 addonInstance->toAddon.addonInstance->FreeJoystickInfo(info);
782 }
783
784 inline static PERIPHERAL_ERROR ADDON_GetFeatures(const AddonInstance_Peripheral* addonInstance,
785 const JOYSTICK_INFO* joystick, const char* controller_id,
786 unsigned int* feature_count, JOYSTICK_FEATURE** features)
787 {
788 return addonInstance->toAddon.addonInstance->GetFeatures(joystick, controller_id, feature_count, features);
789 }
790
791 inline static void ADDON_FreeFeatures(const AddonInstance_Peripheral* addonInstance, unsigned int feature_count, JOYSTICK_FEATURE* features)
792 {
793 addonInstance->toAddon.addonInstance->FreeFeatures(feature_count, features);
794 }
795
796 inline static PERIPHERAL_ERROR ADDON_MapFeatures(const AddonInstance_Peripheral* addonInstance,
797 const JOYSTICK_INFO* joystick, const char* controller_id,
798 unsigned int feature_count, const JOYSTICK_FEATURE* features)
799 {
800 return addonInstance->toAddon.addonInstance->MapFeatures(joystick, controller_id, feature_count, features);
801 }
802
803 inline static PERIPHERAL_ERROR ADDON_GetIgnoredPrimitives(const AddonInstance_Peripheral* addonInstance,
804 const JOYSTICK_INFO* joystick, unsigned int* primitive_count,
805 JOYSTICK_DRIVER_PRIMITIVE** primitives)
806 {
807 return addonInstance->toAddon.addonInstance->GetIgnoredPrimitives(joystick, primitive_count, primitives);
808 }
809
810 inline static void ADDON_FreePrimitives(const AddonInstance_Peripheral* addonInstance,
811 unsigned int primitive_count, JOYSTICK_DRIVER_PRIMITIVE* primitives)
812 {
813 addonInstance->toAddon.addonInstance->FreePrimitives(primitive_count, primitives);
814 }
815
816 inline static PERIPHERAL_ERROR ADDON_SetIgnoredPrimitives(const AddonInstance_Peripheral* addonInstance,
817 const JOYSTICK_INFO* joystick, unsigned int primitive_count,
818 const JOYSTICK_DRIVER_PRIMITIVE* primitives)
819 {
820 return addonInstance->toAddon.addonInstance->SetIgnoredPrimitives(joystick, primitive_count, primitives);
821 }
822
823 inline static void ADDON_SaveButtonMap(const AddonInstance_Peripheral* addonInstance, const JOYSTICK_INFO* joystick)
824 {
825 addonInstance->toAddon.addonInstance->SaveButtonMap(joystick);
826 }
827
828 inline static void ADDON_RevertButtonMap(const AddonInstance_Peripheral* addonInstance, const JOYSTICK_INFO* joystick)
829 {
830 addonInstance->toAddon.addonInstance->RevertButtonMap(joystick);
831 }
832
833 inline static void ADDON_ResetButtonMap(const AddonInstance_Peripheral* addonInstance, const JOYSTICK_INFO* joystick, const char* controller_id)
834 {
835 addonInstance->toAddon.addonInstance->ResetButtonMap(joystick, controller_id);
836 }
837
838 inline static void ADDON_PowerOffJoystick(const AddonInstance_Peripheral* addonInstance, unsigned int index)
839 {
840 addonInstance->toAddon.addonInstance->PowerOffJoystick(index);
841 }
842
843 AddonInstance_Peripheral* m_instanceData;
844 };
845
846} /* namespace addon */
847} /* namespace kodi */