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:
Anna Schumaker 2014-01-04 11:55:52 -05:00 committed by Anna Schumaker
parent 1d559865c8
commit 360ebed1fa
8 changed files with 39 additions and 39 deletions

View File

@ -190,7 +190,7 @@ unsigned int Database<T> :: find_index(const std::string &key)
std::map<const std::string, unsigned int>::iterator it;
it = keys.find(key);
if (it == keys.end())
throw -EEXIST;
throw -E_EXIST;
return it->second;
}
@ -199,7 +199,7 @@ T &Database<T> :: find(const std::string &key)
{
unsigned int index = find_index(key);
if (db[index].valid == false)
throw -EINVAL;
throw -E_INVAL;
return db[index];
}
@ -207,9 +207,9 @@ template <class T>
T &Database<T> :: operator[](unsigned int id)
{
if (id >= db.size())
throw -EEXIST;
throw -E_EXIST;
else if (db[id].valid == false)
throw -EINVAL;
throw -E_INVAL;
return db[id];
}

View File

@ -4,12 +4,12 @@
#ifndef OCARINA_ERROR_H
#define OCARINA_ERROR_H
enum error_t {
EAUDIO = 1, /* Audio error */
EEXIST, /* Requested object does not exist */
EINVAL, /* Invalid operation requested */
EIO, /* I/O error */
ENOTRACK,
enum o_error {
E_AUDIO = 1, /* Audio error */
E_EXIST, /* Requested object does not exist */
E_INVAL, /* Invalid operation requested */
E_IO, /* I/O error */
E_NOTRACK,
};
#endif /* OCARINA_ERROR_H */

View File

@ -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" ]),
"DECK" : Module("deck.cpp", depends = [ "PLAYQUEUE" ]),
"FILE" : Module("file.cpp", package = "glib-2.0"),

View File

@ -84,13 +84,13 @@ void File :: open_read()
{
if (!exists()) {
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);
if (std::fstream::fail()) {
dprint("ERROR: Could not open file for reading (%s)\n", filepath.c_str());
throw -EIO;
throw -E_IO;
}
mode = OPEN_READ;
@ -103,19 +103,19 @@ void File :: open_write()
std::string dir;
if (hint == FILE_TYPE_LEGACY) {
dprint("ERROR: Cannot write to legacy files (%s)\n", filepath.c_str());
throw -EIO;
throw -E_IO;
}
find_dir(dir);
if (g_mkdir_with_parents(dir.c_str(), 0755) != 0) {
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);
if (std::fstream::fail()) {
dprint("ERROR: Could not open file for writing (%s)\n", filepath.c_str());
throw -EIO;
throw -E_IO;
}
mode = OPEN_WRITE;
@ -126,15 +126,15 @@ void File :: open(OpenMode m)
{
if (mode != NOT_OPEN) {
dprint("ERROR: File is already open (%s)\n", filepath.c_str());
throw -EIO;
throw -E_IO;
}
if (m == NOT_OPEN) {
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) {
dprint("ERROR: A file with hint = FILE_TYPE_INVALID cannot be opened\n");
throw -EINVAL;
throw -E_INVAL;
} else if (m == OPEN_READ)
open_read();
else /* m == OPEN_WRITE */

View File

@ -45,7 +45,7 @@ library :: AGInfo :: AGInfo(DB_Type type, TagLib :: Tag *tag)
else if (db_type == DB_GENRE)
primary_key = tag->genre().stripWhiteSpace().to8Bit(true);
else
throw -EINVAL;
throw -E_INVAL;
key_lower = filter :: to_lowercase(primary_key);
}
@ -57,7 +57,7 @@ library :: AGInfo :: AGInfo(DB_Type type, const std::string &str)
primary_key = str;
key_lower = filter :: to_lowercase(primary_key);
} else
throw -EINVAL;
throw -E_INVAL;
}
@ -442,7 +442,7 @@ void library :: add_path(const std::string &dir)
{
unsigned int id;
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));
library_db.save();
@ -467,11 +467,11 @@ void library :: update_path(unsigned int id)
void library :: lookup(unsigned int id, library :: Song *song)
{
if (id >= track_db.num_rows())
throw -EEXIST;
throw -E_EXIST;
song->track = &track_db[id];
if (song->track->valid == false)
throw -EEXIST;
throw -E_EXIST;
song->artist = &artist_db[song->track->artist_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)
{
if (id >= library_db.num_rows())
throw -EEXIST;
throw -E_EXIST;
if (library_db[id].valid == false)
throw -EEXIST;
throw -E_EXIST;
return &library_db[id];
}

View File

@ -19,7 +19,7 @@ void playlist :: add(const std::string &name, unsigned int track_id)
index_insert(playlist_db, name, track_id);
playlist_db.save();
} else
throw -EEXIST;
throw -E_EXIST;
}
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);
playlist_db.save();
} else
throw -EEXIST;
throw -E_EXIST;
}
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;
}
}
throw -EEXIST;
throw -E_EXIST;
}
#ifdef CONFIG_TEST

View File

@ -58,7 +58,7 @@ void test_b(int testno, bool valid, FileLocHint hint)
} catch (int 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;
}
if (valid == false)
test_result(status == -EINVAL, true);
test_result(status == -E_INVAL, true);
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)
test_result(status == -EINVAL, true);
test_result(status == -E_INVAL, true);
else if (hint == FILE_TYPE_LEGACY)
test_result(status == -EIO, true);
test_result(status == -E_IO, true);
else
test_result(status == 0, false);
}
@ -143,7 +143,7 @@ void test_f(int testno, bool valid, FileLocHint hint)
} catch (int error) {
status = error;
}
test_result(status == -EIO, true);
test_result(status == -E_IO, true);
}
/*

View File

@ -44,7 +44,7 @@ void test_0()
try {
playlist :: add("No Such Playlist", i);
} catch (int error) {
check_error(-EEXIST, error);
check_error(-E_EXIST, error);
}
}
}
@ -61,7 +61,7 @@ void test_1()
try {
list_tracks("No Such Playlist");
} catch (int error) {
check_error(-EEXIST, error);
check_error(-E_EXIST, error);
}
}
@ -78,7 +78,7 @@ void test_2()
try {
playlist :: del("No Such Playlist", 2);
} catch (int error) {
check_error(-EEXIST, error);
check_error(-E_EXIST, error);
}
}
@ -98,7 +98,7 @@ void test_3()
try {
list_tracks("No Schu Playlist");
} catch (int error) {
check_error(-EEXIST, error);
check_error(-E_EXIST, error);
}
}