diff options
author | Lars Op den Kamp <lars@opdenkamp.eu> | 2012-11-09 01:29:12 +0100 |
---|---|---|
committer | Lars Op den Kamp <lars@opdenkamp.eu> | 2012-11-10 01:15:07 +0100 |
commit | 2c7ac24c76a72977b0e819fe8f3838be6d3e0ec0 (patch) | |
tree | 7391e363466dcf826baaf3c3ba415b92cc95919b | |
parent | 42f6b3e6a4f9d2321afbc47209a88d1455a27820 (diff) |
[pvr] added FreeString()
-rw-r--r-- | addons/library.xbmc.addon/libXBMC_addon.h | 20 | ||||
-rw-r--r-- | lib/addons/library.xbmc.addon/libXBMC_addon.cpp | 8 | ||||
-rw-r--r-- | xbmc/addons/AddonCallbacks.h | 2 | ||||
-rw-r--r-- | xbmc/addons/AddonCallbacksAddon.cpp | 6 | ||||
-rw-r--r-- | xbmc/addons/AddonCallbacksAddon.h | 1 |
5 files changed, 34 insertions, 3 deletions
diff --git a/addons/library.xbmc.addon/libXBMC_addon.h b/addons/library.xbmc.addon/libXBMC_addon.h index 42fcee2a4e..f805263c8d 100644 --- a/addons/library.xbmc.addon/libXBMC_addon.h +++ b/addons/library.xbmc.addon/libXBMC_addon.h @@ -166,6 +166,10 @@ namespace ADDON dlsym(m_libXBMC_addon, "XBMC_get_localized_string"); if (XBMC_get_localized_string == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + XBMC_free_string = (void (*)(void* HANDLE, void* CB, char* str)) + dlsym(m_libXBMC_addon, "XBMC_free_string"); + if (XBMC_free_string == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + XBMC_get_dvd_menu_language = (char* (*)(void* HANDLE, void* CB)) dlsym(m_libXBMC_addon, "XBMC_get_dvd_menu_language"); if (XBMC_get_dvd_menu_language == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } @@ -294,7 +298,7 @@ namespace ADDON /*! * @brief Translate a string with an unknown encoding to UTF8. * @param str The string to translate. - * @return The string translated to UTF8. Must be freed when done. + * @return The string translated to UTF8. Must be freed by calling FreeString() when done. */ char* UnknownToUTF8(const char* str) { @@ -304,7 +308,7 @@ namespace ADDON /*! * @brief Get a localised message. * @param dwCode The code of the message to get. - * @return The message. Needs to be freed when done. + * @return The message. Must be freed by calling FreeString() when done. */ char* GetLocalizedString(int dwCode) { @@ -314,7 +318,7 @@ namespace ADDON /*! * @brief Get the DVD menu language. - * @return The language. Needs to be freed when done. + * @return The language. Must be freed by calling FreeString() when done. */ char* GetDVDMenuLanguage() { @@ -322,6 +326,15 @@ namespace ADDON } /*! + * @brief Free the memory used by str + * @param str The string to free + */ + void FreeString(char* str) + { + return XBMC_free_string(m_Handle, m_Callbacks, str); + } + + /*! * @brief Open the file with filename via XBMC's CFile. Needs to be closed by calling CloseFile() when done. * @param strFileName The filename to open. * @param flags The flags to pass. Documented in XBMC's File.h @@ -531,6 +544,7 @@ namespace ADDON char* (*XBMC_unknown_to_utf8)(void *HANDLE, void* CB, const char* str); char* (*XBMC_get_localized_string)(void *HANDLE, void* CB, int dwCode); char* (*XBMC_get_dvd_menu_language)(void *HANDLE, void* CB); + void (*XBMC_free_string)(void *HANDLE, void* CB, char* str); 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); diff --git a/lib/addons/library.xbmc.addon/libXBMC_addon.cpp b/lib/addons/library.xbmc.addon/libXBMC_addon.cpp index 243abb0691..3daf0ead3e 100644 --- a/lib/addons/library.xbmc.addon/libXBMC_addon.cpp +++ b/lib/addons/library.xbmc.addon/libXBMC_addon.cpp @@ -109,6 +109,14 @@ DLLEXPORT char* XBMC_get_dvd_menu_language(void *hdl, void* cb) return strdup(buffer.c_str()); } +DLLEXPORT void XBMC_free_string(void* hdl, void* cb, char* str) +{ + if (cb == NULL) + return; + + ((CB_AddOnLib*)cb)->FreeString(((AddonCB*)hdl)->addonData, str); +} + DLLEXPORT void* XBMC_open_file(void *hdl, void* cb, const char* strFileName, unsigned int flags) { if (cb == NULL) diff --git a/xbmc/addons/AddonCallbacks.h b/xbmc/addons/AddonCallbacks.h index f58629840d..3cdca49926 100644 --- a/xbmc/addons/AddonCallbacks.h +++ b/xbmc/addons/AddonCallbacks.h @@ -30,6 +30,7 @@ typedef bool (*AddOnGetSetting)(void *addonData, const char *settingName, void * typedef char* (*AddOnUnknownToUTF8)(const char *sourceDest); typedef char* (*AddOnGetLocalizedString)(const void* addonData, long dwCode); typedef char* (*AddOnGetDVDMenuLanguage)(const void* addonData); +typedef void (*AddOnFreeString)(const void* addonData, char* str); typedef void* (*AddOnOpenFile)(const void* addonData, const char* strFileName, unsigned int flags); typedef void* (*AddOnOpenFileForWrite)(const void* addonData, const char* strFileName, bool bOverWrite); @@ -59,6 +60,7 @@ typedef struct CB_AddOn AddOnUnknownToUTF8 UnknownToUTF8; AddOnGetLocalizedString GetLocalizedString; AddOnGetDVDMenuLanguage GetDVDMenuLanguage; + AddOnFreeString FreeString; AddOnOpenFile OpenFile; AddOnOpenFileForWrite OpenFileForWrite; diff --git a/xbmc/addons/AddonCallbacksAddon.cpp b/xbmc/addons/AddonCallbacksAddon.cpp index fa81496590..3f36e9663e 100644 --- a/xbmc/addons/AddonCallbacksAddon.cpp +++ b/xbmc/addons/AddonCallbacksAddon.cpp @@ -46,6 +46,7 @@ CAddonCallbacksAddon::CAddonCallbacksAddon(CAddon* addon) m_callbacks->UnknownToUTF8 = UnknownToUTF8; m_callbacks->GetLocalizedString = GetLocalizedString; m_callbacks->GetDVDMenuLanguage = GetDVDMenuLanguage; + m_callbacks->FreeString = FreeString; m_callbacks->OpenFile = OpenFile; m_callbacks->OpenFileForWrite = OpenFileForWrite; @@ -270,6 +271,11 @@ char* CAddonCallbacksAddon::GetDVDMenuLanguage(const void* addonData) return buffer; } +void CAddonCallbacksAddon::FreeString(const void* addonData, char* str) +{ + delete[] str; +} + void* CAddonCallbacksAddon::OpenFile(const void* addonData, const char* strFileName, unsigned int flags) { CAddonCallbacks* helper = (CAddonCallbacks*) addonData; diff --git a/xbmc/addons/AddonCallbacksAddon.h b/xbmc/addons/AddonCallbacksAddon.h index d9053f1cfe..ef727904c3 100644 --- a/xbmc/addons/AddonCallbacksAddon.h +++ b/xbmc/addons/AddonCallbacksAddon.h @@ -41,6 +41,7 @@ public: static char* UnknownToUTF8(const char *strSource); static char* GetLocalizedString(const void* addonData, long dwCode); static char* GetDVDMenuLanguage(const void* addonData); + static void FreeString(const void* addonData, char* str); // file operations static void* OpenFile(const void* addonData, const char* strFileName, unsigned int flags); |