[Xfce4-commits] <xfce4-sensors-plugin:master> applied patch 7438 and the one with netcat; began splitting of panel-related stuff and the stand-alone app
Fabian
noreply at xfce.org
Thu Mar 24 23:44:03 CET 2011
Updating branch refs/heads/master
to 2b46dea7b88caae97408387c98ee5a98bfd74f6c (commit)
from 916596d6712d0cff9012f9a0a790396bb4db10fa (commit)
commit 2b46dea7b88caae97408387c98ee5a98bfd74f6c
Author: Fabian <timystery at arcor.de>
Date: Thu Mar 24 23:44:02 2011 +0100
applied patch 7438 and the one with netcat; began splitting of panel-related stuff and the stand-alone app
configure.in.in | 39 +++++++-
include/Makefile.am | 4 +-
include/middlelayer.h | 2 +-
include/nvidia.h | 41 ++++++++
include/sensors-interface-common.h | 174 +----------------------------------
include/sensors-interface-types.h | 28 ++++++
include/types.h | 3 +-
lib/Makefile.am | 20 ++++-
lib/hddtemp.c | 94 +++++++++++++------
lib/libxfce4sensors-1.0.pc.in | 1 +
lib/middlelayer.c | 27 ++++++
lib/nvidia.c | 182 ++++++++++++++++++++++++++++++++++++
panel-plugin/sensors-plugin.c | 2 +-
13 files changed, 407 insertions(+), 210 deletions(-)
diff --git a/configure.in.in b/configure.in.in
index 8cf0caf..9dceae7 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -161,11 +161,11 @@ if test x"$enable_netcat" = x"yes"; then
dnl AC_DEFINE([HAVE_NETCAT], [0], [Define to 1 if hddtemp daemon is queried via netcat])
else
AC_DEFINE([HAVE_NETCAT], [1], [Define to 1 if hddtemp daemon is queried via netcat])
- AC_DEFINE_UNQUOTED([NETCAT_PATH], ["$NETCAT_PATH"], [Complete path to netcat])
+ AC_DEFINE_UNQUOTED([NETCAT_PATH], [$NETCAT_PATH], [Complete path to netcat])
AC_SUBST([NETCAT_PATH])
- AC_DEFINE_UNQUOTED([NETCAT_HOST], ["$NETCAT_HOST"], [Host for netcat])
+ AC_DEFINE_UNQUOTED([NETCAT_HOST], [$NETCAT_HOST], [Host for netcat])
AC_SUBST([NETCAT_HOST])
- AC_DEFINE_UNQUOTED([HDDTEMP_PORT], ["$HDDTEMP_PORT"], [Port for hddtemp with netcat])
+ AC_DEFINE_UNQUOTED([HDDTEMP_PORT], [$HDDTEMP_PORT], [Port for hddtemp with netcat])
AC_SUBST([HDDTEMP_PORT])
fi
@@ -217,8 +217,41 @@ if test x"$enable_sysfsacpi" = x"yes"; then
enable_procacpi=yes
fi
+dnl Check for nvidia blahblah to be used
+AC_ARG_ENABLE([xnvctrl],
+ AC_HELP_STRING([--enable-xnvctrl],
+ [Use nvctrl to obtain Nvidia GPU temperature value @<:@default=auto@:>@]),
+ [],
+[
+ enable_xnvctrl=auto
+])
+
+if test x"$enable_xnvctrl" = x"auto"; then
+ AC_CHECK_FILE([/usr/include/NVCtrl],
+ [
+ enable_xnvctrl=yes
+ ],
+ [
+ enable_xnvctrl=no
+ ])
+fi
+
+if test x"$enable_xnvctrl" = x"yes"; then
+ AC_DEFINE([HAVE_NVIDIA], [1], [Define to 1 if media-video/nvidia-drivers installed])
+ NVIDIA_CFLAGS="-I/usr/include/NVCtrl"
+ NVIDIA_LIBS="-lX11 -lXext -lXNVCtrl"
+ enable_xnvctrl=yes
+AC_SUBST([NVIDIA_CFLAGS])
+AC_SUBST([NVIDIA_LDFLAGS])
+fi
+
+
+
+
+
AM_CONDITIONAL([HAVE_ACPI], [test x$enable_procacpi = x"yes"])
AM_CONDITIONAL([HAVE_SYSFS_ACPI], [test x$enable_sysfsacpi = x"yes"])
+AM_CONDITIONAL([HAVE_NVIDIA], [test x$enable_xnvctrl = x"yes"])
dnl Check for full debugging
diff --git a/include/Makefile.am b/include/Makefile.am
index 0662562..158e83c 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -6,10 +6,12 @@ EXTRA_DIST = \
cpu.h \
Makefile.am \
sensors-interface-common.h \
+ sensors-interface-plugin.h \
types.h \
configuration.h \
lmsensors.h \
middlelayer.h \
- sensors-interface.h
+ sensors-interface.h \
+ nvidia.h
# vi:set ts=4 sw=4 noet ai nocindent syntax=automake:
diff --git a/include/middlelayer.h b/include/middlelayer.h
index 7c22513..2a8e026 100644
--- a/include/middlelayer.h
+++ b/include/middlelayer.h
@@ -25,7 +25,7 @@
/* Package/Local includes in same folder */
#include "types.h"
-#include "sensors-interface-common.h"
+#include "sensors-interface-plugin.h" // includes ....common.h
/* Gtk/Glib includes */
#include <glib.h>
diff --git a/include/nvidia.h b/include/nvidia.h
new file mode 100644
index 0000000..4452a9d
--- /dev/null
+++ b/include/nvidia.h
@@ -0,0 +1,41 @@
+/* Copyright (c) 2011 Amir Aupov <fads93 at gmail.com>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef XFCE4_SENSORS_NVIDIA_H
+#define XFCE4_SENSORS_NVIDIA_H
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* Gtk/Glib includes */
+#include <glib.h>
+#include <NVCtrl/NVCtrl.h>
+/*
+ * Initialize nvidia sensor
+ */
+int initialize_nvidia (GPtrArray *chips);
+
+/*
+ * Refresh an nvidia chip's feature
+ */
+void refresh_nvidia (gpointer chip_feature, gpointer data);
+
+
+double get_nvidia_value (int gpu);
+
+#endif /* XFCE4_SENSORS_NVIDIA_H */
diff --git a/include/sensors-interface-common.h b/include/sensors-interface-common.h
index 654bbb4..94c4011 100644
--- a/include/sensors-interface-common.h
+++ b/include/sensors-interface-common.h
@@ -30,11 +30,10 @@
#include <glib.h>
/* #include <glib/gprintf.h> */
-/* Xfce includes */
-#include <libxfce4panel/libxfce4panel.h>
/* Package includes */
#include <types.h>
+#include <sensors-interface-plugin.h>
/* Definitions */
#define BORDER 8
@@ -45,172 +44,6 @@
#define COLOR_WARN "#F0F000"
#define COLOR_NORMAL "#00C000"
-/**
- * compound widget displaying a progressbar and optional label
- */
-typedef struct {
- /* the progress bar */
- GtkWidget *progressbar;
-
- /* the label */
- GtkWidget *label;
-
- /* the surrounding box */
- GtkWidget *databox;
-} t_barpanel;
-
-
-typedef enum {
- DISPLAY_TEXT = 1,
- DISPLAY_BARS,
- DISPLAY_TACHO
-} display_t;
-
-/**
- * Sensors module
- */
-typedef struct {
-
- XfcePanelPlugin *plugin;
-
- /* eventbox to catch events */
- GtkWidget *eventbox;
-
- /* our XfceSensors widget */
- GtkWidget *widget_sensors;
-
- /* panel value display */
- GtkWidget *panel_label_data;
-
- /* optional label for plugin */
- GtkWidget *panel_label_text;
-
- /* update the tooltip */
- gint timeout_id;
-
- /* font size for display in panel */
- gchar *font_size;
- gint font_size_numerical;
- gchar *font;
-
- /* temperature scale for display in panel */
- t_tempscale scale;
-
- /* panel size to compute number of cols/columns */
- gint panel_size;
-
- gint lines_size;
-
- /* panel orientation */
- GtkOrientation orientation;
-
- /* if the bars have been initialized */
- gboolean bars_created;
-
- /* if the tachos have been initialized */
- gboolean tachos_created;
-
- /* show title in panel */
- gboolean show_title;
-
- /* show labels in panel (GUI mode only) */
- gboolean show_labels;
-
- /* show units in textual view */
- gboolean show_units;
-
- /* show small spacings only in textual view */
- gboolean show_smallspacings;
-
- /* show colored bars (GUI mode only) */
- gboolean show_colored_bars;
-
- /* use the progress-bar UI */
- //gboolean display_values_graphically;
- display_t display_values_type;
-
- /* suppress Hddtemp failure messages and any other messages */
- gboolean suppressmessage;
-
- /* sensor update time */
- gint sensors_refresh_time;
-
- /* sensor relevant stuff */
- /* no problem if less than 11 sensors, else will have to enlarge the
- following arrays. NYI!! */
- gint num_sensorchips;
-
- /* gint sensorsCount[SENSORS]; */
-
- /* contains the progress bar panels */
- /* FIXME: Might be replaced by GPtrArray as well */
- GtkWidget* panels[10][256];
- /* GArray *panels_array; */
-
- /* contains the tacho panels */
- /* FIXME: Might be replaced by GPtrArray as well */
- GtkWidget* tachos[10][256];
-
- /* contains structure from libsensors */
- /* const sensors_chip_name *chipName[SENSORS]; */
-
- /* formatted sensor chip names, e.g. 'asb-100-45' */
- /* gchar *sensorId[SENSORS]; */
-
- /* unformatted sensor feature names, e.g. 'Vendor' */
- /* gchar *sensorNames[SENSORS][FEATURES_PER_SENSOR]; */
-
- /* minimum and maximum values (GUI mode only) */
- /* glong sensorMinValues[SENSORS][FEATURES_PER_SENSOR]; */
- /* glong sensorMaxValues[SENSORS][FEATURES_PER_SENSOR]; */
-
- /* unformatted sensor feature values */
- /* double sensorRawValues[SENSORS][FEATURES_PER_SENSOR]; */
-
- /* formatted (%f5.2) sensor feature values */
- /* gchar *sensorValues[SENSORS][FEATURES_PER_SENSOR]; */
-
- /* TRUE if sensorNames are set */
- /* gboolean sensorValid[SENSORS][FEATURES_PER_SENSOR]; */
-
- /* show sensor in panel */
- /* gboolean sensorCheckBoxes[SENSORS][FEATURES_PER_SENSOR]; */
-
- /* sensor types to display values in appropriate format */
- /* sensor_type sensor_types[SENSORS][FEATURES_PER_SENSOR]; */
- GPtrArray *chips;
-
- /* sensor colors in panel */
- /* gchar *sensorColors[SENSORS][FEATURES_PER_SENSOR]; */
-
- /* number in list <--> number in array */
- /* gint sensorAddress[NUM_SENSOR_CHIPS][FEATURES_PER_SENSOR]; */
-
- /* double-click improvement as suggested on xfce4-goodies at berlios.de */
- /* whether to execute command on double click */
- gboolean exec_command;
-
- /* command to excute */
- gchar* command_name;
-
- /* callback_id for doubleclicks */
- gint doubleclick_id;
-
- /* hddtemp disks */
- //GPtrArray *disklist;
- /* gint num_disks; */
-
- /* ACPI thermal zones */
- /*GPtrArray *acpi_zones;
- gint num_acpi_zones; */
-
- gchar *plugin_config_file;
-
- gint preferred_width;
- gint preferred_height;
-}
-t_sensors;
-
/**
* sensor panel widget
@@ -284,11 +117,6 @@ maximum_changed (GtkCellRendererText *cellrenderertext, gchar *path_str,
extern void
temperature_unit_change (GtkWidget *widget, t_sensors_dialog *sd);
-/* Regularly included functions in library */
-t_sensors * sensors_new (XfcePanelPlugin *plugin, gchar * plugin_config_file);
-
-void sensors_init_default_values (t_sensors *sensors, XfcePanelPlugin *plugin);
-
void format_sensor_value (t_tempscale scale, t_chipfeature *chipfeature,
double sensorFeature, gchar **help);
diff --git a/include/sensors-interface-types.h b/include/sensors-interface-types.h
new file mode 100644
index 0000000..a81c690
--- /dev/null
+++ b/include/sensors-interface-types.h
@@ -0,0 +1,28 @@
+#ifndef __SENSORS_INTERFACE_TYPES
+#define __SENSORS_INTERFACE_TYPES
+
+#include <gtk/gtk.h>
+
+/**
+ * compound widget displaying a progressbar and optional label
+ */
+typedef struct {
+ /* the progress bar */
+ GtkWidget *progressbar;
+
+ /* the label */
+ GtkWidget *label;
+
+ /* the surrounding box */
+ GtkWidget *databox;
+} t_barpanel;
+
+
+typedef enum {
+ DISPLAY_TEXT = 1,
+ DISPLAY_BARS,
+ DISPLAY_TACHO
+} display_t;
+
+#endif
+
diff --git a/include/types.h b/include/types.h
index f700901..e1859a2 100644
--- a/include/types.h
+++ b/include/types.h
@@ -60,7 +60,8 @@ typedef enum {
typedef enum {
LMSENSOR,
HDD,
- ACPI
+ ACPI,
+ GPU
} t_chiptype;
/*
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 7daad8a..5578844 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -22,6 +22,11 @@ ACPI_SOURCES = acpi.c
#acpi.h
endif
+if HAVE_NVIDIA
+NVIDIA_SOURCES = nvidia.c
+#nvidia.c
+endif
+
libxfce4sensors_la_SOURCES = \
middlelayer.c \
configuration.c \
@@ -30,7 +35,8 @@ libxfce4sensors_la_SOURCES = \
cpu.c \
$(SENSORS_SOURCES) \
$(HDDTEMP_SOURCES) \
- $(ACPI_SOURCES)
+ $(ACPI_SOURCES) \
+ $(NVIDIA_SOURCES)
# configuration.h \
# sensors-plugin.h \
@@ -44,8 +50,12 @@ libxfce4sensors_la_CFLAGS = \
@GLIB_CFLAGS@ \
@LIBXFCEGUI4_CFLAGS@ \
@LIBXFCE4UTIL_CFLAGS@ \
- @LIBXFCE4PANEL_CFLAGS@ \
- @LIBSENSORS_CFLAGS@
+ @LIBXFCE4PANEL_CFLAGS@ \
+ @LIBSENSORS_CFLAGS@
+
+if HAVE_NVIDIA
+libxfce4sensors_la_CFLAGS += @NVIDIA_CFLAGS@
+endif
if HAVE_LIBNOTIFY
libxfce4sensors_la_CFLAGS += @LIBNOTIFY_CFLAGS@
@@ -76,6 +86,10 @@ libxfce4sensors_la_LIBADD = \
@LIBSENSORS_LDFLAGS@ \
@LIBM@
+if HAVE_NVIDIA
+libxfce4sensors_la_LIBADD += @NVIDIA_LIBS@
+endif
+
if HAVE_LIBNOTIFY
libxfce4sensors_la_LIBADD += @LIBNOTIFY_LIBS@
endif
diff --git a/lib/hddtemp.c b/lib/hddtemp.c
index 9734aa1..4218588 100644
--- a/lib/hddtemp.c
+++ b/lib/hddtemp.c
@@ -75,6 +75,9 @@
# define SINGLE_DELIMITER "|"
#endif
+#define REPLY_MAX_SIZE 512
+
+
/* forward declaration for GCC 4.3 -Wall */
#ifdef HAVE_LIBNOTIFY
void notification_suppress_messages (NotifyNotification *n, gchar *action, gpointer *data);
@@ -199,33 +202,15 @@ void quick_message (gchar *message)
void
read_disks_netcat (t_chip *chip)
{
- char *stdoutput, *stderrput, *cmdline, *tmp, *tmp2, *tmp3;
- gboolean result;
- gint exit_status = 0;
- GError *error = NULL;
+ char reply[REPLY_MAX_SIZE], *tmp, *tmp2, *tmp3;
+ size_t result;
t_chipfeature *cf;
- cmdline = g_strdup_printf ("%s localhost %s", NETCAT_PATH, HDDTEMP_PORT);
- //g_printf("cmdline=%s\n", cmdline);
-
- result = g_spawn_command_line_sync ( (const gchar*) cmdline,
- &stdoutput, &stderrput, &exit_status, &error);
+ result = get_hddtemp_d_str(reply, REPLY_MAX_SIZE);
+ DBG ("reply=%s\n", reply);
- g_free (cmdline);
-
- if (!result)
- {
- g_free (error);
- return;
- }
-
- if (stderrput)
- g_free (stderrput);
-
- //g_printf("stdouput=%s\n", stdoutput);
-
- tmp = str_split (stdoutput, DOUBLE_DELIMITER);
+ tmp = str_split (reply, DOUBLE_DELIMITER);
do {
//g_printf ("Found token: %s\n", tmp);
cf = g_new0(t_chipfeature, 1);
@@ -455,18 +440,73 @@ initialize_hddtemp (GPtrArray *chips, gboolean *suppressmessage)
}
+
+int
+get_hddtemp_d_str (char *buffer, size_t bufsize)
+{
+ int sock;
+ struct sockaddr_in servername;
+ struct hostent *hostinfo;
+ int nbytes = 0, nchunk = 0;
+
+ /* Create the socket. */
+ sock = socket(PF_INET, SOCK_STREAM, 0);
+ if (sock < 0) {
+ return -1;
+ }
+
+ /* Connect to the server. */
+ servername.sin_family = AF_INET;
+ servername.sin_port = htons(HDDTEMP_PORT);
+ hostinfo = gethostbyname("localhost");
+ if (hostinfo == NULL) {
+/* fprintf (stderr, "Unknown host %s.\n", hostname);*/
+ return -1;
+ }
+ servername.sin_addr = *(struct in_addr *) hostinfo->h_addr;
+
+ if (connect (sock, (struct sockaddr *) &servername, sizeof (servername)) < 0) {
+/* perror ("connect (client)");*/
+ return -1;
+ }
+
+ /* Read data from server. */
+ for (;;) {
+ nchunk = read(sock, buffer+nbytes, bufsize-nbytes-1);
+ if (nchunk < 0) {
+ /* Read error. */
+ /* perror ("read");*/
+ close (sock);
+ return -1;
+ } else if (nchunk == 0) {
+ /* End-of-file. */
+ break;
+ } else {
+ /* Data read. */
+ nbytes += nchunk;
+ }
+ }
+
+ buffer[nbytes] = 0;
+ close (sock);
+ return nbytes;
+}
+
+
double
get_hddtemp_value (char* disk, gboolean *suppressmessage)
{
- gchar *standard_output, *standard_error;
- gchar *cmd_line, *msg_text;
+ gchar *standard_output=NULL, *standard_error=NULL;
+ gchar *cmd_line=NULL, *msg_text=NULL;
+ char reply[REPLY_MAX_SIZE];
+ size_t read_size;
#ifndef HAVE_LIBNOTIFY
gchar *checktext = NULL;
#endif
gint exit_status=0;
double value;
- gboolean result, nevershowagain;
- GError *error;
+ gboolean result=FALSE, nevershowagain;
+ GError *error=NULL;
#ifdef HAVE_NETCAT
gchar *tmp, *tmp2, *tmp3;
diff --git a/lib/libxfce4sensors-1.0.pc.in b/lib/libxfce4sensors-1.0.pc.in
index 8be3b1a..74f52e9 100644
--- a/lib/libxfce4sensors-1.0.pc.in
+++ b/lib/libxfce4sensors-1.0.pc.in
@@ -5,6 +5,7 @@ libdir=@libdir@
includedir=@includedir@
libexecdir=@libexecdir@
localedir=@localedir@
+datarootdir=@datarootdir@
Name: libxfce4sensors
Description: Library for the Xfce 4 Sensors Plugin and Viewer
diff --git a/lib/middlelayer.c b/lib/middlelayer.c
index 6595515..baab393 100644
--- a/lib/middlelayer.c
+++ b/lib/middlelayer.c
@@ -51,6 +51,9 @@
#ifdef HAVE_ACPI
#include <acpi.h>
#endif
+#ifdef HAVE_NVIDIA
+ #include <nvidia.h>
+#endif
int
initialize_all (GPtrArray **chips, gboolean *suppressmessage)
@@ -73,6 +76,10 @@ initialize_all (GPtrArray **chips, gboolean *suppressmessage)
res += initialize_ACPI (*chips);
#endif
+ #ifdef HAVE_NVIDIA
+ res += initialize_nvidia (*chips);
+ #endif
+
TRACE ("leaves initialize_all, chips->len=%d", (*chips)->len);
return res;
@@ -111,6 +118,13 @@ refresh_chip (gpointer chip, gpointer data)
}
#endif
+ #ifdef HAVE_NVIDIA
+ if (c->type==GPU) {
+ g_ptr_array_foreach (c->chip_features, refresh_nvidia, NULL);
+ return;
+ }
+ #endif
+
TRACE ("leaves refresh_chip");
}
@@ -205,6 +219,19 @@ sensor_get_value (t_chip *chip, int number, double *value, gboolean *suppressmes
return -1;
#endif
}
+ if (chip->type==GPU ) {
+ #ifdef HAVE_NVIDIA
+ g_assert (number<chip->num_features);
+ feature = (t_chipfeature *) g_ptr_array_index (chip->chip_features, number);
+ g_assert (feature!=NULL);
+ refresh_nvidia ((gpointer) feature, NULL);
+ //*value = get_nvidia_value(feature->address);
+ *value = feature->raw_value;
+ return 0;
+ #else
+ return -1;
+ #endif
+ }
else {
feature = NULL;
return -1;
diff --git a/lib/nvidia.c b/lib/nvidia.c
new file mode 100644
index 0000000..13d3b3e
--- /dev/null
+++ b/lib/nvidia.c
@@ -0,0 +1,182 @@
+/* Copyright (c) 2011 Amir Aupov <fads93 at gmail.com>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/* Package includes */
+#include <X11/Xlib.h>
+#include <NVCtrl/NVCtrl.h>
+#include <NVCtrl/NVCtrlLib.h>
+#include <nvidia.h>
+#include <types.h>
+#include <sensors-interface-common.h>
+#include <middlelayer.h>
+
+/* Gtk/Glib includes */
+#include <glib.h>
+
+/* Global includes */
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdlib.h>
+
+/* Global variables */
+Display *nvidia_sensors_display;
+
+/* Local functions */
+int read_gpus (t_chip *chip);
+
+/* Defines */
+#define ZERO_KELVIN -273
+
+int initialize_nvidia (GPtrArray *chips) {
+ int retval;
+ int num_gpus;
+ t_chip *chip;
+ t_chipfeature *chipfeature;
+
+ TRACE ("enters initialize_nvidia");
+
+ chip = g_new0 (t_chip, 1);
+ //chip -> chip_name = g_strdup(_("nvidia"));
+ chip -> chip_features = g_ptr_array_new ();
+ chip -> num_features = 0;
+ chip -> description = g_strdup(_("NVidia GPU core temperature"));
+ chip -> name = g_strdup(_("nvidia"));
+ chip -> sensorId = g_strdup("nvidia");
+ chip -> type = GPU;
+
+ num_gpus = read_gpus (chip);
+ if (chip -> num_features > 0) {
+ int i;
+ for (i = 0; i < num_gpus; i++) {
+ chipfeature = g_ptr_array_index (chip -> chip_features, i);
+ g_assert (chipfeature != NULL);
+ chipfeature -> address = i;
+ chipfeature -> name = g_strdup(chipfeature -> devicename);
+ chipfeature -> color = g_strdup ("#000000");
+ chipfeature -> valid = TRUE;
+ chipfeature -> formatted_value = g_strdup ("0.0");
+ chipfeature -> raw_value = 0.0;
+ chipfeature -> class = TEMPERATURE;
+ chipfeature -> min_value = 10.0;
+ chipfeature -> max_value = 50.0;
+ chipfeature -> show = FALSE;
+ }
+ g_ptr_array_add (chips, chip);
+ retval = 2;
+ } else retval = 0;
+
+ TRACE ("leaves initialize_nvidia");
+
+ return retval;
+}
+
+double get_nvidia_value (int gpu) {
+ int temp;
+
+ TRACE ("enters get_nvidia_value for %d gpu", gpu);
+
+ if (!(XNVCTRLQueryTargetAttribute (nvidia_sensors_display,
+ NV_CTRL_TARGET_TYPE_GPU,
+ gpu,
+ 0,
+ NV_CTRL_GPU_CORE_TEMPERATURE,
+ &temp))) {
+ TRACE ("NVCtrl doesn't work properly");
+ return ZERO_KELVIN;
+ }
+
+ TRACE ("leaves get_nvidia_value for %d gpu", gpu);
+
+ return 1.d * temp;
+}
+
+void refresh_nvidia (gpointer chip_feature, gpointer data) {
+ t_chipfeature *cf;
+ double value;
+ t_sensors *sensors;
+
+ g_assert (chip_feature != NULL);
+
+ TRACE ("enters refresh_nvidia");
+
+ if (data) sensors = (t_sensors *) data;
+ cf = (t_chipfeature *) chip_feature;
+ value = get_nvidia_value (cf -> address);
+ if (value == ZERO_KELVIN) return;
+
+ g_free (cf -> formatted_value);
+ cf -> formatted_value = g_strdup_printf(_("%ld °C"), value);
+ cf -> raw_value = value;
+
+ TRACE ("leaves refresh_nvidia");
+
+}
+
+int read_gpus (t_chip *chip) {
+ t_chipfeature *chipfeature;
+ int num_gpus;
+ int event, error;
+ int i;
+
+ TRACE ("enters read_gpus");
+
+ /* create the connection to the X server */
+ if (!(nvidia_sensors_display = XOpenDisplay (NULL))) {
+ TRACE ("failed to connect to X server");
+ return 0;
+ }
+
+ /* check if the NVCtrl is available on this X server
+ * if so - add sensors*/
+ if (!(XNVCTRLQueryExtension (nvidia_sensors_display,
+ &event, &error))) {
+ TRACE ("NVCtrl is not available");
+ return 0;
+ }
+
+ if (!(XNVCTRLQueryTargetCount (nvidia_sensors_display,
+ NV_CTRL_TARGET_TYPE_GPU,
+ &num_gpus))) {
+ TRACE ("No NVidia devices found");
+ return 0;
+ }
+
+ for (i = 0; i < num_gpus; i++){
+ gchar *device_name = (gchar*) malloc (100 * sizeof(gchar));
+ if (XNVCTRLQueryTargetStringAttribute (
+ nvidia_sensors_display,
+ NV_CTRL_TARGET_TYPE_GPU,
+ i,
+ 0,
+ NV_CTRL_STRING_PRODUCT_NAME,
+ &device_name))
+ TRACE ("GPU%d:%s", i, device_name);
+ chipfeature = g_new0 (t_chipfeature, 1);
+ chipfeature -> devicename = g_strdup (device_name);
+ chipfeature -> name = g_strdup (device_name);
+ g_ptr_array_add (chip -> chip_features, chipfeature);
+ chip -> num_features++;
+ }
+
+ TRACE ("leaves read_gpus");
+ return num_gpus;
+}
+
diff --git a/panel-plugin/sensors-plugin.c b/panel-plugin/sensors-plugin.c
index 519d0f4..30cb69a 100644
--- a/panel-plugin/sensors-plugin.c
+++ b/panel-plugin/sensors-plugin.c
@@ -46,7 +46,7 @@
/* Package includes */
#include <configuration.h>
#include <sensors-interface.h>
-#include <sensors-interface-common.h>
+#include <sensors-interface-plugin.h> // includes sensors-interface-common.h
#include <middlelayer.h>
#include <cpu.h>
More information about the Xfce4-commits
mailing list