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