audiod: Make struct slot_info local to audiod.c.
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 4 Jan 2015 04:55:43 +0000 (04:55 +0000)
committerAndre Noll <maan@tuebingen.mpg.de>
Sat, 4 Apr 2015 17:53:37 +0000 (17:53 +0000)
Thanks to the previous commit there is only one user of struct
slot_info left in audiod_command.c: decoder_flags(). Moving this
function to audiod.c allows to make the structure private to audiod.c,
along with the slot array and the MAX_STREAM_SLOTS and FOR_EACH_SLOT
macros.

Since audiod_command still needs the decoder flags for the stat command,
the function is made public and renamed to audiod_get_decoder_flags().

audiod.c
audiod.h
audiod_command.c

index e73d14135b855b77f361a020d5c0484c4842b13f..1f226265b0c9c79593f255bba4805cfdb8a53e9a 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -68,6 +68,30 @@ struct audio_format_info {
        struct timeval restart_barrier;
 };
 
+/* Describes one instance of a receiver-filter-writer chain. */
+struct slot_info {
+       /* Number of the audio format in this slot. */
+       int format;
+       /* The stream_start status item announced by para_server.  */
+       struct timeval server_stream_start;
+       /* The offset status item announced by para_server. */
+       unsigned offset_seconds;
+       /* The seconds_total status item announced by para_server. */
+       unsigned seconds_total;
+       /* The receiver info associated with this slot. */
+       struct receiver_node *receiver_node;
+       /* The array of filter nodes. */
+       struct filter_node *fns;
+       /* The array of writers attached to the last filter. */
+       struct writer_node *wns;
+};
+
+/** Maximal number of simultaneous instances. */
+#define MAX_STREAM_SLOTS 5
+
+/** Iterate over all slots. */
+#define FOR_EACH_SLOT(_slot) for (_slot = 0; _slot < MAX_STREAM_SLOTS; _slot++)
+
 /**
  * para_audiod uses \p MAX_STREAM_SLOTS different slots, each of which may
  * be associated with a receiver/filter/writer triple. This array holds all
@@ -198,6 +222,35 @@ static int get_audio_format_num(const char *name)
        return -E_UNSUPPORTED_AUDIO_FORMAT;
 }
 
+/**
+ * Return the flags for the \a decoder_flags status item.
+ *
+ * Allocates a string which contains one octal digit per slot.  Bit zero (value
+ * 1) is set if a receiver is active. Bit one (value 2) and bit three (value 4)
+ * have the analogous meaning for filter and writer, respectively.
+ *
+ * \return String that must be freed by the caller.
+ */
+__malloc char *audiod_get_decoder_flags(void)
+{
+       int i;
+       char flags[MAX_STREAM_SLOTS + 1];
+
+       FOR_EACH_SLOT(i) {
+               struct slot_info *s = &slot[i];
+               char flag = '0';
+               if (s->receiver_node)
+                       flag += 1;
+               if (s->fns)
+                       flag += 2;
+               if (s->wns)
+                       flag += 4;
+               flags[i] = flag;
+       }
+       flags[MAX_STREAM_SLOTS] = '\0';
+       return para_strdup(flags);
+}
+
 static int get_matching_audio_format_nums(const char *re)
 {
        int i, ret;
index 7fc9eb14aa25ba5df6bf35347a452148922fd02a..94288eec702dd016dbebcaa2f5bf68a882aab1e7 100644 (file)
--- a/audiod.h
+++ b/audiod.h
@@ -13,9 +13,6 @@ enum {AUDIOD_AUDIO_FORMATS_ENUM};
 /** array of audio format names supported by para_audiod */
 extern const char *audio_formats[];
 
-/** maximal number of simultaneous instances */
-#define MAX_STREAM_SLOTS 5
-
 /**
  * the possible modes of operation
  *
@@ -39,30 +36,7 @@ struct audiod_command {
        const char *help;
 };
 
-/**
- * Describes one instance of a receiver-filter-writer chain.
- *
- * \sa receiver_node, receiver, filter, filter_node, writer, writer_node,
- * writer_node_group.
- */
-struct slot_info {
-       /** Number of the audio format in this slot. */
-       int format;
-       /** The stream_start status item announced by para_server.  */
-       struct timeval server_stream_start;
-       /** The offset status item announced by para_server. */
-       unsigned offset_seconds;
-       /** The seconds_total status item announced by para_server. */
-       unsigned seconds_total;
-       /** The receiver info associated with this slot. */
-       struct receiver_node *receiver_node;
-       /** The array of filter nodes. */
-       struct filter_node *fns;
-       /** The array of writers attached to the last filter. */
-       struct writer_node *wns;
-};
-
-extern struct slot_info slot[MAX_STREAM_SLOTS];
+__malloc char *audiod_get_decoder_flags(void);
 extern struct audiod_args_info conf;
 extern int audiod_status;
 
@@ -74,6 +48,3 @@ struct btr_node *audiod_get_btr_root(void);
 void stat_client_write_item(int item_num);
 void clear_and_dump_items(void);
 void close_stat_clients(void);
-
-/** iterate over all slots */
-#define FOR_EACH_SLOT(_slot) for (_slot = 0; _slot < MAX_STREAM_SLOTS; _slot++)
index 790c0102c896d6a49d90c4f84d7db8ed6404abad..b847e5aa264fa4ccb9e8c9aafcfcb61713ae2131 100644 (file)
@@ -216,26 +216,6 @@ __malloc static char *audiod_status_string(void)
        return para_strdup(status);
 }
 
-__malloc static char *decoder_flags(void)
-{
-       int i;
-       char flags[MAX_STREAM_SLOTS + 1];
-
-       FOR_EACH_SLOT(i) {
-               struct slot_info *s = &slot[i];
-               char flag = '0';
-               if (s->receiver_node)
-                       flag += 1;
-               if (s->fns)
-                       flag += 2;
-               if (s->wns)
-                       flag += 4;
-               flags[i] = flag;
-       }
-       flags[MAX_STREAM_SLOTS] = '\0';
-       return para_strdup(flags);
-}
-
 static int dump_commands(int fd)
 {
        char *buf = para_strdup(""), *tmp = NULL;
@@ -525,7 +505,7 @@ void audiod_status_dump(bool force)
                free(new);
 
        old = stat_item_values[SI_DECODER_FLAGS];
-       new = decoder_flags();
+       new = audiod_get_decoder_flags();
        if (force || !old || strcmp(old, new)) {
                free(old);
                stat_item_values[SI_DECODER_FLAGS] = new;