]> pilppa.org Git - nws-w1.git/blob - src_client/NetworkServiceClient_W1.cc
44dcd731154ba0a60bcf6a639a39dc49b6a0ad4e
[nws-w1.git] / src_client / NetworkServiceClient_W1.cc
1 /*
2  * test_client.cc
3  *
4  *  Created on: Jun 9, 2010
5  *      Author: lamikr
6  */
7
8 #include <plp/log.h>
9 #include <plp/retval.h>
10 #include <plp/bus/BusServer.hh>
11 #include <plp/bus/BusClient.hh>
12 #include <plp/bus/BusMessage.hh>
13
14 #include <plp/devicebus/client/ClientListenerImpl.hh>
15 #include <plp/devicebus/client/DeviceManagerClient.hh>
16 #include <plp/devicebus/client/DeviceManagerController.hh>
17
18 using namespace std;
19 using namespace plpbus;
20 using namespace plp;
21 using namespace plpdevicebus;
22
23 int main(int argc, char** argv)
24 {
25         DeviceManagerController         *controller;
26         const list<Device *>            *dev_lst;
27         list<Device *>::iterator        dev_iter;
28         Device                          *device;
29         string                          id;
30         int                             err_flg;
31         Data                            *data;
32         DataRange                       *dr;
33         Date                            sdate;
34         Date                            edate;
35
36         dev_lst         = NULL;
37         controller      = new DeviceManagerController();
38         if (controller != NULL) {
39                 dev_lst = controller->get_device_list(&err_flg);
40                 if ((err_flg == PLP_OK) &&
41                      (dev_lst != NULL)) {
42                         for (dev_iter = ((list<Device *> *)dev_lst)->begin(); dev_iter != ((list<Device *> *)dev_lst)->end(); dev_iter++) {
43                                 device  = (Device *)*dev_iter;
44                                 id      = device->get_id();
45                                 device->printout();
46                                 log_info("id: %s\n", id.c_str());
47                                 data    = controller->get_latest_data(id, &err_flg);
48                                 if ((data != NULL) &&
49                                     (err_flg == PLP_OK)) {
50                                         log_info("latest data for device: %s\n", id.c_str());
51                                         data->printout();
52                                         delete(data);
53                                 }
54                                 else {
55                                         log_error("Could not get latest data for device id: %s\n", id.c_str());
56                                 }
57                                 dr      = controller->get_data_range(id, &err_flg);
58                                 if (dr != NULL) {
59                                         data    = dr->get_first();
60                                         if (data != NULL) {
61                                                 log_debug("first data for device: %s\n", id.c_str());
62                                                 data->printout();
63                                                 delete(data);
64                                         }
65                                         data    = dr->get_last();
66                                         if (data != NULL) {
67                                                 log_debug("last data for device: %s\n", id.c_str());
68                                                 data->printout();
69
70                                                 edate   = data->get_date();
71                                                 delete(data);
72
73                                                 edate.copy(&sdate);
74                                                 edate.day       = edate.day;
75                                                 sdate.day       = sdate.day - 2;
76                                                 DataRange       *dr2;
77
78                                                 log_debug("first date: %s\n", sdate.to_string().c_str());
79                                                 log_debug("last date: %s\n", edate.to_string().c_str());
80                                                 dr2     = controller->get_data(id, &sdate, &edate, &err_flg);
81                                                 dr2->printout();
82                                                 delete(dr2);
83                                         }
84                                         delete(dr);
85                                 }
86                         }
87                 }
88                 else {
89                         log_error("Could not get device list, device list NULL or error code returned.\n");
90                 }
91                 //if (dev_lst != NULL)
92                 //      delete(dev_lst);
93                 delete(controller);
94                 sleep(3);
95         }
96         return 0;
97 }