Simple output gathering design
[sysstatus.git] / src / status / netif.c
index 23e6520a61f6cdecfcdb71e4800e392577351d0d..3c0fef0ba1e2c8b6d435a17d5396750bf7a878c9 100644 (file)
@@ -3,7 +3,7 @@
 #include <unistd.h>
 #include <string.h>
 
-#include "status/netif.h"
+#include "common.h"
 #include "tools.h"
 #include "config.h"
 
 #endif
 
 
-void status_netif(char *ifname)
+void status_netif(GlobalData *g, char *ifname)
 {
+  StatusItem s;
+  char text[16] = { 0 };
+
   char ifpath[256];
   int ifpathlen;
 
@@ -24,6 +27,9 @@ void status_netif(char *ifname)
   int ifsumpower;
 
 
+  statusitem_init(&s);
+  s.text = text;
+
   /* Prepare path */
   ifpathlen = sizeof(NETIF_BASEDIR) - 1 + strlen(ifname);
   if (ifpathlen + 1 + sizeof("/statistics/rx_bytes") >= sizeof(ifpath)) {
@@ -38,7 +44,7 @@ void status_netif(char *ifname)
 
   /* Is the interface up? */
   if (access(ifpath, F_OK)) {
-    //printf(" ^fg(grey)[%s] ", ifname);
+    //s.color = "grey";
     return;
   }
 
@@ -47,9 +53,9 @@ void status_netif(char *ifname)
   stlen = fileRead(stline, sizeof(stline), ifpath);
   if (stlen > 0) {
     if (stline[0] == '1') {
-      fputs("^fg(yellow)", stdout);
+      s.color = "yellow";
     } else {
-      //fputs("^fg(red)", stdout);
+      //s.color = "red";
       return;
     }
   } else {
@@ -73,8 +79,11 @@ void status_netif(char *ifname)
     ifsum = ifsum / 1024;
   }
 
-  printf(" %s: %.*f %c ", ifname,
-                          ifsumpower ? ifsumpower - 1 : ifsumpower,
-                          ifsum,
-                          powerToChar(ifsumpower));
+  snprintf(text, sizeof(text), "%s: %.*f %c",
+            ifname,
+            ifsumpower ? ifsumpower - 1 : ifsumpower,
+            ifsum,
+            powerToChar(ifsumpower));
+
+  line_append_item(g, &s);
 }