AUDIO_FILE_RENAME,
AUDIO_FILE_ADD,
AUDIO_FILE_REMOVE,
- LYRICS_ADD,
- LYRICS_REMOVE,
- LYRICS_RENAME,
- IMAGE_ADD,
- IMAGE_REMOVE,
- IMAGE_RENAME,
+ BLOB_ADD,
+ BLOB_RENAME,
+ BLOB_REMOVE,
};
struct afs_info *old_afsi;
};
-union afs_event_data {
- struct {
- const char *name;
- unsigned char bitnum;
- } rmatt_event_data;
- struct osl_row *row;
- struct {
- const struct osl_row *row;
- struct afs_info *old_afsi;
- } afsi_change;
-
-};
-
struct afs_table {
void (*init)(struct afs_table *t);
const char *name;
int score_update(const struct osl_row *aft_row, long new_score);
int get_num_admissible_files(unsigned *num);
int score_delete(const struct osl_row *aft_row);
+int clear_score_table(void);
int row_belongs_to_score_table(const struct osl_row *aft_row, unsigned *rank);
/* attribute */
static int com_rmblob_callback(struct osl_table *table,
const struct osl_object *query,
- __a_unused struct osl_object *result)
+ struct osl_object *result)
{
int ret;
struct rmblob_data rmbd = {.num_removed = 0};
para_printf(&rmbd.pb, "%s\n", PARA_STRERROR(-ret));
if (!rmbd.num_removed)
para_printf(&rmbd.pb, "no matches, nothing removed\n");
- else
+ else {
para_printf(&rmbd.pb, "removed %d blobs\n", rmbd.num_removed);
+ afs_event(BLOB_RENAME, NULL, table);
+ }
result->data = rmbd.pb.buf;
result->size = rmbd.pb.size;
return 1;
}
-static int com_rmblob(callback_function *f, __a_unused int fd, int argc,
+static int com_rmblob(callback_function *f, int fd, int argc,
char * const * const argv)
{
int ret;
objs[BLOBCOL_NAME].size = name_len;
objs[BLOBCOL_DEF].data = name + name_len;
objs[BLOBCOL_DEF].size = query->size - name_len;
- return osl_add_row(table, objs);
+ ret = osl_add_row(table, objs);
+ if (ret < 0)
+ return ret;
+ afs_event(BLOB_ADD, NULL, table);
+ return 1;
}
static int com_addblob(callback_function *f, int fd, int argc,
return ret;
obj.data = dest;
obj.size = strlen(dest) + 1;
- return osl_update_object(table, row, BLOBCOL_NAME, &obj);
+ ret = osl_update_object(table, row, BLOBCOL_NAME, &obj);
+ if (ret < 0)
+ return ret;
+ afs_event(BLOB_RENAME, NULL, table);
+ return 1;
}
-static int com_mvblob(callback_function *f, __a_unused int fd,
+static int com_mvblob(callback_function *f, __a_unused int fd,
int argc, char * const * const argv)
{
if (argc != 3)
int ret;
char *mood_name;
+ PARA_NOTICE_LOG("reloading current mood\n");
if (!current_mood)
return 1;
mood_name = para_strdup(current_mood->name);
close_current_mood();
+ ret = clear_score_table();
+ if (ret < 0)
+ return ret;
ret = change_current_mood(mood_name);
free(mood_name);
return ret;
void *data)
{
switch(event) {
+ /*
+ * The three blob events might change the set of admissible files,
+ * so we must reload the score list.
+ */
+ case BLOB_RENAME:
+ case BLOB_REMOVE:
+ case BLOB_ADD:
+ if (data == moods_table || data == playlists_table)
+ return 1; /* no reload necessary for these */
+ return reload_current_mood();
+ /* these also require reload of the score table */
case ATTRIBUTE_ADD:
case ATTRIBUTE_REMOVE:
case ATTRIBUTE_RENAME:
return reload_current_mood();
+ /* changes to the aft only require to re-examine the audio file */
case AFSI_CHANGE: {
struct afsi_change_event_data *aced = data;
return mood_update_audio_file(aced->aft_row, aced->old_afsi);
return osl_open_table(&score_table_desc, &score_table);
}
-static int score_event_handler(enum afs_events event, struct para_buffer *pb,
- void *data)
+/**
+ * Remove all entries from the score table, but keep the table open.
+ *
+ * \return Standard.
+ */
+int clear_score_table(void)
{
- int ret;
+ score_close();
+ return score_open(NULL);
+}
- switch(event) {
- case ATTRIBUTE_ADD:
- case ATTRIBUTE_REMOVE:
- case ATTRIBUTE_RENAME: {
- score_close();
- return score_open(NULL);
- }
- default: return 1;
- }
+static int score_event_handler(__a_unused enum afs_events event,
+ __a_unused struct para_buffer *pb, __a_unused void *data)
+{
+ return 1;
}
/**