]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
afs: Replace DATABASE_DIR by a runtime config option.
authorAndre Noll <maan@systemlinux.org>
Mon, 10 Sep 2007 19:52:00 +0000 (21:52 +0200)
committerAndre Noll <maan@systemlinux.org>
Mon, 10 Sep 2007 19:52:00 +0000 (21:52 +0200)
Also, split afs_init() into two parts: The new open_afs_tables() that
does what its name suggests and the remaining part that initializes
the scheduler.

afs.c
afs.h
aft.c
attribute.c
blob.c
score.c
server.ggo

diff --git a/afs.c b/afs.c
index 5e9bd118c41574fd7feaf110c0ee0673e8247dc4..21148f0e7d8aca0cd40708d0f9d536f58769ad20 100644 (file)
--- a/afs.c
+++ b/afs.c
@@ -723,43 +723,46 @@ void register_tasks(uint32_t cookie)
        register_command_task(cookie);
 }
 
-__noreturn int afs_init(uint32_t cookie, int socket_fd)
+static int open_afs_tables(void)
 {
        int ret;
-       enum play_mode current_play_mode;
-       struct sched s;
-
-       server_socket = socket_fd;
-       PARA_INFO_LOG("server_socket: %d, afs_socket_cookie: %u\n",
-               server_socket, (unsigned) cookie);
-
-       ret = attribute_init(&afs_tables[TBLNUM_ATTRIBUTES]);
+       char *db;
+
+       if (conf.afs_database_dir_given)
+               db = conf.afs_database_dir_arg;
+       else {
+               char *home = para_homedir();
+               db = make_message("%s/.paraslash/afs_database", home);
+               free(home);
+       }
+       PARA_INFO_LOG("afs_database dir %s\n", db);
+       ret = para_mkdir(db, 0777);
+       if (ret < 0 && ret != -E_EXIST)
+               goto err;
+       ret = attribute_init(&afs_tables[TBLNUM_ATTRIBUTES], db);
        if (ret < 0)
-               goto attribute_init_error;
-       ret = moods_init(&afs_tables[TBLNUM_MOODS]);
+               goto err;
+       ret = moods_init(&afs_tables[TBLNUM_MOODS], db);
        if (ret < 0)
                goto moods_init_error;
-       ret = playlists_init(&afs_tables[TBLNUM_PLAYLIST]);
+       ret = playlists_init(&afs_tables[TBLNUM_PLAYLIST], db);
        if (ret < 0)
                goto playlists_init_error;
-       ret = lyrics_init(&afs_tables[TBLNUM_LYRICS]);
+       ret = lyrics_init(&afs_tables[TBLNUM_LYRICS], db);
        if (ret < 0)
                goto lyrics_init_error;
-       ret = images_init(&afs_tables[TBLNUM_IMAGES]);
+       ret = images_init(&afs_tables[TBLNUM_IMAGES], db);
        if (ret < 0)
                goto images_init_error;
-       ret = score_init(&afs_tables[TBLNUM_SCORES]);
+       ret = score_init(&afs_tables[TBLNUM_SCORES], db);
        if (ret < 0)
                goto score_init_error;
-       ret = aft_init(&afs_tables[TBLNUM_AUDIO_FILES]);
+       ret = aft_init(&afs_tables[TBLNUM_AUDIO_FILES], db);
        if (ret < 0)
                goto aft_init_error;
-
-       current_play_mode = init_admissible_files();
-       register_tasks(cookie);
-       s.default_timeout.tv_sec = 0;
-       s.default_timeout.tv_usec = 99 * 1000;
-       sched(&s);
+       if (!conf.afs_database_dir_given)
+               free(db);
+       return 1;
 
 aft_init_error:
        score_shutdown(OSL_MARK_CLEAN);
@@ -773,7 +776,32 @@ playlists_init_error:
        moods_shutdown(OSL_MARK_CLEAN);
 moods_init_error:
        attribute_shutdown(OSL_MARK_CLEAN);
-attribute_init_error:
+err:
+       if (!conf.afs_database_dir_given)
+               free(db);
+       return ret;
+}
+
+__noreturn int afs_init(uint32_t cookie, int socket_fd)
+{
+       enum play_mode current_play_mode;
+       struct sched s;
+       int ret = open_afs_tables();
+
+       if (ret < 0) {
+               PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret));
+               exit(EXIT_FAILURE);
+       }
+       server_socket = socket_fd;
+       PARA_INFO_LOG("server_socket: %d, afs_socket_cookie: %u\n",
+               server_socket, (unsigned) cookie);
+       current_play_mode = init_admissible_files();
+       register_tasks(cookie);
+       s.default_timeout.tv_sec = 0;
+       s.default_timeout.tv_usec = 99 * 1000;
+       ret = sched(&s);
+       assert(ret < 0);
+       PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret));
        exit(EXIT_FAILURE);
 }
 
@@ -793,12 +821,16 @@ static int create_all_tables(void)
        return 1;
 }
 
-/* TODO load tables after init */
-int com_init(__a_unused int fd, int argc, char * const * const argv)
+int com_init(int fd, int argc, char * const * const argv)
 {
        int i, j, ret;
-       if (argc == 1)
-               return create_all_tables();
+
+       if (argc == 1) {
+               ret = create_all_tables();
+               if (ret < 0)
+                       return ret;
+               return open_afs_tables();
+       }
        for (i = 1; i < argc; i++) {
                for (j = 0; j < NUM_AFS_TABLES; j++) {
                        struct table_info *ti = afs_tables + j;
@@ -807,7 +839,9 @@ int com_init(__a_unused int fd, int argc, char * const * const argv)
                                continue;
                        if (strcmp(argv[i], ti->desc->name))
                                continue;
-                       PARA_NOTICE_LOG("creating table %s\n", argv[i]);
+                       ret = send_va_buffer(fd, "creating table %s\n", argv[i]);
+                       if (ret < 0)
+                               return ret;
                        ret = osl_create_table(ti->desc);
                        if (ret < 0)
                                return ret;
@@ -816,5 +850,5 @@ int com_init(__a_unused int fd, int argc, char * const * const argv)
                if (j == NUM_AFS_TABLES)
                        return -E_BAD_TABLE_NAME;
        }
-       return 1;
+       return open_afs_tables();
 }
diff --git a/afs.h b/afs.h
index 22d70ad987e25c32b267e6831c4400aa78d27c23..801347208136b7089744921310fee6d11e81a829 100644 (file)
--- a/afs.h
+++ b/afs.h
@@ -2,8 +2,6 @@
 #include "osl.h"
 #include "hash.h"
 
-#define DATABASE_DIR "/home/maan/tmp/osl" /* FIXME */
-
 struct afs_info {
        uint64_t last_played;
        uint64_t attributes;
@@ -109,7 +107,7 @@ int open_next_audio_file(struct audio_file_data *afd);
 int close_audio_file(struct audio_file_data *afd);
 
 /* score */
-int score_init(struct table_info *ti);
+int score_init(struct table_info *ti, const char *db);
 void score_shutdown(enum osl_close_flags flags);
 int admissible_file_loop(void *data, osl_rbtree_loop_func *func);
 int admissible_file_loop_reverse(void *data, osl_rbtree_loop_func *func);
@@ -122,14 +120,14 @@ int score_delete(const struct osl_row *aft_row);
 int row_belongs_to_score_table(const struct osl_row *aft_row);
 
 /* attribute */
-int attribute_init(struct table_info *ti);
+int attribute_init(struct table_info *ti, const char *db);
 void attribute_shutdown(enum osl_close_flags flags);
 void get_attribute_bitmap(uint64_t *atts, char *buf);
 int get_attribute_bitnum_by_name(const char *att_name, unsigned char *bitnum);
 int get_attribute_text(uint64_t *atts, const char *delim, char **text);
 
 /* aft */
-int aft_init(struct table_info *ti);
+int aft_init(struct table_info *ti, const char *db);
 void aft_shutdown(enum osl_close_flags flags);
 int aft_get_row_of_path(char *path, struct osl_row **row);
 int open_and_update_audio_file(struct osl_row *aft_row, struct audio_file_data *afd);
@@ -158,7 +156,7 @@ int playlist_update_audio_file(struct osl_row *aft_row);
 
 
 #define DECLARE_BLOB_SYMBOLS(table_name, cmd_prefix) \
-       int table_name ## _init(struct table_info *ti); \
+       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); \
        extern struct osl_table *table_name ## _table;
@@ -170,8 +168,7 @@ DECLARE_BLOB_SYMBOLS(playlists, pl);
 
 enum blob_table_columns {BLOBCOL_ID, BLOBCOL_NAME, BLOBCOL_DEF, NUM_BLOB_COLUMNS};
 #define DEFINE_BLOB_TABLE_DESC(table_name) \
-       const struct osl_table_description table_name ## _table_desc = { \
-               .dir = DATABASE_DIR, \
+       struct osl_table_description table_name ## _table_desc = { \
                .name = #table_name, \
                .num_columns = NUM_BLOB_COLUMNS, \
                .flags = OSL_LARGE_TABLE, \
diff --git a/aft.c b/aft.c
index 1d7680714f05d39e1c0c057aaaf95b412e1626b6..3c33aae0c747513a39ddd4426a413a30e5644b58 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -126,8 +126,7 @@ static struct osl_column_description aft_cols[] = {
        }
 };
 
-static const struct osl_table_description audio_file_table_desc = {
-       .dir = DATABASE_DIR,
+static struct osl_table_description audio_file_table_desc = {
        .name = "audio_files",
        .num_columns = NUM_AFT_COLUMNS,
        .flags = OSL_LARGE_TABLE,
@@ -1712,16 +1711,18 @@ void aft_shutdown(enum osl_close_flags flags)
 /**
  * Open the audio file table.
  *
- * \param ti Gets initialized by this function
+ * \param ti Gets initialized by this function.
+ * \param db The database directory.
  *
  * \return Positive on success, negative on errors.
  *
  * \sa osl_open_table().
  */
-int aft_init(struct table_info *ti)
+int aft_init(struct table_info *ti, const char *db)
 {
        int ret;
 
+       audio_file_table_desc.dir = db;
        ti->desc = &audio_file_table_desc;
        ret = osl_open_table(ti->desc, &ti->table);
        if (ret >= 0) {
index 925795be2902e8aad7f45b1a3f67673397248186..af3dfb063be01ea0a8ec8c63cde0457d0dd5a600 100644 (file)
@@ -37,8 +37,7 @@ static struct osl_column_description att_cols[] = {
        }
 };
 
-static const struct osl_table_description attribute_table_desc = {
-       .dir = DATABASE_DIR,
+static struct osl_table_description attribute_table_desc = {
        .name = "attributes",
        .num_columns = NUM_ATT_COLUMNS,
        .flags = 0,
@@ -380,10 +379,11 @@ void attribute_shutdown(enum osl_close_flags flags)
        osl_close_table(attribute_table, flags);
 }
 
-int attribute_init(struct table_info *ti)
+int attribute_init(struct table_info *ti, const char *db)
 {
        int ret;
 
+       attribute_table_desc.dir = db;
        ti->desc = &attribute_table_desc;
        ret = osl_open_table(ti->desc, &ti->table);
        greatest_att_bitnum = -1; /* no atts available */
diff --git a/blob.c b/blob.c
index fa5134d7e0e066a3e8ea0627a11d1482c87b861e..559564506e399d39c9a43123745c5941a9ee75da 100644 (file)
--- a/blob.c
+++ b/blob.c
@@ -352,11 +352,11 @@ static int blob_get_name_by_id(struct osl_table *table, uint32_t id,
        }
 
 static int blob_init(struct osl_table **table,
-               const struct osl_table_description *desc,
-               struct table_info *ti)
+               struct osl_table_description *desc,
+               struct table_info *ti, const char *db)
 {
        int ret;
-
+       desc->dir = db;
        ti->desc = desc;
        ret = osl_open_table(ti->desc, &ti->table);
        if (ret >= 0) {
@@ -369,10 +369,10 @@ static int blob_init(struct osl_table **table,
 
 /** Define the \p init function for this blob type. */
 #define DEFINE_BLOB_INIT(table_name) \
-       int table_name ## _init(struct table_info *ti) \
+       int table_name ## _init(struct table_info *ti, const char *db) \
        { \
                return blob_init(&table_name ## _table, \
-                       &table_name ## _table_desc, ti); \
+                       &table_name ## _table_desc, ti, db); \
        }
 
 
diff --git a/score.c b/score.c
index 6c15a0f571e8cd79647493910f64edc7679c947c..86c6c4bb366af7e1e9f6d2ddec3d820b45f74a51 100644 (file)
--- a/score.c
+++ b/score.c
@@ -78,7 +78,6 @@ static struct osl_column_description score_cols[] = {
 };
 
 static struct osl_table_description score_table_desc = {
-       .dir = DATABASE_DIR,
        .name = "score",
        .num_columns = NUM_SCORE_COLUMNS,
        .flags = 0,
@@ -349,13 +348,15 @@ void score_shutdown(enum osl_close_flags flags)
  * Init the scoring subsystem.
  *
  * \param ti Gets filled in by the function.
+ * \param db The database directory.
  *
  * \return The return value of the underlying call to osl_open_table().
  *
  * \sa score_shutdown().
  */
-int score_init(struct table_info *ti)
+int score_init(struct table_info *ti, const char *db)
 {
+       score_table_desc.dir = db;
        ti->desc = &score_table_desc;
        ti->flags = TBLFLAG_SKIP_CREATE;
        int ret = osl_open_table(ti->desc, &ti->table);
index dedb0e864ea49d5a57b78885214536a757e0dc6d..54aea85a9738bdf398ee047ec151616574f28c56 100644 (file)
@@ -132,6 +132,20 @@ option "selector" S
        string typestr="name"
        optional
 
+#############################
+section "audio file selector"
+#############################
+
+option "afs_database_dir" D
+#~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+"Directory containing the osl database of the
+audio file selector.
+(default='~/.paraslash/afs_database'"
+
+       string typestr="path"
+       optional
+
 
 option "afs_socket" s
 #~~~~~~~~~~~~~~~~~~~~