errors: Rename error codes
Gstreamer includes <errno.h>, which already defines several of these symbols. I rename them to avoid namespace collisions. Perhaps a better solution would be to use the errno.h definitions directly? Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
parent
1d559865c8
commit
360ebed1fa
|
@ -190,7 +190,7 @@ unsigned int Database<T> :: find_index(const std::string &key)
|
||||||
std::map<const std::string, unsigned int>::iterator it;
|
std::map<const std::string, unsigned int>::iterator it;
|
||||||
it = keys.find(key);
|
it = keys.find(key);
|
||||||
if (it == keys.end())
|
if (it == keys.end())
|
||||||
throw -EEXIST;
|
throw -E_EXIST;
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ T &Database<T> :: find(const std::string &key)
|
||||||
{
|
{
|
||||||
unsigned int index = find_index(key);
|
unsigned int index = find_index(key);
|
||||||
if (db[index].valid == false)
|
if (db[index].valid == false)
|
||||||
throw -EINVAL;
|
throw -E_INVAL;
|
||||||
return db[index];
|
return db[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,9 +207,9 @@ template <class T>
|
||||||
T &Database<T> :: operator[](unsigned int id)
|
T &Database<T> :: operator[](unsigned int id)
|
||||||
{
|
{
|
||||||
if (id >= db.size())
|
if (id >= db.size())
|
||||||
throw -EEXIST;
|
throw -E_EXIST;
|
||||||
else if (db[id].valid == false)
|
else if (db[id].valid == false)
|
||||||
throw -EINVAL;
|
throw -E_INVAL;
|
||||||
return db[id];
|
return db[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,12 @@
|
||||||
#ifndef OCARINA_ERROR_H
|
#ifndef OCARINA_ERROR_H
|
||||||
#define OCARINA_ERROR_H
|
#define OCARINA_ERROR_H
|
||||||
|
|
||||||
enum error_t {
|
enum o_error {
|
||||||
EAUDIO = 1, /* Audio error */
|
E_AUDIO = 1, /* Audio error */
|
||||||
EEXIST, /* Requested object does not exist */
|
E_EXIST, /* Requested object does not exist */
|
||||||
EINVAL, /* Invalid operation requested */
|
E_INVAL, /* Invalid operation requested */
|
||||||
EIO, /* I/O error */
|
E_IO, /* I/O error */
|
||||||
ENOTRACK,
|
E_NOTRACK,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* OCARINA_ERROR_H */
|
#endif /* OCARINA_ERROR_H */
|
||||||
|
|
|
@ -15,7 +15,7 @@ modules = {
|
||||||
# #
|
# #
|
||||||
###########################
|
###########################
|
||||||
|
|
||||||
"AUDIO" : Module("audio.cpp", package = "gstreamer-1.0", depends = [ "DECK", "LIBRARY" ]),
|
"AUDIO" : Module("audio.cpp", package = "gstreamer-1.0", depends = [ "DECK" ]),
|
||||||
"DATABASE" : Module("database.cpp", depends = [ "FILE" ]),
|
"DATABASE" : Module("database.cpp", depends = [ "FILE" ]),
|
||||||
"DECK" : Module("deck.cpp", depends = [ "PLAYQUEUE" ]),
|
"DECK" : Module("deck.cpp", depends = [ "PLAYQUEUE" ]),
|
||||||
"FILE" : Module("file.cpp", package = "glib-2.0"),
|
"FILE" : Module("file.cpp", package = "glib-2.0"),
|
||||||
|
|
16
lib/file.cpp
16
lib/file.cpp
|
@ -84,13 +84,13 @@ void File :: open_read()
|
||||||
{
|
{
|
||||||
if (!exists()) {
|
if (!exists()) {
|
||||||
dprint("ERROR: File does not exist (%s)\n", filepath.c_str());
|
dprint("ERROR: File does not exist (%s)\n", filepath.c_str());
|
||||||
throw -EEXIST;
|
throw -E_EXIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::fstream::open(filepath.c_str(), std::fstream::in);
|
std::fstream::open(filepath.c_str(), std::fstream::in);
|
||||||
if (std::fstream::fail()) {
|
if (std::fstream::fail()) {
|
||||||
dprint("ERROR: Could not open file for reading (%s)\n", filepath.c_str());
|
dprint("ERROR: Could not open file for reading (%s)\n", filepath.c_str());
|
||||||
throw -EIO;
|
throw -E_IO;
|
||||||
}
|
}
|
||||||
|
|
||||||
mode = OPEN_READ;
|
mode = OPEN_READ;
|
||||||
|
@ -103,19 +103,19 @@ void File :: open_write()
|
||||||
std::string dir;
|
std::string dir;
|
||||||
if (hint == FILE_TYPE_LEGACY) {
|
if (hint == FILE_TYPE_LEGACY) {
|
||||||
dprint("ERROR: Cannot write to legacy files (%s)\n", filepath.c_str());
|
dprint("ERROR: Cannot write to legacy files (%s)\n", filepath.c_str());
|
||||||
throw -EIO;
|
throw -E_IO;
|
||||||
}
|
}
|
||||||
|
|
||||||
find_dir(dir);
|
find_dir(dir);
|
||||||
if (g_mkdir_with_parents(dir.c_str(), 0755) != 0) {
|
if (g_mkdir_with_parents(dir.c_str(), 0755) != 0) {
|
||||||
dprint("ERROR: Could not make directory (%s)\n", dir.c_str());
|
dprint("ERROR: Could not make directory (%s)\n", dir.c_str());
|
||||||
throw -EIO;
|
throw -E_IO;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::fstream::open(filepath.c_str(), std::fstream::out);
|
std::fstream::open(filepath.c_str(), std::fstream::out);
|
||||||
if (std::fstream::fail()) {
|
if (std::fstream::fail()) {
|
||||||
dprint("ERROR: Could not open file for writing (%s)\n", filepath.c_str());
|
dprint("ERROR: Could not open file for writing (%s)\n", filepath.c_str());
|
||||||
throw -EIO;
|
throw -E_IO;
|
||||||
}
|
}
|
||||||
|
|
||||||
mode = OPEN_WRITE;
|
mode = OPEN_WRITE;
|
||||||
|
@ -126,15 +126,15 @@ void File :: open(OpenMode m)
|
||||||
{
|
{
|
||||||
if (mode != NOT_OPEN) {
|
if (mode != NOT_OPEN) {
|
||||||
dprint("ERROR: File is already open (%s)\n", filepath.c_str());
|
dprint("ERROR: File is already open (%s)\n", filepath.c_str());
|
||||||
throw -EIO;
|
throw -E_IO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m == NOT_OPEN) {
|
if (m == NOT_OPEN) {
|
||||||
dprint("ERROR: NOT_OPEN is not a legal OpenMode (%s)\n", filepath.c_str());
|
dprint("ERROR: NOT_OPEN is not a legal OpenMode (%s)\n", filepath.c_str());
|
||||||
throw -EINVAL;
|
throw -E_INVAL;
|
||||||
} else if (hint == FILE_TYPE_INVALID) {
|
} else if (hint == FILE_TYPE_INVALID) {
|
||||||
dprint("ERROR: A file with hint = FILE_TYPE_INVALID cannot be opened\n");
|
dprint("ERROR: A file with hint = FILE_TYPE_INVALID cannot be opened\n");
|
||||||
throw -EINVAL;
|
throw -E_INVAL;
|
||||||
} else if (m == OPEN_READ)
|
} else if (m == OPEN_READ)
|
||||||
open_read();
|
open_read();
|
||||||
else /* m == OPEN_WRITE */
|
else /* m == OPEN_WRITE */
|
||||||
|
|
|
@ -45,7 +45,7 @@ library :: AGInfo :: AGInfo(DB_Type type, TagLib :: Tag *tag)
|
||||||
else if (db_type == DB_GENRE)
|
else if (db_type == DB_GENRE)
|
||||||
primary_key = tag->genre().stripWhiteSpace().to8Bit(true);
|
primary_key = tag->genre().stripWhiteSpace().to8Bit(true);
|
||||||
else
|
else
|
||||||
throw -EINVAL;
|
throw -E_INVAL;
|
||||||
|
|
||||||
key_lower = filter :: to_lowercase(primary_key);
|
key_lower = filter :: to_lowercase(primary_key);
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ library :: AGInfo :: AGInfo(DB_Type type, const std::string &str)
|
||||||
primary_key = str;
|
primary_key = str;
|
||||||
key_lower = filter :: to_lowercase(primary_key);
|
key_lower = filter :: to_lowercase(primary_key);
|
||||||
} else
|
} else
|
||||||
throw -EINVAL;
|
throw -E_INVAL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,7 +442,7 @@ void library :: add_path(const std::string &dir)
|
||||||
{
|
{
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
if (g_file_test(dir.c_str(), G_FILE_TEST_IS_DIR) == false)
|
if (g_file_test(dir.c_str(), G_FILE_TEST_IS_DIR) == false)
|
||||||
throw -EINVAL;
|
throw -E_INVAL;
|
||||||
|
|
||||||
id = library_db.insert(library :: Library(dir, true));
|
id = library_db.insert(library :: Library(dir, true));
|
||||||
library_db.save();
|
library_db.save();
|
||||||
|
@ -467,11 +467,11 @@ void library :: update_path(unsigned int id)
|
||||||
void library :: lookup(unsigned int id, library :: Song *song)
|
void library :: lookup(unsigned int id, library :: Song *song)
|
||||||
{
|
{
|
||||||
if (id >= track_db.num_rows())
|
if (id >= track_db.num_rows())
|
||||||
throw -EEXIST;
|
throw -E_EXIST;
|
||||||
|
|
||||||
song->track = &track_db[id];
|
song->track = &track_db[id];
|
||||||
if (song->track->valid == false)
|
if (song->track->valid == false)
|
||||||
throw -EEXIST;
|
throw -E_EXIST;
|
||||||
|
|
||||||
song->artist = &artist_db[song->track->artist_id];
|
song->artist = &artist_db[song->track->artist_id];
|
||||||
song->album = &album_db[song->track->album_id];
|
song->album = &album_db[song->track->album_id];
|
||||||
|
@ -482,9 +482,9 @@ void library :: lookup(unsigned int id, library :: Song *song)
|
||||||
library :: Library *library :: lookup_path(unsigned int id)
|
library :: Library *library :: lookup_path(unsigned int id)
|
||||||
{
|
{
|
||||||
if (id >= library_db.num_rows())
|
if (id >= library_db.num_rows())
|
||||||
throw -EEXIST;
|
throw -E_EXIST;
|
||||||
if (library_db[id].valid == false)
|
if (library_db[id].valid == false)
|
||||||
throw -EEXIST;
|
throw -E_EXIST;
|
||||||
return &library_db[id];
|
return &library_db[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ void playlist :: add(const std::string &name, unsigned int track_id)
|
||||||
index_insert(playlist_db, name, track_id);
|
index_insert(playlist_db, name, track_id);
|
||||||
playlist_db.save();
|
playlist_db.save();
|
||||||
} else
|
} else
|
||||||
throw -EEXIST;
|
throw -E_EXIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
void playlist :: del(const std::string &name, unsigned int track_id)
|
void playlist :: del(const std::string &name, unsigned int track_id)
|
||||||
|
@ -28,7 +28,7 @@ void playlist :: del(const std::string &name, unsigned int track_id)
|
||||||
index_remove(playlist_db, name, track_id);
|
index_remove(playlist_db, name, track_id);
|
||||||
playlist_db.save();
|
playlist_db.save();
|
||||||
} else
|
} else
|
||||||
throw -EEXIST;
|
throw -E_EXIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::set<unsigned int> &playlist :: get_tracks(const std::string &name)
|
const std::set<unsigned int> &playlist :: get_tracks(const std::string &name)
|
||||||
|
@ -40,7 +40,7 @@ const std::set<unsigned int> &playlist :: get_tracks(const std::string &name)
|
||||||
return empty_set;
|
return empty_set;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw -EEXIST;
|
throw -E_EXIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_TEST
|
#ifdef CONFIG_TEST
|
||||||
|
|
|
@ -58,7 +58,7 @@ void test_b(int testno, bool valid, FileLocHint hint)
|
||||||
} catch (int error) {
|
} catch (int error) {
|
||||||
status = error;
|
status = error;
|
||||||
}
|
}
|
||||||
test_result(status == -EINVAL, true);
|
test_result(status == -E_INVAL, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -74,9 +74,9 @@ void test_c(int testno, bool valid, FileLocHint hint)
|
||||||
status = error;
|
status = error;
|
||||||
}
|
}
|
||||||
if (valid == false)
|
if (valid == false)
|
||||||
test_result(status == -EINVAL, true);
|
test_result(status == -E_INVAL, true);
|
||||||
else
|
else
|
||||||
test_result(status == -EEXIST, true);
|
test_result(status == -E_EXIST, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -94,9 +94,9 @@ void test_d(int testno, bool valid, FileLocHint hint)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valid == false)
|
if (valid == false)
|
||||||
test_result(status == -EINVAL, true);
|
test_result(status == -E_INVAL, true);
|
||||||
else if (hint == FILE_TYPE_LEGACY)
|
else if (hint == FILE_TYPE_LEGACY)
|
||||||
test_result(status == -EIO, true);
|
test_result(status == -E_IO, true);
|
||||||
else
|
else
|
||||||
test_result(status == 0, false);
|
test_result(status == 0, false);
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ void test_f(int testno, bool valid, FileLocHint hint)
|
||||||
} catch (int error) {
|
} catch (int error) {
|
||||||
status = error;
|
status = error;
|
||||||
}
|
}
|
||||||
test_result(status == -EIO, true);
|
test_result(status == -E_IO, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -44,7 +44,7 @@ void test_0()
|
||||||
try {
|
try {
|
||||||
playlist :: add("No Such Playlist", i);
|
playlist :: add("No Such Playlist", i);
|
||||||
} catch (int error) {
|
} catch (int error) {
|
||||||
check_error(-EEXIST, error);
|
check_error(-E_EXIST, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ void test_1()
|
||||||
try {
|
try {
|
||||||
list_tracks("No Such Playlist");
|
list_tracks("No Such Playlist");
|
||||||
} catch (int error) {
|
} catch (int error) {
|
||||||
check_error(-EEXIST, error);
|
check_error(-E_EXIST, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ void test_2()
|
||||||
try {
|
try {
|
||||||
playlist :: del("No Such Playlist", 2);
|
playlist :: del("No Such Playlist", 2);
|
||||||
} catch (int error) {
|
} catch (int error) {
|
||||||
check_error(-EEXIST, error);
|
check_error(-E_EXIST, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ void test_3()
|
||||||
try {
|
try {
|
||||||
list_tracks("No Schu Playlist");
|
list_tracks("No Schu Playlist");
|
||||||
} catch (int error) {
|
} catch (int error) {
|
||||||
check_error(-EEXIST, error);
|
check_error(-E_EXIST, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue