X-Git-Url: https://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Fserver%2Fserver.c;h=e50984c0672e566c02765d6f1aa14a2b1fc223d4;hb=45c8086f97097df36ba8cd0552f152be80f79b12;hp=83956091ac1ed587cdb31eb704a35eb086ce665c;hpb=e99f993d7ab18a6ea62d876da38c678ece82a599;p=psensor.git diff --git a/src/server/server.c b/src/server/server.c index 8395609..e50984c 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -1,21 +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-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 + */ #include #include #define _(str) gettext(str) @@ -38,11 +38,12 @@ #ifdef HAVE_GTOP #include "sysinfo.h" +#include "cpu.h" #endif #include "psensor_json.h" -#include "plib/url.h" -#include "plib/plib_io.h" +#include "url.h" +#include "p_io.h" #include "server.h" static const char *program_name; @@ -91,15 +92,15 @@ void print_help() puts(""); puts("Options:"); puts(_("\ - -h, --help display this help and exit\n\ - -v, --version display version information and exit")); + -h, --help display this help and exit\n\ + -v, --version display version information and exit")); puts(""); puts(_("\ - -d,--debug run in debug mode\n\ - -p,--port=PORT webserver port\n\ - -w,--wdir=DIR directory containing webserver pages")); + -d,--debug run in debug mode\n\ + -p,--port=PORT webserver port\n\ + -w,--wdir=DIR directory containing webserver pages")); puts(""); @@ -129,8 +130,13 @@ char *get_path(const char *url, const char *www_dir) return res; } +#if MHD_VERSION >= 0x00090200 +static int +file_reader(void *cls, uint64_t pos, char *buf, size_t max) +#else static int file_reader(void *cls, uint64_t pos, char *buf, int max) +#endif { FILE *file = cls; @@ -155,6 +161,8 @@ create_response_api(const char *nurl, } else if (!strcmp(nurl, URL_API_1_0_SYSINFO)) { page = sysinfo_to_json_string(&server_data.psysinfo); + } else if (!strcmp(nurl, URL_API_1_0_CPU_USAGE)) { + page = sensor_to_json_string(server_data.cpu_usage); #endif } else if (!strncmp(nurl, URL_BASE_API_1_0_SENSORS, strlen(URL_BASE_API_1_0_SENSORS)) @@ -351,6 +359,10 @@ int main(int argc, char *argv[]) server_data.sensors = get_all_sensors(600); +#ifdef HAVE_GTOP + server_data.cpu_usage = create_cpu_usage_sensor(600); +#endif + if (!*server_data.sensors) fprintf(stderr, _("ERROR: no sensors detected\n")); @@ -363,15 +375,16 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - printf(_("Web server started on port: %d\n"), port); - printf(_("WWW directory: %s\n"), server_data.www_dir); - printf(_("URL: http://localhost:%d\n"), port); + log_printf(LOG_INFO, _("Web server started on port: %d"), port); + log_printf(LOG_INFO, _("WWW directory: %s"), server_data.www_dir); + log_printf(LOG_INFO, _("URL: http://localhost:%d"), port); while (!server_stop_requested) { pthread_mutex_lock(&mutex); #ifdef HAVE_GTOP sysinfo_update(&server_data.psysinfo); + cpu_usage_sensor_update(server_data.cpu_usage); #endif psensor_list_update_measures(server_data.sensors); @@ -383,11 +396,15 @@ int main(int argc, char *argv[]) /* sanity cleanup for valgrind */ psensor_list_free(server_data.sensors); +#ifdef HAVE_GTOP + psensor_free(server_data.cpu_usage); +#endif free(server_data.www_dir); sensors_cleanup(); #ifdef HAVE_GTOP sysinfo_cleanup(); + cpu_cleanup(); #endif return EXIT_SUCCESS;