Obtain afs status items directly from afs.
[paraslash.git] / aft.c
diff --git a/aft.c b/aft.c
index 23b36a88e51e3469f3b4fd00770a5d4e1881872e..7027e7f95d45104c559cd5720ebd377fc2d047a8 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -24,6 +24,7 @@
 #include "portable_io.h"
 
 static struct osl_table *audio_file_table;
 #include "portable_io.h"
 
 static struct osl_table *audio_file_table;
+static char *current_status_items;
 
 /** The different sorting methods of the ls command. */
 enum ls_sorting_method {
 
 /** The different sorting methods of the ls command. */
 enum ls_sorting_method {
@@ -962,72 +963,6 @@ out:
        return ret;
 }
 
        return ret;
 }
 
-/**
- * Write a list of audio-file related status items with empty values.
- *
- * \param buf Result pointer.
- *
- * This is used by vss when currently no audio file is open.
- */
-void make_empty_status_items(char *buf)
-{
-       sprintf(buf,
-               "%s: \n" /* path */
-               "%s: \n" /* dirname */
-               "%s: \n" /* basename */
-               "%s: \n" /* score */
-               "%s: \n" /* attributes bitmap */
-               "%s: \n" /* attributes txt */
-               "%s: \n" /* hash */
-               "%s: \n" /* image id */
-               "%s: \n" /* image name */
-               "%s: \n" /* lyrics id */
-               "%s: \n" /* lyrics name */
-               "%s: \n" /* bitrate */
-               "%s: \n" /* format */
-               "%s: \n" /* frequency */
-               "%s: \n" /* channels */
-               "%s: \n" /* duration */
-               "%s: \n" /* seconds total */
-               "%s: \n" /* num played */
-               "%s: \n" /* last played */
-               "%s: \n" /* techinfo */
-               "%s: \n" /* artist */
-               "%s: \n" /* title */
-               "%s: \n" /* year */
-               "%s: \n" /* album */
-               "%s: \n" /* comment */
-               "%s: \n" /* amplification */
-               ,
-               status_item_list[SI_PATH],
-               status_item_list[SI_DIRECTORY],
-               status_item_list[SI_BASENAME],
-               status_item_list[SI_SCORE],
-               status_item_list[SI_ATTRIBUTES_BITMAP],
-               status_item_list[SI_ATTRIBUTES_TXT],
-               status_item_list[SI_HASH],
-               status_item_list[SI_IMAGE_ID],
-               status_item_list[SI_IMAGE_NAME],
-               status_item_list[SI_LYRICS_ID],
-               status_item_list[SI_LYRICS_NAME],
-               status_item_list[SI_BITRATE],
-               status_item_list[SI_FORMAT],
-               status_item_list[SI_FREQUENCY],
-               status_item_list[SI_CHANNELS],
-               status_item_list[SI_DURATION],
-               status_item_list[SI_SECONDS_TOTAL],
-               status_item_list[SI_NUM_PLAYED],
-               status_item_list[SI_LAST_PLAYED],
-               status_item_list[SI_TECHINFO],
-               status_item_list[SI_ARTIST],
-               status_item_list[SI_TITLE],
-               status_item_list[SI_YEAR],
-               status_item_list[SI_ALBUM],
-               status_item_list[SI_COMMENT],
-               status_item_list[SI_AMPLIFICATION]
-       );
-}
-
 static int make_status_items(struct audio_file_data *afd,
                struct afs_info *afsi, char *path, long score,
                HASH_TYPE *hash)
 static int make_status_items(struct audio_file_data *afd,
                struct afs_info *afsi, char *path, long score,
                HASH_TYPE *hash)
@@ -1043,19 +978,17 @@ static int make_status_items(struct audio_file_data *afd,
                .flags = LS_FLAG_FULL_PATH | LS_FLAG_ADMISSIBLE_ONLY,
                .mode = LS_MODE_VERBOSE,
        };
                .flags = LS_FLAG_FULL_PATH | LS_FLAG_ADMISSIBLE_ONLY,
                .mode = LS_MODE_VERBOSE,
        };
-       struct para_buffer pb = {.max_size = VERBOSE_LS_OUTPUT_SIZE - 1};
+       struct para_buffer pb = {.max_size = SHMMAX - 1};
        time_t current_time;
        int ret;
 
        time(&current_time);
        ret = print_list_item(&d, &opts, &pb, current_time);
        if (ret < 0)
        time_t current_time;
        int ret;
 
        time(&current_time);
        ret = print_list_item(&d, &opts, &pb, current_time);
        if (ret < 0)
-               goto out;
-       strncpy(afd->verbose_ls_output, pb.buf, VERBOSE_LS_OUTPUT_SIZE);
-       afd->verbose_ls_output[VERBOSE_LS_OUTPUT_SIZE - 1] = '\0';
-out:
-       free(pb.buf);
-       return ret;
+               return ret;
+       free(current_status_items);
+       current_status_items = pb.buf;
+       return 1;
 }
 
 /**
 }
 
 /**
@@ -2444,6 +2377,18 @@ int com_cpsi(int fd, int argc,  char * const * const argv)
        return ret;
 }
 
        return ret;
 }
 
+void afs_stat_callback(int fd, __a_unused const struct osl_object *query)
+{
+       if (current_status_items)
+               pass_buffer_as_shm(current_status_items,
+                       strlen(current_status_items), &fd);
+}
+
+int send_afs_status(int fd)
+{
+       return send_callback_request(afs_stat_callback, NULL, send_result, &fd);
+}
+
 /* TODO: optionally fix problems by removing offending rows */
 static int check_audio_file(struct osl_row *row, void *data)
 {
 /* TODO: optionally fix problems by removing offending rows */
 static int check_audio_file(struct osl_row *row, void *data)
 {
@@ -2522,6 +2467,8 @@ static void aft_close(void)
 {
        osl_close_table(audio_file_table, OSL_MARK_CLEAN);
        audio_file_table = NULL;
 {
        osl_close_table(audio_file_table, OSL_MARK_CLEAN);
        audio_file_table = NULL;
+       free(current_status_items);
+       current_status_items = NULL;
 }
 
 /**
 }
 
 /**