]> pilppa.org Git - nws-w1.git/blob - src_client/NetworkServiceClient_W1.cc
7d801be3306d9c794265fbc43e87c82a3c8eed2f
[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
34         dev_lst         = NULL;
35         controller      = new DeviceManagerController();
36         if (controller != NULL) {
37                 dev_lst = controller->get_device_list(&err_flg);
38                 if ((err_flg == PLP_OK) &&
39                      (dev_lst != NULL)) {
40                         for (dev_iter = ((list<Device *> *)dev_lst)->begin(); dev_iter != ((list<Device *> *)dev_lst)->end(); dev_iter++) {
41                                 device  = (Device *)*dev_iter;
42                                 id      = device->get_id();
43                                 device->printout();
44                                 log_info("id: %s\n", id.c_str());
45                                 data    = controller->get_latest_data(id, &err_flg);
46                                 if ((data != NULL) &&
47                                     (err_flg == PLP_OK)) {
48                                         log_info("latest data for device: %s\n", id.c_str());
49                                         data->printout();
50                                         delete(data);
51                                 }
52                                 else {
53                                         log_error("Could not get latest data for device id: %s\n", id.c_str());
54                                 }
55                                 dr      = controller->get_data_range(id, &err_flg);
56                                 if (dr != NULL) {
57                                         data    = dr->get_first();
58                                         if (data != NULL) {
59                                                 log_debug("first data for device: %s\n", id.c_str());
60                                                 data->printout();
61                                                 delete(data);
62                                         }
63                                         data    = dr->get_last();
64                                         if (data != NULL) {
65                                                 log_debug("last data for device: %s\n", id.c_str());
66                                                 data->printout();
67                                                 delete(data);
68                                         }
69                                 }
70                                 delete(dr);
71                         }
72                 }
73                 else {
74                         log_error("Could not get device list, device list NULL or error code returned.\n");
75                 }
76                 //if (dev_lst != NULL)
77                 //      delete(dev_lst);
78                 delete(controller);
79                 sleep(3);
80         }
81         return 0;
82 }