diff options
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_addon.h')
| -rw-r--r-- | xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_addon.h | 710 |
1 files changed, 710 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_addon.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_addon.h new file mode 100644 index 0000000..e8d5ec7 --- /dev/null +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/libXBMC_addon.h | |||
| @@ -0,0 +1,710 @@ | |||
| 1 | #pragma once | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2005-2013 Team XBMC | ||
| 4 | * http://xbmc.org | ||
| 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 XBMC; see the file COPYING. If not, see | ||
| 18 | * <http://www.gnu.org/licenses/>. | ||
| 19 | * | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include <string> | ||
| 23 | #include <vector> | ||
| 24 | #include <string.h> | ||
| 25 | #include <stdlib.h> | ||
| 26 | #include <stdio.h> | ||
| 27 | #include <stdint.h> | ||
| 28 | #include <stdarg.h> | ||
| 29 | |||
| 30 | #if defined(BUILD_KODI_ADDON) | ||
| 31 | #include "IFileTypes.h" | ||
| 32 | #else | ||
| 33 | #include "filesystem/IFileTypes.h" | ||
| 34 | #endif | ||
| 35 | |||
| 36 | struct VFSDirEntry; | ||
| 37 | |||
| 38 | #ifdef _WIN32 // windows | ||
| 39 | #ifndef _SSIZE_T_DEFINED | ||
| 40 | typedef intptr_t ssize_t; | ||
| 41 | #define _SSIZE_T_DEFINED | ||
| 42 | #endif // !_SSIZE_T_DEFINED | ||
| 43 | |||
| 44 | #if defined(BUILD_KODI_ADDON) | ||
| 45 | #include "p8-platform/windows/dlfcn-win32.h" | ||
| 46 | #else | ||
| 47 | #include "dlfcn-win32.h" | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #define ADDON_DLL "\\library.xbmc.addon\\libXBMC_addon" ADDON_HELPER_EXT | ||
| 51 | #define ADDON_HELPER_EXT ".dll" | ||
| 52 | #else // windows | ||
| 53 | // the ADDON_HELPER_ARCH is the platform dependend name which is used | ||
| 54 | // as part of the name of dynamic addon libraries. It has to match the | ||
| 55 | // strings which are set in configure.ac for the "ARCH" variable. | ||
| 56 | #if defined(__APPLE__) // osx | ||
| 57 | #if defined(__arm__) || defined(__aarch64__) | ||
| 58 | #define ADDON_HELPER_ARCH "arm-osx" | ||
| 59 | #else | ||
| 60 | #define ADDON_HELPER_ARCH "x86-osx" | ||
| 61 | #endif | ||
| 62 | #define ADDON_HELPER_EXT ".dylib" | ||
| 63 | #else // linux | ||
| 64 | #if defined(__x86_64__) | ||
| 65 | #define ADDON_HELPER_ARCH "x86_64-linux" | ||
| 66 | #elif defined(_POWERPC) | ||
| 67 | #define ADDON_HELPER_ARCH "powerpc-linux" | ||
| 68 | #elif defined(_POWERPC64) | ||
| 69 | #define ADDON_HELPER_ARCH "powerpc64-linux" | ||
| 70 | #elif defined(__ARMEL__) | ||
| 71 | #define ADDON_HELPER_ARCH "arm" | ||
| 72 | #elif defined(__aarch64__) | ||
| 73 | #define ADDON_HELPER_ARCH "aarch64" | ||
| 74 | #elif defined(__mips__) | ||
| 75 | #define ADDON_HELPER_ARCH "mips" | ||
| 76 | #else | ||
| 77 | #define ADDON_HELPER_ARCH "i486-linux" | ||
| 78 | #endif | ||
| 79 | #define ADDON_HELPER_EXT ".so" | ||
| 80 | #endif | ||
| 81 | #include <dlfcn.h> // linux+osx | ||
| 82 | #define ADDON_DLL_NAME "libXBMC_addon-" ADDON_HELPER_ARCH ADDON_HELPER_EXT | ||
| 83 | #define ADDON_DLL "/library.xbmc.addon/" ADDON_DLL_NAME | ||
| 84 | #endif | ||
| 85 | #if defined(ANDROID) | ||
| 86 | #include <sys/stat.h> | ||
| 87 | #endif | ||
| 88 | |||
| 89 | #ifdef LOG_DEBUG | ||
| 90 | #undef LOG_DEBUG | ||
| 91 | #endif | ||
| 92 | #ifdef LOG_INFO | ||
| 93 | #undef LOG_INFO | ||
| 94 | #endif | ||
| 95 | #ifdef LOG_NOTICE | ||
| 96 | #undef LOG_NOTICE | ||
| 97 | #endif | ||
| 98 | #ifdef LOG_ERROR | ||
| 99 | #undef LOG_ERROR | ||
| 100 | #endif | ||
| 101 | |||
| 102 | namespace ADDON | ||
| 103 | { | ||
| 104 | typedef enum addon_log | ||
| 105 | { | ||
| 106 | LOG_DEBUG, | ||
| 107 | LOG_INFO, | ||
| 108 | LOG_NOTICE, | ||
| 109 | LOG_ERROR | ||
| 110 | } addon_log_t; | ||
| 111 | |||
| 112 | typedef enum queue_msg | ||
| 113 | { | ||
| 114 | QUEUE_INFO, | ||
| 115 | QUEUE_WARNING, | ||
| 116 | QUEUE_ERROR | ||
| 117 | } queue_msg_t; | ||
| 118 | |||
| 119 | class CHelper_libXBMC_addon | ||
| 120 | { | ||
| 121 | public: | ||
| 122 | CHelper_libXBMC_addon() | ||
| 123 | { | ||
| 124 | m_libXBMC_addon = NULL; | ||
| 125 | m_Handle = NULL; | ||
| 126 | } | ||
| 127 | |||
| 128 | ~CHelper_libXBMC_addon() | ||
| 129 | { | ||
| 130 | if (m_libXBMC_addon) | ||
| 131 | { | ||
| 132 | XBMC_unregister_me(m_Handle, m_Callbacks); | ||
| 133 | dlclose(m_libXBMC_addon); | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | bool RegisterMe(void *Handle) | ||
| 138 | { | ||
| 139 | m_Handle = Handle; | ||
| 140 | |||
| 141 | std::string libBasePath; | ||
| 142 | libBasePath = ((cb_array*)m_Handle)->libPath; | ||
| 143 | libBasePath += ADDON_DLL; | ||
| 144 | |||
| 145 | #if defined(ANDROID) | ||
| 146 | struct stat st; | ||
| 147 | if(stat(libBasePath.c_str(),&st) != 0) | ||
| 148 | { | ||
| 149 | std::string tempbin = getenv("XBMC_ANDROID_LIBS"); | ||
| 150 | libBasePath = tempbin + "/" + ADDON_DLL_NAME; | ||
| 151 | } | ||
| 152 | #endif | ||
| 153 | |||
| 154 | m_libXBMC_addon = dlopen(libBasePath.c_str(), RTLD_LAZY); | ||
| 155 | if (m_libXBMC_addon == NULL) | ||
| 156 | { | ||
| 157 | fprintf(stderr, "Unable to load %s\n", dlerror()); | ||
| 158 | return false; | ||
| 159 | } | ||
| 160 | |||
| 161 | XBMC_register_me = (void* (*)(void *HANDLE)) | ||
| 162 | dlsym(m_libXBMC_addon, "XBMC_register_me"); | ||
| 163 | if (XBMC_register_me == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 164 | |||
| 165 | XBMC_unregister_me = (void (*)(void* HANDLE, void* CB)) | ||
| 166 | dlsym(m_libXBMC_addon, "XBMC_unregister_me"); | ||
| 167 | if (XBMC_unregister_me == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 168 | |||
| 169 | XBMC_log = (void (*)(void* HANDLE, void* CB, const addon_log_t loglevel, const char *msg)) | ||
| 170 | dlsym(m_libXBMC_addon, "XBMC_log"); | ||
| 171 | if (XBMC_log == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 172 | |||
| 173 | XBMC_get_setting = (bool (*)(void* HANDLE, void* CB, const char* settingName, void *settingValue)) | ||
| 174 | dlsym(m_libXBMC_addon, "XBMC_get_setting"); | ||
| 175 | if (XBMC_get_setting == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 176 | |||
| 177 | XBMC_queue_notification = (void (*)(void* HANDLE, void* CB, const queue_msg_t loglevel, const char *msg)) | ||
| 178 | dlsym(m_libXBMC_addon, "XBMC_queue_notification"); | ||
| 179 | if (XBMC_queue_notification == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 180 | |||
| 181 | XBMC_wake_on_lan = (bool (*)(void* HANDLE, void *CB, const char *mac)) | ||
| 182 | dlsym(m_libXBMC_addon, "XBMC_wake_on_lan"); | ||
| 183 | if (XBMC_wake_on_lan == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 184 | |||
| 185 | XBMC_unknown_to_utf8 = (char* (*)(void* HANDLE, void* CB, const char* str)) | ||
| 186 | dlsym(m_libXBMC_addon, "XBMC_unknown_to_utf8"); | ||
| 187 | if (XBMC_unknown_to_utf8 == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 188 | |||
| 189 | XBMC_get_localized_string = (char* (*)(void* HANDLE, void* CB, int dwCode)) | ||
| 190 | dlsym(m_libXBMC_addon, "XBMC_get_localized_string"); | ||
| 191 | if (XBMC_get_localized_string == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 192 | |||
| 193 | XBMC_free_string = (void (*)(void* HANDLE, void* CB, char* str)) | ||
| 194 | dlsym(m_libXBMC_addon, "XBMC_free_string"); | ||
| 195 | if (XBMC_free_string == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 196 | |||
| 197 | XBMC_get_dvd_menu_language = (char* (*)(void* HANDLE, void* CB)) | ||
| 198 | dlsym(m_libXBMC_addon, "XBMC_get_dvd_menu_language"); | ||
| 199 | if (XBMC_get_dvd_menu_language == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 200 | |||
| 201 | XBMC_open_file = (void* (*)(void* HANDLE, void* CB, const char* strFileName, unsigned int flags)) | ||
| 202 | dlsym(m_libXBMC_addon, "XBMC_open_file"); | ||
| 203 | if (XBMC_open_file == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 204 | |||
| 205 | XBMC_open_file_for_write = (void* (*)(void* HANDLE, void* CB, const char* strFileName, bool bOverWrite)) | ||
| 206 | dlsym(m_libXBMC_addon, "XBMC_open_file_for_write"); | ||
| 207 | if (XBMC_open_file_for_write == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 208 | |||
| 209 | XBMC_read_file = (ssize_t (*)(void* HANDLE, void* CB, void* file, void* lpBuf, size_t uiBufSize)) | ||
| 210 | dlsym(m_libXBMC_addon, "XBMC_read_file"); | ||
| 211 | if (XBMC_read_file == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 212 | |||
| 213 | XBMC_read_file_string = (bool (*)(void* HANDLE, void* CB, void* file, char *szLine, int iLineLength)) | ||
| 214 | dlsym(m_libXBMC_addon, "XBMC_read_file_string"); | ||
| 215 | if (XBMC_read_file_string == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 216 | |||
| 217 | XBMC_write_file = (ssize_t (*)(void* HANDLE, void* CB, void* file, const void* lpBuf, size_t uiBufSize)) | ||
| 218 | dlsym(m_libXBMC_addon, "XBMC_write_file"); | ||
| 219 | if (XBMC_write_file == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 220 | |||
| 221 | XBMC_flush_file = (void (*)(void* HANDLE, void* CB, void* file)) | ||
| 222 | dlsym(m_libXBMC_addon, "XBMC_flush_file"); | ||
| 223 | if (XBMC_flush_file == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 224 | |||
| 225 | XBMC_seek_file = (int64_t (*)(void* HANDLE, void* CB, void* file, int64_t iFilePosition, int iWhence)) | ||
| 226 | dlsym(m_libXBMC_addon, "XBMC_seek_file"); | ||
| 227 | if (XBMC_seek_file == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 228 | |||
| 229 | XBMC_truncate_file = (int (*)(void* HANDLE, void* CB, void* file, int64_t iSize)) | ||
| 230 | dlsym(m_libXBMC_addon, "XBMC_truncate_file"); | ||
| 231 | if (XBMC_truncate_file == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 232 | |||
| 233 | XBMC_get_file_position = (int64_t (*)(void* HANDLE, void* CB, void* file)) | ||
| 234 | dlsym(m_libXBMC_addon, "XBMC_get_file_position"); | ||
| 235 | if (XBMC_get_file_position == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 236 | |||
| 237 | XBMC_get_file_length = (int64_t (*)(void* HANDLE, void* CB, void* file)) | ||
| 238 | dlsym(m_libXBMC_addon, "XBMC_get_file_length"); | ||
| 239 | if (XBMC_get_file_length == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 240 | |||
| 241 | XBMC_get_file_download_speed = (double(*)(void* HANDLE, void* CB, void* file)) | ||
| 242 | dlsym(m_libXBMC_addon, "XBMC_get_file_download_speed"); | ||
| 243 | if (XBMC_get_file_download_speed == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 244 | |||
| 245 | XBMC_close_file = (void (*)(void* HANDLE, void* CB, void* file)) | ||
| 246 | dlsym(m_libXBMC_addon, "XBMC_close_file"); | ||
| 247 | if (XBMC_close_file == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 248 | |||
| 249 | XBMC_get_file_chunk_size = (int (*)(void* HANDLE, void* CB, void* file)) | ||
| 250 | dlsym(m_libXBMC_addon, "XBMC_get_file_chunk_size"); | ||
| 251 | if (XBMC_get_file_chunk_size == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 252 | |||
| 253 | XBMC_file_exists = (bool (*)(void* HANDLE, void* CB, const char *strFileName, bool bUseCache)) | ||
| 254 | dlsym(m_libXBMC_addon, "XBMC_file_exists"); | ||
| 255 | if (XBMC_file_exists == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 256 | |||
| 257 | XBMC_stat_file = (int (*)(void* HANDLE, void* CB, const char *strFileName, struct __stat64* buffer)) | ||
| 258 | dlsym(m_libXBMC_addon, "XBMC_stat_file"); | ||
| 259 | if (XBMC_stat_file == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 260 | |||
| 261 | XBMC_delete_file = (bool (*)(void* HANDLE, void* CB, const char *strFileName)) | ||
| 262 | dlsym(m_libXBMC_addon, "XBMC_delete_file"); | ||
| 263 | if (XBMC_delete_file == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 264 | |||
| 265 | XBMC_can_open_directory = (bool (*)(void* HANDLE, void* CB, const char* strURL)) | ||
| 266 | dlsym(m_libXBMC_addon, "XBMC_can_open_directory"); | ||
| 267 | if (XBMC_can_open_directory == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 268 | |||
| 269 | XBMC_create_directory = (bool (*)(void* HANDLE, void* CB, const char* strPath)) | ||
| 270 | dlsym(m_libXBMC_addon, "XBMC_create_directory"); | ||
| 271 | if (XBMC_create_directory == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 272 | |||
| 273 | XBMC_directory_exists = (bool (*)(void* HANDLE, void* CB, const char* strPath)) | ||
| 274 | dlsym(m_libXBMC_addon, "XBMC_directory_exists"); | ||
| 275 | if (XBMC_directory_exists == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 276 | |||
| 277 | XBMC_remove_directory = (bool (*)(void* HANDLE, void* CB, const char* strPath)) | ||
| 278 | dlsym(m_libXBMC_addon, "XBMC_remove_directory"); | ||
| 279 | if (XBMC_remove_directory == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 280 | |||
| 281 | XBMC_get_directory = (bool (*)(void* HANDLE, void* CB, const char* strPath, const char* mask, VFSDirEntry** items, unsigned int* num_items)) | ||
| 282 | dlsym(m_libXBMC_addon, "XBMC_get_directory"); | ||
| 283 | if (XBMC_get_directory == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 284 | |||
| 285 | XBMC_free_directory = (void (*)(void* HANDLE, void* CB, VFSDirEntry* items, unsigned int num_items)) | ||
| 286 | dlsym(m_libXBMC_addon, "XBMC_free_directory"); | ||
| 287 | if (XBMC_free_directory == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 288 | |||
| 289 | XBMC_curl_create = (void* (*)(void *HANDLE, void* CB, const char* strURL)) | ||
| 290 | dlsym(m_libXBMC_addon, "XBMC_curl_create"); | ||
| 291 | if (XBMC_curl_create == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 292 | |||
| 293 | XBMC_curl_add_option = (bool (*)(void *HANDLE, void* CB, void *file, XFILE::CURLOPTIONTYPE type, const char* name, const char *value)) | ||
| 294 | dlsym(m_libXBMC_addon, "XBMC_curl_add_option"); | ||
| 295 | if (XBMC_curl_add_option == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 296 | |||
| 297 | XBMC_curl_open = (bool (*)(void *HANDLE, void* CB, void *file, unsigned int flags)) | ||
| 298 | dlsym(m_libXBMC_addon, "XBMC_curl_open"); | ||
| 299 | if (XBMC_curl_open == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } | ||
| 300 | |||
| 301 | m_Callbacks = XBMC_register_me(m_Handle); | ||
| 302 | return m_Callbacks != NULL; | ||
| 303 | } | ||
| 304 | |||
| 305 | /*! | ||
| 306 | * @brief Add a message to XBMC's log. | ||
| 307 | * @param loglevel The log level of the message. | ||
| 308 | * @param format The format of the message to pass to XBMC. | ||
| 309 | */ | ||
| 310 | void Log(const addon_log_t loglevel, const char *format, ... ) | ||
| 311 | { | ||
| 312 | char buffer[16384]; | ||
| 313 | va_list args; | ||
| 314 | va_start (args, format); | ||
| 315 | vsprintf (buffer, format, args); | ||
| 316 | va_end (args); | ||
| 317 | return XBMC_log(m_Handle, m_Callbacks, loglevel, buffer); | ||
| 318 | } | ||
| 319 | |||
| 320 | /*! | ||
| 321 | * @brief Get a settings value for this add-on. | ||
| 322 | * @param settingName The name of the setting to get. | ||
| 323 | * @param settingValue The value. | ||
| 324 | * @return True if the settings was fetched successfully, false otherwise. | ||
| 325 | */ | ||
| 326 | bool GetSetting(const char* settingName, void *settingValue) | ||
| 327 | { | ||
| 328 | return XBMC_get_setting(m_Handle, m_Callbacks, settingName, settingValue); | ||
| 329 | } | ||
| 330 | |||
| 331 | /*! | ||
| 332 | * @brief Queue a notification in the GUI. | ||
| 333 | * @param type The message type. | ||
| 334 | * @param format The format of the message to pass to display in XBMC. | ||
| 335 | */ | ||
| 336 | void QueueNotification(const queue_msg_t type, const char *format, ... ) | ||
| 337 | { | ||
| 338 | char buffer[16384]; | ||
| 339 | va_list args; | ||
| 340 | va_start (args, format); | ||
| 341 | vsprintf (buffer, format, args); | ||
| 342 | va_end (args); | ||
| 343 | return XBMC_queue_notification(m_Handle, m_Callbacks, type, buffer); | ||
| 344 | } | ||
| 345 | |||
| 346 | /*! | ||
| 347 | * @brief Send WakeOnLan magic packet. | ||
| 348 | * @param mac Network address of the host to wake. | ||
| 349 | * @return True if the magic packet was successfully sent, false otherwise. | ||
| 350 | */ | ||
| 351 | bool WakeOnLan(const char* mac) | ||
| 352 | { | ||
| 353 | return XBMC_wake_on_lan(m_Handle, m_Callbacks, mac); | ||
| 354 | } | ||
| 355 | |||
| 356 | /*! | ||
| 357 | * @brief Translate a string with an unknown encoding to UTF8. | ||
| 358 | * @param str The string to translate. | ||
| 359 | * @return The string translated to UTF8. Must be freed by calling FreeString() when done. | ||
| 360 | */ | ||
| 361 | char* UnknownToUTF8(const char* str) | ||
| 362 | { | ||
| 363 | return XBMC_unknown_to_utf8(m_Handle, m_Callbacks, str); | ||
| 364 | } | ||
| 365 | |||
| 366 | /*! | ||
| 367 | * @brief Get a localised message. | ||
| 368 | * @param dwCode The code of the message to get. | ||
| 369 | * @return The message. Must be freed by calling FreeString() when done. | ||
| 370 | */ | ||
| 371 | char* GetLocalizedString(int dwCode) | ||
| 372 | { | ||
| 373 | return XBMC_get_localized_string(m_Handle, m_Callbacks, dwCode); | ||
| 374 | } | ||
| 375 | |||
| 376 | |||
| 377 | /*! | ||
| 378 | * @brief Get the DVD menu language. | ||
| 379 | * @return The language. Must be freed by calling FreeString() when done. | ||
| 380 | */ | ||
| 381 | char* GetDVDMenuLanguage() | ||
| 382 | { | ||
| 383 | return XBMC_get_dvd_menu_language(m_Handle, m_Callbacks); | ||
| 384 | } | ||
| 385 | |||
| 386 | /*! | ||
| 387 | * @brief Free the memory used by str | ||
| 388 | * @param str The string to free | ||
| 389 | */ | ||
| 390 | void FreeString(char* str) | ||
| 391 | { | ||
| 392 | return XBMC_free_string(m_Handle, m_Callbacks, str); | ||
| 393 | } | ||
| 394 | |||
| 395 | /*! | ||
| 396 | * @brief Open the file with filename via XBMC's CFile. Needs to be closed by calling CloseFile() when done. | ||
| 397 | * @param strFileName The filename to open. | ||
| 398 | * @param flags The flags to pass. Documented in XBMC's File.h | ||
| 399 | * @return A handle for the file, or NULL if it couldn't be opened. | ||
| 400 | */ | ||
| 401 | void* OpenFile(const char* strFileName, unsigned int flags) | ||
| 402 | { | ||
| 403 | return XBMC_open_file(m_Handle, m_Callbacks, strFileName, flags); | ||
| 404 | } | ||
| 405 | |||
| 406 | /*! | ||
| 407 | * @brief Open the file with filename via XBMC's CFile in write mode. Needs to be closed by calling CloseFile() when done. | ||
| 408 | * @param strFileName The filename to open. | ||
| 409 | * @param bOverWrite True to overwrite, false otherwise. | ||
| 410 | * @return A handle for the file, or NULL if it couldn't be opened. | ||
| 411 | */ | ||
| 412 | void* OpenFileForWrite(const char* strFileName, bool bOverWrite) | ||
| 413 | { | ||
| 414 | return XBMC_open_file_for_write(m_Handle, m_Callbacks, strFileName, bOverWrite); | ||
| 415 | } | ||
| 416 | |||
| 417 | /*! | ||
| 418 | * @brief Read from an open file. | ||
| 419 | * @param file The file handle to read from. | ||
| 420 | * @param lpBuf The buffer to store the data in. | ||
| 421 | * @param uiBufSize The size of the buffer. | ||
| 422 | * @return number of successfully read bytes if any bytes were read and stored in | ||
| 423 | * buffer, zero if no bytes are available to read (end of file was reached) | ||
| 424 | * or undetectable error occur, -1 in case of any explicit error | ||
| 425 | */ | ||
| 426 | ssize_t ReadFile(void* file, void* lpBuf, size_t uiBufSize) | ||
| 427 | { | ||
| 428 | return XBMC_read_file(m_Handle, m_Callbacks, file, lpBuf, uiBufSize); | ||
| 429 | } | ||
| 430 | |||
| 431 | /*! | ||
| 432 | * @brief Read a string from an open file. | ||
| 433 | * @param file The file handle to read from. | ||
| 434 | * @param szLine The buffer to store the data in. | ||
| 435 | * @param iLineLength The size of the buffer. | ||
| 436 | * @return True when a line was read, false otherwise. | ||
| 437 | */ | ||
| 438 | bool ReadFileString(void* file, char *szLine, int iLineLength) | ||
| 439 | { | ||
| 440 | return XBMC_read_file_string(m_Handle, m_Callbacks, file, szLine, iLineLength); | ||
| 441 | } | ||
| 442 | |||
| 443 | /*! | ||
| 444 | * @brief Write to a file opened in write mode. | ||
| 445 | * @param file The file handle to write to. | ||
| 446 | * @param lpBuf The data to write. | ||
| 447 | * @param uiBufSize Size of the data to write. | ||
| 448 | * @return number of successfully written bytes if any bytes were written, | ||
| 449 | * zero if no bytes were written and no detectable error occur, | ||
| 450 | * -1 in case of any explicit error | ||
| 451 | */ | ||
| 452 | ssize_t WriteFile(void* file, const void* lpBuf, size_t uiBufSize) | ||
| 453 | { | ||
| 454 | return XBMC_write_file(m_Handle, m_Callbacks, file, lpBuf, uiBufSize); | ||
| 455 | } | ||
| 456 | |||
| 457 | /*! | ||
| 458 | * @brief Flush buffered data. | ||
| 459 | * @param file The file handle to flush the data for. | ||
| 460 | */ | ||
| 461 | void FlushFile(void* file) | ||
| 462 | { | ||
| 463 | return XBMC_flush_file(m_Handle, m_Callbacks, file); | ||
| 464 | } | ||
| 465 | |||
| 466 | /*! | ||
| 467 | * @brief Seek in an open file. | ||
| 468 | * @param file The file handle to see in. | ||
| 469 | * @param iFilePosition The new position. | ||
| 470 | * @param iWhence Seek argument. See stdio.h for possible values. | ||
| 471 | * @return The new position. | ||
| 472 | */ | ||
| 473 | int64_t SeekFile(void* file, int64_t iFilePosition, int iWhence) | ||
| 474 | { | ||
| 475 | return XBMC_seek_file(m_Handle, m_Callbacks, file, iFilePosition, iWhence); | ||
| 476 | } | ||
| 477 | |||
| 478 | /*! | ||
| 479 | * @brief Truncate a file to the requested size. | ||
| 480 | * @param file The file handle to truncate. | ||
| 481 | * @param iSize The new max size. | ||
| 482 | * @return New size? | ||
| 483 | */ | ||
| 484 | int TruncateFile(void* file, int64_t iSize) | ||
| 485 | { | ||
| 486 | return XBMC_truncate_file(m_Handle, m_Callbacks, file, iSize); | ||
| 487 | } | ||
| 488 | |||
| 489 | /*! | ||
| 490 | * @brief The current position in an open file. | ||
| 491 | * @param file The file handle to get the position for. | ||
| 492 | * @return The requested position. | ||
| 493 | */ | ||
| 494 | int64_t GetFilePosition(void* file) | ||
| 495 | { | ||
| 496 | return XBMC_get_file_position(m_Handle, m_Callbacks, file); | ||
| 497 | } | ||
| 498 | |||
| 499 | /*! | ||
| 500 | * @brief Get the file size of an open file. | ||
| 501 | * @param file The file to get the size for. | ||
| 502 | * @return The requested size. | ||
| 503 | */ | ||
| 504 | int64_t GetFileLength(void* file) | ||
| 505 | { | ||
| 506 | return XBMC_get_file_length(m_Handle, m_Callbacks, file); | ||
| 507 | } | ||
| 508 | |||
| 509 | /*! | ||
| 510 | * @brief Get the download speed of an open file if available. | ||
| 511 | * @param file The file to get the size for. | ||
| 512 | * @return The download speed in seconds. | ||
| 513 | */ | ||
| 514 | double GetFileDownloadSpeed(void* file) | ||
| 515 | { | ||
| 516 | return XBMC_get_file_download_speed(m_Handle, m_Callbacks, file); | ||
| 517 | } | ||
| 518 | |||
| 519 | /*! | ||
| 520 | * @brief Close an open file. | ||
| 521 | * @param file The file handle to close. | ||
| 522 | */ | ||
| 523 | void CloseFile(void* file) | ||
| 524 | { | ||
| 525 | return XBMC_close_file(m_Handle, m_Callbacks, file); | ||
| 526 | } | ||
| 527 | |||
| 528 | /*! | ||
| 529 | * @brief Get the chunk size for an open file. | ||
| 530 | * @param file the file handle to get the size for. | ||
| 531 | * @return The requested size. | ||
| 532 | */ | ||
| 533 | int GetFileChunkSize(void* file) | ||
| 534 | { | ||
| 535 | return XBMC_get_file_chunk_size(m_Handle, m_Callbacks, file); | ||
| 536 | } | ||
| 537 | |||
| 538 | /*! | ||
| 539 | * @brief Check if a file exists. | ||
| 540 | * @param strFileName The filename to check. | ||
| 541 | * @param bUseCache Check in file cache. | ||
| 542 | * @return true if the file exists false otherwise. | ||
| 543 | */ | ||
| 544 | bool FileExists(const char *strFileName, bool bUseCache) | ||
| 545 | { | ||
| 546 | return XBMC_file_exists(m_Handle, m_Callbacks, strFileName, bUseCache); | ||
| 547 | } | ||
| 548 | |||
| 549 | /*! | ||
| 550 | * @brief Reads file status. | ||
| 551 | * @param strFileName The filename to read the status from. | ||
| 552 | * @param buffer The file status is written into this buffer. | ||
| 553 | * @return The file status was successfully read. | ||
| 554 | */ | ||
| 555 | int StatFile(const char *strFileName, struct __stat64* buffer) | ||
| 556 | { | ||
| 557 | return XBMC_stat_file(m_Handle, m_Callbacks, strFileName, buffer); | ||
| 558 | } | ||
| 559 | |||
| 560 | /*! | ||
| 561 | * @brief Deletes a file. | ||
| 562 | * @param strFileName The filename to delete. | ||
| 563 | * @return The file was successfully deleted. | ||
| 564 | */ | ||
| 565 | bool DeleteFile(const char *strFileName) | ||
| 566 | { | ||
| 567 | return XBMC_delete_file(m_Handle, m_Callbacks, strFileName); | ||
| 568 | } | ||
| 569 | |||
| 570 | /*! | ||
| 571 | * @brief Checks whether a directory can be opened. | ||
| 572 | * @param strUrl The URL of the directory to check. | ||
| 573 | * @return True when it can be opened, false otherwise. | ||
| 574 | */ | ||
| 575 | bool CanOpenDirectory(const char* strUrl) | ||
| 576 | { | ||
| 577 | return XBMC_can_open_directory(m_Handle, m_Callbacks, strUrl); | ||
| 578 | } | ||
| 579 | |||
| 580 | /*! | ||
| 581 | * @brief Creates a directory. | ||
| 582 | * @param strPath Path to the directory. | ||
| 583 | * @return True when it was created, false otherwise. | ||
| 584 | */ | ||
| 585 | bool CreateDirectory(const char *strPath) | ||
| 586 | { | ||
| 587 | return XBMC_create_directory(m_Handle, m_Callbacks, strPath); | ||
| 588 | } | ||
| 589 | |||
| 590 | /*! | ||
| 591 | * @brief Checks if a directory exists. | ||
| 592 | * @param strPath Path to the directory. | ||
| 593 | * @return True when it exists, false otherwise. | ||
| 594 | */ | ||
| 595 | bool DirectoryExists(const char *strPath) | ||
| 596 | { | ||
| 597 | return XBMC_directory_exists(m_Handle, m_Callbacks, strPath); | ||
| 598 | } | ||
| 599 | |||
| 600 | /*! | ||
| 601 | * @brief Removes a directory. | ||
| 602 | * @param strPath Path to the directory. | ||
| 603 | * @return True when it was removed, false otherwise. | ||
| 604 | */ | ||
| 605 | bool RemoveDirectory(const char *strPath) | ||
| 606 | { | ||
| 607 | return XBMC_remove_directory(m_Handle, m_Callbacks, strPath); | ||
| 608 | } | ||
| 609 | |||
| 610 | /*! | ||
| 611 | * @brief Lists a directory. | ||
| 612 | * @param strPath Path to the directory. | ||
| 613 | * @param mask File mask | ||
| 614 | * @param items The directory entries | ||
| 615 | * @param num_items Number of entries in directory | ||
| 616 | * @return True if listing was successful, false otherwise. | ||
| 617 | */ | ||
| 618 | bool GetDirectory(const char *strPath, const char* mask, VFSDirEntry** items, unsigned int* num_items) | ||
| 619 | { | ||
| 620 | return XBMC_get_directory(m_Handle, m_Callbacks, strPath, mask, items, num_items); | ||
| 621 | } | ||
| 622 | |||
| 623 | /*! | ||
| 624 | * @brief Free a directory list | ||
| 625 | * @param items The directory entries | ||
| 626 | * @param num_items Number of entries in directory | ||
| 627 | */ | ||
| 628 | void FreeDirectory(VFSDirEntry* items, unsigned int num_items) | ||
| 629 | { | ||
| 630 | return XBMC_free_directory(m_Handle, m_Callbacks, items, num_items); | ||
| 631 | } | ||
| 632 | |||
| 633 | /*! | ||
| 634 | * @brief Create a Curl representation | ||
| 635 | * @param strURL the URL of the Type. | ||
| 636 | */ | ||
| 637 | void* CURLCreate(const char* strURL) | ||
| 638 | { | ||
| 639 | return XBMC_curl_create(m_Handle, m_Callbacks, strURL); | ||
| 640 | } | ||
| 641 | |||
| 642 | /*! | ||
| 643 | * @brief Adds options to the curl file created with CURLCeate | ||
| 644 | * @param file file pointer to the file returned by CURLCeate | ||
| 645 | * @param type option type to set | ||
| 646 | * @param name name of the option | ||
| 647 | * @param value value of the option | ||
| 648 | */ | ||
| 649 | bool CURLAddOption(void* file, XFILE::CURLOPTIONTYPE type, const char* name, const char * value) | ||
| 650 | { | ||
| 651 | return XBMC_curl_add_option(m_Handle, m_Callbacks, file, type, name, value); | ||
| 652 | } | ||
| 653 | |||
| 654 | /*! | ||
| 655 | * @brief Opens the curl file created with CURLCeate | ||
| 656 | * @param file file pointer to the file returned by CURLCeate | ||
| 657 | * @param flags one or more bitwise or combinded flags form XFILE | ||
| 658 | */ | ||
| 659 | bool CURLOpen(void* file, unsigned int flags) | ||
| 660 | { | ||
| 661 | return XBMC_curl_open(m_Handle, m_Callbacks, file, flags); | ||
| 662 | } | ||
| 663 | |||
| 664 | protected: | ||
| 665 | void* (*XBMC_register_me)(void *HANDLE); | ||
| 666 | void (*XBMC_unregister_me)(void *HANDLE, void* CB); | ||
| 667 | void (*XBMC_log)(void *HANDLE, void* CB, const addon_log_t loglevel, const char *msg); | ||
| 668 | bool (*XBMC_get_setting)(void *HANDLE, void* CB, const char* settingName, void *settingValue); | ||
| 669 | void (*XBMC_queue_notification)(void *HANDLE, void* CB, const queue_msg_t type, const char *msg); | ||
| 670 | bool (*XBMC_wake_on_lan)(void *HANDLE, void* CB, const char* mac); | ||
| 671 | char* (*XBMC_unknown_to_utf8)(void *HANDLE, void* CB, const char* str); | ||
| 672 | char* (*XBMC_get_localized_string)(void *HANDLE, void* CB, int dwCode); | ||
| 673 | char* (*XBMC_get_dvd_menu_language)(void *HANDLE, void* CB); | ||
| 674 | void (*XBMC_free_string)(void *HANDLE, void* CB, char* str); | ||
| 675 | void* (*XBMC_open_file)(void *HANDLE, void* CB, const char* strFileName, unsigned int flags); | ||
| 676 | void* (*XBMC_open_file_for_write)(void *HANDLE, void* CB, const char* strFileName, bool bOverWrite); | ||
| 677 | ssize_t (*XBMC_read_file)(void *HANDLE, void* CB, void* file, void* lpBuf, size_t uiBufSize); | ||
| 678 | bool (*XBMC_read_file_string)(void *HANDLE, void* CB, void* file, char *szLine, int iLineLength); | ||
| 679 | ssize_t(*XBMC_write_file)(void *HANDLE, void* CB, void* file, const void* lpBuf, size_t uiBufSize); | ||
| 680 | void (*XBMC_flush_file)(void *HANDLE, void* CB, void* file); | ||
| 681 | int64_t (*XBMC_seek_file)(void *HANDLE, void* CB, void* file, int64_t iFilePosition, int iWhence); | ||
| 682 | int (*XBMC_truncate_file)(void *HANDLE, void* CB, void* file, int64_t iSize); | ||
| 683 | int64_t (*XBMC_get_file_position)(void *HANDLE, void* CB, void* file); | ||
| 684 | int64_t (*XBMC_get_file_length)(void *HANDLE, void* CB, void* file); | ||
| 685 | double(*XBMC_get_file_download_speed)(void *HANDLE, void* CB, void* file); | ||
| 686 | void (*XBMC_close_file)(void *HANDLE, void* CB, void* file); | ||
| 687 | int (*XBMC_get_file_chunk_size)(void *HANDLE, void* CB, void* file); | ||
| 688 | bool (*XBMC_file_exists)(void *HANDLE, void* CB, const char *strFileName, bool bUseCache); | ||
| 689 | int (*XBMC_stat_file)(void *HANDLE, void* CB, const char *strFileName, struct __stat64* buffer); | ||
| 690 | bool (*XBMC_delete_file)(void *HANDLE, void* CB, const char *strFileName); | ||
| 691 | bool (*XBMC_can_open_directory)(void *HANDLE, void* CB, const char* strURL); | ||
| 692 | bool (*XBMC_create_directory)(void *HANDLE, void* CB, const char* strPath); | ||
| 693 | bool (*XBMC_directory_exists)(void *HANDLE, void* CB, const char* strPath); | ||
| 694 | bool (*XBMC_remove_directory)(void *HANDLE, void* CB, const char* strPath); | ||
| 695 | bool (*XBMC_get_directory)(void *HANDLE, void* CB, const char* strPath, const char* mask, VFSDirEntry** items, unsigned int* num_items); | ||
| 696 | void (*XBMC_free_directory)(void *HANDLE, void* CB, VFSDirEntry* items, unsigned int num_items); | ||
| 697 | void* (*XBMC_curl_create)(void *HANDLE, void* CB, const char* strURL); | ||
| 698 | bool (*XBMC_curl_add_option)(void *HANDLE, void* CB, void *file, XFILE::CURLOPTIONTYPE type, const char* name, const char *value); | ||
| 699 | bool (*XBMC_curl_open)(void *m_Handle, void *m_Callbacks, void *file, unsigned int flags); | ||
| 700 | |||
| 701 | private: | ||
| 702 | void *m_libXBMC_addon; | ||
| 703 | void *m_Handle; | ||
| 704 | void *m_Callbacks; | ||
| 705 | struct cb_array | ||
| 706 | { | ||
| 707 | const char* libPath; | ||
| 708 | }; | ||
| 709 | }; | ||
| 710 | }; | ||
