aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Morten Kvarving <cptspiff@gmail.com>2016-01-09 20:26:21 +0100
committerArne Morten Kvarving <cptspiff@gmail.com>2016-01-09 20:26:21 +0100
commit3f51d46a0f1d2e95e20f834beea3ff49581f0c51 (patch)
tree6e1411dd17a3e644eb307fadf8de1d7daa9f9ff0
parentf8a52f88982c96438a765efe297f1cbad84ef4bb (diff)
added: addon callback for listing a directory
-rw-r--r--addons/library.xbmc.addon/libXBMC_addon.h36
-rw-r--r--lib/addons/library.xbmc.addon/libXBMC_addon.cpp16
-rw-r--r--xbmc/addons/AddonCallbacks.h6
-rw-r--r--xbmc/addons/AddonCallbacksAddon.cpp54
-rw-r--r--xbmc/addons/AddonCallbacksAddon.h4
-rw-r--r--xbmc/addons/addon-bindings.mk1
-rw-r--r--xbmc/addons/include/kodi_vfs_types.h32
7 files changed, 148 insertions, 1 deletions
diff --git a/addons/library.xbmc.addon/libXBMC_addon.h b/addons/library.xbmc.addon/libXBMC_addon.h
index 06f61bab56..fd2fe9dc23 100644
--- a/addons/library.xbmc.addon/libXBMC_addon.h
+++ b/addons/library.xbmc.addon/libXBMC_addon.h
@@ -27,6 +27,8 @@
#include <stdint.h>
#include <stdarg.h>
+struct VFSDirEntry;
+
#ifdef _WIN32 // windows
#ifndef _SSIZE_T_DEFINED
typedef intptr_t ssize_t;
@@ -265,6 +267,14 @@ namespace ADDON
dlsym(m_libXBMC_addon, "XBMC_remove_directory");
if (XBMC_remove_directory == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
+ XBMC_get_directory = (bool (*)(void* HANDLE, void* CB, const char* strPath, const char* mask, VFSDirEntry** items, unsigned int* num_items))
+ dlsym(m_libXBMC_addon, "XBMC_get_directory");
+ if (XBMC_get_directory == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
+
+ XBMC_free_directory = (void (*)(void* HANDLE, void* CB, VFSDirEntry* items, unsigned int num_items))
+ dlsym(m_libXBMC_addon, "XBMC_free_directory");
+ if (XBMC_free_directory == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }
+
m_Callbacks = XBMC_register_me(m_Handle);
return m_Callbacks != NULL;
}
@@ -564,6 +574,29 @@ namespace ADDON
return XBMC_remove_directory(m_Handle, m_Callbacks, strPath);
}
+ /*!
+ * @brief Lists a directory.
+ * @param strPath Path to the directory.
+ * @param mask File mask
+ * @param items The directory entries
+ * @param num_items Number of entries in directory
+ * @return True if listing was successful, false otherwise.
+ */
+ bool GetDirectory(const char *strPath, const char* mask, VFSDirEntry** items, unsigned int* num_items)
+ {
+ return XBMC_get_directory(m_Handle, m_Callbacks, strPath, mask, items, num_items);
+ }
+
+ /*!
+ * @brief Free a directory list
+ * @param items The directory entries
+ * @param num_items Number of entries in directory
+ */
+ void FreeDirectory(VFSDirEntry* items, unsigned int num_items)
+ {
+ return XBMC_free_directory(m_Handle, m_Callbacks, items, num_items);
+ }
+
protected:
void* (*XBMC_register_me)(void *HANDLE);
void (*XBMC_unregister_me)(void *HANDLE, void* CB);
@@ -594,7 +627,8 @@ namespace ADDON
bool (*XBMC_create_directory)(void *HANDLE, void* CB, const char* strPath);
bool (*XBMC_directory_exists)(void *HANDLE, void* CB, const char* strPath);
bool (*XBMC_remove_directory)(void *HANDLE, void* CB, const char* strPath);
-
+ bool (*XBMC_get_directory)(void *HANDLE, void* CB, const char* strPath, const char* mask, VFSDirEntry** items, unsigned int* num_items);
+ void (*XBMC_free_directory)(void *HANDLE, void* CB, VFSDirEntry* items, unsigned int num_items);
private:
void *m_libXBMC_addon;
void *m_Handle;
diff --git a/lib/addons/library.xbmc.addon/libXBMC_addon.cpp b/lib/addons/library.xbmc.addon/libXBMC_addon.cpp
index e00bc77584..ffc5bbcb6b 100644
--- a/lib/addons/library.xbmc.addon/libXBMC_addon.cpp
+++ b/lib/addons/library.xbmc.addon/libXBMC_addon.cpp
@@ -276,4 +276,20 @@ DLLEXPORT bool XBMC_remove_directory(void *hdl, void* cb, const char *strPath)
return ((CB_AddOnLib*)cb)->RemoveDirectory(((AddonCB*)hdl)->addonData, strPath);
}
+DLLEXPORT bool XBMC_get_directory(void *hdl, void* cb, const char *strPath, const char* mask, VFSDirEntry** items, unsigned int* num_items)
+{
+ if (cb == NULL)
+ return false;
+
+ return ((CB_AddOnLib*)cb)->GetDirectory(((AddonCB*)hdl)->addonData, strPath, mask, items, num_items);
+}
+
+DLLEXPORT void XBMC_free_directory(void *hdl, void* cb, VFSDirEntry* items, unsigned int num_items)
+{
+ if (cb == NULL)
+ return;
+
+ ((CB_AddOnLib*)cb)->FreeDirectory(((AddonCB*)hdl)->addonData, items, num_items);
+}
+
};
diff --git a/xbmc/addons/AddonCallbacks.h b/xbmc/addons/AddonCallbacks.h
index eb4f65e9c1..d12c9a4715 100644
--- a/xbmc/addons/AddonCallbacks.h
+++ b/xbmc/addons/AddonCallbacks.h
@@ -37,6 +37,8 @@ typedef intptr_t ssize_t;
#endif // !_SSIZE_T_DEFINED
#endif // TARGET_WINDOWS
+struct VFSDirEntry;
+
typedef void (*AddOnLogCallback)(void *addonData, const ADDON::addon_log_t loglevel, const char *msg);
typedef void (*AddOnQueueNotification)(void *addonData, const ADDON::queue_msg_t type, const char *msg);
typedef bool (*AddOnWakeOnLan)(const char* mac);
@@ -65,6 +67,8 @@ typedef bool (*AddOnCanOpenDirectory)(const void* addonData, const char* strURL)
typedef bool (*AddOnCreateDirectory)(const void* addonData, const char *strPath);
typedef bool (*AddOnDirectoryExists)(const void* addonData, const char *strPath);
typedef bool (*AddOnRemoveDirectory)(const void* addonData, const char *strPath);
+typedef bool (*AddOnGetDirectory)(const void* addonData, const char *strPath, const char* mask, VFSDirEntry** items, unsigned int* num_items);
+typedef void (*AddOnFreeDirectory)(const void* addonData, VFSDirEntry* items, unsigned int num_items);
typedef struct CB_AddOn
{
@@ -96,6 +100,8 @@ typedef struct CB_AddOn
AddOnCreateDirectory CreateDirectory;
AddOnDirectoryExists DirectoryExists;
AddOnRemoveDirectory RemoveDirectory;
+ AddOnGetDirectory GetDirectory;
+ AddOnFreeDirectory FreeDirectory;
} CB_AddOnLib;
typedef xbmc_codec_t (*CODECGetCodecByName)(const void* addonData, const char* strCodecName);
diff --git a/xbmc/addons/AddonCallbacksAddon.cpp b/xbmc/addons/AddonCallbacksAddon.cpp
index 90e739da51..0f5a9931d2 100644
--- a/xbmc/addons/AddonCallbacksAddon.cpp
+++ b/xbmc/addons/AddonCallbacksAddon.cpp
@@ -31,6 +31,7 @@
#include "utils/CharsetConverter.h"
#include "utils/StringUtils.h"
#include "utils/XMLUtils.h"
+#include "addons/include/kodi_vfs_types.h"
using namespace XFILE;
@@ -72,6 +73,8 @@ CAddonCallbacksAddon::CAddonCallbacksAddon(CAddon* addon)
m_callbacks->CreateDirectory = CreateDirectory;
m_callbacks->DirectoryExists = DirectoryExists;
m_callbacks->RemoveDirectory = RemoveDirectory;
+ m_callbacks->GetDirectory = GetDirectory;
+ m_callbacks->FreeDirectory = FreeDirectory;
}
CAddonCallbacksAddon::~CAddonCallbacksAddon()
@@ -532,4 +535,55 @@ bool CAddonCallbacksAddon::RemoveDirectory(const void* addonData, const char *st
return CDirectory::Remove(strPath);
}
+static void CFileItemListToVFSDirEntries(VFSDirEntry* entries,
+ const CFileItemList& items)
+{
+ for (int i=0;i<items.Size();++i)
+ {
+ entries[i].label = strdup(items[i]->GetLabel().c_str());
+ entries[i].path = strdup(items[i]->GetPath().c_str());
+ entries[i].size = items[i]->m_dwSize;
+ entries[i].folder = items[i]->m_bIsFolder;
+ }
+}
+
+bool CAddonCallbacksAddon::GetDirectory(const void* addonData, const char *strPath, const char* mask, VFSDirEntry** items, unsigned int* num_items)
+{
+ CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
+ if (!helper)
+ return false;
+
+ CFileItemList fileItems;
+ if (!CDirectory::GetDirectory(strPath, fileItems, mask, DIR_FLAG_NO_FILE_DIRS))
+ return false;
+
+ if (fileItems.Size() > 0)
+ {
+ *num_items = static_cast<unsigned int>(fileItems.Size());
+ *items = new VFSDirEntry[fileItems.Size()];
+ }
+ else
+ {
+ *num_items = 0;
+ *items = nullptr;
+ }
+
+ CFileItemListToVFSDirEntries(*items, fileItems);
+ return true;
+}
+
+void CAddonCallbacksAddon::FreeDirectory(const void* addonData, VFSDirEntry* items, unsigned int num_items)
+{
+ CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
+ if (!helper)
+ return;
+
+ for (unsigned int i=0;i<num_items;++i)
+ {
+ free(items[i].label);
+ free(items[i].path);
+ }
+ delete[] items;
+}
+
}; /* namespace ADDON */
diff --git a/xbmc/addons/AddonCallbacksAddon.h b/xbmc/addons/AddonCallbacksAddon.h
index 6eed7cdbfd..e53b859239 100644
--- a/xbmc/addons/AddonCallbacksAddon.h
+++ b/xbmc/addons/AddonCallbacksAddon.h
@@ -21,6 +21,8 @@
#include "AddonCallbacks.h"
+struct VFSDirEntry;
+
namespace ADDON
{
@@ -64,6 +66,8 @@ public:
static bool CreateDirectory(const void* addonData, const char *strPath);
static bool DirectoryExists(const void* addonData, const char *strPath);
static bool RemoveDirectory(const void* addonData, const char *strPath);
+ static bool GetDirectory(const void* addondata, const char* strPath, const char* mask, VFSDirEntry** items, unsigned int* num_items);
+ static void FreeDirectory(const void* addondata, VFSDirEntry* items, unsigned int num_items);
private:
CB_AddOnLib *m_callbacks; /*!< callback addresses */
diff --git a/xbmc/addons/addon-bindings.mk b/xbmc/addons/addon-bindings.mk
index bac201ceb8..289b2bbeab 100644
--- a/xbmc/addons/addon-bindings.mk
+++ b/xbmc/addons/addon-bindings.mk
@@ -14,6 +14,7 @@ BINDINGS+=xbmc/addons/include/xbmc_pvr_dll.h
BINDINGS+=xbmc/addons/include/xbmc_pvr_types.h
BINDINGS+=xbmc/addons/include/xbmc_scr_dll.h
BINDINGS+=xbmc/addons/include/xbmc_scr_types.h
+BINDINGS+=xbmc/addons/include/kodi_vfs_types.h
BINDINGS+=xbmc/addons/include/xbmc_vis_dll.h
BINDINGS+=xbmc/addons/include/xbmc_vis_types.h
BINDINGS+=xbmc/addons/include/xbmc_stream_utils.hpp
diff --git a/xbmc/addons/include/kodi_vfs_types.h b/xbmc/addons/include/kodi_vfs_types.h
new file mode 100644
index 0000000000..b62c7b0c7f
--- /dev/null
+++ b/xbmc/addons/include/kodi_vfs_types.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2015 Team Kodi
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Kodi; see the file COPYING. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+#pragma once
+
+#include <stdint.h>
+
+extern "C"
+{
+ struct VFSDirEntry
+ {
+ char* label; //!< item label
+ char* path; //!< item path
+ bool folder; //!< Item is a folder
+ uint64_t size; //!< Size of file represented by item
+ };
+}