gnome-applets r11119 - trunk/multiload



Author: callum
Date: Sun Nov  9 18:38:25 2008
New Revision: 11119
URL: http://svn.gnome.org/viewvc/gnome-applets?rev=11119&view=rev

Log:
Add missing files from the recent multiload update.

Added:
   trunk/multiload/netspeed.c
   trunk/multiload/netspeed.h

Added: trunk/multiload/netspeed.c
==============================================================================
--- (empty file)
+++ trunk/multiload/netspeed.c	Sun Nov  9 18:38:25 2008
@@ -0,0 +1,64 @@
+#include <config.h>
+#include <glib.h>
+#include <time.h>
+
+#include "netspeed.h"
+
+enum { N_STATES = 4 };
+
+struct _NetSpeed
+{
+	LoadGraph *graph;
+	gulong states[N_STATES];
+	size_t cur;
+};
+
+NetSpeed* netspeed_new(LoadGraph *g)
+{
+	NetSpeed *ns = g_new0(NetSpeed, 1);
+	ns->graph = g;
+	return ns;
+}
+
+void netspeed_delete(NetSpeed *ns)
+{
+	g_free(ns);
+}
+
+void netspeed_add(NetSpeed *ns, gulong tx)
+{
+	ns->cur = (ns->cur + 1) % N_STATES;
+	ns->states[ns->cur] = tx;
+}
+
+/* Something very similar to g_format_size_for_display() but for rates.
+ * This should give the same display as in g-s-m */
+static char*
+format_rate_for_display(guint rate)
+{
+	char* bytes = g_format_size_for_display(rate);
+	return g_strdup_printf(_("%s/s"), bytes);
+}
+
+char* netspeed_get(NetSpeed *ns)
+{
+	gulong older, newer;
+	guint rate;
+
+	newer = ns->states[ns->cur];
+	older = ns->states[(ns->cur + 1) % N_STATES];
+
+	if ((older != 0) && (newer > older))
+		rate = (newer - older) * 1000 / ((N_STATES - 1) * ns->graph->speed);
+	else
+	        /* We end up here if we haven't got enough data yet or the
+		   network interface has jumped back (or there has never
+		   been any activity on any interface). A value of 0 is
+		   likely to be accurate, but if it is wrong it will be
+		   clearly wrong. In any event, it should fix itself in a
+		   few seconds. */
+	        rate = 0;
+
+	return format_rate_for_display(rate);
+}
+

Added: trunk/multiload/netspeed.h
==============================================================================
--- (empty file)
+++ trunk/multiload/netspeed.h	Sun Nov  9 18:38:25 2008
@@ -0,0 +1,15 @@
+#ifndef H_MULTILOAD_NETSPEED_
+#define H_MULTILOAD_NETSPEED_
+
+#include <glib/gtypes.h>
+
+typedef struct _NetSpeed NetSpeed;
+
+#include "global.h"
+
+NetSpeed* netspeed_new(LoadGraph *graph);
+void netspeed_delete(NetSpeed *ns);
+void netspeed_add(NetSpeed *ns, gulong tx);
+char* netspeed_get(NetSpeed *ns);
+
+#endif /* H_MULTILOAD_NETSPEED_ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]