]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - aft.c
Replace struct table_info by struct afs_table.
[paraslash.git] / aft.c
diff --git a/aft.c b/aft.c
index 431bedb63c1c1bb58a632aa055eeaf8a98198ce7..c63ab47106866dd5caa9e99062377c742b999a68 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -8,12 +8,12 @@
 
 #include "para.h"
 #include "error.h"
+#include "string.h"
 #include <sys/mman.h>
 #include <fnmatch.h>
 #include "afh.h"
 #include "afs.h"
 #include "net.h"
-#include "string.h"
 #include "vss.h"
 
 static struct osl_table *audio_file_table;
@@ -298,12 +298,19 @@ bad_path:
        return -E_BAD_PATH;
 }
 
+/** The on-disk layout of a afhi struct. */
 enum afhi_offsets {
+       /** Where the number of seconds is stored. */
        AFHI_SECONDS_TOTAL_OFFSET = 0,
+       /** Position of the bitrate. */
        AFHI_BITRATE_OFFSET = 4,
+       /** Position of the frequency. */
        AFHI_FREQUENCY_OFFSET = 8,
+       /** Number of channels is stored here. */
        AFHI_CHANNELS_OFFSET = 12,
+       /** The tag info position. */
        AFHI_INFO_STRING_OFFSET = 13,
+       /** Minimal on-disk size of a valid afhi struct. */
        MIN_AFHI_SIZE = 14
 };
 
@@ -670,6 +677,7 @@ static int get_local_time(uint64_t *seconds, char *buf, size_t size,
        return 1;
 }
 
+/** Compute the number of (decimal) digits of a number. */
 #define GET_NUM_DIGITS(x, num) { \
        typeof((x)) _tmp = PARA_ABS(x); \
        *num = 1; \
@@ -1363,13 +1371,17 @@ afhi <=> force or no HS
 
 */
 
-
-#define ADD_FLAG_LAZY 1
-#define ADD_FLAG_FORCE 2
-#define ADD_FLAG_VERBOSE 4
-#define ADD_FLAG_ALL 8
-
-/* TODO: change log messages so that they get written to the result buffer */
+/** Flags passed to the add command. */
+enum com_add_flags {
+       /** Skip paths that exist already. */
+       ADD_FLAG_LAZY = 1,
+       /** Force adding. */
+       ADD_FLAG_FORCE = 2,
+       /** Print what is being done. */
+       ADD_FLAG_VERBOSE = 4,
+       /** Try to add files with unknown suffixes. */
+       ADD_FLAG_ALL = 8,
+};
 
 static int com_add_callback(const struct osl_object *query,
                struct osl_object *result)
@@ -1683,8 +1695,15 @@ int com_add(int fd, int argc, char * const * const argv)
 
 }
 
+/**
+ * Flags used by the touch command.
+ *
+ * \sa com_touch().
+ */
 enum touch_flags {
+       /** Whether the \p FNM_PATHNAME flag should be passed to fnmatch(). */
        TOUCH_FLAG_FNM_PATHNAME = 1,
+       /** Activates verbose mode. */
        TOUCH_FLAG_VERBOSE = 2
 };
 
@@ -1947,12 +1966,23 @@ int com_afs_rm(int fd, int argc,  char * const * const argv)
        return ret;
 }
 
+/**
+ * Flags used by the cpsi command.
+ *
+ * \sa com_cpsi().
+ */
 enum cpsi_flags {
+       /** Whether the lyrics id should be copied. */
        CPSI_FLAG_COPY_LYRICS_ID = 1,
+       /** Whether the image id should be copied. */
        CPSI_FLAG_COPY_IMAGE_ID = 2,
+       /** Whether the lastplayed time should be copied. */
        CPSI_FLAG_COPY_LASTPLAYED = 4,
+       /** Whether the numplayed count should be copied. */
        CPSI_FLAG_COPY_NUMPLAYED = 8,
+       /** Whether the attributes should be copied. */
        CPSI_FLAG_COPY_ATTRIBUTES = 16,
+       /** Activates verbose mode. */
        CPSI_FLAG_VERBOSE = 32,
 };
 
@@ -2123,6 +2153,16 @@ static int check_audio_file(struct osl_row *row, void *data)
        return 1;
 }
 
+/**
+ * Check the audio file table for inconsistencies.
+ *
+ * \param query Unused.
+ * \param result Contains message string upon return.
+ *
+ * This function always succeeds.
+ *
+ * \sa com_check().
+ */
 int aft_check_callback(__a_unused const struct osl_object *query, struct osl_object *result)
 {
        struct para_buffer pb = {.buf = NULL};
@@ -2135,8 +2175,6 @@ int aft_check_callback(__a_unused const struct osl_object *query, struct osl_obj
 
 }
 
-
-
 /**
  * Close the audio file table.
  *
@@ -2144,29 +2182,27 @@ int aft_check_callback(__a_unused const struct osl_object *query, struct osl_obj
  *
  * \sa osl_close_table().
  */
-void aft_shutdown(enum osl_close_flags flags)
+static void aft_close(void)
 {
-       osl_close_table(audio_file_table, flags);
+       osl_close_table(audio_file_table, OSL_MARK_CLEAN);
        audio_file_table = NULL;
 }
 
 /**
  * Open the audio file table.
  *
- * \param ti Gets initialized by this function.
- * \param db The database directory.
+ * \param dir The database directory.
  *
- * \return Positive on success, negative on errors.
+ * \return Standard.
  *
  * \sa osl_open_table().
  */
-int aft_init(struct table_info *ti, const char *db)
+static int aft_open(const char *dir)
 {
        int ret;
 
-       audio_file_table_desc.dir = db;
-       ti->desc = &audio_file_table_desc;
-       ret = osl_open_table(ti->desc, &audio_file_table);
+       audio_file_table_desc.dir = dir;
+       ret = osl_open_table(&audio_file_table_desc, &audio_file_table);
        if (ret >= 0) {
                unsigned num;
                osl_get_num_rows(audio_file_table, &num);
@@ -2175,5 +2211,21 @@ int aft_init(struct table_info *ti, const char *db)
        }
        PARA_INFO_LOG("failed to open audio file table\n");
        audio_file_table = NULL;
-       return ret == -E_NOENT? 1 : ret;
+       if (ret >= 0 || is_errno(-ret, ENOENT))
+               return 1;
+       return ret;
+}
+
+static int aft_create(const char *dir)
+{
+       audio_file_table_desc.dir = dir;
+       return osl_create_table(&audio_file_table_desc);
+}
+
+void aft_init(struct afs_table *t)
+{
+       t->name = audio_file_table_desc.name;
+       t->open = aft_open;
+       t->close = aft_close;
+       t->create = aft_create;
 }