]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
make get_playlist_data() generic.
authorAndre Noll <maan@systemlinux.org>
Tue, 25 Sep 2007 12:16:14 +0000 (14:16 +0200)
committerAndre Noll <maan@systemlinux.org>
Tue, 25 Sep 2007 12:16:14 +0000 (14:16 +0200)
Other blob types might use an analogous function as well, so introduce
blob_get_name_and_def_by_row() in blob.c, and use some preprocessor
magic to define such a function for each blob type.

Change all users of get_playlist_data() to use the new
pl_blob_get_name_and_def_by_row() and remove get_playlist_data().

afs.h
blob.c
playlist.c

diff --git a/afs.h b/afs.h
index 2f192c65e06d9eed8741294d91855726c1e43667..9294ccfe6e864aa0ff624aff8e80d4742d622eea 100644 (file)
--- a/afs.h
+++ b/afs.h
@@ -143,6 +143,8 @@ int playlist_check_callback(__a_unused const struct osl_object *query,
        int table_name ## _init(struct table_info *ti, const char *db); \
        void table_name ## _shutdown(enum osl_close_flags flags); \
        int cmd_prefix ## _get_name_by_id(uint32_t id, char **name); \
        int table_name ## _init(struct table_info *ti, const char *db); \
        void table_name ## _shutdown(enum osl_close_flags flags); \
        int cmd_prefix ## _get_name_by_id(uint32_t id, char **name); \
+       int cmd_prefix ## _get_name_and_def_by_row(struct osl_row *row, \
+               char **name, struct osl_object *def); \
        extern struct osl_table *table_name ## _table;
 
 DECLARE_BLOB_SYMBOLS(lyrics, lyr);
        extern struct osl_table *table_name ## _table;
 
 DECLARE_BLOB_SYMBOLS(lyrics, lyr);
diff --git a/blob.c b/blob.c
index 0980aad5c14838b61a45e87db5958b9c7b560d75..617e94f1edd03113d8d194b32c07af2bc25b9b3b 100644 (file)
--- a/blob.c
+++ b/blob.c
@@ -440,6 +440,25 @@ static int blob_get_name_by_id(struct osl_table *table, uint32_t id,
                return blob_get_name_by_id(table_name ## _table, id, name); \
        }
 
                return blob_get_name_by_id(table_name ## _table, id, name); \
        }
 
+static int blob_get_name_and_def_by_row(struct osl_table *table, struct osl_row *row,
+       char **name, struct osl_object *def)
+{
+       struct osl_object obj;
+       int ret = osl_get_object(table, row, BLOBCOL_NAME, &obj);
+       if (ret < 0)
+               return ret;
+       *name = obj.data;
+       return osl_open_disk_object(table, row, BLOBCOL_DEF, def);
+}
+/** Define the \p get_name_and_def_by_row function for this blob type. */
+#define DEFINE_GET_NAME_AND_DEF_BY_ROW(table_name, cmd_prefix) \
+       int cmd_prefix ## _get_name_and_def_by_row(struct osl_row *row, \
+               char **name, struct osl_object *def) \
+       { \
+               return blob_get_name_and_def_by_row(table_name ## _table, \
+                       row, name, def); \
+       }
+
 /** Define the \p shutdown function for this blob type. */
 #define DEFINE_BLOB_SHUTDOWN(table_name) \
        void table_name ## _shutdown(enum osl_close_flags flags) \
 /** Define the \p shutdown function for this blob type. */
 #define DEFINE_BLOB_SHUTDOWN(table_name) \
        void table_name ## _shutdown(enum osl_close_flags flags) \
@@ -481,6 +500,7 @@ static int blob_init(struct osl_table **table,
        DEFINE_BLOB_COMMAND(rm, table_name, cmd_prefix) \
        DEFINE_BLOB_COMMAND(mv, table_name, cmd_prefix) \
        DEFINE_GET_NAME_BY_ID(table_name, cmd_prefix); \
        DEFINE_BLOB_COMMAND(rm, table_name, cmd_prefix) \
        DEFINE_BLOB_COMMAND(mv, table_name, cmd_prefix) \
        DEFINE_GET_NAME_BY_ID(table_name, cmd_prefix); \
+       DEFINE_GET_NAME_AND_DEF_BY_ROW(table_name, cmd_prefix); \
        DEFINE_BLOB_SHUTDOWN(table_name); \
        DEFINE_BLOB_INIT(table_name);
 
        DEFINE_BLOB_SHUTDOWN(table_name); \
        DEFINE_BLOB_INIT(table_name);
 
index 429ad2b53a116ffc1da2d4710b51e6db39161324..6f9f9669618377370daa1f330dd1b76f464eeb7e 100644 (file)
@@ -47,18 +47,6 @@ static int add_playlist_entry(char *path, void *data)
        return 1;
 }
 
        return 1;
 }
 
-static int get_playlist_data(struct osl_row *row, char **playlist_name,
-               struct osl_object *playlist_def)
-{
-       struct osl_object obj;
-       int ret = osl_get_object(playlists_table, row, BLOBCOL_NAME, &obj);
-       if (ret < 0)
-               return ret;
-       *playlist_name = obj.data;
-       return osl_open_disk_object(playlists_table, row, BLOBCOL_DEF,
-               playlist_def);
-}
-
 /* returns -E_PLAYLIST_LOADED on _success_ to terminate the loop */
 static int load_playlist(struct osl_row *row, void *data)
 {
 /* returns -E_PLAYLIST_LOADED on _success_ to terminate the loop */
 static int load_playlist(struct osl_row *row, void *data)
 {
@@ -67,7 +55,7 @@ static int load_playlist(struct osl_row *row, void *data)
        char *playlist_name;
        int ret;
 
        char *playlist_name;
        int ret;
 
-       ret = get_playlist_data(row, &playlist_name, &playlist_def);
+       ret = pl_get_name_and_def_by_row(row, &playlist_name, &playlist_def);
        if (ret < 0)
                goto err;
        playlist->length = 0;
        if (ret < 0)
                goto err;
        playlist->length = 0;
@@ -118,7 +106,7 @@ static int check_playlist(struct osl_row *row, void *data)
        struct para_buffer *pb = data;
        struct osl_object playlist_def;
        char *playlist_name;
        struct para_buffer *pb = data;
        struct osl_object playlist_def;
        char *playlist_name;
-       int ret = get_playlist_data(row, &playlist_name, &playlist_def);
+       int ret = pl_get_name_and_def_by_row(row, &playlist_name, &playlist_def);
 
        if (ret < 0) {
                para_printf(pb, "failed to get playlist data: %s\n",
 
        if (ret < 0) {
                para_printf(pb, "failed to get playlist data: %s\n",