From f82b303f7c2a7475b6807d87e42d1ea660caa878 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Wed, 25 Apr 2012 10:25:22 +0000 Subject: [PATCH] move sensors list creation to a separate fct --- src/main.c | 58 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/src/main.c b/src/main.c index c42f18e..9bec3f3 100644 --- a/src/main.c +++ b/src/main.c @@ -432,6 +432,42 @@ static void cleanup(struct ui_psensor *ui) log_close(); } +/* + * Creates the list of sensors. + * + * 'url': remote psensor server url, null for local monitoring. + * 'use_libatasmart': whether the libatasmart must be used. + */ +static struct psensor **create_sensors_list(const char *url, + unsigned int use_libatasmart) +{ + struct psensor **sensors; + + if (url) { +#ifdef HAVE_REMOTE_SUPPORT + rsensor_init(); + sensors = get_remote_sensors(url, 600); +#else + fprintf(stderr, + _("ERROR: Not compiled with remote sensor support.\n")); + exit(EXIT_FAILURE); +#endif + } else { + sensors = get_all_sensors(use_libatasmart, 600); +#ifdef HAVE_NVIDIA + sensors = nvidia_psensor_list_add(sensors, 600); +#endif +#ifdef HAVE_LIBATIADL + sensors = amd_psensor_list_add(sensors, 600); +#endif +#ifdef HAVE_GTOP + sensors = cpu_psensor_list_add(sensors, 600); +#endif + } + + return sensors; +} + int main(int argc, char **argv) { struct ui_psensor ui; @@ -521,27 +557,7 @@ int main(int argc, char **argv) psensor_init(); - if (url) { -#ifdef HAVE_REMOTE_SUPPORT - rsensor_init(); - ui.sensors = get_remote_sensors(url, 600); -#else - fprintf(stderr, - _("ERROR: Not compiled with remote sensor support.\n")); - exit(EXIT_FAILURE); -#endif - } else { - ui.sensors = get_all_sensors(use_libatasmart, 600); -#ifdef HAVE_NVIDIA - ui.sensors = nvidia_psensor_list_add(ui.sensors, 600); -#endif -#ifdef HAVE_LIBATIADL - ui.sensors = amd_psensor_list_add(ui.sensors, 600); -#endif -#ifdef HAVE_GTOP - ui.sensors = cpu_psensor_list_add(ui.sensors, 600); -#endif - } + ui.sensors = create_sensors_list(url, use_libatasmart); associate_preferences(ui.sensors); associate_colors(ui.sensors); -- 2.7.4