diff options
author | Christian Fetzer <fetzer.ch@googlemail.com> | 2012-09-25 20:57:50 +0200 |
---|---|---|
committer | Christian Fetzer <fetzer.ch@googlemail.com> | 2012-09-25 20:57:50 +0200 |
commit | 70ece4bf55e4d866c95d1a3355c3eb65cb0d486d (patch) | |
tree | cfd57f786a7d3c3753477bc930ba21fab652658c /addons/library.xbmc.addon | |
parent | 0d4dc0822ba0a37681a2e1e8f59e1872b888be5b (diff) |
[addons] Removed global variables in addon callback shared libraries
Diffstat (limited to 'addons/library.xbmc.addon')
-rw-r--r-- | addons/library.xbmc.addon/libXBMC_addon.h | 217 |
1 files changed, 153 insertions, 64 deletions
diff --git a/addons/library.xbmc.addon/libXBMC_addon.h b/addons/library.xbmc.addon/libXBMC_addon.h index f26112cf1a..c2be8f3773 100644 --- a/addons/library.xbmc.addon/libXBMC_addon.h +++ b/addons/library.xbmc.addon/libXBMC_addon.h @@ -25,6 +25,7 @@ #include <stdlib.h> #include <stdio.h> #include <stdint.h> +#include <stdarg.h> #ifdef _WIN32 // windows #include "dlfcn-win32.h" @@ -104,7 +105,7 @@ namespace ADDON { if (m_libXBMC_addon) { - XBMC_unregister_me(); + XBMC_unregister_me(m_Handle, m_Callbacks); dlclose(m_libXBMC_addon); } } @@ -124,91 +125,92 @@ namespace ADDON return false; } - XBMC_register_me = (int (*)(void *HANDLE)) + XBMC_register_me = (void* (*)(void *HANDLE)) dlsym(m_libXBMC_addon, "XBMC_register_me"); - if (XBMC_register_me == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + if (XBMC_register_me == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - XBMC_unregister_me = (void (*)()) + XBMC_unregister_me = (void (*)(void* HANDLE, void* CB)) dlsym(m_libXBMC_addon, "XBMC_unregister_me"); if (XBMC_unregister_me == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - Log = (void (*)(const addon_log_t loglevel, const char *format, ... )) + XBMC_log = (void (*)(void* HANDLE, void* CB, const addon_log_t loglevel, const char *msg)) dlsym(m_libXBMC_addon, "XBMC_log"); - if (Log == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + if (XBMC_log == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - GetSetting = (bool (*)(const char* settingName, void *settingValue)) + XBMC_get_setting = (bool (*)(void* HANDLE, void* CB, const char* settingName, void *settingValue)) dlsym(m_libXBMC_addon, "XBMC_get_setting"); - if (GetSetting == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + if (XBMC_get_setting == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - QueueNotification = (void (*)(const queue_msg_t loglevel, const char *format, ... )) + XBMC_queue_notification = (void (*)(void* HANDLE, void* CB, const queue_msg_t loglevel, const char *msg)) dlsym(m_libXBMC_addon, "XBMC_queue_notification"); - if (QueueNotification == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + if (XBMC_queue_notification == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - UnknownToUTF8 = (void (*)(std::string &str)) + XBMC_unknown_to_utf8 = (void (*)(void* HANDLE, void* CB, std::string &str)) dlsym(m_libXBMC_addon, "XBMC_unknown_to_utf8"); - if (UnknownToUTF8 == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + if (XBMC_unknown_to_utf8 == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - GetLocalizedString = (const char* (*)(int dwCode)) + XBMC_get_localized_string = (const char* (*)(void* HANDLE, void* CB, int dwCode)) dlsym(m_libXBMC_addon, "XBMC_get_localized_string"); - if (GetLocalizedString == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + if (XBMC_get_localized_string == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - GetDVDMenuLanguage = (const char* (*)()) + XBMC_get_dvd_menu_language = (const char* (*)(void* HANDLE, void* CB)) dlsym(m_libXBMC_addon, "XBMC_get_dvd_menu_language"); - if (GetDVDMenuLanguage == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + if (XBMC_get_dvd_menu_language == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - OpenFile = (void* (*)(const char* strFileName, unsigned int flags)) + XBMC_open_file = (void* (*)(void* HANDLE, void* CB, const char* strFileName, unsigned int flags)) dlsym(m_libXBMC_addon, "XBMC_open_file"); - if (OpenFile == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + if (XBMC_open_file == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - OpenFileForWrite = (void* (*)(const char* strFileName, bool bOverWrite)) + XBMC_open_file_for_write = (void* (*)(void* HANDLE, void* CB, const char* strFileName, bool bOverWrite)) dlsym(m_libXBMC_addon, "XBMC_open_file_for_write"); - if (OpenFileForWrite == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + if (XBMC_open_file_for_write == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - ReadFile = (unsigned int (*)(void* file, void* lpBuf, int64_t uiBufSize)) + XBMC_read_file = (unsigned int (*)(void* HANDLE, void* CB, void* file, void* lpBuf, int64_t uiBufSize)) dlsym(m_libXBMC_addon, "XBMC_read_file"); - if (ReadFile == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + if (XBMC_read_file == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - ReadFileString = (bool (*)(void* file, char *szLine, int iLineLength)) + XBMC_read_file_string = (bool (*)(void* HANDLE, void* CB, void* file, char *szLine, int iLineLength)) dlsym(m_libXBMC_addon, "XBMC_read_file_string"); - if (ReadFileString == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + if (XBMC_read_file_string == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - WriteFile = (int (*)(void* file, const void* lpBuf, int64_t uiBufSize)) + XBMC_write_file = (int (*)(void* HANDLE, void* CB, void* file, const void* lpBuf, int64_t uiBufSize)) dlsym(m_libXBMC_addon, "XBMC_write_file"); - if (WriteFile == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + if (XBMC_write_file == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - FlushFile = (void (*)(void* file)) + XBMC_flush_file = (void (*)(void* HANDLE, void* CB, void* file)) dlsym(m_libXBMC_addon, "XBMC_flush_file"); - if (FlushFile == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + if (XBMC_flush_file == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - SeekFile = (int64_t (*)(void* file, int64_t iFilePosition, int iWhence)) + XBMC_seek_file = (int64_t (*)(void* HANDLE, void* CB, void* file, int64_t iFilePosition, int iWhence)) dlsym(m_libXBMC_addon, "XBMC_seek_file"); - if (SeekFile == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + if (XBMC_seek_file == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - TruncateFile = (int (*)(void* file, int64_t iSize)) + XBMC_truncate_file = (int (*)(void* HANDLE, void* CB, void* file, int64_t iSize)) dlsym(m_libXBMC_addon, "XBMC_truncate_file"); - if (TruncateFile == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + if (XBMC_truncate_file == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - GetFilePosition = (int64_t (*)(void* file)) + XBMC_get_file_position = (int64_t (*)(void* HANDLE, void* CB, void* file)) dlsym(m_libXBMC_addon, "XBMC_get_file_position"); - if (GetFilePosition == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + if (XBMC_get_file_position == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - GetFileLength = (int64_t (*)(void* file)) + XBMC_get_file_length = (int64_t (*)(void* HANDLE, void* CB, void* file)) dlsym(m_libXBMC_addon, "XBMC_get_file_length"); - if (GetFileLength == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + if (XBMC_get_file_length == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - CloseFile = (void (*)(void* file)) + XBMC_close_file = (void (*)(void* HANDLE, void* CB, void* file)) dlsym(m_libXBMC_addon, "XBMC_close_file"); - if (CloseFile == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + if (XBMC_close_file == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - GetFileChunkSize = (int (*)(void* file)) + XBMC_get_file_chunk_size = (int (*)(void* HANDLE, void* CB, void* file)) dlsym(m_libXBMC_addon, "XBMC_get_file_chunk_size"); - if (GetFileChunkSize == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + if (XBMC_get_file_chunk_size == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - CanOpenDirectory = (bool (*)(const char* strURL)) + XBMC_can_open_directory = (bool (*)(void* HANDLE, void* CB, const char* strURL)) dlsym(m_libXBMC_addon, "XBMC_can_open_directory"); - if (CanOpenDirectory == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + if (XBMC_can_open_directory == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } - return XBMC_register_me(m_Handle) > 0; + m_Callbacks = XBMC_register_me(m_Handle); + return m_Callbacks != NULL; } /*! @@ -216,7 +218,15 @@ namespace ADDON * @param loglevel The log level of the message. * @param format The format of the message to pass to XBMC. */ - void (*Log)(const addon_log_t loglevel, const char *format, ... ); + void Log(const addon_log_t loglevel, const char *format, ... ) + { + char buffer[16384]; + va_list args; + va_start (args, format); + vsprintf (buffer, format, args); + va_end (args); + return XBMC_log(m_Handle, m_Callbacks, loglevel, buffer); + } /*! * @brief Get a settings value for this add-on. @@ -224,34 +234,54 @@ namespace ADDON * @param settingValue The value. * @return True if the settings was fetched successfully, false otherwise. */ - bool (*GetSetting)(const char* settingName, void *settingValue); + bool GetSetting(const char* settingName, void *settingValue) + { + return XBMC_get_setting(m_Handle, m_Callbacks, settingName, settingValue); + } /*! * @brief Queue a notification in the GUI. * @param type The message type. * @param format The format of the message to pass to display in XBMC. */ - void (*QueueNotification)(const queue_msg_t type, const char *format, ... ); + void QueueNotification(const queue_msg_t type, const char *format, ... ) + { + char buffer[16384]; + va_list args; + va_start (args, format); + vsprintf (buffer, format, args); + va_end (args); + return XBMC_queue_notification(m_Handle, m_Callbacks, type, buffer); + } /*! * @brief Translate a string with an unknown encoding to UTF8. * @param sourceDest The string to translate. */ - void (*UnknownToUTF8)(std::string &str); + void UnknownToUTF8(std::string &str) + { + return XBMC_unknown_to_utf8(m_Handle, m_Callbacks, str); + } /*! * @brief Get a localised message. * @param dwCode The code of the message to get. * @return The message. Needs to be freed when done. */ - const char* (*GetLocalizedString)(int dwCode); + const char* GetLocalizedString(int dwCode) + { + return XBMC_get_localized_string(m_Handle, m_Callbacks, dwCode); + } /*! * @brief Get the DVD menu language. * @return The language. Needs to be freed when done. */ - const char* (*GetDVDMenuLanguage)(); + const char* GetDVDMenuLanguage() + { + return XBMC_get_dvd_menu_language(m_Handle, m_Callbacks); + } /*! * @brief Open the file with filename via XBMC's CFile. Needs to be closed by calling CloseFile() when done. @@ -259,7 +289,10 @@ namespace ADDON * @param flags The flags to pass. Documented in XBMC's File.h * @return A handle for the file, or NULL if it couldn't be opened. */ - void* (*OpenFile)(const char* strFileName, unsigned int flags); + void* OpenFile(const char* strFileName, unsigned int flags) + { + return XBMC_open_file(m_Handle, m_Callbacks, strFileName, flags); + } /*! * @brief Open the file with filename via XBMC's CFile in write mode. Needs to be closed by calling CloseFile() when done. @@ -267,7 +300,10 @@ namespace ADDON * @param bOverWrite True to overwrite, false otherwise. * @return A handle for the file, or NULL if it couldn't be opened. */ - void* (*OpenFileForWrite)(const char* strFileName, bool bOverWrite); + void* OpenFileForWrite(const char* strFileName, bool bOverWrite) + { + return XBMC_open_file_for_write(m_Handle, m_Callbacks, strFileName, bOverWrite); + } /*! * @brief Read from an open file. @@ -276,7 +312,10 @@ namespace ADDON * @param uiBufSize The size of the buffer. * @return Number of bytes read. */ - unsigned int (*ReadFile)(void* file, void* lpBuf, int64_t uiBufSize); + unsigned int ReadFile(void* file, void* lpBuf, int64_t uiBufSize) + { + return XBMC_read_file(m_Handle, m_Callbacks, file, lpBuf, uiBufSize); + } /*! * @brief Read a string from an open file. @@ -285,7 +324,10 @@ namespace ADDON * @param iLineLength The size of the buffer. * @return True when a line was read, false otherwise. */ - bool (*ReadFileString)(void* file, char *szLine, int iLineLength); + bool ReadFileString(void* file, char *szLine, int iLineLength) + { + return XBMC_read_file_string(m_Handle, m_Callbacks, file, szLine, iLineLength); + } /*! * @brief Write to a file opened in write mode. @@ -294,13 +336,19 @@ namespace ADDON * @param uiBufSize Size of the data to write. * @return The number of bytes read. */ - int (*WriteFile)(void* file, const void* lpBuf, int64_t uiBufSize); + int WriteFile(void* file, const void* lpBuf, int64_t uiBufSize) + { + return XBMC_write_file(m_Handle, m_Callbacks, file, lpBuf, uiBufSize); + } /*! * @brief Flush buffered data. * @param file The file handle to flush the data for. */ - void (*FlushFile)(void* file); + void FlushFile(void* file) + { + return XBMC_flush_file(m_Handle, m_Callbacks, file); + } /*! * @brief Seek in an open file. @@ -309,7 +357,10 @@ namespace ADDON * @param iWhence Seek argument. See stdio.h for possible values. * @return The new position. */ - int64_t (*SeekFile)(void* file, int64_t iFilePosition, int iWhence); + int64_t SeekFile(void* file, int64_t iFilePosition, int iWhence) + { + return XBMC_seek_file(m_Handle, m_Callbacks, file, iFilePosition, iWhence); + } /*! * @brief Truncate a file to the requested size. @@ -317,49 +368,87 @@ namespace ADDON * @param iSize The new max size. * @return New size? */ - int (*TruncateFile)(void* file, int64_t iSize); + int TruncateFile(void* file, int64_t iSize) + { + return XBMC_truncate_file(m_Handle, m_Callbacks, file, iSize); + } /*! * @brief The current position in an open file. * @param file The file handle to get the position for. * @return The requested position. */ - int64_t (*GetFilePosition)(void* file); + int64_t GetFilePosition(void* file) + { + return XBMC_get_file_position(m_Handle, m_Callbacks, file); + } /*! * @brief Get the file size of an open file. * @param file The file to get the size for. * @return The requested size. */ - int64_t (*GetFileLength)(void* file); + int64_t GetFileLength(void* file) + { + return XBMC_get_file_length(m_Handle, m_Callbacks, file); + } /*! * @brief Close an open file. * @param file The file handle to close. */ - void (*CloseFile)(void* file); + void CloseFile(void* file) + { + return XBMC_close_file(m_Handle, m_Callbacks, file); + } /*! * @brief Get the chunk size for an open file. * @param file the file handle to get the size for. * @return The requested size. */ - int (*GetFileChunkSize)(void* file); + int GetFileChunkSize(void* file) + { + return XBMC_get_file_chunk_size(m_Handle, m_Callbacks, file); + } /*! * @brief Checks whether a directory can be opened. * @param strUrl The URL of the directory to check. * @return True when it can be opened, false otherwise. */ - bool (*CanOpenDirectory)(const char* strUrl); + bool CanOpenDirectory(const char* strUrl) + { + return XBMC_can_open_directory(m_Handle, m_Callbacks, strUrl); + } protected: - int (*XBMC_register_me)(void *HANDLE); - void (*XBMC_unregister_me)(); + void* (*XBMC_register_me)(void *HANDLE); + void (*XBMC_unregister_me)(void *HANDLE, void* CB); + void (*XBMC_log)(void *HANDLE, void* CB, const addon_log_t loglevel, const char *msg); + bool (*XBMC_get_setting)(void *HANDLE, void* CB, const char* settingName, void *settingValue); + void (*XBMC_queue_notification)(void *HANDLE, void* CB, const queue_msg_t type, const char *msg); + void (*XBMC_unknown_to_utf8)(void *HANDLE, void* CB, std::string &str); + const char* (*XBMC_get_localized_string)(void *HANDLE, void* CB, int dwCode); + const char* (*XBMC_get_dvd_menu_language)(void *HANDLE, void* CB); + void* (*XBMC_open_file)(void *HANDLE, void* CB, const char* strFileName, unsigned int flags); + void* (*XBMC_open_file_for_write)(void *HANDLE, void* CB, const char* strFileName, bool bOverWrite); + unsigned int (*XBMC_read_file)(void *HANDLE, void* CB, void* file, void* lpBuf, int64_t uiBufSize); + bool (*XBMC_read_file_string)(void *HANDLE, void* CB, void* file, char *szLine, int iLineLength); + int (*XBMC_write_file)(void *HANDLE, void* CB, void* file, const void* lpBuf, int64_t uiBufSize); + void (*XBMC_flush_file)(void *HANDLE, void* CB, void* file); + int64_t (*XBMC_seek_file)(void *HANDLE, void* CB, void* file, int64_t iFilePosition, int iWhence); + int (*XBMC_truncate_file)(void *HANDLE, void* CB, void* file, int64_t iSize); + int64_t (*XBMC_get_file_position)(void *HANDLE, void* CB, void* file); + int64_t (*XBMC_get_file_length)(void *HANDLE, void* CB, void* file); + void (*XBMC_close_file)(void *HANDLE, void* CB, void* file); + int (*XBMC_get_file_chunk_size)(void *HANDLE, void* CB, void* file); + bool (*XBMC_can_open_directory)(void *HANDLE, void* CB, const char* strURL); private: void *m_libXBMC_addon; void *m_Handle; + void *m_Callbacks; struct cb_array { const char* libPath; |