]> pilppa.org Git - nws-w1.git/blob - src_client/NetworkServiceClient_W1.cc
memory leak fixes
[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
33         dev_lst         = NULL;
34         controller      = new DeviceManagerController();
35         if (controller != NULL) {
36                 dev_lst = controller->get_device_list(&err_flg);
37                 if ((err_flg == PLP_OK) &&
38                      (dev_lst != NULL)) {
39                         for (dev_iter = ((list<Device *> *)dev_lst)->begin(); dev_iter != ((list<Device *> *)dev_lst)->end(); dev_iter++) {
40                                 device  = (Device *)*dev_iter;
41                                 id      = device->get_id();
42                                 device->printout();
43                                 log_info("id: %s\n", id.c_str());
44                                 data    = controller->get_latest_data(id, &err_flg);
45                                 if ((data != NULL) &&
46                                     (err_flg == PLP_OK)) {
47                                         log_info("latest data:\n");
48                                         data->printout();
49                                         delete(data);
50                                 }
51                                 else {
52                                         log_error("Could not get latest data for device id: %s\n", id.c_str());
53                                 }
54                         }
55                 }
56                 else {
57                         log_error("Could not get device list, device list NULL or error code returned.\n");
58                 }
59                 //if (dev_lst != NULL)
60                 //      delete(dev_lst);
61                 delete(controller);
62                 sleep(3);
63         }
64         return 0;
65 }