tizen 2.3.1 release
[external/buxton.git] / demo / hellocreategroup.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 create_cb(BuxtonResponse response, void *data)
36 {
37         if (buxton_response_status(response) != 0) {
38                 printf("Failed to create group\n");
39         } else {
40                 printf("Created group\n");
41         }
42 }
43
44 int main(void)
45 {
46         BuxtonClient client;
47         BuxtonKey key;
48         struct pollfd pfd[1];
49         int r;
50         int fd;
51
52         if ((fd = buxton_open(&client)) < 0) {
53                 printf("couldn't connect\n");
54                 return -1;
55         }
56
57         key = buxton_key_create("hello", NULL, "user", STRING);
58         if (!key) {
59                 return -1;
60         }
61
62         if (buxton_create_group(client, key, create_cb,
63                                 NULL, false)) {
64                 printf("create group call failed to run\n");
65                 return -1;
66         }
67
68         pfd[0].fd = fd;
69         pfd[0].events = POLLIN;
70         pfd[0].revents = 0;
71         r = poll(pfd, 1, 5000);
72
73         if (r <= 0) {
74                 printf("poll error\n");
75                 return -1;
76         }
77
78         if (!buxton_client_handle_response(client)) {
79                 printf("bad response from daemon\n");
80                 return -1;
81         }
82
83         buxton_key_free(key);
84         buxton_close(client);
85         return 0;
86 }
87
88 /*
89  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
90  *
91  * Local variables:
92  * c-basic-offset: 8
93  * tab-width: 8
94  * indent-tabs-mode: t
95  * End:
96  *
97  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
98  * :indentSize=8:tabSize=8:noTabs=false:
99  */