31 LOGE(
"Not Supported!");
39 virtual int index() {
return -1; }
55 const char* str,
int len),
73 virtual const char*
toStr() {
return nullptr; }
115 LOGI(
"setCallbackSelectStream not provided");
152 Stream* (*nextStreamCallback)(
int offset) =
nullptr;
176 virtual void addName(
const char* nameWithPath) = 0;
187 : dataSource(dataSource), prefix(prefix) {}
188 void setPrefix(
const char* prefix) { this->prefix = prefix; }
190 if (ch ==
'\n' || ch ==
'\r') {
192 if (line_buffer.
length() > 0) {
194 if (prefix !=
nullptr) {
198 name.add(line_buffer.
c_str());
199 LOGD(
"adding '%s'", name.c_str());
200 dataSource.
addName(name.c_str());
203 LOGD(
"adding '%s'", line_buffer.
c_str());
206 line_buffer.
clear(
false);
211 line_buffer.
add((
char)ch);
216 size_t write(
const uint8_t* buffer,
size_t size)
override {
217 for (
size_t i = 0; i < size; i++) {
225 if (line_buffer.
length() > 0) {
233 Str line_buffer{200};
234 const char* prefix =
nullptr;
255template <
typename FileType>
258 typedef FileType* (*FileToStreamCallback)(
const char* path,
278 if (
files.empty())
return nullptr;
294 if (
files.empty() || index < 0 || index >= (
int)
files.size()) {
308 LOGE(
"No file to stream callback set!");
315 if (path ==
nullptr)
return nullptr;
322 LOGE(
"File not found: %s", path);
331 if (path ==
nullptr)
return -1;
334 for (
int i = 0; i < (int)
files.size(); i++) {
336 if (fullPath.
equals(path)) {
344 void addName(
const char* nameWithPath)
override {
346 if (nameWithPath ==
nullptr)
return;
347 LOGI(
"addName: '%s'", nameWithPath);
350 StrView nameWithPathStr(nameWithPath);
351 int lastSlashPos = nameWithPathStr.
lastIndexOf(
"/");
352 int len = nameWithPathStr.
length();
356 if (lastSlashPos < 0) {
359 nameStr.
set(nameWithPath);
362 pathStr.
substring(nameWithPath, 0, lastSlashPos);
363 nameStr.
substring(nameWithPath, lastSlashPos + 1, len);
371 files.push_back(entry);
378 if (nameWithPath ==
nullptr)
return false;
380 int idx =
indexOf(nameWithPath);
382 LOGI(
"deleteName: '%s' at index %d", nameWithPath, idx);
386 LOGW(
"deleteName: File not found: '%s'", nameWithPath);
393 if (idx >=
files.size()) {
394 LOGW(
"deleteIndex: Invalid index: %d (size: %d)", (
int)idx,
files.size());
398 LOGI(
"deleteIndex: Removing file at index %d", (
int)idx);
413 template <
typename T,
size_t N>
415 for (
size_t i = 0; i < N; i++) {
444 static FileType empty;
449 virtual const char*
toStr()
override {
470 if (path ==
nullptr) path =
"";
491 if (index < 0 || index >= (
int)
files.size()) {
514 if (pathIndex >= 0 && pathIndex < (
int)
path_registry.size()) {
538template <
typename FileType>
541 typedef FileType* (*FileToStreamCallback)(
const char* path, FileType& file);
591 LOGI(
"selectStream: %d -> %s",
index, filePath);
598 LOGE(
"No file to stream callback set or invalid file path!");
605 if (path ==
nullptr)
return nullptr;
612 LOGE(
"File not found: %s", path);
621 if (path ==
nullptr)
return -1;
663 static FileType empty;
676 virtual const char*
toStr()
override {
#define LOGW(...)
Definition AudioLoggerIDF.h:29
#define TRACED()
Definition AudioLoggerIDF.h:31
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGD(...)
Definition AudioLoggerIDF.h:27
#define LOGE(...)
Definition AudioLoggerIDF.h:30
File entry to minimize RAM usage by using path index and name.
Definition AudioSource.h:160
int path_index
Definition AudioSource.h:161
Str name
Definition AudioSource.h:162
FileEntry()
Definition AudioSource.h:164
FileEntry(int pathIdx, const char *fileName)
Definition AudioSource.h:166