summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_peripheral.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2016-03-14 14:56:55 +0100
committermanuel <manuel@mausz.at>2016-03-14 14:56:55 +0100
commit4b3b7807b7df1964778855b5c0daab4cc417bd91 (patch)
tree2d801f7ee868f6b6be5221bc2674eaf95f0e7074 /xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_peripheral.h
parent1e0e2df2619a2c7fdc20806884eb81f36d458c61 (diff)
downloadkodi-pvr-build-4b3b7807b7df1964778855b5c0daab4cc417bd91.tar.gz
kodi-pvr-build-4b3b7807b7df1964778855b5c0daab4cc417bd91.tar.bz2
kodi-pvr-build-4b3b7807b7df1964778855b5c0daab4cc417bd91.zip
sync with upstream
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.h140
1 files changed, 140 insertions, 0 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
new file mode 100644
index 0000000..9f3f986
--- /dev/null
+++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libKODI_peripheral.h
@@ -0,0 +1,140 @@
1/*
2 * Copyright (C) 2014-2016 Team Kodi
3 * http://kodi.tv
4 *
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this Program; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 */
20#pragma once
21
22#include "libXBMC_addon.h"
23#include "kodi_peripheral_callbacks.h"
24
25#include <string>
26#include <stdio.h>
27
28#if defined(ANDROID)
29 #include <sys/stat.h>
30#endif
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
43{
44
45class CHelper_libKODI_peripheral
46{
47public:
48 CHelper_libKODI_peripheral(void)
49 {
50 m_handle = NULL;
51 m_callbacks = NULL;
52 m_libKODI_peripheral = NULL;
53 }
54
55 ~CHelper_libKODI_peripheral(void)
56 {
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 }
74
75 /*!
76 * @brief Resolve all callback methods
77 * @param handle Pointer to the add-on
78 * @return True when all methods were resolved, false otherwise.
79 */
80 bool RegisterMe(void* handle)
81 {
82 m_handle = handle;
83
84 std::string libBasePath;
85 libBasePath = ((cb_array*)m_handle)->libPath;
86 libBasePath += PERIPHERAL_HELPER_DLL;
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
109 m_callbacks = PERIPHERAL_register_me(m_handle);
110 return m_callbacks != NULL;
111 }
112
113 void TriggerScan(void)
114 {
115 return PERIPHERAL_trigger_scan(m_handle, m_callbacks);
116 }
117
118 void RefreshButtonMaps(const std::string& strDeviceName = "", const std::string& strControllerId = "")
119 {
120 return PERIPHERAL_refresh_button_maps(m_handle, m_callbacks, strDeviceName.c_str(), strControllerId.c_str());
121 }
122
123protected:
124 CB_PeripheralLib* (*PERIPHERAL_register_me)(void* handle);
125 void (*PERIPHERAL_unregister_me)(void* handle, CB_PeripheralLib* cb);
126 void (*PERIPHERAL_trigger_scan)(void* handle, CB_PeripheralLib* cb);
127 void (*PERIPHERAL_refresh_button_maps)(void* handle, CB_PeripheralLib* cb, const char* deviceName, const char* controllerId);
128
129private:
130 void* m_handle;
131 CB_PeripheralLib* m_callbacks;
132 void* m_libKODI_peripheral;
133
134 struct cb_array
135 {
136 const char* libPath;
137 };
138};
139
140}