library: Add a lookup_path() function
This returns a pointer to the library :: Library structure requested. The gui will use this to display information about each path. Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
parent
fa51433b94
commit
5dd5ec6db0
|
@ -690,9 +690,6 @@ Library: (lib/library.cpp)
|
|||
If dir is not a directory:
|
||||
throw -EINVAL
|
||||
|
||||
Add new row to the library_db table, begin an update only
|
||||
on the new path.
|
||||
|
||||
void library :: del_path(unsigned int lib_id);
|
||||
Invalidate a library_db row and all tracks owned by that path
|
||||
if lib_id is not valid, throw -EEXIST.
|
||||
|
@ -708,7 +705,7 @@ Library: (lib/library.cpp)
|
|||
Fill out a Song structure for the provided track_id.
|
||||
Throw -EEXIST if there is no track mapping to track_id.
|
||||
|
||||
struct library :: Library *library :: get_path_info(unsigned int id);
|
||||
struct library :: Library *library :: lookup_path(unsigned int id);
|
||||
Return the library path with index id.
|
||||
Throw -EEXIST if there is no such path.
|
||||
|
||||
|
|
|
@ -163,9 +163,6 @@ Library: (lib/library.cpp)
|
|||
If dir is not a directory:
|
||||
throw -EINVAL
|
||||
|
||||
Add new row to the library_db table, begin an update only
|
||||
on the new path.
|
||||
|
||||
void library :: del_path(unsigned int lib_id);
|
||||
Invalidate a library_db row and all tracks owned by that path
|
||||
if lib_id is not valid, throw -EEXIST.
|
||||
|
@ -181,7 +178,7 @@ Library: (lib/library.cpp)
|
|||
Fill out a Song structure for the provided track_id.
|
||||
Throw -EEXIST if there is no track mapping to track_id.
|
||||
|
||||
struct library :: Library *library :: get_path_info(unsigned int id);
|
||||
struct library :: Library *library :: lookup_path(unsigned int id);
|
||||
Return the library path with index id.
|
||||
Throw -EEXIST if there is no such path.
|
||||
|
||||
|
|
|
@ -122,6 +122,7 @@ namespace library
|
|||
void update_path(unsigned int);
|
||||
void update_all();
|
||||
void lookup(unsigned int, library :: Song *);
|
||||
Library *lookup_path(unsigned int);
|
||||
void import();
|
||||
#ifdef CONFIG_DEBUG
|
||||
void print_db(DB_Type);
|
||||
|
|
|
@ -203,8 +203,6 @@ library :: Track :: Track(TagLib :: Tag *tag, TagLib :: AudioProperties *audio,
|
|||
ss << "0";
|
||||
ss << seconds;
|
||||
length_str = ss.str();
|
||||
|
||||
library_db[library_id].size++;
|
||||
}
|
||||
|
||||
library :: Track :: Track(struct ImportData *data, unsigned int lib,
|
||||
|
@ -229,8 +227,6 @@ library :: Track :: Track(struct ImportData *data, unsigned int lib,
|
|||
ss << "0";
|
||||
ss << seconds;
|
||||
length_str = ss.str();
|
||||
|
||||
library_db[library_id].size++;
|
||||
}
|
||||
|
||||
void library :: Track :: read(File &f)
|
||||
|
@ -299,6 +295,7 @@ static void read_tags(unsigned int lib_id, const std :: string &path)
|
|||
genre_id = genre_db.insert(library :: AGInfo(library :: DB_GENRE, tag));
|
||||
track_db.insert(library :: Track(tag, audio, lib_id, artist_id,
|
||||
album_id, genre_id, path));
|
||||
library_db[lib_id].size++;
|
||||
}
|
||||
|
||||
static void process_path(unsigned int lib_id, const std :: string &dir,
|
||||
|
@ -392,6 +389,7 @@ static void do_import_track(File &f, unsigned int lib_id)
|
|||
album_id = album_db.insert(library :: Album(album, year, artist_id));
|
||||
genre_id = genre_db.insert(library :: AGInfo(library :: DB_GENRE, genre));
|
||||
track_db.insert(library :: Track(&data, lib_id, artist_id, album_id, genre_id));
|
||||
library_db[lib_id].size++;
|
||||
}
|
||||
|
||||
static void do_import_library(std::string &s)
|
||||
|
@ -481,6 +479,15 @@ void library :: lookup(unsigned int id, library :: Song *song)
|
|||
song->library = &library_db[song->track->library_id];
|
||||
}
|
||||
|
||||
library :: Library *library :: lookup_path(unsigned int id)
|
||||
{
|
||||
if (id >= library_db.num_rows())
|
||||
throw -EEXIST;
|
||||
if (library_db[id].valid == false)
|
||||
throw -EEXIST;
|
||||
return &library_db[id];
|
||||
}
|
||||
|
||||
void library :: import()
|
||||
{
|
||||
unsigned int i = 0;
|
||||
|
|
|
@ -84,7 +84,33 @@ void test_lookup(const std::string &test, const unsigned int track_id, bool expe
|
|||
song.genre->key_lower.c_str(),
|
||||
song.library->root_path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void test_path_lookup(const std::string &test, unsigned int lib_id, bool expected)
|
||||
{
|
||||
library :: Library *lib;
|
||||
|
||||
print("Test %s (lib_id == %u): ", test.c_str(), lib_id);
|
||||
|
||||
try {
|
||||
lib = library :: lookup_path(lib_id);
|
||||
if (expected == true)
|
||||
print("PASSED\n");
|
||||
else
|
||||
print("FAILED, no error produced\n");
|
||||
|
||||
print("%s (", lib->root_path.c_str());
|
||||
if (lib->enabled)
|
||||
print("enabled");
|
||||
else
|
||||
print("disabled");
|
||||
print(") size = %u\n", lib->size);
|
||||
} catch (int error) {
|
||||
if (expected == true)
|
||||
print("FAILED, unexpected error %d\n", error);
|
||||
else
|
||||
print("PASSED\n");
|
||||
}
|
||||
}
|
||||
|
||||
void test_print_dbs(const std::string &test)
|
||||
|
@ -173,6 +199,11 @@ void test_5()
|
|||
test_lookup("5d", 42, true);
|
||||
/* Lookup beyond db */
|
||||
test_lookup("5e", 100000, false);
|
||||
|
||||
/* Lookup path id = 0 */
|
||||
test_path_lookup("5f", 0, true);
|
||||
/* Lookup path id that doesn't exist */
|
||||
test_path_lookup("5g", 1, false);
|
||||
print("\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ Valid rows: 0
|
|||
Test 1a: PASSED
|
||||
Allocated rows: 1
|
||||
Valid rows: 1
|
||||
db[0] = /tmp/library/0 (enabled)
|
||||
db[0] = /tmp/library/0 (enabled), size = 150
|
||||
Test 1b
|
||||
Allocated rows: 1
|
||||
Valid rows: 0
|
||||
|
@ -22,27 +22,27 @@ Valid rows: 0
|
|||
Test 2a: PASSED
|
||||
Allocated rows: 1
|
||||
Valid rows: 1
|
||||
db[0] = /tmp/library/0 (enabled)
|
||||
db[0] = /tmp/library/0 (enabled), size = 150
|
||||
Test 2b: PASSED
|
||||
Allocated rows: 2
|
||||
Valid rows: 2
|
||||
db[0] = /tmp/library/0 (enabled)
|
||||
db[1] = /tmp/library/1 (enabled)
|
||||
db[0] = /tmp/library/0 (enabled), size = 150
|
||||
db[1] = /tmp/library/1 (enabled), size = 150
|
||||
Test 2c: PASSED
|
||||
Allocated rows: 3
|
||||
Valid rows: 3
|
||||
db[0] = /tmp/library/0 (enabled)
|
||||
db[1] = /tmp/library/1 (enabled)
|
||||
db[2] = /tmp/library/2 (enabled)
|
||||
db[0] = /tmp/library/0 (enabled), size = 150
|
||||
db[1] = /tmp/library/1 (enabled), size = 150
|
||||
db[2] = /tmp/library/2 (enabled), size = 150
|
||||
Test 2d
|
||||
Allocated rows: 3
|
||||
Valid rows: 2
|
||||
db[0] = /tmp/library/0 (enabled)
|
||||
db[2] = /tmp/library/2 (enabled)
|
||||
db[0] = /tmp/library/0 (enabled), size = 150
|
||||
db[2] = /tmp/library/2 (enabled), size = 150
|
||||
Test 2e
|
||||
Allocated rows: 3
|
||||
Valid rows: 1
|
||||
db[2] = /tmp/library/2 (enabled)
|
||||
db[2] = /tmp/library/2 (enabled), size = 150
|
||||
Test 2f
|
||||
Allocated rows: 3
|
||||
Valid rows: 0
|
||||
|
@ -50,32 +50,32 @@ Valid rows: 0
|
|||
Test 3a: PASSED
|
||||
Allocated rows: 1
|
||||
Valid rows: 1
|
||||
db[0] = /tmp/library/0 (enabled)
|
||||
db[0] = /tmp/library/0 (enabled), size = 150
|
||||
Test 3b: PASSED
|
||||
Allocated rows: 2
|
||||
Valid rows: 2
|
||||
db[0] = /tmp/library/0 (enabled)
|
||||
db[1] = /tmp/library/1 (enabled)
|
||||
db[0] = /tmp/library/0 (enabled), size = 150
|
||||
db[1] = /tmp/library/1 (enabled), size = 150
|
||||
Test 3c: PASSED
|
||||
Allocated rows: 3
|
||||
Valid rows: 3
|
||||
db[0] = /tmp/library/0 (enabled)
|
||||
db[1] = /tmp/library/1 (enabled)
|
||||
db[2] = /tmp/library/2 (enabled)
|
||||
db[0] = /tmp/library/0 (enabled), size = 150
|
||||
db[1] = /tmp/library/1 (enabled), size = 150
|
||||
db[2] = /tmp/library/2 (enabled), size = 150
|
||||
Test 3d
|
||||
Allocated rows: 0
|
||||
Valid rows: 0
|
||||
Test 3e
|
||||
Allocated rows: 3
|
||||
Valid rows: 3
|
||||
db[0] = /tmp/library/0 (enabled)
|
||||
db[1] = /tmp/library/1 (enabled)
|
||||
db[2] = /tmp/library/2 (enabled)
|
||||
db[0] = /tmp/library/0 (enabled), size = 0
|
||||
db[1] = /tmp/library/1 (enabled), size = 0
|
||||
db[2] = /tmp/library/2 (enabled), size = 0
|
||||
|
||||
Test 4a: PASSED
|
||||
Allocated rows: 1
|
||||
Valid rows: 1
|
||||
db[0] = /tmp/library/0 (enabled)
|
||||
db[0] = /tmp/library/0 (enabled), size = 150
|
||||
Allocated rows: 5
|
||||
Valid rows: 5
|
||||
db[0] = Artist: Artist 2
|
||||
|
@ -715,7 +715,7 @@ Test 5a (track_id == 0): PASSED
|
|||
Test 5b: PASSED
|
||||
Allocated rows: 1
|
||||
Valid rows: 1
|
||||
db[0] = /tmp/library/0 (enabled)
|
||||
db[0] = /tmp/library/0 (enabled), size = 150
|
||||
Test 5c (track_id == 0): PASSED
|
||||
Track 10 (track 10) by Artist 2 (artist 2) from Album 2 (album 2) Length: 1:00
|
||||
Genre: Tryout (tryout), Library: /tmp/library/0
|
||||
|
@ -723,11 +723,14 @@ Test 5d (track_id == 42): PASSED
|
|||
Track 8 (track 8) by Artist 4 (artist 4) from Album 1 (album 1) Length: 0:01
|
||||
Genre: Trial (trial), Library: /tmp/library/0
|
||||
Test 5e (track_id == 100000): PASSED
|
||||
Test 5f (lib_id == 0): PASSED
|
||||
/tmp/library/0 (enabled) size = 150
|
||||
Test 5g (lib_id == 1): PASSED
|
||||
|
||||
Test 6a: PASSED
|
||||
Allocated rows: 1
|
||||
Valid rows: 1
|
||||
db[0] = /tmp/library/0 (enabled)
|
||||
db[0] = /tmp/library/0 (enabled), size = 150
|
||||
|
||||
6b: Updating library 0 (nothing should change)
|
||||
Allocated rows: 150
|
||||
|
@ -1364,6 +1367,9 @@ Removing file: /tmp/library/0/Artist 2/Album 0/4 - Track 4.ogg
|
|||
Removing file: /tmp/library/0/Artist 2/Album 0/3 - Track 3.ogg
|
||||
Removing file: /tmp/library/0/Artist 2/Album 0/2 - Track 2.ogg
|
||||
Removing file: /tmp/library/0/Artist 2/Album 0/1 - Track 1.ogg
|
||||
Allocated rows: 1
|
||||
Valid rows: 1
|
||||
db[0] = /tmp/library/0 (enabled), size = 120
|
||||
Allocated rows: 150
|
||||
Valid rows: 120
|
||||
db[30] = 10. Track 10 by Artist 4 from Album 2 (2013)
|
||||
|
@ -2456,3 +2462,22 @@ db[179] = 1. Track 1 by Artist 2 from Album 0 (2011)
|
|||
Genre: Test, Length: 10 (seconds)
|
||||
Play count: 0, last played 0/0/0
|
||||
Artist 2/Album 0/1 - Track 1.ogg
|
||||
|
||||
Test 7a: PASSED
|
||||
Allocated rows: 1
|
||||
Valid rows: 1
|
||||
db[0] = /tmp/library/2 (enabled), size = 150
|
||||
|
||||
Importing: /home/anna/.ocarina-test/library/0
|
||||
Version mismatch: 1 != 2
|
||||
Importing: /home/anna/.ocarina-test/library/1
|
||||
Library already contains path: /tmp/library/2, skipping
|
||||
Importing: /home/anna/.ocarina-test/library/2
|
||||
Adding path: /tmp/library/3
|
||||
Importing: /home/anna/.ocarina-test/library/3
|
||||
Adding path: /tmp/library/4
|
||||
Allocated rows: 3
|
||||
Valid rows: 3
|
||||
db[0] = /tmp/library/2 (enabled), size = 150
|
||||
db[1] = /tmp/library/3 (enabled), size = 150
|
||||
db[2] = /tmp/library/4 (enabled), size = 150
|
||||
|
|
Loading…
Reference in New Issue