]> pilppa.com Git - nws-w1.git/commitdiff
fixed the latest data return for device list method
authorMika Laitio <lamikr@pilppa.org>
Sun, 12 Aug 2012 22:48:32 +0000 (01:48 +0300)
committerMika Laitio <lamikr@pilppa.org>
Sun, 12 Aug 2012 22:48:32 +0000 (01:48 +0300)
Signed-off-by: Mika Laitio <lamikr@pilppa.org>
src_client/NetworkServiceClient_W1.cc
src_server/NetworkServiceServer_W1.cc

index 3d5687d6d180243960f99a4fe29653942ad3a918..bed3a989e78d8c120369c389795bb825c2990a4b 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include <plp/log.h>
+#include <plp/retval.h>
 #include <plp/bus/BusServer.hh>
 #include <plp/bus/BusClient.hh>
 #include <plp/bus/BusMessage.hh>
@@ -26,17 +27,25 @@ int main(int argc, char** argv)
        list<Device *>::iterator        dev_iter;
        Device                          *device;
        string                          id;
+       int                             err_flg;
 
        controller      = new DeviceManagerController();
        if (controller != NULL) {
-               dev_lst = controller->get_device_list();
-               if (dev_lst != NULL) {
-                       for (dev_iter = ((list<Device *> *)dev_lst)->begin(); dev_iter != ((list<Device *> *)dev_lst)->end(); dev_iter++) {
-                               device  = (Device *)*dev_iter;
-                               id      = device->get_id();
-                               log_debug("device id: %s\n", id.c_str());
-                               //dev_man->send_request__get_latest_data(client, id);
+               dev_lst = controller->get_device_list(&err_flg);
+               if (err_flg == PLP_OK) {
+                       if (dev_lst != NULL) {
+                               for (dev_iter = ((list<Device *> *)dev_lst)->begin(); dev_iter != ((list<Device *> *)dev_lst)->end(); dev_iter++) {
+                                       device  = (Device *)*dev_iter;
+                                       id      = device->get_id();
+                                       device->printout();
+                               }
                        }
+                       else {
+                               log_error("Could not get device list, device list NULL");
+                       }
+               }
+               else {
+                       log_error("Could not get device list, error code: %d", err_flg);
                }
                delete(controller);
                sleep(3);
index af68ad36028f0dc3a89b65532364c986a884f6f8..3e8802243bacebe3e8fb4cb66db65779c68b0ee3 100644 (file)
@@ -5,6 +5,7 @@
 #include <errno.h>
 
 #include <plp/log.h>
+#include <plp/str_util.h>
 #include <plp/bus/BusServer.hh>
 
 #include <w1/Factory.hh>
@@ -19,29 +20,10 @@ using namespace plpbus;
 using namespace plpdevicebus;
 using namespace w1;
 
-#define DEFAULT_READ_INTERVAL_SECONDS  600
+#define DEFAULT_READ_INTERVAL_SEC      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;
+void printout_usage() {
+       log_info("usage:\n\tnws-w1 <save_path for results> <read_interval_in seconds>\n");
 }
 
 int main(int argc, char** argv)
@@ -50,28 +32,34 @@ int main(int argc, char** argv)
        ServerListenerImpl      *listener;
        DeviceManagerServer     *dev_man;
        string                  save_loc;
-       long                    read_interval_sec;
+       long                    interval_sec;
        string                  server_name;
-       list<Device *>  dev_lst;
+       list<Device *>          dev_lst;
+       bool                    succ;
 
        server_name     = W1_SERVER_NAME;
        save_loc        = "/tmp/w1data";
-       read_interval_sec       = DEFAULT_READ_INTERVAL_SECONDS;
+       interval_sec    = DEFAULT_READ_INTERVAL_SEC;
        if (argc > 1) {
                save_loc        = argv[1];
                log_info("storage location: %s\n", save_loc.c_str());
        }
        else {
                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");
+               log_info("\tnws-w1 %s %ld\n\n", save_loc.c_str(), interval_sec);
+               printout_usage();
        }
        if (argc > 2) {
-               try_parse_long(argv[2], &read_interval_sec);
+               succ    = parse_long(argv[2], &interval_sec);
+               if (succ == false) {
+                       interval_sec    = DEFAULT_READ_INTERVAL_SEC;
+                       log_error("failed to parse read interval parameter, using default value: %ld", interval_sec);
+                       printout_usage();
+               }
        }
-       log_info("device polling interval: %ld seconds\n", read_interval_sec);
+       log_info("device polling interval: %ld seconds\n", interval_sec);
        DeviceConfig::set_base_dir_name(save_loc);
-       DeviceConfig::set_read_interval_seconds(read_interval_sec);
+       DeviceConfig::set_read_interval_seconds(interval_sec);
        log_info("starting server: %s\n", server_name.c_str());
        dev_lst         = Factory::get_device_list();
        server          = new BusServer();