tizen 2.3 release
[external/buxton.git] / demo / helloset.c
1 /*
2  * This file is part of buxton.
3  *
4  * Copyright (C) 2013 Intel Corporation
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  */
26
27 #define _GNU_SOURCE
28 #include <poll.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include "buxton.h"
34
35 void set_cb(BuxtonResponse response, void *data)
36 {
37         BuxtonKey key;
38         char *name;
39
40         if (buxton_response_status(response) != 0) {
41                 printf("Failed to set value\n");
42                 return;
43         }
44
45         key = buxton_response_key(response);
46         name = buxton_key_get_name(key);
47         printf("Set value for key %s\n", name);
48         buxton_key_free(key);
49         free(name);
50 }
51
52 int main(void)
53 {
54         BuxtonClient client;
55         BuxtonKey key;
56         struct pollfd pfd[1];
57         int r;
58         int fd;
59         int32_t set;
60
61         if ((fd = buxton_open(&client)) < 0) {
62                 printf("couldn't connect\n");
63                 return -1;
64         }
65
66         key = buxton_key_create("hello", "test", "user", INT32);
67         if (!key) {
68                 return -1;
69         }
70
71         set = 10;
72
73         if (buxton_set_value(client, key, &set, set_cb,
74                              NULL, false)) {
75                 printf("set call failed to run\n");
76                 return -1;
77         }
78
79         pfd[0].fd = fd;
80         pfd[0].events = POLLIN;
81         pfd[0].revents = 0;
82         r = poll(pfd, 1, 5000);
83
84         if (r <= 0) {
85                 printf("poll error\n");
86                 return -1;
87         }
88
89         if (!buxton_client_handle_response(client)) {
90                 printf("bad response from daemon\n");
91                 return -1;
92         }
93
94         buxton_key_free(key);
95         buxton_close(client);
96         return 0;
97 }
98
99 /*
100  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
101  *
102  * Local variables:
103  * c-basic-offset: 8
104  * tab-width: 8
105  * indent-tabs-mode: t
106  * End:
107  *
108  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
109  * :indentSize=8:tabSize=8:noTabs=false:
110  */