tizen 2.3 release
[external/buxton.git] / demo / hellosetlabel.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_label_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 label\n");
42                 return;
43         }
44
45         key = buxton_response_key(response);
46         name = buxton_key_get_name(key);
47         printf("Set label 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         char* label = "label-test";
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         if (buxton_set_label(client, key, label, set_label_cb,
72                              NULL, false)) {
73                 printf("set label call failed to run\n");
74                 return -1;
75         }
76
77         pfd[0].fd = fd;
78         pfd[0].events = POLLIN;
79         pfd[0].revents = 0;
80         r = poll(pfd, 1, 5000);
81
82         if (r <= 0) {
83                 printf("poll error\n");
84                 return -1;
85         }
86
87         if (!buxton_client_handle_response(client)) {
88                 printf("bad response from daemon\n");
89                 return -1;
90         }
91
92         buxton_key_free(key);
93         buxton_close(client);
94         return 0;
95 }
96
97 /*
98  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
99  *
100  * Local variables:
101  * c-basic-offset: 8
102  * tab-width: 8
103  * indent-tabs-mode: t
104  * End:
105  *
106  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
107  * :indentSize=8:tabSize=8:noTabs=false:
108  */