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