summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_peripheral.h
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_peripheral.h')
-rw-r--r--xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_peripheral.h114
1 files changed, 35 insertions, 79 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_peripheral.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_peripheral.h
index a28e48d..d1d8e4b 100644
--- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_peripheral.h
+++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_peripheral.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2014-2016 Team Kodi 2 * Copyright (C) 2014-2017 Team Kodi
3 * http://kodi.tv 3 * http://kodi.tv
4 * 4 *
5 * This Program is free software; you can redistribute it and/or modify 5 * This Program is free software; you can redistribute it and/or modify
@@ -20,7 +20,7 @@
20#pragma once 20#pragma once
21 21
22#include "libXBMC_addon.h" 22#include "libXBMC_addon.h"
23#include "kodi_peripheral_callbacks.h" 23#include "kodi_peripheral_types.h"
24 24
25#include <string> 25#include <string>
26#include <stdio.h> 26#include <stdio.h>
@@ -29,16 +29,6 @@
29 #include <sys/stat.h> 29 #include <sys/stat.h>
30#endif 30#endif
31 31
32#ifdef _WIN32
33 #define PERIPHERAL_HELPER_DLL "\\library.kodi.peripheral\\libKODI_peripheral" ADDON_HELPER_EXT
34#else
35 #define PERIPHERAL_HELPER_DLL_NAME "libKODI_peripheral-" ADDON_HELPER_ARCH ADDON_HELPER_EXT
36 #define PERIPHERAL_HELPER_DLL "/library.kodi.peripheral/" PERIPHERAL_HELPER_DLL_NAME
37#endif
38
39#define PERIPHERAL_REGISTER_SYMBOL(dll, functionPtr) \
40 CHelper_libKODI_peripheral::RegisterSymbol(dll, functionPtr, #functionPtr)
41
42namespace ADDON 32namespace ADDON
43{ 33{
44 34
@@ -47,29 +37,12 @@ class CHelper_libKODI_peripheral
47public: 37public:
48 CHelper_libKODI_peripheral(void) 38 CHelper_libKODI_peripheral(void)
49 { 39 {
50 m_handle = NULL; 40 m_Handle = nullptr;
51 m_callbacks = NULL; 41 m_Callbacks = nullptr;
52 m_libKODI_peripheral = NULL;
53 } 42 }
54 43
55 ~CHelper_libKODI_peripheral(void) 44 ~CHelper_libKODI_peripheral(void)
56 { 45 {
57 if (m_libKODI_peripheral)
58 {
59 PERIPHERAL_unregister_me(m_handle, m_callbacks);
60 dlclose(m_libKODI_peripheral);
61 }
62 }
63
64 template <typename T>
65 static bool RegisterSymbol(void* dll, T& functionPtr, const char* strFunctionPtr)
66 {
67 if ((functionPtr = (T)dlsym(dll, strFunctionPtr)) == NULL)
68 {
69 fprintf(stderr, "ERROR: Unable to assign function %s: %s\n", strFunctionPtr, dlerror());
70 return false;
71 }
72 return true;
73 } 46 }
74 47
75 /*! 48 /*!
@@ -79,69 +52,52 @@ public:
79 */ 52 */
80 bool RegisterMe(void* handle) 53 bool RegisterMe(void* handle)
81 { 54 {
82 m_handle = handle; 55 m_Handle = static_cast<AddonCB*>(handle);
83 56 if (m_Handle)
84 std::string libBasePath; 57 m_Callbacks = (AddonInstance_Peripheral*)m_Handle->PeripheralLib_RegisterMe(m_Handle->addonData);
85 libBasePath = ((cb_array*)m_handle)->libPath; 58 if (!m_Callbacks)
86 libBasePath += PERIPHERAL_HELPER_DLL; 59 fprintf(stderr, "libKODI_peripheral-ERROR: PeripheralLib_register_me can't get callback table from Kodi !!!\n");
87
88#if defined(ANDROID)
89 struct stat st;
90 if (stat(libBasePath.c_str(),&st) != 0)
91 {
92 std::string tempbin = getenv("XBMC_ANDROID_LIBS");
93 libBasePath = tempbin + "/" + PERIPHERAL_HELPER_DLL_NAME;
94 }
95#endif
96
97 m_libKODI_peripheral = dlopen(libBasePath.c_str(), RTLD_LAZY);
98 if (m_libKODI_peripheral == NULL)
99 {
100 fprintf(stderr, "Unable to load %s\n", dlerror());
101 return false;
102 }
103
104 if (!PERIPHERAL_REGISTER_SYMBOL(m_libKODI_peripheral, PERIPHERAL_register_me)) return false;
105 if (!PERIPHERAL_REGISTER_SYMBOL(m_libKODI_peripheral, PERIPHERAL_unregister_me)) return false;
106 if (!PERIPHERAL_REGISTER_SYMBOL(m_libKODI_peripheral, PERIPHERAL_trigger_scan)) return false;
107 if (!PERIPHERAL_REGISTER_SYMBOL(m_libKODI_peripheral, PERIPHERAL_refresh_button_maps)) return false;
108 if (!PERIPHERAL_REGISTER_SYMBOL(m_libKODI_peripheral, PERIPHERAL_feature_count)) return false;
109 60
110 m_callbacks = PERIPHERAL_register_me(m_handle); 61 return m_Callbacks != nullptr;
111 return m_callbacks != NULL;
112 } 62 }
113 63
64 /*!
65 * @brief Trigger a scan for peripherals
66 *
67 * The add-on calls this if a change in hardware is detected.
68 */
114 void TriggerScan(void) 69 void TriggerScan(void)
115 { 70 {
116 return PERIPHERAL_trigger_scan(m_handle, m_callbacks); 71 return m_Callbacks->toKodi.TriggerScan(m_Callbacks->toKodi.kodiInstance);
117 } 72 }
118 73
74 /*!
75 * @brief Notify the frontend that button maps have changed
76 *
77 * @param[optional] deviceName The name of the device to refresh, or empty/null for all devices
78 * @param[optional] controllerId The controller ID to refresh, or empty/null for all controllers
79 */
119 void RefreshButtonMaps(const std::string& strDeviceName = "", const std::string& strControllerId = "") 80 void RefreshButtonMaps(const std::string& strDeviceName = "", const std::string& strControllerId = "")
120 { 81 {
121 return PERIPHERAL_refresh_button_maps(m_handle, m_callbacks, strDeviceName.c_str(), strControllerId.c_str()); 82 return m_Callbacks->toKodi.RefreshButtonMaps(m_Callbacks->toKodi.kodiInstance, strDeviceName.c_str(), strControllerId.c_str());
122 } 83 }
123 84
85 /*!
86 * @brief Return the number of features belonging to the specified controller
87 *
88 * @param controllerId The controller ID to enumerate
89 * @param type[optional] Type to filter by, or JOYSTICK_FEATURE_TYPE_UNKNOWN for all features
90 *
91 * @return The number of features matching the request parameters
92 */
124 unsigned int FeatureCount(const std::string& strControllerId, JOYSTICK_FEATURE_TYPE type = JOYSTICK_FEATURE_TYPE_UNKNOWN) 93 unsigned int FeatureCount(const std::string& strControllerId, JOYSTICK_FEATURE_TYPE type = JOYSTICK_FEATURE_TYPE_UNKNOWN)
125 { 94 {
126 return PERIPHERAL_feature_count(m_handle, m_callbacks, strControllerId.c_str(), type); 95 return m_Callbacks->toKodi.FeatureCount(m_Callbacks->toKodi.kodiInstance, strControllerId.c_str(), type);
127 } 96 }
128 97
129protected:
130 CB_PeripheralLib* (*PERIPHERAL_register_me)(void* handle);
131 void (*PERIPHERAL_unregister_me)(void* handle, CB_PeripheralLib* cb);
132 void (*PERIPHERAL_trigger_scan)(void* handle, CB_PeripheralLib* cb);
133 void (*PERIPHERAL_refresh_button_maps)(void* handle, CB_PeripheralLib* cb, const char* deviceName, const char* controllerId);
134 unsigned int (*PERIPHERAL_feature_count)(void* handle, CB_PeripheralLib* cb, const char* controllerId, JOYSTICK_FEATURE_TYPE type);
135
136private: 98private:
137 void* m_handle; 99 AddonCB* m_Handle;
138 CB_PeripheralLib* m_callbacks; 100 AddonInstance_Peripheral* m_Callbacks;
139 void* m_libKODI_peripheral;
140
141 struct cb_array
142 {
143 const char* libPath;
144 };
145}; 101};
146 102
147} 103} /* namespace ADDON */