libsaria: New current_track() function

Instead of taking a callback function,  I instead find a pointer to the
current track and return this to the caller.
This commit is contained in:
Bryan Schumaker 2011-12-30 19:47:13 -05:00
parent 0ef8e44207
commit 4dac0fe096
4 changed files with 21 additions and 23 deletions

View File

@ -8,7 +8,7 @@ namespace libsaria
void init(int, char **);
void quit();
void current_track(void (*)(Track *));
libsaria::Track *current_track();
}
#endif /* LIBSARIA_H */

View File

@ -17,6 +17,6 @@ struct file
string get_saria_dir();
void make_saria_dir();
bool get_inode(string, sid_t &);
sid_t lookup_songid(string &);
#endif /* LIBSARIA_PATH_H */

View File

@ -4,27 +4,28 @@
#include <libsaria/audio.h>
#include <libsaria/path.h>
static int current_inode(sid_t &inode)
{
string file = libsaria::audio::get_current_file();
if (file == "")
return false;
return get_inode(file, inode);
}
static libsaria::Track tmp_track;
namespace libsaria
{
void current_track(void (*func)(Track *))
libsaria::Track *current_track()
{
sid_t inode;
Track blank, *current;
sid_t songid;
libsaria::Track *current;
string file = libsaria::audio::get_current_file();
if (current_inode(inode) < 0)
current = &blank;
else
current = libsaria::library::get_info(inode);
func(current);
if (file == "")
return NULL;
songid = lookup_songid(file);
current = libsaria::library::get_info(songid);
if (current)
return current;
tmp_track = libsaria::Track(file, songid);
tmp_track.do_cleanup();
return &tmp_track;
}
};

View File

@ -40,14 +40,11 @@ void make_saria_dir()
mkdir(saria.c_str(), mode);
}
bool get_inode(string filepath, sid_t &ino)
sid_t lookup_songid(string &filepath)
{
int err;
struct stat stat;
err = lstat(filepath.c_str(), &stat);
int err = lstat(filepath.c_str(), &stat);
if (err != 0)
return false;
ino = stat.st_ino;
return true;
return stat.st_ino;
}