libsaria: Add the library path to the libsaria namespace
I want to move it to a global header file, so it needs to be added to the libsaria namespace. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
3d511a1f19
commit
d6c48ca177
|
@ -18,7 +18,7 @@ static void do_load()
|
|||
in >> size;
|
||||
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
path_list.push_back(LibraryPath());
|
||||
path_list.push_back(libsaria::LibraryPath());
|
||||
path_list.back().load_file(in);
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ namespace libsaria
|
|||
void library::save()
|
||||
{
|
||||
OutFile out("library.lib");
|
||||
list<LibraryPath>::iterator it;
|
||||
list<libsaria::LibraryPath>::iterator it;
|
||||
|
||||
out << path_list.size() << "\n";
|
||||
for (it = path_list.begin(); it != path_list.end(); it++)
|
||||
|
|
|
@ -8,9 +8,9 @@ using namespace std;
|
|||
#include <libsaria/library.h>
|
||||
#include "library.h"
|
||||
|
||||
list<LibraryPath> path_list;
|
||||
list<libsaria::LibraryPath> path_list;
|
||||
|
||||
static void do_update(list<LibraryPath>::iterator it)
|
||||
static void do_update(list<libsaria::LibraryPath>::iterator it)
|
||||
{
|
||||
it->validate();
|
||||
it->update();
|
||||
|
|
|
@ -5,6 +5,6 @@
|
|||
using namespace std;
|
||||
#include "path/path.h"
|
||||
|
||||
extern list<LibraryPath> path_list;
|
||||
extern list<libsaria::LibraryPath> path_list;
|
||||
|
||||
#endif /* LIBSARIA_LIBRARY_SOURCE_H */
|
||||
|
|
|
@ -2,28 +2,31 @@
|
|||
#include "../library.h"
|
||||
#include "path.h"
|
||||
|
||||
void LibraryPath::load_file(InFile &in)
|
||||
namespace libsaria
|
||||
{
|
||||
unsigned int size;
|
||||
libsaria::Track *track;
|
||||
void LibraryPath::load_file(InFile &in)
|
||||
{
|
||||
unsigned int size;
|
||||
libsaria::Track *track;
|
||||
|
||||
in >> path;
|
||||
in >> size;
|
||||
println("Library path dir: " + path);
|
||||
println("Library path size: %d", size);
|
||||
in >> path;
|
||||
in >> size;
|
||||
println("Library path dir: " + path);
|
||||
println("Library path size: %d", size);
|
||||
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
track = new libsaria::Track(in);
|
||||
file_list.push_back(track);
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
track = new libsaria::Track(in);
|
||||
file_list.push_back(track);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryPath::save(OutFile &out)
|
||||
{
|
||||
list<libsaria::Track *>::iterator it;
|
||||
void LibraryPath::save(OutFile &out)
|
||||
{
|
||||
list<libsaria::Track *>::iterator it;
|
||||
|
||||
out << path << file_list.size() << "\n";
|
||||
for (it = file_list.begin(); it != file_list.end(); it++)
|
||||
(*it)->save(out);
|
||||
}
|
||||
out << path << file_list.size() << "\n";
|
||||
for (it = file_list.begin(); it != file_list.end(); it++)
|
||||
(*it)->save(out);
|
||||
}
|
||||
|
||||
}; /* Namespace: libsaria */
|
||||
|
|
|
@ -4,48 +4,53 @@
|
|||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
LibraryPath::LibraryPath()
|
||||
namespace libsaria
|
||||
{
|
||||
}
|
||||
|
||||
LibraryPath::LibraryPath(string dir)
|
||||
{
|
||||
path = dir;
|
||||
}
|
||||
|
||||
LibraryPath::~LibraryPath()
|
||||
{
|
||||
list<libsaria::Track *>::iterator it;
|
||||
for (it = file_list.begin(); it != file_list.end(); it++)
|
||||
delete (*it);
|
||||
}
|
||||
|
||||
void LibraryPath::prepare_for_removal()
|
||||
{
|
||||
list<libsaria::Track *>::iterator it;
|
||||
for (it = file_list.begin(); it != file_list.end(); it++)
|
||||
(*it)->do_cleanup();
|
||||
}
|
||||
|
||||
string LibraryPath::get_path()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
void LibraryPath::get_info(void (*info_func)(struct libsaria::library::PathInfo &))
|
||||
{
|
||||
struct libsaria::library::PathInfo info;
|
||||
info.path = path;
|
||||
info.size = file_list.size();
|
||||
info_func(info);
|
||||
}
|
||||
|
||||
bool LibraryPath::has_id(sid_t id)
|
||||
{
|
||||
list<libsaria::Track *>::iterator it;
|
||||
for (it = file_list.begin(); it != file_list.end(); it++) {
|
||||
if ((*it)->get_songid() == id)
|
||||
return true;
|
||||
LibraryPath::LibraryPath()
|
||||
{
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
LibraryPath::LibraryPath(string dir)
|
||||
{
|
||||
path = dir;
|
||||
}
|
||||
|
||||
LibraryPath::~LibraryPath()
|
||||
{
|
||||
list<libsaria::Track *>::iterator it;
|
||||
for (it = file_list.begin(); it != file_list.end(); it++)
|
||||
delete (*it);
|
||||
}
|
||||
|
||||
void LibraryPath::prepare_for_removal()
|
||||
{
|
||||
list<libsaria::Track *>::iterator it;
|
||||
for (it = file_list.begin(); it != file_list.end(); it++)
|
||||
(*it)->do_cleanup();
|
||||
}
|
||||
|
||||
string LibraryPath::get_path()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
void LibraryPath::get_info(void (*info_func)(struct libsaria::library::PathInfo &))
|
||||
{
|
||||
struct libsaria::library::PathInfo info;
|
||||
info.path = path;
|
||||
info.size = file_list.size();
|
||||
info_func(info);
|
||||
}
|
||||
|
||||
bool LibraryPath::has_id(sid_t id)
|
||||
{
|
||||
list<libsaria::Track *>::iterator it;
|
||||
for (it = file_list.begin(); it != file_list.end(); it++) {
|
||||
if ((*it)->get_songid() == id)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} /* Namespace: libsaria */
|
||||
|
|
|
@ -8,28 +8,30 @@
|
|||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
class LibraryPath
|
||||
namespace libsaria
|
||||
{
|
||||
private:
|
||||
string path;
|
||||
list<libsaria::Track *> file_list;
|
||||
bool has_id(sid_t);
|
||||
class LibraryPath {
|
||||
private:
|
||||
string path;
|
||||
list<libsaria::Track *> file_list;
|
||||
bool has_id(sid_t);
|
||||
|
||||
public:
|
||||
LibraryPath();
|
||||
LibraryPath(string);
|
||||
~LibraryPath();
|
||||
public:
|
||||
LibraryPath();
|
||||
LibraryPath(string);
|
||||
~LibraryPath();
|
||||
|
||||
void load_file(InFile &);
|
||||
string get_path();
|
||||
void prepare_for_removal();
|
||||
void get_info(void (*)(struct libsaria::library::PathInfo &));
|
||||
void add_track(string &, sid_t &);
|
||||
void validate_track(libsaria::Track *);
|
||||
void save(OutFile &);
|
||||
void load_file(InFile &);
|
||||
string get_path();
|
||||
void prepare_for_removal();
|
||||
void get_info(void (*)(struct libsaria::library::PathInfo &));
|
||||
void add_track(string &, sid_t &);
|
||||
void validate_track(libsaria::Track *);
|
||||
void save(OutFile &);
|
||||
|
||||
void update();
|
||||
void validate();
|
||||
};
|
||||
void update();
|
||||
void validate();
|
||||
};
|
||||
}; /* Namespace: libsaria */
|
||||
|
||||
#endif /* LIBSARIA_LIBRARY_PATH_H */
|
||||
|
|
|
@ -14,11 +14,11 @@ using namespace std;
|
|||
class ScanTask : public IdleTask
|
||||
{
|
||||
private:
|
||||
LibraryPath *lib_path;
|
||||
libsaria::LibraryPath *lib_path;
|
||||
list<pair<string, sid_t> > files;
|
||||
|
||||
public:
|
||||
ScanTask(LibraryPath *path)
|
||||
ScanTask(libsaria::LibraryPath *path)
|
||||
{
|
||||
lib_path = path;
|
||||
}
|
||||
|
@ -36,11 +36,11 @@ class ScanTask : public IdleTask
|
|||
class ReaddirTask : public IdleTask
|
||||
{
|
||||
private:
|
||||
LibraryPath *lib_path;
|
||||
libsaria::LibraryPath *lib_path;
|
||||
ScanTask *read_dir(string, ScanTask *);
|
||||
|
||||
public:
|
||||
ReaddirTask(LibraryPath *path)
|
||||
ReaddirTask(libsaria::LibraryPath *path)
|
||||
{
|
||||
lib_path = path;
|
||||
};
|
||||
|
@ -48,7 +48,7 @@ class ReaddirTask : public IdleTask
|
|||
void run_task();
|
||||
};
|
||||
|
||||
static ScanTask *scandir(string dir, LibraryPath *lib_path, ScanTask *scan);
|
||||
static ScanTask *scandir(string dir, libsaria::LibraryPath *lib_path, ScanTask *scan);
|
||||
|
||||
void ScanTask::run_task()
|
||||
{
|
||||
|
@ -74,7 +74,7 @@ void ScanTask::run_task()
|
|||
}
|
||||
|
||||
static inline ScanTask *scan_entry(struct dirent *dirp,
|
||||
LibraryPath *lib_path,
|
||||
libsaria::LibraryPath *lib_path,
|
||||
string &dir,
|
||||
ScanTask *scan)
|
||||
{
|
||||
|
@ -101,7 +101,7 @@ static inline ScanTask *scan_entry(struct dirent *dirp,
|
|||
return scan;
|
||||
}
|
||||
|
||||
static ScanTask *scandir(string dir, LibraryPath *lib_path, ScanTask *scan)
|
||||
static ScanTask *scandir(string dir, libsaria::LibraryPath *lib_path, ScanTask *scan)
|
||||
{
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
|
@ -126,17 +126,22 @@ void ReaddirTask::run_task()
|
|||
scan->queue();
|
||||
}
|
||||
|
||||
void LibraryPath::add_track(string &filepath, sid_t &songid)
|
||||
namespace libsaria
|
||||
{
|
||||
libsaria::Track *track;
|
||||
if (has_id(songid) == false) {
|
||||
track = new libsaria::Track(filepath, songid);
|
||||
file_list.push_back(track);
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryPath::update()
|
||||
{
|
||||
ReaddirTask *task = new ReaddirTask(this);
|
||||
task->queue();
|
||||
}
|
||||
void LibraryPath::add_track(string &filepath, sid_t &songid)
|
||||
{
|
||||
libsaria::Track *track;
|
||||
if (has_id(songid) == false) {
|
||||
track = new libsaria::Track(filepath, songid);
|
||||
file_list.push_back(track);
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryPath::update()
|
||||
{
|
||||
ReaddirTask *task = new ReaddirTask(this);
|
||||
task->queue();
|
||||
}
|
||||
|
||||
} /* Namespace: libsaria */
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
class ValidateTask : public IdleTask
|
||||
{
|
||||
private:
|
||||
LibraryPath *lib_path;
|
||||
libsaria::LibraryPath *lib_path;
|
||||
list<libsaria::Track *> tracks;
|
||||
|
||||
public:
|
||||
ValidateTask(LibraryPath *path)
|
||||
ValidateTask(libsaria::LibraryPath *path)
|
||||
{
|
||||
lib_path = path;
|
||||
}
|
||||
|
@ -34,27 +34,32 @@ void ValidateTask::run_task()
|
|||
}
|
||||
}
|
||||
|
||||
void LibraryPath::validate_track(libsaria::Track *track)
|
||||
namespace libsaria
|
||||
{
|
||||
string filepath = track->get_filepath();
|
||||
if (lookup_songid(filepath) == track->get_songid())
|
||||
return;
|
||||
track->do_cleanup();
|
||||
delete track;
|
||||
file_list.remove(track);
|
||||
}
|
||||
|
||||
void LibraryPath::validate()
|
||||
{
|
||||
list<libsaria::Track *>::iterator it;
|
||||
ValidateTask *validate = new ValidateTask(this);
|
||||
println("Validating");
|
||||
|
||||
for (it = file_list.begin(); it != file_list.end(); it++) {
|
||||
if (validate->add_track(*it) > MAX_VALIDATE) {
|
||||
validate->queue();
|
||||
validate = new ValidateTask(this);
|
||||
}
|
||||
void LibraryPath::validate_track(libsaria::Track *track)
|
||||
{
|
||||
string filepath = track->get_filepath();
|
||||
if (lookup_songid(filepath) == track->get_songid())
|
||||
return;
|
||||
track->do_cleanup();
|
||||
delete track;
|
||||
file_list.remove(track);
|
||||
}
|
||||
validate->queue();
|
||||
}
|
||||
|
||||
void LibraryPath::validate()
|
||||
{
|
||||
list<libsaria::Track *>::iterator it;
|
||||
ValidateTask *validate = new ValidateTask(this);
|
||||
println("Validating");
|
||||
|
||||
for (it = file_list.begin(); it != file_list.end(); it++) {
|
||||
if (validate->add_track(*it) > MAX_VALIDATE) {
|
||||
validate->queue();
|
||||
validate = new ValidateTask(this);
|
||||
}
|
||||
}
|
||||
validate->queue();
|
||||
}
|
||||
|
||||
} /* Namespace: libsaria */
|
||||
|
|
Loading…
Reference in New Issue