diff --git a/include/database.hpp b/include/database.hpp index 7f9f8a08..70554b5a 100644 --- a/include/database.hpp +++ b/include/database.hpp @@ -190,7 +190,7 @@ unsigned int Database :: find_index(const std::string &key) std::map::iterator it; it = keys.find(key); if (it == keys.end()) - throw -EEXIST; + throw -E_EXIST; return it->second; } @@ -199,7 +199,7 @@ T &Database :: 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 T &Database :: 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]; } diff --git a/include/error.h b/include/error.h index b27692f3..f24e2812 100644 --- a/include/error.h +++ b/include/error.h @@ -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 */ diff --git a/lib/Sconscript b/lib/Sconscript index c3298b3a..f253e9c3 100644 --- a/lib/Sconscript +++ b/lib/Sconscript @@ -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"), diff --git a/lib/file.cpp b/lib/file.cpp index 0d254078..171706f4 100644 --- a/lib/file.cpp +++ b/lib/file.cpp @@ -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 */ diff --git a/lib/library.cpp b/lib/library.cpp index 51d87e33..aa7a610d 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -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]; } diff --git a/lib/playlist.cpp b/lib/playlist.cpp index 35abd90a..78f819d4 100644 --- a/lib/playlist.cpp +++ b/lib/playlist.cpp @@ -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 &playlist :: get_tracks(const std::string &name) @@ -40,7 +40,7 @@ const std::set &playlist :: get_tracks(const std::string &name) return empty_set; } } - throw -EEXIST; + throw -E_EXIST; } #ifdef CONFIG_TEST diff --git a/tests/file/file.cpp b/tests/file/file.cpp index 5d183317..7f005b41 100644 --- a/tests/file/file.cpp +++ b/tests/file/file.cpp @@ -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); } /* diff --git a/tests/playlist/playlist.cpp b/tests/playlist/playlist.cpp index 41b12f80..47ad6f87 100644 --- a/tests/playlist/playlist.cpp +++ b/tests/playlist/playlist.cpp @@ -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); } }