summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac14
-rw-r--r--plugins/Makefile.am5
-rw-r--r--plugins/netbsd/Makefile.am23
-rw-r--r--plugins/netbsd/netbsd-plugin.c189
-rw-r--r--plugins/netbsd/netbsd-plugin.h24
5 files changed, 255 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 99c8642..0296d06 100644
--- a/configure.ac
+++ b/configure.ac
@@ -242,6 +242,19 @@ else
AC_DEFINE_UNQUOTED(ATICONFIG_EXE, ["$aticonfig_exe"], [aticonfig executable])
fi
+# enable netbsd plugin
+AC_ARG_ENABLE(netbsd,
+ AS_HELP_STRING([--enable-netbsd],
+ [Enable NetBSD plugin.]),
+ enable_netbsd=$enableval, enable_netbsd="no")
+
+if test "x$enable_netbsd" = "xyes" ; then
+ echo "Enabling NetBSD support"
+fi
+
+# use same test as above, because AM_CONDITIONAL may not be in if/else
+AM_CONDITIONAL(NETBSD, test "x$enable_netbsd" = "xyes")
+
AC_SUBST(CFLAGS)
# for help docs stuff
AC_PATH_PROG(XSLTPROC, xsltproc, no)
@@ -279,6 +292,7 @@ AC_CONFIG_FILES([
plugins/ibm-acpi/Makefile
plugins/libsensors/Makefile
plugins/mbmon/Makefile
+ plugins/netbsd/Makefile
plugins/nvidia/Makefile
plugins/aticonfig/Makefile
plugins/omnibook/Makefile
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 3e0f9e2..ef8a789 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -9,6 +9,7 @@ DIST_SUBDIRS = \
ibm-acpi \
libsensors \
mbmon \
+ netbsd \
nvidia \
omnibook \
pmu-sys \
@@ -41,6 +42,10 @@ else
SUBDIRS += i2c-proc i2c-sys
endif
+if NETBSD
+SUBDIRS += netbsd
+endif
+
if NVIDIA
SUBDIRS += nvidia
endif
diff --git a/plugins/netbsd/Makefile.am b/plugins/netbsd/Makefile.am
new file mode 100644
index 0000000..61e506f
--- /dev/null
+++ b/plugins/netbsd/Makefile.am
@@ -0,0 +1,23 @@
+# NetBSD plugin
+plugindir = $(libdir)/mate-sensors-applet/plugins
+
+AM_CPPFLAGS = -DMATELOCALEDIR=\""$(datadir)/locale/"\" \
+ -DG_LOG_DOMAIN=\""Sensors Applet"\" \
+ -DPIXMAPS_DIR=\""$(datadir)/pixmaps/$(PACKAGE)/"\" \
+ -DDATADIR=\""$(datadir)"\" \
+ -DLIBDIR=\""$(libdir)"\" \
+ -DSYSCONFDIR=\""$(sysconfdir)"\" \
+ -DPREFIX=\""$(prefix)"\" \
+ -I$(top_srcdir) \
+ $(GLIB_CFLAGS)
+
+
+plugin_LTLIBRARIES = libnetbsd.la
+
+libnetbsd_la_SOURCES = \
+ netbsd-plugin.h \
+ netbsd-plugin.c
+
+libnetbsd_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS) $(GLIB_LIBS) -lprop
+
+libnetbsd_la_LIBADD = $(top_builddir)/lib/libmate-sensors-applet-plugin.la
diff --git a/plugins/netbsd/netbsd-plugin.c b/plugins/netbsd/netbsd-plugin.c
new file mode 100644
index 0000000..50f5da3
--- /dev/null
+++ b/plugins/netbsd/netbsd-plugin.c
@@ -0,0 +1,189 @@
+/*
+ * Copyright (C) 2018 Jared McNeill <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <prop/proplib.h>
+#include <sys/envsys.h>
+
+#include "netbsd-plugin.h"
+
+static int sysmon_fd = -1;
+
+static gdouble netbsd_plugin_get_sensor_value(const gchar *path,
+ const gchar *id,
+ SensorType type,
+ GError **error) {
+
+ prop_dictionary_t dict;
+ prop_array_t array;
+ prop_object_iterator_t iter, siter;
+ prop_object_t obj, sobj;
+ const gchar *desc = NULL, *state = NULL;
+ gdouble sensor_val = -1.0f;
+ int64_t val;
+
+ if (prop_dictionary_recv_ioctl(sysmon_fd, ENVSYS_GETDICTIONARY, &dict) == -1)
+ return sensor_val;
+
+ iter = prop_dictionary_iterator(dict);
+ while ((obj = prop_object_iterator_next(iter)) != NULL) {
+ if (strcmp(path, prop_dictionary_keysym_cstring_nocopy(obj)) != 0)
+ continue;
+
+ array = prop_dictionary_get_keysym(dict, obj);
+ siter = prop_array_iterator(array);
+ while ((sobj = prop_object_iterator_next(siter)) != NULL) {
+ if (prop_dictionary_get_cstring_nocopy(sobj, "description", &desc) == false)
+ continue;
+ if (strcmp(id, desc) != 0)
+ continue;
+
+ prop_dictionary_get_cstring_nocopy(sobj, "state", &state);
+ prop_dictionary_get_int64(sobj, "cur-value", &val);
+
+ if (strcmp(state, "valid") == 0) {
+ switch (type) {
+ case TEMP_SENSOR:
+ /* K to C */
+ sensor_val = ((val - 273150000) / 1000000.0);
+ break;
+ case FAN_SENSOR:
+ /* RPM */
+ sensor_val = (gdouble)val;
+ break;
+ case VOLTAGE_SENSOR:
+ /* uV to V */
+ sensor_val = val / 1000000.0;
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ }
+ prop_object_iterator_release(siter);
+ break;
+ }
+ prop_object_iterator_release(iter);
+
+ prop_object_release(dict);
+
+ return sensor_val;
+}
+
+static IconType netbsd_plugin_get_sensor_icon(const gchar *desc) {
+ IconType icontype = GENERIC_ICON;
+
+ if (strcasestr(desc, "cpu") != NULL)
+ icontype = CPU_ICON;
+ else if (strcasestr(desc, "gpu") != NULL)
+ icontype = GPU_ICON;
+ else if (strcasestr(desc, "batt") != NULL)
+ icontype = BATTERY_ICON;
+ else if (strcasestr(desc, "mem") != NULL)
+ icontype = MEMORY_ICON;
+ else if (strcasestr(desc, "disk") != NULL || strcasestr(desc, "hdd") != NULL)
+ icontype = HDD_ICON;
+
+ return icontype;
+}
+
+static void netbsd_plugin_get_sensors(GList **sensors) {
+ prop_dictionary_t dict;
+ prop_array_t array;
+ prop_object_iterator_t iter, siter;
+ prop_object_t obj, sobj;
+
+ sysmon_fd = open("/dev/sysmon", O_RDONLY);
+ if (sysmon_fd == -1)
+ return;
+
+ if (prop_dictionary_recv_ioctl(sysmon_fd, ENVSYS_GETDICTIONARY, &dict) == -1) {
+ close(sysmon_fd);
+ return;
+ }
+
+ iter = prop_dictionary_iterator(dict);
+ while ((obj = prop_object_iterator_next(iter)) != NULL) {
+ const gchar *path = prop_dictionary_keysym_cstring_nocopy(obj);
+ array = prop_dictionary_get_keysym(dict, obj);
+ siter = prop_array_iterator(array);
+ while ((sobj = prop_object_iterator_next(siter)) != NULL) {
+ const gchar *type = NULL, *desc = NULL;
+ if (prop_dictionary_get_cstring_nocopy(sobj, "type", &type) == false)
+ continue;
+ if (prop_dictionary_get_cstring_nocopy(sobj, "description", &desc) == false)
+ continue;
+
+ SensorType sensortype;
+ if (strcmp(type, "Fan") == 0)
+ sensortype = FAN_SENSOR;
+ else if (strcmp(type, "Temperature") == 0)
+ sensortype = TEMP_SENSOR;
+ else if (strcmp(type, "Voltage AC") == 0 || strcmp(type, "Voltage DC") == 0)
+ sensortype = VOLTAGE_SENSOR;
+ else
+ continue;
+
+ IconType icontype = netbsd_plugin_get_sensor_icon(desc);
+
+ sensors_applet_plugin_add_sensor(sensors,
+ g_strdup(path),
+ g_strdup(desc),
+ g_strdup(desc),
+ sensortype,
+ TRUE,
+ icontype,
+ DEFAULT_GRAPH_COLOR);
+ }
+ prop_object_iterator_release(siter);
+ }
+ prop_object_iterator_release(iter);
+
+ prop_object_release(dict);
+}
+
+static GList *netbsd_plugin_init(void) {
+ GList *sensors = NULL;
+
+ netbsd_plugin_get_sensors(&sensors);
+
+ return sensors;
+}
+
+/* API functions */
+const gchar *sensors_applet_plugin_name(void) {
+ return "netbsd";
+}
+
+GList *sensors_applet_plugin_init(void) {
+ return netbsd_plugin_init();
+}
+
+gdouble sensors_applet_plugin_get_sensor_value(const gchar *path,
+ const gchar *id,
+ SensorType type,
+ GError **error) {
+
+ return netbsd_plugin_get_sensor_value(path, id, type, error);
+}
diff --git a/plugins/netbsd/netbsd-plugin.h b/plugins/netbsd/netbsd-plugin.h
new file mode 100644
index 0000000..c2d2013
--- /dev/null
+++ b/plugins/netbsd/netbsd-plugin.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2018 Jared McNeill <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef NETBSD_PLUGIN_H
+#define NETBSD_PLUGIN_H
+
+#include <sensors-applet/sensors-applet-plugin.h>
+
+#endif /* NETBSD_PLUGIN_H */