X-Git-Url: https://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fnvidia.c;h=5b2bdea3974a4940d85c50535feb9428c852a56e;hb=b01d095d6b123bcc7ed221cccf2c04295834cc84;hp=a8060c3601cec50c112c6edcbca63545e36db9a6;hpb=06a780020823612636aff82034336588cc0f7a7a;p=psensor.git diff --git a/src/lib/nvidia.c b/src/lib/nvidia.c index a8060c3..5b2bdea 100644 --- a/src/lib/nvidia.c +++ b/src/lib/nvidia.c @@ -1,22 +1,21 @@ /* - Copyright (C) 2010-2011 jeanfi@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., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - + * Copyright (C) 2010-2012 jeanfi@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., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ #include #include #define _(str) gettext(str) @@ -52,7 +51,7 @@ static int get_temp(struct psensor *sensor) if (res == True) return temp; - fprintf(stderr, _("ERROR: failed to retrieve nvidia temperature\n")); + log_err(_("Failed to retrieve NVIDIA temperature.")); return 0; } @@ -67,8 +66,11 @@ static struct psensor *create_sensor(int id, int values_len) sid = malloc(strlen("nvidia") + 1 + strlen(name) + 1); sprintf(sid, "nvidia %s", name); - s = psensor_create(sid, strdup(name), - SENSOR_TYPE_NVIDIA, values_len); + s = psensor_create(sid, + strdup(name), + strdup("Nvidia GPU"), + SENSOR_TYPE_NVIDIA_TEMP, + values_len); s->nvidia_id = id; @@ -88,8 +90,7 @@ static int init() display = XOpenDisplay(NULL); if (!display) { - fprintf(stderr, - _("ERROR: Cannot open connection to X Server\n")); + log_err(_("Cannot open connection to X11 server.")); return 0; } @@ -97,7 +98,7 @@ static int init() XNVCTRLQueryTargetCount(display, NV_CTRL_TARGET_TYPE_GPU, &n)) return n; - fprintf(stderr, _("ERROR: Cannot retrieve NVidia information\n")); + log_err(_("Failed to retrieve NVIDIA information.")); return 0; } @@ -110,15 +111,15 @@ void nvidia_psensor_list_update(struct psensor **sensors) while (*ss) { s = *ss; - if (s->type == SENSOR_TYPE_NVIDIA) + if (s->type == SENSOR_TYPE_NVIDIA_TEMP) psensor_set_current_value(s, get_temp(s)); ss++; } } -struct psensor * * -nvidia_psensor_list_add(struct psensor **sensors, int values_len) +struct psensor **nvidia_psensor_list_add(struct psensor **sensors, + int values_len) { int i, n; struct psensor **tmp, **ss, *s; @@ -139,3 +140,11 @@ nvidia_psensor_list_add(struct psensor **sensors, int values_len) return ss; } + +void nvidia_cleanup() +{ + if (display) { + XCloseDisplay(display); + display = NULL; + } +}