audioc stat: Make status item mask 64 bits wide.
authorAndre Noll <maan@systemlinux.org>
Sat, 4 Jul 2009 14:21:36 +0000 (16:21 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 4 Jul 2009 14:21:36 +0000 (16:21 +0200)
We already have more than 32 status items.

audiod_command.c
para.h
stat.c

index 3467dbe1a1990c566b353c7450a828828996bdbc..fe30b2476e6dd99738325df1fccb4c34d646d3b4 100644 (file)
@@ -170,19 +170,20 @@ int com_stat(int fd, __a_unused int argc, __a_unused char **argv)
 {
        int i, ret;
        char *buf = NULL;
-       long unsigned mask = ~0LU;
+       uint64_t mask = 0;
+       const uint64_t one = 1;
 
        if (argc > 1) {
-               mask = 0;
                for (i = 1; i < argc; i++) {
                        ret = stat_item_valid(argv[i]);
                        if (ret < 0)
                                return ret;
-                       mask |= (1 << ret);
+                       mask |= (one << ret);
                }
-       }
-       PARA_INFO_LOG("mask: 0x%lx\n", mask);
-       if (mask & (1 << SI_PLAY_TIME)) {
+       } else
+               mask--; /* set all bits */
+       PARA_INFO_LOG("mask: 0x%llx\n", (long long unsigned)mask);
+       if (mask & (one << SI_PLAY_TIME)) {
                int slot_num = get_play_time_slot_num();
                char *ts = get_time_string(slot_num);
                if (ts) {
@@ -192,7 +193,7 @@ int com_stat(int fd, __a_unused int argc, __a_unused char **argv)
                        free(ts);
                }
        }
-       if (mask & (1 << SI_AUDIOD_UPTIME)) {
+       if (mask & (one << SI_AUDIOD_UPTIME)) {
                char *tmp, *us = uptime_str();
                tmp = make_message("%s: %s\n",
                        status_item_list[SI_AUDIOD_UPTIME], us);
@@ -202,14 +203,14 @@ int com_stat(int fd, __a_unused int argc, __a_unused char **argv)
                        goto out;
                free(tmp);
        }
-       if (mask & (1 << SI_AUDIOD_STATUS)) {
+       if (mask & (one << SI_AUDIOD_STATUS)) {
                char *s = audiod_status_string();
                ret = client_write(fd, s);
                if (ret < 0)
                        goto out;
                free(s);
        }
-       if (mask & (1 << SI_DECODER_FLAGS)) {
+       if (mask & (one << SI_DECODER_FLAGS)) {
                char *df = decoder_flags();
                ret = client_write(fd, df);
                if (ret < 0)
@@ -218,7 +219,7 @@ int com_stat(int fd, __a_unused int argc, __a_unused char **argv)
        }
        FOR_EACH_STATUS_ITEM(i) {
                char *tmp, *v;
-               if (!((1 << i) & mask))
+               if (!((one << i) & mask))
                        continue;
                v = stat_item_values[i];
                tmp = make_message("%s%s%s", buf? buf: "",
diff --git a/para.h b/para.h
index 7cdc5e078b360fbb9730e9e5f79b9306c2f6d9fb..e4e9a53dd96c740e2178b9d439cf8ed6e790ffb3 100644 (file)
--- a/para.h
+++ b/para.h
@@ -183,7 +183,7 @@ extern const char *status_item_list[];
 int stat_item_valid(const char *item);
 int stat_line_valid(const char *);
 void stat_client_write(const char *msg, int itemnum);
-int stat_client_add(int fd, long unsigned mask);
+int stat_client_add(int fd, uint64_t mask);
 
 __printf_2_3 void para_log(int, const char*, ...);
 
diff --git a/stat.c b/stat.c
index 4ba1b0e8485a8125d2fcdd6353e8508e83417340..0306cba4b2432ba7c09a0310d6ef762d581843a6 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -35,7 +35,7 @@ struct stat_client {
        /** The stat client's file descriptor. */
        int fd;
        /** Bitmask of those status items the client is interested in. */
-       long unsigned item_mask;
+       uint64_t item_mask;
        /** Its entry in the list of stat clients. */
        struct list_head node;
 };
@@ -68,7 +68,7 @@ static void dump_stat_client_list(void)
  * \return Positive value on success, or -E_TOO_MANY_CLIENTS if
  * the number of connected clients exceeds #MAX_STAT_CLIENTS.
  */
-int stat_client_add(int fd, long unsigned mask)
+int stat_client_add(int fd, uint64_t mask)
 {
        struct stat_client *new_client;
 
@@ -103,13 +103,14 @@ void stat_client_write(const char *msg, int itemnum)
 {
        struct stat_client *sc, *tmp;
        size_t len = strlen(msg);
+       const uint64_t one = 1;
 
        if (!initialized || !len)
                return;
        list_for_each_entry_safe(sc, tmp, &client_list, node) {
                int fd = sc->fd, ret;
 
-               if (!((1 << itemnum) & sc->item_mask))
+               if (!((one << itemnum) & sc->item_mask))
                        continue;
                if (write_ok(fd) > 0) {
                        ret = write(fd, msg, len);