]> pilppa.com Git - nws-w1.git/commitdiff
add read interval parameter for nws-w1
authorMika Laitio <lamikr@pilppa.org>
Tue, 24 Jul 2012 01:42:28 +0000 (04:42 +0300)
committerMika Laitio <lamikr@pilppa.org>
Tue, 24 Jul 2012 01:42:28 +0000 (04:42 +0300)
Signed-off-by: Mika Laitio <lamikr@pilppa.org>
src_server/NetworkServiceServer_W1.cc

index 5bebc04ae57531294a77d212daafe85770c56a07..af68ad36028f0dc3a89b65532364c986a884f6f8 100644 (file)
@@ -2,6 +2,8 @@
 #include <list>
 
 #include <string.h>
+#include <errno.h>
+
 #include <plp/log.h>
 #include <plp/bus/BusServer.hh>
 
@@ -17,25 +19,59 @@ using namespace plpbus;
 using namespace plpdevicebus;
 using namespace w1;
 
+#define DEFAULT_READ_INTERVAL_SECONDS  600
+
+bool try_parse_long(const char *str, long *result) {
+       int     new_result;
+       char    *endptr;
+       bool    ret_val;
+
+       ret_val         = false;
+       errno           = 0;
+       new_result      = strtol(str, &endptr, 10);
+       if (errno != 0) {
+               log_error("invalid input %s, could not convert to integer.\n", str);
+       }
+       else {
+               if (endptr == str) {
+                       log_error("invalid input %s, could not convert to integer.\n", str);
+               }
+               else {
+                       *result = new_result;
+                       ret_val = true;
+               }
+       }
+       return ret_val;
+}
+
 int main(int argc, char** argv)
 {
        BusServer               *server;
        ServerListenerImpl      *listener;
        DeviceManagerServer     *dev_man;
        string                  save_loc;
+       long                    read_interval_sec;
        string                  server_name;
        list<Device *>  dev_lst;
 
        server_name     = W1_SERVER_NAME;
-       save_loc        = DeviceConfig::get_base_dir_name();
-       if (argc >= 2) {
+       save_loc        = "/tmp/w1data";
+       read_interval_sec       = DEFAULT_READ_INTERVAL_SECONDS;
+       if (argc > 1) {
                save_loc        = argv[1];
                log_info("storage location: %s\n", save_loc.c_str());
-               DeviceConfig::set_base_dir_name(save_loc);
        }
        else {
-               log_warning("No storage location parameter given, using default location: %s\n", save_loc.c_str());
+               log_info("no parameter given using default values:\n");
+               log_info("\tnws-w1 %s %ld\n\n", save_loc.c_str(), read_interval_sec);
+               log_info("usage:\n\tnws-w1 <result_save_path> <read_interval_seconds>\n");
+       }
+       if (argc > 2) {
+               try_parse_long(argv[2], &read_interval_sec);
        }
+       log_info("device polling interval: %ld seconds\n", read_interval_sec);
+       DeviceConfig::set_base_dir_name(save_loc);
+       DeviceConfig::set_read_interval_seconds(read_interval_sec);
        log_info("starting server: %s\n", server_name.c_str());
        dev_lst         = Factory::get_device_list();
        server          = new BusServer();