summaryrefslogtreecommitdiff
path: root/src/database/include
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-04-26 15:21:32 +1000
committerjacqueline <me@jacqueline.id.au>2023-04-26 15:21:32 +1000
commitfbe047a35fff100cb5f42d10984bccde137f586e (patch)
treeab05dff1142f6a6a14f4b03a4340672a5e65976a /src/database/include
parent083f4011aa740d492d9a9ceb07c7228003f5ad39 (diff)
downloadtangara-fw-fbe047a35fff100cb5f42d10984bccde137f586e.tar.gz
Add some basic data and retrieval
Diffstat (limited to 'src/database/include')
-rw-r--r--src/database/include/database.hpp23
-rw-r--r--src/database/include/file_gatherer.hpp11
-rw-r--r--src/database/include/tag_processor.hpp13
3 files changed, 40 insertions, 7 deletions
diff --git a/src/database/include/database.hpp b/src/database/include/database.hpp
index b9df5fd4..cb1437df 100644
--- a/src/database/include/database.hpp
+++ b/src/database/include/database.hpp
@@ -1,13 +1,18 @@
#pragma once
+#include <string>
#include <memory>
+#include <optional>
#include "leveldb/cache.h"
#include "leveldb/db.h"
+#include "leveldb/iterator.h"
#include "result.hpp"
namespace database {
+class Iterator;
+
class Database {
public:
enum DatabaseError {
@@ -18,7 +23,10 @@ class Database {
~Database();
auto Initialise() -> void;
- auto Update() -> void;
+ auto ByTitle() -> Iterator;
+
+ Database(const Database&) = delete;
+ Database& operator=(const Database&) = delete;
private:
std::unique_ptr<leveldb::DB> db_;
@@ -27,4 +35,17 @@ class Database {
Database(leveldb::DB* db, leveldb::Cache* cache);
};
+class Iterator {
+ public:
+ explicit Iterator(leveldb::Iterator *it) : it_(it) {}
+
+ auto Next() -> std::optional<std::string>;
+
+ Iterator(const Iterator&) = delete;
+ Iterator& operator=(const Iterator&) = delete;
+
+ private:
+ std::unique_ptr<leveldb::Iterator> it_;
+};
+
} // namespace database
diff --git a/src/database/include/file_gatherer.hpp b/src/database/include/file_gatherer.hpp
index 47d40f88..7cf00b41 100644
--- a/src/database/include/file_gatherer.hpp
+++ b/src/database/include/file_gatherer.hpp
@@ -12,7 +12,7 @@ namespace database {
static_assert(sizeof(TCHAR) == sizeof(char), "TCHAR must be CHAR");
template <typename Callback>
-auto FindFiles(FATFS* fs, const std::string& root, Callback cb) -> void {
+auto FindFiles(const std::string& root, Callback cb) -> void {
std::deque<std::string> to_explore;
to_explore.push_back(root);
@@ -20,7 +20,7 @@ auto FindFiles(FATFS* fs, const std::string& root, Callback cb) -> void {
std::string next_path_str = to_explore.front();
const TCHAR* next_path = static_cast<const TCHAR*>(next_path_str.c_str());
- DIR dir;
+ FF_DIR dir;
FRESULT res = f_opendir(&dir, next_path);
if (res != FR_OK) {
// TODO: log.
@@ -30,10 +30,10 @@ auto FindFiles(FATFS* fs, const std::string& root, Callback cb) -> void {
for (;;) {
FILINFO info;
res = f_readdir(&dir, &info);
- if (info.fname == NULL) {
+ if (res != FR_OK || info.fname[0] == 0) {
// No more files in the directory.
break;
- } else if (info.fattrib & (AM_HID | AM_SYS)) {
+ } else if (info.fattrib & (AM_HID | AM_SYS) || info.fname[0] == '.') {
// System or hidden file. Ignore it and move on.
continue;
} else {
@@ -45,7 +45,8 @@ auto FindFiles(FATFS* fs, const std::string& root, Callback cb) -> void {
to_explore.push_back(full_path.str());
} else {
// This is a file! Let the callback know about it.
- std::invoke(cb, full_path.str(), info);
+ //std::invoke(cb, full_path.str(), info);
+ std::invoke(cb, full_path.str());
}
}
}
diff --git a/src/database/include/tag_processor.hpp b/src/database/include/tag_processor.hpp
index 0257fc92..88c95b61 100644
--- a/src/database/include/tag_processor.hpp
+++ b/src/database/include/tag_processor.hpp
@@ -1,3 +1,14 @@
#pragma once
-namespace database {} // namespace database
+#include <string>
+
+namespace database {
+
+struct FileInfo {
+ bool is_playable;
+ std::string title;
+};
+
+auto GetInfo(const std::string &path, FileInfo *out) -> bool;
+
+} // namespace database