projects
/
psensor.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixed restoration of the panel divider position.
[psensor.git]
/
src
/
lib
/
hdd_hddtemp.c
diff --git
a/src/lib/hdd_hddtemp.c
b/src/lib/hdd_hddtemp.c
index
1013c59
..
68797e1
100644
(file)
--- a/
src/lib/hdd_hddtemp.c
+++ b/
src/lib/hdd_hddtemp.c
@@
-1,5
+1,5
@@
/*
/*
- * Copyright (C) 2010-201
2
jeanfi@gmail.com
+ * Copyright (C) 2010-201
4
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
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@
-16,14
+16,15
@@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
+
+/* Part of the code in this file is based on GNOME sensors applet code
+ * hddtemp-plugin.c see http://sensors-applet.sourceforge.net/
+ */
+
#include <locale.h>
#include <libintl.h>
#define _(str) gettext(str)
#include <locale.h>
#include <libintl.h>
#define _(str) gettext(str)
-/*
- * Following code is based on GNOME sensors applet code
- * hddtemp-plugin.c see http://sensors-applet.sourceforge.net/
- */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@
-33,30
+34,32
@@
#include <arpa/inet.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <unistd.h>
-#include "hdd.h"
-#include "psensor.h"
+#include <hdd.h>
+#include <psensor.h>
+
+static const char *PROVIDER_NAME = "hddtemp";
-#define HDDTEMP_SERVER_IP_ADDRESS "127.0.0.1"
-#define HDDTEMP_PORT_NUMBER 7634
-#define HDDTEMP_OUTPUT_BUFFER_LENGTH 4048
+static const char *HDDTEMP_SERVER_IP_ADDRESS = "127.0.0.1";
+static const int HDDTEMP_PORT_NUMBER = 7634;
+static const int HDDTEMP_OUTPUT_BUFFER_LENGTH = 4048;
struct hdd_info {
char *name;
int temp;
};
struct hdd_info {
char *name;
int temp;
};
-static char *fetch()
+static char *fetch(
void
)
{
{
- int sockfd;
+ int sockfd
, output_length
;
ssize_t n = 1;
ssize_t n = 1;
- int output_length = 0;
- char *pc;
- char *buffer;
+ char *pc, *buffer;
struct sockaddr_in address;
struct sockaddr_in address;
+ output_length = 0;
+
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
- log_err(_("
hddtemp: failed to open socket.")
);
+ log_err(_("
%s: failed to open socket."), PROVIDER_NAME
);
return NULL;
}
return NULL;
}
@@
-69,7
+72,7
@@
static char *fetch()
if (connect(sockfd,
(struct sockaddr *)&address,
(socklen_t) sizeof(address)) == -1) {
if (connect(sockfd,
(struct sockaddr *)&address,
(socklen_t) sizeof(address)) == -1) {
- log_err(_("
hddtemp: failed to open connection.")
);
+ log_err(_("
%s: failed to open connection."), PROVIDER_NAME
);
} else {
buffer = malloc(HDDTEMP_OUTPUT_BUFFER_LENGTH);
} else {
buffer = malloc(HDDTEMP_OUTPUT_BUFFER_LENGTH);
@@
-115,7
+118,12
@@
static int str_index(char *str, char d)
static struct psensor *
create_sensor(char *id, char *name, int values_max_length)
{
static struct psensor *
create_sensor(char *id, char *name, int values_max_length)
{
- return psensor_create(id, name, SENSOR_TYPE_HDD_TEMP_HDDTEMP,
+ int t;
+
+ t = SENSOR_TYPE_HDD | SENSOR_TYPE_HDDTEMP | SENSOR_TYPE_TEMP;
+
+ return psensor_create(id, name, strdup(_("Disk")),
+ t,
values_max_length);
}
values_max_length);
}
@@
-166,77
+174,89
@@
static char *next_hdd_info(char *string, struct hdd_info *info)
return c;
}
return c;
}
-struct psensor **hddtemp_psensor_list_add(struct psensor **sensors,
-
int values_max_length)
+void
+
hddtemp_psensor_list_append(struct psensor ***sensors,
int values_max_length)
{
{
- char *hddtemp_output = fetch();
- char *c;
+ char *hddtemp_output, *c, *id;
struct hdd_info info;
struct hdd_info info;
- struct psensor **result;
+ struct psensor *sensor;
+
+ hddtemp_output = fetch();
if (!hddtemp_output)
if (!hddtemp_output)
- return
sensors
;
+ return;
if (hddtemp_output[0] != '|') {
if (hddtemp_output[0] != '|') {
- log_err(_("hddtemp: wrong string: %s."), hddtemp_output);
+ log_err(_("%s: wrong string: %s."),
+ PROVIDER_NAME,
+ hddtemp_output);
free(hddtemp_output);
free(hddtemp_output);
- return
sensors
;
+ return;
}
c = hddtemp_output;
}
c = hddtemp_output;
- result = sensors;
-
while (c && (c = next_hdd_info(c, &info))) {
while (c && (c = next_hdd_info(c, &info))) {
- struct psensor *sensor;
- struct psensor **tmp_sensors;
-
- char *id = malloc(strlen("hdd ") + strlen(info.name) + 1);
- strcpy(id, "hdd ");
- strcat(id, info.name);
+ id = malloc(strlen(PROVIDER_NAME) + 1 + strlen(info.name) + 1);
+ sprintf(id, "%s %s", PROVIDER_NAME, info.name);
sensor = create_sensor(id, info.name, values_max_length);
sensor = create_sensor(id, info.name, values_max_length);
- tmp_sensors = psensor_list_add(result, sensor);
-
- if (result != sensors)
- free(result);
-
- result = tmp_sensors;
+ psensor_list_append(sensors, sensor);
}
free(hddtemp_output);
}
free(hddtemp_output);
-
- return result;
}
static void update(struct psensor **sensors, struct hdd_info *info)
{
}
static void update(struct psensor **sensors, struct hdd_info *info)
{
- struct psensor **sensor_cur = sensors;
+ while (*sensors) {
+ if (!((*sensors)->type & SENSOR_TYPE_REMOTE)
+ && (*sensors)->type & SENSOR_TYPE_HDDTEMP
+ && !strcmp((*sensors)->id + 8, info->name))
+ psensor_set_current_value(*sensors,
+ (double)info->temp);
+
+ sensors++;
+ }
+}
- while (*sensor_cur) {
- if ((*sensor_cur)->type == SENSOR_TYPE_HDD_TEMP_HDDTEMP
- && !strcmp((*sensor_cur)->id + 4, info->name))
- psensor_set_current_value(*sensor_cur,
- (float)info->temp);
+static bool contains_hddtemp_sensor(struct psensor **sensors)
+{
+ struct psensor *s;
- sensor_cur++;
+ if (!sensors)
+ return false;
+
+ while (*sensors) {
+ s = *sensors;
+ if (!(s->type & SENSOR_TYPE_REMOTE)
+ && (s->type & SENSOR_TYPE_HDDTEMP))
+ return true;
+ sensors++;
}
}
+
+ return false;
}
void hddtemp_psensor_list_update(struct psensor **sensors)
{
}
void hddtemp_psensor_list_update(struct psensor **sensors)
{
- char *hddtemp_output = fetch();
+ char *hddtemp_output;
+
+ if (!contains_hddtemp_sensor(sensors))
+ return;
+
+ hddtemp_output = fetch();
if (!hddtemp_output)
return;
if (hddtemp_output[0] == '|') {
if (!hddtemp_output)
return;
if (hddtemp_output[0] == '|') {
-
char *c = hddtemp_output;
struct hdd_info info;
char *c = hddtemp_output;
struct hdd_info info;
+
info.name = NULL;
info.temp = 0;
info.name = NULL;
info.temp = 0;
@@
-247,7
+267,9
@@
void hddtemp_psensor_list_update(struct psensor **sensors)
free(info.name);
}
} else {
free(info.name);
}
} else {
- log_err(_("hddtemp: wrong string: %s."), hddtemp_output);
+ log_err(_("%s: wrong string: %s."),
+ PROVIDER_NAME,
+ hddtemp_output);
}
free(hddtemp_output);
}
free(hddtemp_output);