sensors protected by pthread mutex instead of g_mutex
[psensor.git] / src / server / server.c
index 90b3796..8ed87e8 100644 (file)
@@ -76,7 +76,7 @@ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
 
 static int server_stop_requested;
 
-void print_version()
+static void print_version()
 {
        printf("psensor-server %s\n", VERSION);
        printf(_("Copyright (C) %s jeanfi@gmail.com\n"
@@ -87,7 +87,7 @@ void print_version()
               "2010-2012");
 }
 
-void print_help()
+static void print_help()
 {
        printf(_("Usage: %s [OPTION]...\n"), program_name);
 
@@ -150,10 +150,8 @@ file_reader(void *cls, uint64_t pos, char *buf, int max)
        return fread(buf, 1, max, file);
 }
 
-struct MHD_Response *
-create_response_api(const char *nurl,
-                   const char *method,
-                   unsigned int *rp_code)
+static struct MHD_Response *
+create_response_api(const char *nurl, const char *method, unsigned int *rp_code)
 {
        struct MHD_Response *resp;
        struct psensor *s;
@@ -199,11 +197,10 @@ create_response_api(const char *nurl,
        return NULL;
 }
 
-struct MHD_Response *
-create_response_file(const char *nurl,
-                    const char *method,
-                    unsigned int *rp_code,
-                    const char *fpath)
+static struct MHD_Response *create_response_file(const char *nurl,
+                                                const char *method,
+                                                unsigned int *rp_code,
+                                                const char *fpath)
 {
        struct stat st;
        int ret;
@@ -238,7 +235,7 @@ create_response_file(const char *nurl,
        return NULL;
 }
 
-struct MHD_Response *
+static struct MHD_Response *
 create_response(const char *nurl, const char *method, unsigned int *rp_code)
 {
        struct MHD_Response *resp = NULL;
@@ -264,14 +261,13 @@ create_response(const char *nurl, const char *method, unsigned int *rp_code)
        }
 }
 
-static int
-cbk_http_request(void *cls,
-                struct MHD_Connection *connection,
-                const char *url,
-                const char *method,
-                const char *version,
-                const char *upload_data,
-                size_t *upload_data_size, void **ptr)
+static int cbk_http_request(void *cls,
+                           struct MHD_Connection *connection,
+                           const char *url,
+                           const char *method,
+                           const char *version,
+                           const char *upload_data,
+                           size_t *upload_data_size, void **ptr)
 {
        static int dummy;
        struct MHD_Response *response;
@@ -313,7 +309,7 @@ cbk_http_request(void *cls,
 int main(int argc, char *argv[])
 {
        struct MHD_Daemon *d;
-       int port, opti, optc, cmdok;
+       int port, opti, optc, cmdok, ret;
        char *log_file, *slog_file;
 
        program_name = argv[0];
@@ -408,8 +404,11 @@ int main(int argc, char *argv[])
        log_info(_("WWW directory: %s"), server_data.www_dir);
        log_info(_("URL: http://localhost:%d"), port);
 
-       if (slog_file)
-               slog_init(slog_file, server_data.sensors);
+       if (slog_file) {
+               ret = slog_activate(slog_file, server_data.sensors, &mutex, 5);
+               if (!ret)
+                       log_err(_("Failed to activate logging of sensors."));
+       }
 
        while (!server_stop_requested) {
                pthread_mutex_lock(&mutex);
@@ -422,8 +421,6 @@ int main(int argc, char *argv[])
 
                psensor_log_measures(server_data.sensors);
 
-               slog_write_sensors(server_data.sensors);
-
                pthread_mutex_unlock(&mutex);
                sleep(5);
        }