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);
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);
}
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;
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;
if (j == NUM_AFS_TABLES)
return -E_BAD_TABLE_NAME;
}
- return 1;
+ return open_afs_tables();
}
#include "osl.h"
#include "hash.h"
-#define DATABASE_DIR "/home/maan/tmp/osl" /* FIXME */
-
struct afs_info {
uint64_t last_played;
uint64_t attributes;
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);
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);
#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;
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, \
}
};
-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,
/**
* 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) {
}
};
-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,
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 */
}
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) {
/** 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); \
}
};
static struct osl_table_description score_table_desc = {
- .dir = DATABASE_DIR,
.name = "score",
.num_columns = NUM_SCORE_COLUMNS,
.flags = 0,
* 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);
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
#~~~~~~~~~~~~~~~~~~~~